【问题标题】:React Native Navigation Sidebar and TabBar toggled navigationReact Native Navigation Sidebar 和 TabBar 切换导航
【发布时间】:2020-12-09 01:33:47
【问题描述】:

我想在侧边栏和标签导航之间切换。我拥有它,因此它当前根据屏幕大小在选项卡和侧边栏之间切换,但是由于它们是单独的导航器,它会重置导航堆栈。当我更改导航器时,有什么方法可以保留导航堆栈?

如果有办法让 Drawer 和 TabBar 导航器同时具有相同的屏幕,那也可以解决我的问题。

  <Stack.Navigator
      screenOptions={{ headerShown: false }}
      mode="modal"
      initialRouteName="WalkthroughScreen"
    >
      {deviceSize(layout.width) > 0 ||
      (layout.width < 50 && Platform.OS === 'web') ? (
        <Stack.Screen name="Root" component={DrawerNavigator} />
      ) : (
        <Stack.Screen name="Root" component={BottomTabNavigator} />
      )}

【问题讨论】:

  • 您找到适合您需要的东西了吗?我正在寻找类似的东西。根据我们是否处于桌面模式,显示抽屉导航器,如果是移动模式,则显示底部选项卡导航器。
  • @EstebanChornet 查看我刚刚发布的答案,如果您需要更多信息,请告诉我。

标签: react-navigation react-native-navigation react-navigation-v5


【解决方案1】:

我最终做的只是为移动应用程序使用底部导航,为网络和移动网络使用抽屉导航。所以我的代码如下所示:

      {Platform.OS === 'web' ? (
        <Stack.Screen name="Root" component={DrawerNavigator} />
      ) : (
        <Stack.Screen name="Root" component={BottomTabNavigator} />
      )}

之所以如此,而不是其他方式是因为它只使用平台,因此导航器没有理由切换中间进程。所以我决定放弃标签,使用移动网络的汉堡菜单,带有侧边抽屉和大屏幕上的永久侧边抽屉。

所以在我的抽屉导航器&lt;DrawerNavigation.Navigator&gt; 我这样设置drawerType

      drawerType={deviceSize(layout.screenWidth) === 0 ? 'front' : 'permanent'}

【讨论】:

  • 感谢您的回答!仅供参考,我最终决定使用 react-native 中的 useWindowDimensions(),如果是 width &gt;= 960px,则显示抽屉导航器,否则显示底部选项卡。在 iPad 上,纵向模式是选项卡,横向模式是抽屉。
  • @EstebanChornet 的问题是,如果有人调整浏览器的大小,导航将被重置,他们将失去位置
猜你喜欢
  • 2020-06-07
  • 1970-01-01
  • 2021-05-29
  • 2020-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多