简体   繁体   English

React Native-Tab Navigator内Drawer Navigator内的Stack Navigator

[英]React Native - Stack Navigator inside Drawer Navigator inside Tab Navigator

I have some troubles while mixing different navigators. 混合使用不同的导航器时遇到一些麻烦。 Here is my navigator file : 这是我的导航器文件:

const DrawerNav = DrawerNavigator({
    Screen1: { screen: Screen1 },
    Screen2: { screen: Screen2 },
})

const TabNav = TabNavigator({
    Drawers: { screen: DrawerNav },
    Params: { screen: Params },
    Search: { screen: Search },
},
{
    tabBarPosition: 'bottom',
});

export default StackNavigator({
    Home: { screen: TabNav },
}, stackNavigatorConfig);

The problems are when I open the Drawer Navigator : 问题是当我打开抽屉导航器时:

  • The first tab lose the tabBarIcon and the tabBarLabel configuration from the "Drawers" container (which is set in Screen1). 第一个选项卡丢失了“抽屉”容器(在Screen1中设置)的tabBarIcon和tabBarLabel配置。 The icon disappear, and the label becomes "Drawers" (the Name in the TabNavigator declaration) instead of the original tabBarLabel value set in the 图标消失,标签变为“抽屉”(TabNavigator声明中的名称),而不是在标签中设置的原始tabBarLabel值。
  • The Header of the Stack Navigator is still visible above the Drawer, and lose the style I have set in the Screen1 navigationOptions. 在抽屉上方仍然可以看到Stack Navigator的Header,并且失去了我在Screen1 navigationOptions中设置的样式。 (for this one, I can eventually remove the Stack Navigator and create my own header, its was just faster to use the Stack Navigator) (为此,我最终可以删除Stack Navigator并创建自己的标头,使用Stack Navigator的速度更快)

Here is two images with the different states (drawer closed / opened) : 这是两个具有不同状态(抽屉关闭/打开)的图像:

抽屉关闭

抽屉打开

I don't quite understand why you are using a drawer inside a tab. 我不太明白为什么您要在标签内使用抽屉。

In order to be able to navigate through all the app the drawer must be included in the stack: 为了能够浏览所有应用程序,抽屉必须包含在堆栈中:

const TabNav = TabNavigator({
        Params: { screen: Params },
        Search: { screen: Search },
    },
    {
        tabBarPosition: 'bottom',
    }
);

const DrawerNav = DrawerNavigator({
    Screen1: { screen: Screen1 },
    Screen2: { screen: Screen2 },
    TabNav: { screen: TabNav },
})

export default StackNavigator({
    Home: { screen: TabNav },
    DrawerNav: { screen: DrawerNav }
}, stackNavigatorConfig);

In the other hand, if what you are looking for is to fire the drawer through a click on that tab, you need to hack the tab from the source, or fire a function when that empty screen render that make a call to: 另一方面,如果您要查找的是通过单击该选项卡来触发抽屉,则需要从源中破解该选项卡,或者在该空白屏幕呈现时调用以下功能来触发函数:

this.props.navigation.navigate('DrawerOpen'); // open drawer
this.props.navigation.navigate('DrawerClose'); // close drawer
this.props.navigation.navigate('DrawerToggle'); // fires 'DrawerOpen'/'DrawerClose' accordingly

I hope that help.. 希望有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 堆导航器在React Native中的抽屉导航器内部不起作用 - Stack navigator not working inside drawer navigator in react native 是否有可能在 react-native 的抽屉导航器中嵌套选项卡导航器? - Is there a possibility of nesting tab navigator inside a drawer navigator in react-native? 反应导航 - 反应原生 - 如何阻止嵌套在抽屉导航器内的堆栈导航器中的抽屉? - React navigation - react native - How to block drawer in Stack Navigator nested inside Drawer Navigator? 在本机反应中使用抽屉导航器和堆栈导航器 - using drawer navigator and stack navigator in react native React Native 中的嵌套堆栈导航器和抽屉导航器 - Nested Stack Navigator and Drawer Navigator in React Native 在 react native 中将堆栈导航器与抽屉导航器结合使用 - Combining a stack navigator with a drawer navigator in react native 抽屉导航器嵌套在堆栈导航器中 - Drawer navigator nested inside stack navigator 抽屉导航器内的堆栈导航器出现错误 - Stack Navigator inside Drawer Navigator is giving error React-native - 选项卡导航器嵌套在抽屉内 - React-native - tab navigator nested inside drawer 如何通过单个导航文件在Tab Navigator的Stack Navigator中包含Drawer Navigator - How to include Drawer Navigator inside Stack Navigator inside Tab Navigator with a single navigation file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM