在版本 4 中,我在 contentComponent 中使用 DrawerItems onItemPress 重置了 StackNavigation:
const AppDrawerNavigator = createDrawerNavigator(
{
Stack1: {
screen: Stack1,
navigationOptions: { // options}
},
Stack2: {
screen: Stack2,
navigationOptions: { // options}
},
{
initialRouteName: 'Stack1',
contentOptions: {
activeTintColor: '#346bc7',
},
contentComponent: props => {
return (
<ScrollView>
<SafeAreaView forceInset={{ top: 'always', horizontal: 'never' }} >
<DrawerItems {...props} onItemPress={router => {
const navigateAction = NavigationActions.navigate({
routeName: router.route.routeName,
params: {},
action: NavigationActions.navigate({ routeName: router.route.routes[0].routeName }),
});
props.navigation.dispatch(navigateAction);
}}
/>
</SafeAreaView>
</ScrollView>
)
}
},
);
React Navigation 5 有一个全新的 API,所以我的旧重置代码不起作用。如何在 DrawerNavigator v.5 中执行此操作?