Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Navigation 5.x navigation transition animation based on param

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,
        }}
      />
like image 449
Kasra Avatar asked Mar 02 '23 05:03

Kasra


1 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
});
like image 113
Martin F. Avatar answered Mar 05 '23 16:03

Martin F.