Say I\'ve navigated through 4 screens in my StackNavigator App and now I want to go back to the first screen. There seems to be three different ways to do this and they do n
For 2020 / react-navigation-stack I use the following code when setting up the StackNavigator:
import { createStackNavigator, CardStyleInterpolators } from 'react-navigation-stack';
import { Easing } from 'react-native';
const Navigator = createStackNavigator({
// ...
}, {
defaultNavigationOptions: ({ navigation }) => {
const animation = navigation.getParam('_animation');
return {
// ...
cardStyleInterpolator: CardStyleInterpolators.forHorizontalIOS,
...(animation === 'back' && {
gestureDirection: 'horizontal-inverted',
}),
...(animation === 'skip' && {
transitionSpec: {
open: { animation: 'timing', config: { duration: 0, easing: Easing.step1 }, },
close: { animation: 'timing', config: { duration: 0, easing: Easing.step0 }, },
},
}),
};
},
});
and the the _animation param to override the animation style
// replace to a route not in the stack normally creates a forward animation, but
// we want a backwards animation
this.props.navigation.dispatch(
StackActions.replace({ routeName: 'Login', params: { _animation: 'back' } })
);