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
In addition, we can generate the TypeScript types for the `FeedTabs` navigator and use it in the types of `RootStack` without needing to write them manually:
Copy file name to clipboardExpand all lines: versioned_docs/version-7.x/static-configuration.md
+43-16Lines changed: 43 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -191,6 +191,48 @@ The above example will only render the `HomeScreen` if the user is logged in.
191
191
192
192
For more details, see [Authentication flow](auth-flow.md?config=static).
193
193
194
+
### Passing dynamic props
195
+
196
+
To pass dynamic props to the navigator created using `createXNavigator`, you can pass a component to the `with` method:
197
+
198
+
```js
199
+
constDrawer=createDrawerNavigator({
200
+
screenOptions: {
201
+
headerTintColor:'white',
202
+
headerStyle: {
203
+
backgroundColor:'tomato',
204
+
},
205
+
},
206
+
screens: {
207
+
Home: HomeScreen,
208
+
},
209
+
}).with(({ Navigator }) => {
210
+
constisLargeScreen=useIsLargeScreen();
211
+
212
+
return (
213
+
<Navigator
214
+
screenOptions={{
215
+
drawerType: isLargeScreen ?'permanent':'front',
216
+
}}
217
+
/>
218
+
);
219
+
});
220
+
```
221
+
222
+
The component passed to `with` receives the `Navigator` component to render as a prop. It accepts any props supported by the navigator.
223
+
224
+
The `screenOptions` and `screenListeners` props passed to the component will be shallow merged with the ones defined in the static config if any.
225
+
226
+
### Creating a component
227
+
228
+
The `getComponent()` method on the object returned by `createXNavigator` functions returns a React component to render for the navigator:
229
+
230
+
```js
231
+
constRootStackNavigator=RootStack.getComponent();
232
+
```
233
+
234
+
This is useful when [combining static and dynamic APIs](combine-static-with-dynamic.md), and not intended to be used directly if you're using static configuration for your whole app.
235
+
194
236
## `createStaticNavigation`
195
237
196
238
The `createStaticNavigation` function takes the static config returned by `createXNavigator` functions and returns a React component to render:
@@ -228,21 +270,6 @@ Similar to `NavigationContainer`, the component returned by `createStaticNavigat
228
270
229
271
See [How does automatic path generation work](configuring-links.md#how-does-automatic-path-generation-work) for more details.
230
272
231
-
## `createComponentForStaticNavigation`
232
-
233
-
The `createComponentForStaticNavigation` function takes the static config returned by `createXNavigator` functions and returns a React component to render. The second argument is a name for the component that'd be used in React DevTools:
The returned component doesn't take any props. All of the configuration is inferred from the static config. It's essentially the same as defining a component using the dynamic API.
243
-
244
-
This looks similar to `createStaticNavigation` however they are very different. When using static configuration, you'd never use this function directly. The only time you'd use this is if you're migrating away from static configuration and want to reuse existing code you wrote instead of rewriting it to the dynamic API. See [Combining static and dynamic APIs](combine-static-with-dynamic.md) for more details.
245
-
246
273
## `createPathConfigForStaticNavigation`
247
274
248
275
The `createPathConfigForStaticNavigation` function takes the static config returned by `createXNavigator` functions and returns a path config object that can be used within the linking config.
@@ -257,4 +284,4 @@ const config = {
257
284
};
258
285
```
259
286
260
-
Similar to `createComponentForStaticNavigation`, this is intended to be used when migrating away from static configuration. See [Combining static and dynamic APIs](combine-static-with-dynamic.md) for more details.
287
+
This is intended to be used when [combining static and dynamic APIs](combine-static-with-dynamic.md).
In addition, we can generate the TypeScript types for the `FeedTabs` navigator and use it in the types of `RootStack` without needing to write them manually:
Copy file name to clipboardExpand all lines: versioned_docs/version-8.x/static-configuration.md
+57-32Lines changed: 57 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -213,7 +213,63 @@ The above example will only render the `HomeScreen` if the user is logged in.
213
213
214
214
For more details, see [Authentication flow](auth-flow.md?config=static).
215
215
216
-
## `createStaticNavigation`
216
+
### Passing dynamic props
217
+
218
+
To pass dynamic props to the navigator created using `createXNavigator`, you can pass a component to the `with` method:
219
+
220
+
```js
221
+
constDrawer=createDrawerNavigator({
222
+
screenOptions: {
223
+
headerTintColor:'white',
224
+
headerStyle: {
225
+
backgroundColor:'tomato',
226
+
},
227
+
},
228
+
screens: {
229
+
Home: HomeScreen,
230
+
},
231
+
}).with(({ Navigator }) => {
232
+
constisLargeScreen=useIsLargeScreen();
233
+
234
+
return (
235
+
<Navigator
236
+
screenOptions={{
237
+
drawerType: isLargeScreen ?'permanent':'front',
238
+
}}
239
+
/>
240
+
);
241
+
});
242
+
```
243
+
244
+
The component passed to `with` receives the `Navigator` component to render as a prop. It accepts any props supported by the navigator.
245
+
246
+
The `screenOptions` and `screenListeners` props passed to the component will be shallow merged with the ones defined in the static config if any.
247
+
248
+
### Creating a component
249
+
250
+
The `getComponent()` method on the object returned by `createXNavigator` functions returns a React component to render for the navigator:
251
+
252
+
```js
253
+
constRootStackNavigator=RootStack.getComponent();
254
+
```
255
+
256
+
This is useful when [combining static and dynamic APIs](combine-static-with-dynamic.md), and not intended to be used directly if you're using static configuration for your whole app.
257
+
258
+
## `createPathConfigForStaticNavigation`
259
+
260
+
The `createPathConfigForStaticNavigation` function takes the static config returned by `createXNavigator` functions and returns a path config object that can be used within the linking config.
This is intended to be used when [combining static and dynamic APIs](combine-static-with-dynamic.md) for more details.
217
273
218
274
The `createStaticNavigation` function takes the static config returned by `createXNavigator` functions and returns a React component to render:
219
275
@@ -251,34 +307,3 @@ Similar to `NavigationContainer`, the component returned by `createStaticNavigat
251
307
See [How does automatic path generation work](configuring-links.md#how-does-automatic-path-generation-work) for more details.
252
308
253
309
By default, linking is enabled in static configuration with automatic path generation. It needs to be explicitly disabled by passing `enabled: false` to the `linking` prop if you don't want linking support.
254
-
255
-
## `createComponentForStaticNavigation`
256
-
257
-
The `createComponentForStaticNavigation` function takes the static config returned by `createXNavigator` functions and returns a React component to render. The second argument is a name for the component that'd be used in React DevTools:
The returned component doesn't take any props. All of the configuration is inferred from the static config. It's essentially the same as defining a component using the dynamic API.
267
-
268
-
This looks similar to `createStaticNavigation` however they are very different. When using static configuration, you'd never use this function directly. The only time you'd use this is if you're migrating away from static configuration and want to reuse existing code you wrote instead of rewriting it to the dynamic API. See [Combining static and dynamic APIs](combine-static-with-dynamic.md) for more details.
269
-
270
-
## `createPathConfigForStaticNavigation`
271
-
272
-
The `createPathConfigForStaticNavigation` function takes the static config returned by `createXNavigator` functions and returns a path config object that can be used within the linking config.
Similar to `createComponentForStaticNavigation`, this is intended to be used when migrating away from static configuration. See [Combining static and dynamic APIs](combine-static-with-dynamic.md) for more details.
0 commit comments