how to open drawer without navigating to the screen from one of the tabs of tabnavigator?

自作多情 提交于 2019-12-11 17:18:13

问题


I am trying to open up the drawer from one my tab called profile as shown in below. When I click on the profile tab it opens up the HomeScreen from ProfileNavigator. Which is right, but I wanna prevent that and only open the drawer with out a default navigation. How do I do it? Also ProfileNavigator is preventing to open my next tab which is Home, any idea why? But I am able to tab of Histroy screen then can come back to Home screen.

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:


Ahh, fixed it. Incase someone looking for an example, You need to add the createDrawerNavigator inside the createBottomTabNavigator. I was doing it the otherway. For example,

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);


来源:https://stackoverflow.com/questions/54580896/how-to-open-drawer-without-navigating-to-the-screen-from-one-of-the-tabs-of-tabn

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