React Navigation 5.x navigation transition animation based on param

Viewed 5312

Is it possible to enable/disable the navigation transition animation based on a specifically passed param?

navigation.navigate('SomeScreen', {
          data: someData,
          withAnimation: true,
        });

In the example above, the withAnimation param is set to true, so I want the animation (forRevealFromBottomAndroid) set here to be active:

<Stack.Screen
        name="SomeScreen"
        component={SomeScreen}
        options={{
          headerLeft: null,
          headerShown: false,
          cardStyleInterpolator:
            CardStyleInterpolators.forRevealFromBottomAndroid,
        }}
      />
2 Answers

Yes it's possible. You can achieve it this way:

In your navigator:

<Stack.Screen
        name="SomeScreen"
        component={SomeScreen}
        options={({route: {params}}) => ({
          headerLeft: null,
          headerShown: false,
          cardStyleInterpolator: params?.withAnimation
              ? CardStyleInterpolators.forHorizontalIOS
              : CardStyleInterpolators.forNoAnimation,
        })}
/>

Where you navigate:

navigation.navigate('SomeScreen', {
    data: someData,
    withAnimation: true
});

Yes, you can do this way:

let animation = false;
cardStyleInterpolator: animation ? CardStyleInterpolators.forNoAnimation : CardStyleInterpolators.forHorizontalIOS
Related