如何在不从 tabnavigator 的选项卡之一导航到屏幕的情况下打开抽屉?

IT技术 reactjs react-native react-redux react-navigation
2021-05-12 23:46:42

我正在尝试从一个名为 profile 的选项卡打开抽屉,如下所示。当我单击配置文件选项卡时,它会从 ProfileNavigator 中打开主屏幕。哪个是对的,但我想防止这种情况发生,只在没有默认导航的情况下打开抽屉。我该怎么做?ProfileNavigator 还阻止打开我的下一个选项卡,即主页,知道为什么吗?但是我可以选择 Histroy 屏幕的选项卡,然后可以返回主屏幕。

const ProfileNavigator = createDrawerNavigator({
  Home: {
    screen: HomeScreen,
  },
  Notifications: {
    screen: ExampleScreen,
  }
});

const DashboardTabNav = createBottomTabNavigator({
  Profile: {
    screen: ProfileNavigator,
    navigationOptions: ({navigation}) => ({
      tabBarOnPress: (tab) => {
        navigation.openDrawer();
      }
    })
  },
  Home: Dashboard,
  History: SettingsScreen,
  Cart: CartScreen
})
1个回答

啊,修好了。如果有人在寻找示例,您需要在 createBottomTabNavigator 中添加 createDrawerNavigator。我是反过来做的。例如,

const ProfileNavigator = createDrawerNavigator({
  Drawer: DashboardTabNav
}, {
  initialRouteName: 'Drawer',
  contentComponent: ExampleScreen,
  drawerWidth: 300

});

// Manifest of possible screens
const PrimaryNav = createStackNavigator({
  DashboardScreen: { screen: ProfileNavigator },
  LoginScreen: { screen: LoginScreen },
  LaunchScreen: { screen: LaunchScreen },
  UpdateUserScreen: { screen: UpdateUserScreen }
}, {
  // Default config for all screens
  headerMode: 'none',
  initialRouteName: 'LoginScreen',
  navigationOptions: {
    headerStyle: styles.header
  }
});
export default createAppContainer(PrimaryNav);