问题
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