Skip to content

Commit 6a9462b

Browse files
committed
Use groups for nesting docs
1 parent 5463a50 commit 6a9462b

File tree

1 file changed

+20
-29
lines changed

1 file changed

+20
-29
lines changed

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

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,6 @@ function App() {
260260
}
261261
```
262262

263-
When nesting multiple stack navigators, we recommend nesting at most 2 stack navigators, unless absolutely necessary to achieve the UI you want.
264-
265263
## Best practices when nesting
266264

267265
We recommend to reduce nesting navigators to minimal. Try to achieve the behavior you want with as little nesting as possible. Nesting has many downsides:
@@ -270,34 +268,27 @@ We recommend to reduce nesting navigators to minimal. Try to achieve the behavio
270268
- Nesting same type of navigators (e.g. tabs inside tabs, drawer inside drawer etc.) might lead to a confusing UX
271269
- With excessive nesting, code becomes difficult to follow when navigating to nested screens, configuring deep link etc.
272270

273-
Think of nesting navigators as a way to achieve the UI you want rather than a way to organize your code. If you want to create separate group of screens for organization, instead of using separate navigators, consider doing something like this:
271+
Think of nesting navigators as a way to achieve the UI you want rather than a way to organize your code. If you want to create separate group of screens for organization, instead of using separate navigators, you can use the [`Group`](group.md) component.
274272

275273
```js
276-
// Define multiple groups of screens in objects like this
277-
const commonScreens = {
278-
Help: HelpScreen,
279-
};
280-
281-
const authScreens = {
282-
SignIn: SignInScreen,
283-
SignUp: SignUpScreen,
284-
};
285-
286-
const userScreens = {
287-
Home: HomeScreen,
288-
Profile: ProfileScreen,
289-
};
290-
291-
// Then use them in your components by looping over the object and creating screen configs
292-
// You could extract this logic to a utility function and reuse it to simplify your code
293274
<Stack.Navigator>
294-
{Object.entries({
295-
// Use the screens normally
296-
...commonScreens,
297-
// Use some screens conditionally based on some condition
298-
...(isLoggedIn ? userScreens : authScreens),
299-
}).map(([name, component]) => (
300-
<Stack.Screen name={name} component={component} />
301-
))}
302-
</Stack.Navigator>;
275+
{isLoggedIn ? (
276+
// Screens for logged in users
277+
<Stack.Group>
278+
<Stack.Screen name="Home" component={Home} />
279+
<Stack.Screen name="Profile" component={Profile} />
280+
</Stack.Group>
281+
) : (
282+
// Auth screens
283+
<Stack.Group screenOptions={{ headerShown: false }}>
284+
<Stack.Screen name="SignIn" component={SignIn} />
285+
<Stack.Screen name="SignUp" component={SignUp} />
286+
</Stack.Group>
287+
)}
288+
{/* Common modal screens */}
289+
<Stack.Group screenOptions={{ presentation: 'modal' }}>
290+
<Stack.Screen name="Help" component={Help} />
291+
<Stack.Screen name="Invite" component={Invite} />
292+
</Stack.Group>
293+
</Stack.Navigator>
303294
```

0 commit comments

Comments
 (0)