Skip to content

Commit e457504

Browse files
committed
Update nesting multiple navigators doc
1 parent 3c4f429 commit e457504

File tree

1 file changed

+35
-13
lines changed

1 file changed

+35
-13
lines changed

versioned_docs/version-6.x/nesting-navigators.md

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,9 @@ This affects what happens when pressing the back button. When there's an initial
200200

201201
## Nesting multiple navigators
202202

203-
It's sometimes useful to nest multiple navigators such as stack or drawer, for example, to have [some screens in a modal stack and some in regular stack](modal.md).
203+
It's sometimes useful to nest multiple navigators such as stack, drawer or tabs.
204204

205-
When nesting multiple stack, drawer or bottom tab navigator, headers from both child and parent navigators would be shown. However, usually it's more desirable to show the header in the child navigator and hide the header in the stack navigator.
205+
When nesting multiple stack, drawer or bottom tab navigator, headers from both child and parent navigators would be shown. However, usually it's more desirable to show the header in the child navigator and hide the header in the screen of the parent navigator.
206206

207207
To achieve this, you can hide the header in the screen containing the navigator using the `headerShown: false` option.
208208

@@ -211,34 +211,56 @@ For example:
211211
```js
212212
function Home() {
213213
return (
214-
<NestedStack.Navigator>
215-
<NestedStack.Screen name="Profile" component={Profile} />
216-
<NestedStack.Screen name="Settings" component={Settings} />
217-
</NestedStack.Navigator>
214+
<Tab.Navigator>
215+
<Tab.Screen name="Profile" component={Profile} />
216+
<Tab.Screen name="Settings" component={Settings} />
217+
</Tab.Navigator>
218218
);
219219
}
220220

221221
function App() {
222222
return (
223223
<NavigationContainer>
224-
<RootStack.Navigator screenOptions={{ presentation: 'modal' }}>
225-
<RootStack.Screen
224+
<Stack.Navigator>
225+
<Stack.Screen
226226
name="Home"
227227
component={Home}
228228
options={{ headerShown: false }}
229229
/>
230-
<RootStack.Screen name="EditPost" component={EditPost} />
231-
</RootStack.Navigator>
230+
<Stack.Screen name="EditPost" component={EditPost} />
231+
</Stack.Navigator>
232232
</NavigationContainer>
233233
);
234234
}
235235
```
236236

237-
A complete example can be found in the [modal guide](modal.md). However, the principle isn't only specific to modals, but any kind of nesting of navigators.
237+
In these examples, we have used a bottom tab navigator directly nested inside another stack navigator, but the same principle applies when there are other navigators in the middle, for example: stack navigator inside a tab navigator which is inside another stack navigator, stack navigator inside drawer navigator etc.
238+
239+
If you don't want headers in any of the navigators, you can specify `headerShown: false` in all of the navigators:
238240

239-
In these examples, we have used a stack navigator directly nested inside another stack navigator, but the same principle applies when there are other navigators in the middle, for example: stack navigator inside a tab navigator which is inside another stack navigator, stack navigator inside drawer navigator etc.
241+
```js
242+
function Home() {
243+
return (
244+
<Tab.Navigator screenOptions={{ headerShown: false }}>
245+
<Tab.Screen name="Profile" component={Profile} />
246+
<Tab.Screen name="Settings" component={Settings} />
247+
</Tab.Navigator>
248+
);
249+
}
250+
251+
function App() {
252+
return (
253+
<NavigationContainer>
254+
<Stack.Navigator screenOptions={{ headerShown: false }}>
255+
<Stack.Screen name="Home" component={Home} />
256+
<Stack.Screen name="EditPost" component={EditPost} />
257+
</Stack.Navigator>
258+
</NavigationContainer>
259+
);
260+
}
261+
```
240262

241-
When nesting multiple stack navigators, we recommend nesting at most 2 stack navigators, unless absolutely necessary.
263+
When nesting multiple stack navigators, we recommend nesting at most 2 stack navigators, unless absolutely necessary to achieve the UI you want.
242264

243265
## Best practices when nesting
244266

0 commit comments

Comments
 (0)