You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: versioned_docs/version-7.x/auth-flow.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -891,7 +891,7 @@ isSignedIn ? (
891
891
892
892
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.
893
893
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.
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:
After creating the navigator, it can be used as children of the `Navigator` component:
39
-
40
-
<TabsgroupId="config"queryString="config">
41
-
<TabItemvalue="static"label="Static"default>
15
+
Groups can be defined using the `groups` property in the navigator configuration:
42
16
43
17
```js name="Stack groups" snack version=7
44
18
import*asReactfrom'react';
@@ -101,9 +75,13 @@ export default function App() {
101
75
}
102
76
```
103
77
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
+
104
80
</TabItem>
105
81
<TabItemvalue="dynamic"label="Dynamic">
106
82
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
+
107
85
```js name="Stack groups" snack version=7
108
86
import*asReactfrom'react';
109
87
import { View, Text } from'react-native';
@@ -152,14 +130,14 @@ export default function App() {
152
130
}
153
131
```
154
132
133
+
It's also possible to nest `Group` components inside other `Group` components.
134
+
155
135
</TabItem>
156
136
</Tabs>
157
137
158
-
It's also possible to nest `Group` components inside other `Group` components.
159
-
160
-
## Props
138
+
## Configuration
161
139
162
-
### `screenOptions`
140
+
### Screen options
163
141
164
142
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:
165
143
@@ -169,11 +147,13 @@ Options to configure how the screens inside the group get presented in the navig
169
147
```js
170
148
constStack=createNativeStackNavigator({
171
149
groups: {
172
-
screenOptions: {
173
-
presentation:'modal',
174
-
},
175
-
screens: {
176
-
/* screens */
150
+
Modal: {
151
+
screenOptions: {
152
+
presentation:'modal',
153
+
},
154
+
screens: {
155
+
/* screens */
156
+
},
177
157
},
178
158
},
179
159
});
@@ -203,11 +183,13 @@ When you pass a function, it'll receive the [`route`](route-object.md) and [`nav
203
183
```js
204
184
constStack=createNativeStackNavigator({
205
185
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
+
},
211
193
},
212
194
},
213
195
});
@@ -233,23 +215,34 @@ These options are merged with the `options` specified in the individual screens,
233
215
234
216
See [Options for screens](screen-options.md) for more details and examples.
235
217
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):
237
221
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):
239
222
<TabsgroupId="config"queryString="config">
240
223
<TabItemvalue="static"label="Static"default>
241
224
225
+
The name of the group is used as the `navigationKey`:
226
+
242
227
```js
243
228
constStack=createNativeStackNavigator({
244
229
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
+
},
248
239
},
249
240
},
250
241
});
251
242
```
252
243
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.
0 commit comments