Skip to content

Commit 84f8329

Browse files
committed
Update screen and group docs to adapt to static config
1 parent 487d379 commit 84f8329

File tree

4 files changed

+103
-233
lines changed

4 files changed

+103
-233
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ isSignedIn ? (
891891

892892
Here we have specific screens such as `SignIn`, `Home` etc. which are only shown depending on the sign in state. But we also have the `Help` screen which can be shown in both cases. This also means that if the signin state changes when the user is in the `Help` screen, they'll stay on the `Help` screen.
893893

894-
This can be a problem, we probably want the user to be taken to the `SignIn` screen or `Home` screen instead of keeping them on the `Help` screen. To make this work, we can use [`navigationKey`](screen.md#navigationkey). When the `navigationKey` changes, React Navigation will remove all the screen.
894+
This can be a problem, we probably want the user to be taken to the `SignIn` screen or `Home` screen instead of keeping them on the `Help` screen. To make this work, we can use [`navigationKey`](screen.md#navigation-key). When the `navigationKey` changes, React Navigation will remove all the screen.
895895

896896
So our updated code will look like following:
897897

@@ -952,7 +952,7 @@ const RootStack = createNativeStackNavigator({
952952
</TabItem>
953953
</Tabs>
954954

955-
If you have a bunch of shared screens, you can also use [`navigationKey` with a `Group`](group.md#navigationkey) to remove all of the screens in the group. For example:
955+
If you have a bunch of shared screens, you can also use [`navigationKey` with a `Group`](group.md#navigation-key) to remove all of the screens in the group. For example:
956956

957957
<Tabs groupId="config" queryString="config">
958958
<TabItem value="static" label="Static" default>

versioned_docs/version-7.x/group.md

Lines changed: 41 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,12 @@ sidebar_label: Group
77
import Tabs from '@theme/Tabs';
88
import TabItem from '@theme/TabItem';
99

10-
`Group` components are used to group several [screens](screen.md) inside a navigator.
11-
12-
A `Group` is returned from a `createXNavigator` function:
10+
A group contains several [screens](screen.md) inside a navigator.
1311

1412
<Tabs groupId="config" queryString="config">
1513
<TabItem value="static" label="Static" default>
1614

17-
```js
18-
const Stack = createStackNavigator({
19-
screens: {
20-
/* content */
21-
},
22-
groups: {
23-
/* content */
24-
},
25-
}); // Stack contains Screen & Navigator properties
26-
```
27-
28-
</TabItem>
29-
<TabItem value="dynamic" label="Dynamic">
30-
31-
```js
32-
const Stack = createStackNavigator(); // Stack contains Screen & Navigator properties
33-
```
34-
35-
</TabItem>
36-
</Tabs>
37-
38-
After creating the navigator, it can be used as children of the `Navigator` component:
39-
40-
<Tabs groupId="config" queryString="config">
41-
<TabItem value="static" label="Static" default>
15+
Groups can be defined using the `groups` property in the navigator configuration:
4216

4317
```js name="Stack groups" snack version=7
4418
import * as React from 'react';
@@ -101,9 +75,13 @@ export default function App() {
10175
}
10276
```
10377

78+
The keys of the `groups` object (e.g. `Guest`, `User`) are used as the [`navigationKey`](#navigation-key) for the group. You can use any string as the key.
79+
10480
</TabItem>
10581
<TabItem value="dynamic" label="Dynamic">
10682

83+
A `Group` component is returned from a `createXNavigator` function. After creating the navigator, it can be used as children of the `Navigator` component:
84+
10785
```js name="Stack groups" snack version=7
10886
import * as React from 'react';
10987
import { View, Text } from 'react-native';
@@ -152,14 +130,14 @@ export default function App() {
152130
}
153131
```
154132

133+
It's also possible to nest `Group` components inside other `Group` components.
134+
155135
</TabItem>
156136
</Tabs>
157137

158-
It's also possible to nest `Group` components inside other `Group` components.
159-
160-
## Props
138+
## Configuration
161139

162-
### `screenOptions`
140+
### Screen options
163141

164142
Options to configure how the screens inside the group get presented in the navigator. It accepts either an object or a function returning an object:
165143

@@ -169,11 +147,13 @@ Options to configure how the screens inside the group get presented in the navig
169147
```js
170148
const Stack = createNativeStackNavigator({
171149
groups: {
172-
screenOptions: {
173-
presentation: 'modal',
174-
},
175-
screens: {
176-
/* screens */
150+
Modal: {
151+
screenOptions: {
152+
presentation: 'modal',
153+
},
154+
screens: {
155+
/* screens */
156+
},
177157
},
178158
},
179159
});
@@ -203,11 +183,13 @@ When you pass a function, it'll receive the [`route`](route-object.md) and [`nav
203183
```js
204184
const Stack = createNativeStackNavigator({
205185
groups: {
206-
screenOptions: ({ route, navigation }) => ({
207-
title: route.params.title,
208-
}),
209-
screens: {
210-
/* screens */
186+
Modal: {
187+
screenOptions: ({ route, navigation }) => ({
188+
title: route.params.title,
189+
}),
190+
screens: {
191+
/* screens */
192+
},
211193
},
212194
},
213195
});
@@ -233,23 +215,34 @@ These options are merged with the `options` specified in the individual screens,
233215

234216
See [Options for screens](screen-options.md) for more details and examples.
235217

236-
### `navigationKey`
218+
### Navigation key
219+
220+
Optional key for a group of screens. If the key changes, all existing screens in this group will be removed (if used in a stack navigator) or reset (if used in a tab or drawer navigator):
237221

238-
Optional key for a group of screens screen. If the key changes, all existing screens in this group will be removed (if used in a stack navigator) or reset (if used in a tab or drawer navigator):
239222
<Tabs groupId="config" queryString="config">
240223
<TabItem value="static" label="Static" default>
241224

225+
The name of the group is used as the `navigationKey`:
226+
242227
```js
243228
const Stack = createNativeStackNavigator({
244229
groups: {
245-
navigationKey: isSignedIn ? 'user' : 'guest',
246-
screens: {
247-
/* screens */
230+
User: {
231+
screens: {
232+
/* screens */
233+
},
234+
},
235+
Guest: {
236+
screens: {
237+
/* screens */
238+
},
248239
},
249240
},
250241
});
251242
```
252243

244+
This means if a screen is defined in 2 groups and the groups use the [`if`](static-configuration.md#if) property, the screen will remount if the condition changes resulting in one group being removed and the other group being used.
245+
253246
</TabItem>
254247
<TabItem value="dynamic" label="Dynamic">
255248

@@ -262,4 +255,4 @@ const Stack = createNativeStackNavigator({
262255
</TabItem>
263256
</Tabs>
264257

265-
This is similar to the [`navigationKey`](screen.md#navigationkey) prop on `Screen`, but applies to a group of screens.
258+
This is similar to the [`navigationKey`](screen.md#navigation-key) prop for screens, but applies to a group of screens.

0 commit comments

Comments
 (0)