简体   繁体   中英

Hiding tab bar in specific screens React-Native

I read through the documentation on this specific question but I still don't quite understand it. Here is my scenario:

I have a BottomTabNavigator with three tabs: Home, Camera, and Profile. With my current setup I can switch between these screens and the TabBar shows up on each screen. However what I want is to have the same three tab items on the TabBar, but have the TabBar not show up in the Camera screen.

If my understanding is correct, the link I have attached only allows you to remove the TabBar from a screen if you remove that tab from the TabBar (eg I can only achieve what I want if I remove Camera from the TabBar but I want to keep the Camera tab in the TabBar).

export default function App() {
  return (
    <NavigationContainer>
      <Tab.Navigator>
        <Tab.Screen
          name="Home"
          component={HomeScreen}
        />
        <Tab.Screen
          name="Camera"
          component={CameraScreen}
        />
        <Tab.Screen
          name="Profile"
          component={ProfileScreen}
        />
      </Tab.Navigator>
    </NavigationContainer>
  );
}

I tried:

options={{ tabBarVisable=false }}

but it didn't work either.

import { getFocusedRouteNameFromRoute } from '@react-navigation/native';    


const getTabBarVisibility = (route) => {    

    const routeName = getFocusedRouteNameFromRoute(route) ?? 'Home';
    const disabledScreens = ['CameraScreen'];
    
    if (disabledScreens.includes(routeName)) {
        return false;
    }
    
    return true;
};    

<Tab.Navigator 
        screenOptions={({route}) => ({            
            tabBarVisible: getTabBarVisibility(route)
        })
    >

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM