关于反应导航v5的问题。
在以前的版本中,我们可以通过在StackNavigator
中执行以下操作来指定特定路由的自定义过渡,非屏幕。
transitionConfig: () => ({ screenInterpolator: sceneProps => { const {scenes, scene} = sceneProps; const prevRoute = scenes[0].route.routeName === 'Route A'; // If prev route is A, and then current route is B, then we do a specific transition if (prevRoute && scene.route.routeName === 'Route B') { return StackViewStyleInterpolator.forVertical(sceneProps); } // Otherwise default to normal transition return StackViewStyleInterpolator.forHorizontal(sceneProps); }, }),
现在,我正在尝试为react-navigation v5实现相同的功能。我知道我可以通过执行以下操作来为每个屏幕指定自定义动画:
<Stack.Screen name="Route B" component={RouteB} options={{ cardStyleInterpolator: CardStyleInterpolators.forVerticalIOS }} />
问题是,我不希望每次导航到
RouteB
时都应用此过渡,仅当上一条路线为RouteA
时,我才希望应用此过渡,就像上面的上一个代码块一样。
在文档中找不到任何示例,因此,希望能为将代码迁移到v5提供一些帮助。
关于反应导航v5的问题。在以前的版本中,我们可以通过在StackNavigator中执行以下操作来指定特定路径(而不是屏幕)的自定义转换:...
类似这样的方法应该起作用: