【问题标题】:Hide TabBar in specific Screens in React Native在 React Native 的特定屏幕中隐藏 TabBar
【发布时间】:2021-08-09 09:09:17
【问题描述】:

我一直在尝试在特定屏幕中隐藏 tabBar,尝试了一些找到的解决方案,但没有一个对我有用(使用 Native-Base)用于 UI。

我有一个 TabNavigator,我在其中传递一个带有屏幕的堆栈。

所以我想要做的是在其中一个屏幕中隐藏 TabBar。 请参阅下面的代码????。

import React from 'react';
import {createBottomTabNavigator} from '@react-navigation/bottom-tabs';
import {createStackNavigator} from '@react-navigation/stack';
import { NativeBaseProvider } from 'native-base';

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

//Stack of Screens linked with the search Menu.
function Recherche() {
  return (
    <Stack.Navigator initialRouteName="Recherche">
      <Stack.Screen
        name="Recherche"
        component={Search}
        options={{title: 'Recherche', headerShown: false}}
      />
      <Stack.Screen
        name="ViewCarte"
        component={ViewCarte}
        options={{title: 'ViewCarte', headerShown: false}}
      />
    </Stack.Navigator>
  );
}
//Stack of Screens linked with the Mon Espace Menu.
function MonEspace() {
  return (
    <Stack.Navigator initialRouteName="Espace">
      <Stack.Screen
        name="Espace"
        component={Espace}
        options={{title: 'Espace', headerShown: false}}
      />
      <Stack.Screen
        name="Compte"
        component={Compte}
        options={{title: 'Compte', headerShown: false}}
      />
    </Stack.Navigator>
  );
}

//Function constructing the  TabBar
function ViewLoc({navigation}) {
  return (
    <NativeBaseProvider>
      <Tab.Navigator
        initialRouteName="Recherche"
        tabBarOptions={{
          activeTintColor: '#0B3D91',
          style: {
            padding: 5,
            height: 60,
          },
          tabStyle: {
            paddingTop: 8,
            paddingBottom: 8,
          },
        }}>
        <Tab.Screen
          name="Recherche"
          component={Recherche}
          options={{
            tabBarIcon: ({color, size}) => (
              <SearchIcon color={color} size={size} />
            ),
          }}
        />
        <Tab.Screen
          name="Mon espace"
          component={MonEspace}
          options={{
            tabBarIcon: ({color, size}) => <ProfileIcon color={color} />,
            tabBarVisible: true,
          }}
        />
      </Tab.Navigator>
    </NativeBaseProvider>
  );
}

试图在屏幕“ViewCarte”和屏幕“Compte”中隐藏 tabBar。

【问题讨论】:

    标签: android reactjs react-native react-router native-base


    【解决方案1】:

    你可以改变导航结构,你的结构应该是这样的

    const RootStack = createStackNavigator();
    const Tab = createBottomTabNavigator();
    
    function TabsNavigatorComponent() {
      return (
          <Tab.Navigator>
             //any screen or stack here will show with tabs.
          </Tab.Navigator>
      )
    }
    
    <NavigationContainer>
       //the main Navigator shoud be Stack
       <RootStack.Navigator>   
    
         //outside any screen to here, to show it without tabs.
         <RootStack.Screen name="screenWithoutTabs" component={ScreenWithoutTabs}/>
    
    
         <RootStack.Screen name="bottomTabs" component={TabsNavigatorComponent}/>
    
       </RootStack.Navigator>
    </NavigationContainer>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多