React Navigation 5从堆栈导航器隐藏标签栏

Leng Long

我想知道如何从嵌套在材料底部标签栏上的堆栈导航器中的特定屏幕隐藏底部标签栏

这是我的堆栈导航器的代码

import React from 'react';
import { createStackNavigator } from '@react-navigation/stack';
import PondScreen from '../screens/PondScreen/PondScreen';
import PondDetailScreen from '../screens/PondScreen/PondDetailScreen';

const Stack = createStackNavigator();

export function PondStack() {
  return (
    <Stack.Navigator
      initialRouteName="PondScreen"
      headerMode="none"
      mode="card"
    >
      <Stack.Screen
        name="PondScreen"
        component={PondScreen}
      />
      <Stack.Screen
        name="PondDetailScreen"
        component={PondDetailScreen}
        options={{
          tabBarVisible: false
        }}
      />
    </Stack.Navigator>
  );
}

这是我的材料底部标签导航器的代码

import React from 'react';
import { View } from 'react-native';
import { createMaterialBottomTabNavigator } from '@react-navigation/material-bottom-tabs';
import { Entypo, Feather } from '@expo/vector-icons';
import { PondStack } from './StackNavigators';
import StockScreen from '../screens/StockScreen';
import OrderScreen from '../screens/OrderScreen';
import SettingsScreen from '../screens/SettingsScreen';

const Tab = createMaterialBottomTabNavigator();

export default function BottomTab() {
  return (
    <Tab.Navigator
      labeled={false}
      initialRouteName="Pond"
      activeColor="#EB3349"
      inactiveColor="#888888"
      backBehavior="none"
      shifting={true}
      barStyle={{
        backgroundColor: '#FFFFFF'
      }}
    >
      <Tab.Screen
        name="Pond"
        component={PondStack}
        options={{
          tabBarIcon: ({ color}) => (
            <View style={{ flex: 1 }}>
              <Entypo name="air" color={color} size={20} />
            </View>
          )
        }}
      />
      <Tab.Screen
        name="Stock"
        component={StockScreen}
        options={{
          tabBarIcon: ({ color }) => (
            <View style={{ flex: 1 }}>
              <Feather name="box" color={color} size={20} />
            </View>
          )
        }}
      />
      <Tab.Screen
        name="Order"
        component={OrderScreen}
        options={{
          tabBarIcon: ({ color}) => (
            <View style={{ flex: 1 }}>
              <Feather name="dollar-sign" color={color} size={20} />
            </View>
          )
        }}
      />
      <Tab.Screen
        name="Settings"
        component={SettingsScreen}
        options={{
          tabBarIcon: ({ color}) => (
            <View style={{ flex: 1 }}>
              <Feather name="settings" color={color} size={20} />
            </View>
          )
        }}
      />
    </Tab.Navigator>
  )
}

我目前正在使用Expo构建我的项目。

我的依赖项(package.json)

{
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web",
    "eject": "expo eject"
  },
  "dependencies": {
    "@react-native-community/masked-view": "^0.1.5",
    "@react-navigation/material-bottom-tabs": "^5.0.0",
    "@react-navigation/native": "^5.0.0",
    "@react-navigation/stack": "^5.0.0",
    "@types/react-native": "^0.61.12",
    "expo": "~36.0.0",
    "react": "~16.9.0",
    "react-dom": "~16.9.0",
    "react-native": "https://github.com/expo/react-native/archive/sdk-36.0.0.tar.gz",
    "react-native-gesture-handler": "~1.5.0",
    "react-native-paper": "^3.6.0",
    "react-native-raw-bottom-sheet": "^2.0.6",
    "react-native-reanimated": "~1.4.0",
    "react-native-safe-area-context": "0.6.0",
    "react-native-screens": "2.0.0-alpha.12",
    "react-native-vector-icons": "^6.6.0",
    "react-native-web": "~0.11.7"
  },
  "devDependencies": {
    "@babel/core": "^7.0.0",
    "babel-preset-expo": "~8.0.0"
  },
  "private": true
}
艾米

我的标签导航与父标签几乎一样的问题,而与孩子的堆栈导航几乎没有问题,因此无法重新排列屏幕层。因此,我寻找了另一个解决方案,并且从文档中发现,父级导航UI始终显示在子级上。但是该文档还提供了一个很好的示例,说明了如何在子级中更改父级标头。因此,我以该示例为例,以实现标签栏的可见性。这就是我的实现方式。

因此,我有一个带有“主页”,“联系人”和“更多”的标签栏导航,并且在每个标签内都有一个堆栈。我隐藏选项卡的屏幕在CameraView中,而该屏幕是“更多”选项卡中的堆栈屏幕。

  • 联络人
  • 更多
    • 个人资料
    • CameraView(在这里我要隐藏标签栏)

导航:

如您所见,我从一种方法中获得了标签栏的可见性。

<NavigationContainer>
  <Tab.Navigator>
    <Tab.Screen name="Home" component={HomeNavigation} />
    <Tab.Screen name="Contacts" component={ContactNavigation} />
    <Tab.Screen
      name="More"
      component={MoreNavigation}
      options={({ route }) => ({
        tabBarVisible: this.getTabBarVisibility(route)
      })}
    />
  </Tab.Navigator>
</NavigationContainer>

方法getTabBarVisibility:

这是我检查路线名称是否为我在StackNavigation中定义的CameraView的地方。

getTabBarVisibility = (route) => {
  const routeName = route.state
    ? route.state.routes[route.state.index].name
    : '';

  if (routeName === 'CameraView') {
    return false;
  }

  return true;
}

和组件MoreNavigation:

这是我对“更多”的堆栈导航,您可以在其中看到屏幕名称为CameraView。

<Stack.Navigator initialRouteName="More">
  <Stack.Screen name="More" component={More}/>
  <Stack.Screen name="UserProfile" component={Profile}/>
  <Stack.Screen name="CameraView" component={CameraView}/>
</Stack.Navigator>

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

将参数传递给标签导航器React Navigation 5

来自分类Dev

在与EXPO正常工作之后,React Navigation v5堆栈导航器停止工作

来自分类Dev

如何在react-navigation v5中从单个屏幕隐藏堆栈导航标题

来自分类Dev

如何在React Native Navigation V5的标签栏中隐藏标签?

来自分类Dev

react-navigation的标签导航器特定标签按钮上的自定义导航操作

来自分类Dev

React Navigation v.5标签栏图标导航至模式

来自分类Dev

React Navigation V5隐藏Stack Navigator中的Bottom标签栏

来自分类Dev

在React Navigation 5中导航到另一个导航器中的屏幕

来自分类Dev

在React Navigation 5.0中导航嵌套导航器

来自分类Dev

自定义标签栏React Navigation 5

来自分类Dev

在React Native v.5中离开某个屏幕时,如何隐藏底部的标签导航器?

来自分类Dev

React Navigation 5将参数传递给嵌套导航器中的屏幕

来自分类Dev

React Navigation 5,将屏幕移动到其他导航器

来自分类Dev

如何重置嵌套导航器(react-navigation v5)

来自分类Dev

如何在React Navigation中使用NavigationService重置导航器?

来自分类Dev

使用嵌套导航器与 react-navigation 和 redux 集成

来自分类Dev

React Native-导航器和标签栏集成

来自分类Dev

React创建堆栈导航器

来自分类Dev

React Navigation 5-如何从headerRight导航?

来自分类Dev

React Navigation 5隐藏抽屉项

来自分类Dev

React Navigation:在组件外部导航

来自分类Dev

如果React Native中React Navigation库提供的堆栈导航器组件的initialRouteName属性不存在,会发生什么情况

来自分类Dev

如何使用React Navigation v.5中的DrawerItemList在抽屉式导航器中传递自定义按钮?

来自分类Dev

在React Native Navigation中的标签中隐藏标签

来自分类Dev

在React Navigation v5.x中隐藏内部屏幕的底部导航

来自分类Dev

参数未传递且createStackNavigator中的导航器不可用-React Navigation

来自分类Dev

React Navigation如何传递到Tab导航器表单登录屏幕?

来自分类Dev

如何在 react-native-navigation 中向导航器添加背景图像

来自分类Dev

React-Navigation(Android)导航错误

Related 相关文章

  1. 1

    将参数传递给标签导航器React Navigation 5

  2. 2

    在与EXPO正常工作之后,React Navigation v5堆栈导航器停止工作

  3. 3

    如何在react-navigation v5中从单个屏幕隐藏堆栈导航标题

  4. 4

    如何在React Native Navigation V5的标签栏中隐藏标签?

  5. 5

    react-navigation的标签导航器特定标签按钮上的自定义导航操作

  6. 6

    React Navigation v.5标签栏图标导航至模式

  7. 7

    React Navigation V5隐藏Stack Navigator中的Bottom标签栏

  8. 8

    在React Navigation 5中导航到另一个导航器中的屏幕

  9. 9

    在React Navigation 5.0中导航嵌套导航器

  10. 10

    自定义标签栏React Navigation 5

  11. 11

    在React Native v.5中离开某个屏幕时,如何隐藏底部的标签导航器?

  12. 12

    React Navigation 5将参数传递给嵌套导航器中的屏幕

  13. 13

    React Navigation 5,将屏幕移动到其他导航器

  14. 14

    如何重置嵌套导航器(react-navigation v5)

  15. 15

    如何在React Navigation中使用NavigationService重置导航器?

  16. 16

    使用嵌套导航器与 react-navigation 和 redux 集成

  17. 17

    React Native-导航器和标签栏集成

  18. 18

    React创建堆栈导航器

  19. 19

    React Navigation 5-如何从headerRight导航?

  20. 20

    React Navigation 5隐藏抽屉项

  21. 21

    React Navigation:在组件外部导航

  22. 22

    如果React Native中React Navigation库提供的堆栈导航器组件的initialRouteName属性不存在,会发生什么情况

  23. 23

    如何使用React Navigation v.5中的DrawerItemList在抽屉式导航器中传递自定义按钮?

  24. 24

    在React Native Navigation中的标签中隐藏标签

  25. 25

    在React Navigation v5.x中隐藏内部屏幕的底部导航

  26. 26

    参数未传递且createStackNavigator中的导航器不可用-React Navigation

  27. 27

    React Navigation如何传递到Tab导航器表单登录屏幕?

  28. 28

    如何在 react-native-navigation 中向导航器添加背景图像

  29. 29

    React-Navigation(Android)导航错误

热门标签

归档