forked from kiwicom/margarita
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
97 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,83 +7,61 @@ import Phone from './Phone'; | |
import Config from '../config'; | ||
|
||
type Props = {| | ||
+scroll: number, | ||
+featuresHeight: number, | ||
+featuresTopPosition: number, | ||
+featuresRef: ?Element, | ||
+isFixed: boolean, | ||
+scrolledOnFeature: ?number, | ||
|}; | ||
|
||
const { | ||
bookingScreen, | ||
mmbScreen, | ||
paymentsScreen, | ||
searchScreen, | ||
} = Config.featuresOrderIndexes; | ||
|
||
const defaultScreenShot = { | ||
src: '/static/screens/search.jpg', | ||
srcSet: | ||
'/static/screens/search.jpg 1x,/static/screens/[email protected] 2x, /static/screens/[email protected] 3x', | ||
}; | ||
const images = [ | ||
{ | ||
|
||
const images = { | ||
[paymentsScreen]: { | ||
src: '/static/screens/payments.jpg', | ||
srcSet: | ||
'/static/screens/payments.jpg 1x,/static/screens/[email protected] 2x, /static/screens/[email protected] 3x', | ||
}, | ||
{ | ||
[mmbScreen]: { | ||
src: '/static/screens/mmb.jpg', | ||
srcSet: | ||
'/static/screens/mmb.jpg 1x,/static/screens/[email protected] 2x, /static/screens/[email protected] 3x', | ||
}, | ||
{ | ||
[bookingScreen]: { | ||
src: '/static/screens/booking.jpg', | ||
srcSet: | ||
'/static/screens/booking.jpg 1x,/static/screens/[email protected] 2x, /static/screens/[email protected] 3x', | ||
}, | ||
{ | ||
[searchScreen]: { | ||
src: '/static/screens/results.jpg', | ||
srcSet: | ||
'/static/screens/results.jpg 1x,/static/screens/[email protected] 2x, /static/screens/[email protected] 3x', | ||
}, | ||
]; | ||
|
||
const buffer = 150; | ||
}; | ||
|
||
const getProperScreenShot = imageIndex => { | ||
if (imageIndex >= 0 || !imageIndex) { | ||
if (imageIndex < images.length) { | ||
if (!imageIndex || imageIndex >= 0) { | ||
if (imageIndex != null && imageIndex < Object.keys(images).length) { | ||
return images[imageIndex]; | ||
} | ||
return defaultScreenShot; | ||
} | ||
return images[0]; | ||
}; | ||
|
||
export default function FloatedPhone({ | ||
scroll, | ||
featuresHeight, | ||
featuresTopPosition, | ||
featuresRef, | ||
}: Props) { | ||
const isDimensionsDataKnown = | ||
featuresHeight !== 0 && featuresTopPosition !== 0; | ||
const imageIndex = isDimensionsDataKnown | ||
? Math.floor( | ||
(featuresTopPosition + | ||
featuresHeight - | ||
scroll - | ||
Config.phoneHeight - | ||
Config.featuresMarginBottom + | ||
buffer) / | ||
Config.featureHeight, | ||
) | ||
: images.length; | ||
const isFixed = | ||
featuresTopPosition === 0 || | ||
featuresHeight === 0 || | ||
scroll < | ||
featuresTopPosition + | ||
featuresHeight - | ||
Config.phoneHeight - | ||
Config.phoneTopMargin; | ||
const properScreenShot = getProperScreenShot(imageIndex); | ||
export default function FloatedPhone({ isFixed, scrolledOnFeature }: Props) { | ||
const properScreenShot = getProperScreenShot(scrolledOnFeature); | ||
return ( | ||
<PhoneImageWrapper isFixed={isFixed}> | ||
{featuresRef !== null && <Phone {...properScreenShot} />} | ||
<Phone {...properScreenShot} /> | ||
</PhoneImageWrapper> | ||
); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.