Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native 从抽屉导航器导航到特定选项卡_React Native_React Navigation - Fatal编程技术网

React native 从抽屉导航器导航到特定选项卡

React native 从抽屉导航器导航到特定选项卡,react-native,react-navigation,React Native,React Navigation,是否可以将选项卡导航器嵌套在抽屉导航器中,然后从抽屉导航到特定选项卡 考虑这一非常基本的设置: const PrimaryNav = createBottomTabNavigator({ ScreenOne, ScreenTwo }) export const DrawerNavigator = createDrawerNavigator({ Home: { screen: PrimaryNav, drawerLabel: 'Option 1', }, I

是否可以将选项卡导航器嵌套在抽屉导航器中,然后从抽屉导航到特定选项卡

考虑这一非常基本的设置:

const PrimaryNav = createBottomTabNavigator({
  ScreenOne,
  ScreenTwo
 })

export const DrawerNavigator = createDrawerNavigator({
  Home: {
    screen: PrimaryNav,
    drawerLabel: 'Option 1',
  },
  Investment: {
    screen: PrimaryNav,
    drawerLabel: 'Option 2',
  }
})
显然,无论单击哪个选项,此设置都将解析为TabNav中的第一项


是否有一种方法可以传递一个选项来专门导航到这些选项卡中的每一个?我知道只需将ScreenOne和ScreenTwo传递到DroperNavigator中的“screen”选项是可能的,但我希望保留这些选项卡。

在react navigation GitHub问题页面中有一个棘手的解决方法:

navigation.dispatch(
    NavigationActions.reset({
      index: 0,
      actions: [NavigationActions.navigate({ routeName: 'PrimaryNav' })]
    })
);
navigation.navigate('ScreenTwo'))

这不是最好的解决方案,但却是我遇到同样问题时唯一能找到的解决方案。

2020:通过嵌套导航器导航

onPress={() => {
  navigation.navigate('Root', {
  screen: 'Screen'
});

此解决方案是否适用于从react navigator项进行导航?抽屉中的物品在哪里可以安装onClick处理程序?@connor我认为应该安装。你在用什么样的抽屉?我认为您可以通过对大多数RN组件使用prop
onPress
来处理点击。类似这样的内容:
this.goToScreenTwo()}>注销
并将上面的代码放在组件类中单独的
goToScreenTwo()
方法中。感谢您帮助我找到解决方案。我没有看到有一个
contentComponent
属性可以传递给
createDrawerNavigator
来创建我自己的自定义组件。很高兴知道这一点!:)有没有其他方法可以做到这一点,如果可能的话,我宁愿不必通过redux跟踪导航?是的,确实节省了我的时间:)