问题
Is it possible to nest a Tab Navigator inside of a Drawer Navigator and then navigate to a specific tab from the Drawer?
Consider this very basic set up:
const PrimaryNav = createBottomTabNavigator({
ScreenOne,
ScreenTwo
})
export const DrawerNavigator = createDrawerNavigator({
Home: {
screen: PrimaryNav,
drawerLabel: 'Option 1',
},
Investment: {
screen: PrimaryNav,
drawerLabel: 'Option 2',
}
})
Obviously, this set up will just resolve to the first item in the TabNav regardless of which option you click.
Is there a way to pass an option to navigate to each of those tabs specifically? I know it would be possible to just pass ScreenOne and ScreenTwo to the "screen" options in DrawerNavigator, but I would like to retain the tabs.
回答1:
There's a hacky workaround mentioned in react-navigation GitHub issues page:
navigation.dispatch(
NavigationActions.reset({
index: 0,
actions: [NavigationActions.navigate({ routeName: 'PrimaryNav' })]
})
);
navigation.navigate('ScreenTwo'))
Not the best solution, but the only thing I could find when I faced the same problem.
来源:https://stackoverflow.com/questions/52748594/navigate-to-specific-tab-from-drawer-navigator