Skip to content

Commit bae13dc

Browse files
committed
Add guide for hiding tab bar on some screens
1 parent 4075d0d commit bae13dc

File tree

5 files changed

+64
-2
lines changed

5 files changed

+64
-2
lines changed

versioned_docs/version-5.x/auth-flow.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ This pattern has been in use by other routing libraries such as React Router for
4444

4545
The magic happens when the value of the `isSignedIn` variable changes. Let's say, initially `isSignedIn` is `false`. This means, either `SignIn` or `SignUp` screens are shown. After the user signs in, the value of `isSignedIn` will change to `true`. React Navigation will see that the `SignIn` and `SignUp` screens are no longer defined and so it will remove them. Then it'll show the `Home` screen automatically because that's the first screen defined when `isSignedIn` is `true`.
4646

47+
It's important to note that when using such a setup, you **don't need to navigate** to the `Home` screen manually by calling `navigation.navigate('Home')`. React Navigation will automatically navigate to the `Home` screen when `isSignedIn` becomes `true`.
48+
4749
This takes advantage of a new feature in React Navigation: being able to dynamically define and alter the screen definitions of a navigator based on props or state. The example shows stack navigator, but you can use the same approach with any navigator.
4850

4951
By conditionally defining different screens based on a variable, we can implement auth flow in a simple way that doesn't require additional logic to make sure that the correct screen is shown.

versioned_docs/version-5.x/bottom-tab-navigator.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ Generic title that can be used as a fallback for `headerTitle` and `tabBarLabel`
170170

171171
`true` or `false` to show or hide the tab bar, if not set then defaults to `true`.
172172

173-
> Note: Hiding tab bar can cause glitches and jumpy behavior. We recommend [nesting](nesting-navigators.md) the tab navigator inside of a stack navigator instead.
173+
> Note: Hiding tab bar can cause glitches and jumpy behavior. We recommend [the tab navigator inside of a stack navigator instead](hiding-tabbar-in-screens.md).
174174
175175
#### `tabBarIcon`
176176

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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.

versioned_docs/version-5.x/screen-options-resolution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ So what's happening here? The `route` prop contains a `state` property which ref
181181
This approach can be used anytime you want to set options for a parent navigator based on a child navigator's state. Common use cases are:
182182
183183
1. Show tab title in stack header: a stack contains a tab navigator and you want to set the title on the stack header (above example)
184-
2. Show screens without tab bar: a tab navigator contains a stack and you want to hide the tab bar on specific screens (not recommended, nest the tab navigator inside a stack navigator instead)
184+
2. Show screens without tab bar: a tab navigator contains a stack and you want to hide the tab bar on specific screens (not recommended, see [Hiding tab bar in specific screens](hiding-tabbar-in-screens.md) instead)
185185
3. Lock drawer on certain screens: a drawer has a stack inside of it and you want to lock the drawer on certain screens
186186
187187
In many cases, similar behavior can be achieved by reorganizing our navigators. We usually recommend this option if it fits your use case.

versioned_sidebars/version-5.x-sidebars.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"version-5.x/drawer-based-navigation",
2323
"version-5.x/auth-flow",
2424
"version-5.x/handling-safe-area",
25+
"version-5.x/hiding-tabbar-in-screens",
2526
"version-5.x/status-bar",
2627
"version-5.x/screen-options-resolution",
2728
"version-5.x/custom-android-back-button-handling",

0 commit comments

Comments
 (0)