如何从特定屏幕中删除标签栏?

how to remove tab bar from a particular screen?

我创建了一个带有 4 个选项卡导航器屏幕的导航器 -> 主页、搜索、上传和库;我有堆栈导航屏幕,如注册、登录、主页选项卡和视频。 现在,我想从上传屏幕中删除底部的标签栏,但不确定是否可行?

下面是我编写的确切代码:

import React from 'react';
import 'react-native-gesture-handler';
import {StatusBar} from 'react-native';
import {NavigationContainer, DarkTheme} from '@react-navigation/native';
import {createStackNavigator} from '@react-navigation/stack';
import {createMaterialBottomTabNavigator} from '@react-navigation/material-bottom-tabs';
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialIcons';

import Home from '../screens/Home';
import Search from '../screens/Search';
import Library from '../screens/Library';
import ProfileAuthor from '../screens/ProffileAuthor';
import Shoot from '../screens/Shoot';
import LoginScreen from '../screens/LoginScreen';
import SignUp from '../screens/SignUp';

const Stack = createStackNavigator();
const Tab = createMaterialBottomTabNavigator();

function myTabs() {
  return (
    <Tab.Navigator
      initialRouteName="Home"
      activeColor="#000"
      inactiveColor="#000"
      barStyle={{
        backgroundColor: '#FFF',
      }}>
      <Tab.Screen
        name="Home"
        component={Home}
        options={{
          title: 'Home',
          tabBarLabel: 'Home',
          tabBarIcon: ({color}) => (
            <MaterialCommunityIcons color={color} name="home" size={26} />
          ),
        }}
      />
      <Tab.Screen
        name="Search"
        component={Search}
        options={{
          title: 'Search',
          tabBarLabel: 'Search',
          tabBarIcon: ({color}) => (
            <MaterialCommunityIcons color={color} name="search" size={26} />
          ),
        }}
      />
      <Tab.Screen
        name="Upload"
        component={Shoot}
        options={{
          title: 'Upload',
          tabBarLabel: 'Upload',
          tabBarIcon: ({color}) => (
            <MaterialCommunityIcons color={color} name="add-box" size={26} />
          ),
        }}
      />
      <Tab.Screen
        name="Library"
        component={Library}
        options={{
          title: 'Library',
          tabBarLabel: 'Library',
          tabBarIcon: ({color}) => (
            <MaterialCommunityIcons
              color={color}
              name="person-outline"
              size={26}
            />
          ),
        }}
      />
    </Tab.Navigator>
  );
}

const Routes = () => {
  return (
    <NavigationContainer theme={DarkTheme}>
      <Stack.Navigator>
        <Stack.Screen
          name="login"
          component={LoginScreen}
          options={{
            header: () => null,
          }}
        />
        <Stack.Screen
          name="signup"
          component={SignUp}
          options={{
            header: () => null,
          }}
        />
        <Stack.Screen
          name="Home"
          component={myTabs}
          options={{
            header: () => null,
          }}
        />
        
        <Stack.Screen
          name="Video"
          component={ProfileAuthor}
          options={{
            header: () => null,
          }}
        />
      </Stack.Navigator>
    </NavigationContainer>
  );
};

export default Routes;

谁能告诉我在这个结构中是否可行,如果是那么如何实现?任何帮助都会很棒。

tabBarVisible: false

当您使用 @react-navigation/bottom-tabs 中的 createBottomTabNavigator 时它正在工作。但是,如果您将使用 @react-navigation/material-bottom-tabs 中的 createMaterialBottomTabNavigator 创建底部选项卡,则它不起作用。 createMaterialBottomTabNavigator无法隐藏标签栏,你看docs里没有这个选项。如果您希望它在堆栈导航器的其他屏幕上消失,您应该尝试将 bottom-tabs 导航器嵌套在堆栈导航器中。以下代码用于 createBottomTabNavigator.

中的隐藏标签栏
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';

const BottomTabs = createBottomTabNavigator();

<BottomTabs.Navigator>
  <BottomTabs.Screen name={AppRoute.MORE} component={MoreStack}
        options={({ route }) => ({
            tabBarVisible: getTabBarVisibility(route),
            tabBarLabel: languages.stack_More
        })}
    />
</BottomTabs.Navigator>


const getTabBarVisibility = (route: any) => {
    const routeName = route.state ? route.state.routes[route.state.index].name: '';
   if (routeName === AppRoute.PROFILE
        || routeName === AppRoute.HELP_CENTER
        || routeName === AppRoute.TERMS_CONDITION) {
       return false;
    }
   return true;
}