如何在不从 tabnavigator 的选项卡之一导航到屏幕的情况下打开抽屉? [英] how to open drawer without navigating to the screen from one of the tabs of tabnavigator?

查看:42
本文介绍了如何在不从 tabnavigator 的选项卡之一导航到屏幕的情况下打开抽屉?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

推荐答案

啊,解决了.如果有人在寻找一个例子,您需要在 createBottomTabNavigator 中添加 createDrawerNavigator.我是反其道而行之.例如,

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

这篇关于如何在不从 tabnavigator 的选项卡之一导航到屏幕的情况下打开抽屉?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆