Navigate to specific tab from Drawer Navigator

為{幸葍}努か 提交于 2020-01-15 04:01:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!