reactjs - 在 react 导航 v5.x 中隐藏内部屏幕的底部导航

标签 reactjs react-native react-navigation react-navigation-v5

我正在升级 React Native,我正在做一个项目。所以,我想在内部屏幕上隐藏底部导航,例如

- Dashboard
--- home <- hide bottom navigation
--- moment <- hide bottom navigation
--- period <- hide bottom navigation
--- contact <- hide bottom navigation
- Calendar
- Notification
- User

我尝试在仪表板屏幕选项上使用 tabBarVisible: false,但它隐藏了仪表板屏幕而不是内部屏幕上的底部导航。请问在内部屏幕上隐藏底部导航的最佳方法是什么?

这是我的导航代码:

底部导航

const BottomNavigation = () => (
  <Tab.Navigator tabBar={props => <MyTabBar {...props} />}>
    <Tab.Screen
      name={ScreenName.dashboard}
      options={{tabBarLabel: 'Dashboard'}}
      component={HomeNavigation}
    />
    <Tab.Screen
      name={ScreenName.calendar}
      options={{
        tabBarLabel: 'Calendar',
      }}
      component={Calendar}
    />
    <Tab.Screen
      name={ScreenName.notification}
      options={{
        tabBarLabel: 'Notification',
      }}
      component={Notification}
    />
    <Tab.Screen
      name={ScreenName.user}
      options={{
        tabBarLabel: 'User',
      }}
      component={User}
    />
  </Tab.Navigator>
);

首页导航

const HomeNavigation = () => (
  <Stack.Navigator
    screenOptions={{
      title: null,
      headerStyle: {elevation: 0, shadowOpacity: 0},
    }}>
    <Stack.Screen
      name={ScreenName.home}
      component={Home}
      options={() => ({
        headerShown: false,
      })}
    />
    <Stack.Screen name={ScreenName.moment} component={Moment} />
    <Stack.Screen name={ScreenName.period} component={Period} />
    <Stack.Screen name={ScreenName.contact} component={Contact} />
  </Stack.Navigator>
);

最佳答案

您应该将底部选项卡导航器放在堆栈导航器的第一个屏幕中,而不是相反:

- Home
--- Dashboard
--- Calendar
--- Notification
--- User
- Moment
- Period
- Contact

这样,当您推送一个新屏幕时,它将位于底部标签栏上方,标签栏将不可见。

https://reactnavigation.org/docs/en/nesting-navigators.html#parent-navigators-ui-is-rendered-on-top-of-child-navigator

关于reactjs - 在 react 导航 v5.x 中隐藏内部屏幕的底部导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60320330/

相关文章:

react-native - useFocusEffect 不更新 setstate

reactjs - 这是避免 "Did you accidentally call a React Hook after an early return?"的安全方法吗

javascript - 为什么 Jest 不会运行? "TypeError: environment.setup is not a function"

ios - 运行 pod install : Invalid attribute name 时出错

javascript - 找到 JWT 后如何导航一次?

javascript - 嵌套 TabNavigator 未渲染?

javascript - 滚动时使 div 高度增大和缩小(React)

javascript - 如何解决 Component should be written as a pure function error in eslint-react?

javascript - 如何修复 "... is not a function"错误?

css - react 原生 :"order"不是有效的样式属性