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
@@ -47,6 +102,25 @@ While it is supported, we recommend to avoid spaces or special characters in scr
47
102
48
103
Options to configure how the screen gets presented in the navigator. It accepts either an object or a function returning an object:
49
104
105
+
<TabsgroupId="config"queryString="config">
106
+
<TabItemvalue="static"label="Static"default>
107
+
108
+
```js
109
+
constStack=createNativeStackNavigator({
110
+
screens: {
111
+
Profile: {
112
+
screen: ProfileScreen,
113
+
options: {
114
+
title:'Awesome app',
115
+
},
116
+
},
117
+
},
118
+
});
119
+
```
120
+
121
+
</TabItem>
122
+
<TabItemvalue="dynamic"label="Dynamic"default>
123
+
50
124
```js
51
125
<Stack.Screen
52
126
name="Profile"
@@ -57,8 +131,30 @@ Options to configure how the screen gets presented in the navigator. It accepts
57
131
/>
58
132
```
59
133
134
+
</TabItem>
135
+
</Tabs>
136
+
60
137
When you pass a function, it'll receive the [`route`](route-object.md) and [`navigation`](navigation-object.md):
61
138
139
+
<TabsgroupId="config"queryString="config">
140
+
<TabItemvalue="static"label="Static"default>
141
+
142
+
```js
143
+
constStack=createNativeStackNavigator({
144
+
screens: {
145
+
Profile: {
146
+
screen: ProfileScreen,
147
+
options: ({ route, navigation }) => ({
148
+
title:route.params.userId,
149
+
}),
150
+
},
151
+
},
152
+
});
153
+
```
154
+
155
+
</TabItem>
156
+
<TabItemvalue="dynamic"label="Dynamic"default>
157
+
62
158
```js
63
159
<Stack.Screen
64
160
name="Profile"
@@ -69,12 +165,32 @@ When you pass a function, it'll receive the [`route`](route-object.md) and [`nav
69
165
/>
70
166
```
71
167
168
+
</TabItem>
169
+
</Tabs>
170
+
72
171
See [Options for screens](screen-options.md) for more details and examples.
73
172
74
173
### `initialParams`
75
174
76
175
Initial params to use for the screen. If a screen is used as `initialRouteName`, it'll contain the params from `initialParams`. If you navigate to a new screen, the params passed are shallow merged with the initial params.
77
176
177
+
<TabsgroupId="config"queryString="config">
178
+
<TabItemvalue="static"label="Static"default>
179
+
180
+
```js
181
+
constStack=createNativeStackNavigator({
182
+
screens: {
183
+
Details: {
184
+
screen: DetailsScreen,
185
+
initialParams: { itemId:42 },
186
+
},
187
+
},
188
+
});
189
+
```
190
+
191
+
</TabItem>
192
+
<TabItemvalue="dynamic"label="Dynamic"default>
193
+
78
194
```js
79
195
<Stack.Screen
80
196
name="Details"
@@ -83,10 +199,30 @@ Initial params to use for the screen. If a screen is used as `initialRouteName`,
83
199
/>
84
200
```
85
201
202
+
</TabItem>
203
+
</Tabs>
204
+
86
205
### `getId`
87
206
88
207
Callback to return an unique ID to use for the screen. It receives an object with the route params:
89
208
209
+
<TabsgroupId="config"queryString="config">
210
+
<TabItemvalue="static"label="Static"default>
211
+
212
+
```js
213
+
constStack=createNativeStackNavigator({
214
+
screens: {
215
+
Profile: {
216
+
screen: ProfileScreen,
217
+
getId: ({ params }) =>params.userId,
218
+
},
219
+
},
220
+
});
221
+
```
222
+
223
+
</TabItem>
224
+
<TabItemvalue="dynamic"label="Dynamic"default>
225
+
90
226
```js
91
227
<Stack.Screen
92
228
name="Profile"
@@ -95,6 +231,9 @@ Callback to return an unique ID to use for the screen. It receives an object wit
95
231
/>
96
232
```
97
233
234
+
</TabItem>
235
+
</Tabs>
236
+
98
237
By default, `navigate('ScreenName', params)` updates the current screen if the screen name matches, otherwise adds a new screen in a stack navigator. So if you're on `ScreenName` and navigate to `ScreenName` again, it won't add a new screen even if the params are different - it'll update the current screen with the new params instead:
99
238
100
239
```js
@@ -143,21 +282,55 @@ If `getId` is specified in a tab or drawer navigator, the screen will remount if
You can use this approach instead of the `component` prop if you want the `ProfileScreen` module to be lazily evaluated when needed. This is especially useful when using [ram bundles](https://reactnative.dev/docs/ram-bundles-inline-requires) to improve initial load.
162
335
163
336
### `children`
@@ -184,6 +357,23 @@ Optional key for this screen. This doesn't need to be unique. If the key changes
184
357
185
358
This can be useful when we have some screens which we want to be removed or reset when the condition changes:
186
359
360
+
<TabsgroupId="config"queryString="config">
361
+
<TabItemvalue="static"label="Static"default>
362
+
363
+
```js
364
+
constStack=createNativeStackNavigator({
365
+
screens: {
366
+
Profile: {
367
+
screen: ProfileScreen,
368
+
navigationKey: isSignedIn ?'user':'guest',
369
+
},
370
+
},
371
+
});
372
+
```
373
+
374
+
</TabItem>
375
+
<TabItemvalue="dynamic"label="Dynamic"default>
376
+
187
377
```js
188
378
<Stack.Screen
189
379
navigationKey={isSignedIn ?'user':'guest'}
@@ -192,6 +382,9 @@ This can be useful when we have some screens which we want to be removed or rese
192
382
/>
193
383
```
194
384
385
+
</TabItem>
386
+
</Tabs>
387
+
195
388
### `listeners`
196
389
197
390
Event listeners to subscribe to. See [`listeners` prop on `Screen`](navigation-events.md#listeners-prop-on-screen) for more details.
0 commit comments