Skip to content

Instantly share code, notes, and snippets.

@jasmo2
Last active July 18, 2019 11:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasmo2/ff4364f4d00d8e8f28beda6f510d4ef1 to your computer and use it in GitHub Desktop.
Save jasmo2/ff4364f4d00d8e8f28beda6f510d4ef1 to your computer and use it in GitHub Desktop.
/*
* At this point the method receive and object
* which has duration as well as percentageRange
* that will be in charge of pushing the outgoing
* screen
*/
export function fromRight({ duration = 300, percentageRange = 0 }) {
return {
transitionSpec: {
duration,
easing: customCurve,
timing: Animated.timing,
useNativeDriver: true,
},
screenInterpolator: ({ layout, position, scene }) => {
const { index } = scene
const { initWidth } = layout
// Here the caculation base on the screen is been made.
const finalWidth = -initWidth * percentageRange
const translateX = position.interpolate({
inputRange: [index - 1, index, index + 1],
outputRange: [initWidth, 0, finalWidth],
})
const opacity = position.interpolate({
inputRange: [index - 1, index - 0.99, index],
outputRange: [0, 1, 1],
})
return { opacity, transform: [{ translateX }] }
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment