Skip to content

Commit 83bd04e

Browse files
committed
Update standard navigator docs
1 parent 2637049 commit 83bd04e

2 files changed

Lines changed: 36 additions & 20 deletions

File tree

versioned_docs/version-7.x/standard-navigator.md

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,17 @@ export type MyTabEventMap = {
8787
};
8888

8989
export type MyTabNavigatorProps = {
90-
// additional navigator props type
90+
// props users pass to the navigator
91+
};
92+
93+
export type MyTabMapperProps = {
94+
// optional props supplied by a navigation library integration
9195
};
9296

9397
export const MyTabNavigator = createStandardNavigator<
9498
MyTabOptions,
9599
MyTabEventMap,
96-
MyTabNavigatorProps
100+
MyTabNavigatorProps & MyTabMapperProps
97101
>(({ state, descriptors, actions, emitter, ...props }) => {
98102
// render the navigator UI using the state and descriptors
99103
// use actions to perform navigation and emitter to emit events
@@ -129,9 +133,9 @@ The `createStandardNavigator` function accepts three generic arguments:
129133
};
130134
```
131135

132-
- **`MyTabNavigatorProps`**
136+
- **`MyTabNavigatorProps & MyTabMapperProps`**
133137

134-
The type of any additional props accepted by the navigator.
138+
The type of any additional public props accepted by the navigator as well as mapper props, i.e. optional props derived from react navigation's state and action helpers.
135139

136140
The callback receives `state`, `descriptors`, `actions`, and `emitter` from the navigation library integration:
137141

@@ -271,20 +275,24 @@ interface MyTabTypeBag extends StandardNavigationTypeBagBase {
271275

272276
const { createNavigator, createScreen } = createStandardNavigationFactories<
273277
MyTabTypeBag,
274-
MyTabNavigatorProps
275-
>(MyTabNavigator, TabRouter);
278+
MyTabNavigatorProps,
279+
MyTabMapperProps
280+
>(MyTabNavigator, TabRouter, ({ state }) => ({
281+
activeRouteName: state.routes[state.index]?.name ?? '',
282+
}));
276283
```
277284

278-
The `createStandardNavigationFactories` function accepts two generic arguments:
285+
The `createStandardNavigationFactories` function accepts up to three generic arguments:
279286

280287
- The type bag for the navigator (e.g. `MyTabTypeBag`), which includes the state, action helpers, screen options, event map, and router options types.
281-
- The type of any additional props accepted by the navigator (e.g. `MyTabNavigatorProps`).
288+
- The type of public props accepted by the navigator (e.g. `MyTabNavigatorProps`). These props are exposed to users in the static config and dynamic navigator component.
289+
- The optional type of props derived from react navigation's state and action helpers in the mapper function (e.g. `MyTabMapperProps`). These props are passed to the standard navigator but aren't exposed to users.
282290

283291
It accepts 3 arguments:
284292

285293
- The standard navigator component.
286294
- The router factory function from React Navigation (e.g. `TabRouter`, `StackRouter`, etc.).
287-
- An optional function to map `{ navigation, state }` to custom props for the navigator component, in case you need any specific state or action helpers not available in the standard ones.
295+
- An optional function to map `{ navigation, state }` to props for the navigator component, in case you need any specific state or action helpers not available in the standard ones.
288296

289297
It returns an object with `createNavigator` and `createScreen` functions that can be used to create the navigator and screens for React Navigation. These should be exported from the entry point.
290298

@@ -379,4 +387,4 @@ const Navigation = createStaticNavigation(MyTabs);
379387

380388
## Expo Router entry point
381389

382-
Work in progress.
390+
See [Expo Router documentation](https://docs.expo.dev/router/advanced/custom-navigators) for more information.

versioned_docs/version-8.x/standard-navigator.md

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,17 @@ export type MyTabEventMap = {
8787
};
8888

8989
export type MyTabNavigatorProps = {
90-
// additional navigator props type
90+
// props users pass to the navigator
91+
};
92+
93+
export type MyTabMapperProps = {
94+
// optional props supplied by a navigation library integration
9195
};
9296

9397
export const MyTabNavigator = createStandardNavigator<
9498
MyTabOptions,
9599
MyTabEventMap,
96-
MyTabNavigatorProps
100+
MyTabNavigatorProps & MyTabMapperProps
97101
>(({ state, descriptors, actions, emitter, ...props }) => {
98102
// render the navigator UI using the state and descriptors
99103
// use actions to perform navigation and emitter to emit events
@@ -129,9 +133,9 @@ The `createStandardNavigator` function accepts three generic arguments:
129133
};
130134
```
131135

132-
- **`MyTabNavigatorProps`**
136+
- **`MyTabNavigatorProps & MyTabMapperProps`**
133137

134-
The type of any additional props accepted by the navigator.
138+
The type of any additional public props accepted by the navigator as well as mapper props, i.e. optional props derived from react navigation's state and action helpers.
135139

136140
The callback receives `state`, `descriptors`, `actions`, and `emitter` from the navigation library integration:
137141

@@ -267,20 +271,24 @@ interface MyTabTypeBag extends StandardNavigationTypeBagBase {
267271

268272
const { createNavigator, createScreen } = createStandardNavigationFactories<
269273
MyTabTypeBag,
270-
MyTabNavigatorProps
271-
>(MyTabNavigator, TabRouter);
274+
MyTabNavigatorProps,
275+
MyTabMapperProps
276+
>(MyTabNavigator, TabRouter, ({ state }) => ({
277+
activeRouteName: state.routes[state.index]?.name ?? '',
278+
}));
272279
```
273280

274-
The `createStandardNavigationFactories` function accepts two generic arguments:
281+
The `createStandardNavigationFactories` function accepts up to three generic arguments:
275282

276283
- The type bag for the navigator (e.g. `MyTabTypeBag`), which includes the state, action helpers, screen options, event map, and router options types.
277-
- The type of any additional props accepted by the navigator (e.g. `MyTabNavigatorProps`).
284+
- The type of public props accepted by the navigator (e.g. `MyTabNavigatorProps`). These props are exposed to users in the static config and dynamic navigator component.
285+
- The optional type of props derived from react navigation's state and action helpers in the mapper function (e.g. `MyTabMapperProps`). These props are passed to the standard navigator but aren't exposed to users.
278286

279287
It accepts 3 arguments:
280288

281289
- The standard navigator component.
282290
- The router factory function from React Navigation (e.g. `TabRouter`, `StackRouter`, etc.).
283-
- An optional function to map `{ navigation, state }` to custom props for the navigator component, in case you need any specific state or action helpers not available in the standard ones.
291+
- An optional function to map `{ navigation, state }` to props for the navigator component, in case you need any specific state or action helpers not available in the standard ones.
284292

285293
It returns an object with `createNavigator` and `createScreen` functions that can be used to create the navigator and screens for React Navigation. These should be exported from the entry point.
286294

@@ -372,4 +380,4 @@ const Navigation = createStaticNavigation(MyTabs);
372380

373381
## Expo Router entry point
374382

375-
Work in progress.
383+
See [Expo Router documentation](https://docs.expo.dev/router/advanced/custom-navigators) for more information.

0 commit comments

Comments
 (0)