React-native-router-flux: Example of custom scene transition

Created on 15 Feb 2017  路  3Comments  路  Source: aksonov/react-native-router-flux

Version

Tell us which versions you are using:

  • react-native-router-flux v3.?.?
  • react-native v0.?.?

Is there any example or source code showing how to implement animationStyle function for scene transition ?

Most helpful comment

Below is code I pretty much had to figure out by myself by reading the source code so it might not be the best example but it's better than nothing.

The documentation for this project could use a lot of work.

<Scene 
  key="pageThree"
  component={PageThree}
  animationStyle={animate}
  applyAnimation={applyAnimation} />

const animate = props => {
  const { position, scene } = props;
  const SCREEN_WIDTH = Dimensions.get("window").width;

  const index = scene.index;
  const inputRange = [ index - 1, index + 1 ];
  const outputRange = [ SCREEN_WIDTH, -SCREEN_WIDTH ];

  const translateX = position.interpolate({ inputRange, outputRange });
  return { transform: [ { translateX } ] };
}

const applyAnimation = (pos, navState) => {
  Animated.spring(pos, { toValue: navState.index, friction: 5 }).start();
};

All 3 comments

Below is code I pretty much had to figure out by myself by reading the source code so it might not be the best example but it's better than nothing.

The documentation for this project could use a lot of work.

<Scene 
  key="pageThree"
  component={PageThree}
  animationStyle={animate}
  applyAnimation={applyAnimation} />

const animate = props => {
  const { position, scene } = props;
  const SCREEN_WIDTH = Dimensions.get("window").width;

  const index = scene.index;
  const inputRange = [ index - 1, index + 1 ];
  const outputRange = [ SCREEN_WIDTH, -SCREEN_WIDTH ];

  const translateX = position.interpolate({ inputRange, outputRange });
  return { transform: [ { translateX } ] };
}

const applyAnimation = (pos, navState) => {
  Animated.spring(pos, { toValue: navState.index, friction: 5 }).start();
};

Thanks a lot!!!

+1 @andrew-d-jackson This was a great help in getting rid of some nav jank...Still supporting a v3 app 馃槩

Was this page helpful?
0 / 5 - 0 ratings

Related issues

xnog picture xnog  路  3Comments

jgibbons picture jgibbons  路  3Comments

wootwoot1234 picture wootwoot1234  路  3Comments

basdvries picture basdvries  路  3Comments

sreejithr picture sreejithr  路  3Comments