|
| 1 | +--- |
| 2 | +id: hiding-tabbar-in-screens |
| 3 | +title: Hiding tab bar in specific screens |
| 4 | +sidebar_label: Hiding tab bar in specific screens |
| 5 | +--- |
| 6 | + |
| 7 | +Sometimes we may want to hide the tab bar in specific screens in a stack navigator nested in a tab navigator. Let's say we have 5 screens: `Home`, `Feed`, `Notifications`, `Profile` and `Settings`, and your navigation structure looks like this: |
| 8 | + |
| 9 | +```js |
| 10 | +function HomeStack() { |
| 11 | + return ( |
| 12 | + <Stack.Navigator> |
| 13 | + <Stack.Screen name="Home" component={Home} /> |
| 14 | + <Stack.Screen name="Profile" component={Profile} /> |
| 15 | + <Stack.Screen name="Settings" component={Settings} /> |
| 16 | + </Stack.Navigator> |
| 17 | + ); |
| 18 | +} |
| 19 | + |
| 20 | +function App() { |
| 21 | + return ( |
| 22 | + <Tab.Navigator> |
| 23 | + <Tab.Screen name="Home" component={HomeStack} /> |
| 24 | + <Tab.Screen name="Feed" component={Feed} /> |
| 25 | + <Tab.Screen name="Settings" component={Settings} /> |
| 26 | + </Tab.Navigator> |
| 27 | + ); |
| 28 | +} |
| 29 | +``` |
| 30 | + |
| 31 | +With this structure, when we navigate to the `Profile` or `Settings` screen, the tab bar is still stay visible over those screens. |
| 32 | + |
| 33 | +But if we want to show the tab bar only on the `Home`, `Feed` and `Notifications` screens, but not on the `Profile` and `Settings` screens, we'll need to change the navigation structure. The easiest way to achieve this is to nest the tab navigator inside the firs screen of the stack instead of nesting stack inside tab navigator: |
| 34 | + |
| 35 | +```js |
| 36 | +function HomeTabs() { |
| 37 | + return ( |
| 38 | + <Tab.Navigator> |
| 39 | + <Tab.Screen name="Home" component={Home} /> |
| 40 | + <Tab.Screen name="Feed" component={Feed} /> |
| 41 | + <Tab.Screen name="Settings" component={Settings} /> |
| 42 | + </Tab.Navigator> |
| 43 | + ); |
| 44 | +} |
| 45 | + |
| 46 | +function App() { |
| 47 | + return ( |
| 48 | + <Stack.Navigator> |
| 49 | + <Stack.Screen name="Home" component={HomeTabs} /> |
| 50 | + <Stack.Screen name="Profile" component={Profile} /> |
| 51 | + <Stack.Screen name="Settings" component={Settings} /> |
| 52 | + </Stack.Navigator> |
| 53 | + ); |
| 54 | +} |
| 55 | +``` |
| 56 | + |
| 57 | +After re-organizing the navigation structure, now if we navigate to the `Profile` or `Settings` screens, the tab bar won't be visible over the screen anymore. |
| 58 | + |
| 59 | +Some tab navigators such as [bottom tab navigator](bottom-tab-navigator.md) also have a `tabBarVisible` option which can be used to hide the tab bar based on instructions in the [Screen options resolution guide](screen-options-resolution.md). However, we don't recommend using it since showing/hiding the tab bar mid-navigation can affect the animation of the stack navigator causing glitchy behaviour. |
0 commit comments