@react-navigation/core 6.4.6 → 7.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/commonjs/BaseNavigationContainer.js +44 -33
- package/lib/commonjs/BaseNavigationContainer.js.map +1 -1
- package/lib/commonjs/DeprecatedNavigationInChildContext.js +16 -0
- package/lib/commonjs/DeprecatedNavigationInChildContext.js.map +1 -0
- package/lib/commonjs/NavigationIndependentTree.js +33 -0
- package/lib/commonjs/NavigationIndependentTree.js.map +1 -0
- package/lib/commonjs/NavigationIndependentTreeContext.js +16 -0
- package/lib/commonjs/NavigationIndependentTreeContext.js.map +1 -0
- package/lib/commonjs/StaticNavigation.js +160 -0
- package/lib/commonjs/StaticNavigation.js.map +1 -0
- package/lib/commonjs/createNavigatorFactory.js +16 -7
- package/lib/commonjs/createNavigatorFactory.js.map +1 -1
- package/lib/commonjs/getActionFromState.js.map +1 -1
- package/lib/commonjs/index.js +52 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/useDescriptors.js +21 -18
- package/lib/commonjs/useDescriptors.js.map +1 -1
- package/lib/commonjs/useNavigationBuilder.js +1 -1
- package/lib/commonjs/useNavigationBuilder.js.map +1 -1
- package/lib/commonjs/useNavigationCache.js +9 -7
- package/lib/commonjs/useNavigationCache.js.map +1 -1
- package/lib/commonjs/useNavigationIndependentTree.js +15 -0
- package/lib/commonjs/useNavigationIndependentTree.js.map +1 -0
- package/lib/commonjs/useOnAction.js +11 -7
- package/lib/commonjs/useOnAction.js.map +1 -1
- package/lib/module/BaseNavigationContainer.js +44 -33
- package/lib/module/BaseNavigationContainer.js.map +1 -1
- package/lib/module/DeprecatedNavigationInChildContext.js +8 -0
- package/lib/module/DeprecatedNavigationInChildContext.js.map +1 -0
- package/lib/module/NavigationIndependentTree.js +25 -0
- package/lib/module/NavigationIndependentTree.js.map +1 -0
- package/lib/module/NavigationIndependentTreeContext.js +8 -0
- package/lib/module/NavigationIndependentTreeContext.js.map +1 -0
- package/lib/module/StaticNavigation.js +156 -0
- package/lib/module/StaticNavigation.js.map +1 -0
- package/lib/module/createNavigatorFactory.js +16 -7
- package/lib/module/createNavigatorFactory.js.map +1 -1
- package/lib/module/getActionFromState.js.map +1 -1
- package/lib/module/index.js +3 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/useDescriptors.js +21 -18
- package/lib/module/useDescriptors.js.map +1 -1
- package/lib/module/useNavigationBuilder.js +1 -1
- package/lib/module/useNavigationBuilder.js.map +1 -1
- package/lib/module/useNavigationCache.js +9 -7
- package/lib/module/useNavigationCache.js.map +1 -1
- package/lib/module/useNavigationIndependentTree.js +6 -0
- package/lib/module/useNavigationIndependentTree.js.map +1 -0
- package/lib/module/useOnAction.js +11 -7
- package/lib/module/useOnAction.js.map +1 -1
- package/lib/typescript/src/BaseNavigationContainer.d.ts +2 -0
- package/lib/typescript/src/BaseNavigationContainer.d.ts.map +1 -1
- package/lib/typescript/src/DeprecatedNavigationInChildContext.d.ts +7 -0
- package/lib/typescript/src/DeprecatedNavigationInChildContext.d.ts.map +1 -0
- package/lib/typescript/src/EnsureSingleNavigator.d.ts +1 -1
- package/lib/typescript/src/EnsureSingleNavigator.d.ts.map +1 -1
- package/lib/typescript/src/NavigationBuilderContext.d.ts +9 -9
- package/lib/typescript/src/NavigationBuilderContext.d.ts.map +1 -1
- package/lib/typescript/src/NavigationIndependentTree.d.ts +8 -0
- package/lib/typescript/src/NavigationIndependentTree.d.ts.map +1 -0
- package/lib/typescript/src/NavigationIndependentTreeContext.d.ts +7 -0
- package/lib/typescript/src/NavigationIndependentTreeContext.d.ts.map +1 -0
- package/lib/typescript/src/PreventRemoveContext.d.ts +1 -1
- package/lib/typescript/src/PreventRemoveContext.d.ts.map +1 -1
- package/lib/typescript/src/PreventRemoveProvider.d.ts +1 -1
- package/lib/typescript/src/PreventRemoveProvider.d.ts.map +1 -1
- package/lib/typescript/src/SceneView.d.ts +1 -1
- package/lib/typescript/src/SceneView.d.ts.map +1 -1
- package/lib/typescript/src/StaticNavigation.d.ts +159 -0
- package/lib/typescript/src/StaticNavigation.d.ts.map +1 -0
- package/lib/typescript/src/createNavigatorFactory.d.ts +8 -2
- package/lib/typescript/src/createNavigatorFactory.d.ts.map +1 -1
- package/lib/typescript/src/getActionFromState.d.ts +2 -2
- package/lib/typescript/src/getActionFromState.d.ts.map +1 -1
- package/lib/typescript/src/getPathFromState.d.ts +2 -2
- package/lib/typescript/src/getPathFromState.d.ts.map +1 -1
- package/lib/typescript/src/getStateFromPath.d.ts +2 -2
- package/lib/typescript/src/getStateFromPath.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +3 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +109 -48
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/useComponent.d.ts +1 -1
- package/lib/typescript/src/useComponent.d.ts.map +1 -1
- package/lib/typescript/src/useCurrentRender.d.ts +1 -1
- package/lib/typescript/src/useCurrentRender.d.ts.map +1 -1
- package/lib/typescript/src/useDescriptors.d.ts +11 -9
- package/lib/typescript/src/useDescriptors.d.ts.map +1 -1
- package/lib/typescript/src/useEventEmitter.d.ts +1 -1
- package/lib/typescript/src/useEventEmitter.d.ts.map +1 -1
- package/lib/typescript/src/useFocusEffect.d.ts +1 -1
- package/lib/typescript/src/useFocusEffect.d.ts.map +1 -1
- package/lib/typescript/src/useFocusEvents.d.ts +1 -1
- package/lib/typescript/src/useFocusEvents.d.ts.map +1 -1
- package/lib/typescript/src/useFocusedListenersChildrenAdapter.d.ts +1 -1
- package/lib/typescript/src/useFocusedListenersChildrenAdapter.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationBuilder.d.ts +19 -15
- package/lib/typescript/src/useNavigationBuilder.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationCache.d.ts +4 -4
- package/lib/typescript/src/useNavigationCache.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationHelpers.d.ts +11 -9
- package/lib/typescript/src/useNavigationHelpers.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationIndependentTree.d.ts +2 -0
- package/lib/typescript/src/useNavigationIndependentTree.d.ts.map +1 -0
- package/lib/typescript/src/useNavigationState.d.ts +1 -1
- package/lib/typescript/src/useNavigationState.d.ts.map +1 -1
- package/lib/typescript/src/useOnAction.d.ts +1 -1
- package/lib/typescript/src/useOnAction.d.ts.map +1 -1
- package/lib/typescript/src/useOnGetState.d.ts +1 -1
- package/lib/typescript/src/useOnGetState.d.ts.map +1 -1
- package/lib/typescript/src/useOnPreventRemove.d.ts +1 -1
- package/lib/typescript/src/useOnPreventRemove.d.ts.map +1 -1
- package/lib/typescript/src/useOnRouteFocus.d.ts +1 -1
- package/lib/typescript/src/useOnRouteFocus.d.ts.map +1 -1
- package/lib/typescript/src/useOptionsGetters.d.ts +1 -1
- package/lib/typescript/src/useOptionsGetters.d.ts.map +1 -1
- package/package.json +11 -11
- package/src/BaseNavigationContainer.tsx +68 -64
- package/src/DeprecatedNavigationInChildContext.tsx +8 -0
- package/src/NavigationIndependentTree.tsx +25 -0
- package/src/NavigationIndependentTreeContext.tsx +8 -0
- package/src/StaticNavigation.tsx +401 -0
- package/src/createNavigatorFactory.tsx +38 -9
- package/src/getActionFromState.tsx +2 -8
- package/src/getPathFromState.tsx +1 -1
- package/src/index.tsx +9 -0
- package/src/types.tsx +111 -29
- package/src/useDescriptors.tsx +24 -19
- package/src/useNavigationBuilder.tsx +10 -5
- package/src/useNavigationCache.tsx +8 -4
- package/src/useNavigationIndependentTree.tsx +7 -0
- package/src/useOnAction.tsx +13 -5
package/src/types.tsx
CHANGED
|
@@ -171,7 +171,7 @@ type NavigationHelpersCommon<
|
|
|
171
171
|
* @param action Action object or update function.
|
|
172
172
|
*/
|
|
173
173
|
dispatch(
|
|
174
|
-
action: NavigationAction | ((state: State) => NavigationAction)
|
|
174
|
+
action: NavigationAction | ((state: Readonly<State>) => NavigationAction)
|
|
175
175
|
): void;
|
|
176
176
|
|
|
177
177
|
/**
|
|
@@ -181,7 +181,7 @@ type NavigationHelpersCommon<
|
|
|
181
181
|
* @param [params] Params object for the route.
|
|
182
182
|
*/
|
|
183
183
|
navigate<RouteName extends keyof ParamList>(
|
|
184
|
-
...args: //
|
|
184
|
+
...args: // This condition allows us to iterate over a union type
|
|
185
185
|
// This is to avoid getting a union of all the params from `ParamList[RouteName]`,
|
|
186
186
|
// which will get our types all mixed up if a union RouteName is passed in.
|
|
187
187
|
RouteName extends unknown
|
|
@@ -198,18 +198,56 @@ type NavigationHelpersCommon<
|
|
|
198
198
|
/**
|
|
199
199
|
* Navigate to a route in current navigation tree.
|
|
200
200
|
*
|
|
201
|
-
* @param route Object with `
|
|
201
|
+
* @param route Object with `name` for the route to navigate to, and a `params` object.
|
|
202
202
|
*/
|
|
203
203
|
navigate<RouteName extends keyof ParamList>(
|
|
204
204
|
options: RouteName extends unknown
|
|
205
|
-
?
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
205
|
+
? {
|
|
206
|
+
name: RouteName;
|
|
207
|
+
params: ParamList[RouteName];
|
|
208
|
+
path?: string;
|
|
209
|
+
merge?: boolean;
|
|
210
|
+
}
|
|
211
|
+
: never
|
|
212
|
+
): void;
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Navigate to a route in current navigation tree.
|
|
216
|
+
*
|
|
217
|
+
* @deprecated Use `navigate` instead.
|
|
218
|
+
*
|
|
219
|
+
* @param name Route name of the route.
|
|
220
|
+
* @param [params] Params object for the route.
|
|
221
|
+
*/
|
|
222
|
+
navigateDeprecated<RouteName extends keyof ParamList>(
|
|
223
|
+
...args: // This condition allows us to iterate over a union type
|
|
224
|
+
// This is to avoid getting a union of all the params from `ParamList[RouteName]`,
|
|
225
|
+
// which will get our types all mixed up if a union RouteName is passed in.
|
|
226
|
+
RouteName extends unknown
|
|
227
|
+
? // This condition checks if the params are optional,
|
|
228
|
+
// which means it's either undefined or a union with undefined
|
|
229
|
+
undefined extends ParamList[RouteName]
|
|
230
|
+
?
|
|
231
|
+
| [screen: RouteName] // if the params are optional, we don't have to provide it
|
|
232
|
+
| [screen: RouteName, params: ParamList[RouteName]]
|
|
233
|
+
: [screen: RouteName, params: ParamList[RouteName]]
|
|
234
|
+
: never
|
|
235
|
+
): void;
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Navigate to a route in current navigation tree.
|
|
239
|
+
*
|
|
240
|
+
* @deprecated Use `navigate` instead.
|
|
241
|
+
*
|
|
242
|
+
* @param route Object with `name` for the route to navigate to, and a `params` object.
|
|
243
|
+
*/
|
|
244
|
+
navigateDeprecated<RouteName extends keyof ParamList>(
|
|
245
|
+
options: RouteName extends unknown
|
|
246
|
+
? {
|
|
247
|
+
name: RouteName;
|
|
248
|
+
params: ParamList[RouteName];
|
|
249
|
+
merge?: boolean;
|
|
250
|
+
}
|
|
213
251
|
: never
|
|
214
252
|
): void;
|
|
215
253
|
|
|
@@ -285,17 +323,25 @@ export type NavigationContainerProps = {
|
|
|
285
323
|
/**
|
|
286
324
|
* Callback which is called with the latest navigation state when it changes.
|
|
287
325
|
*/
|
|
288
|
-
onStateChange?: (state: NavigationState | undefined) => void;
|
|
326
|
+
onStateChange?: (state: Readonly<NavigationState> | undefined) => void;
|
|
327
|
+
/**
|
|
328
|
+
* Callback which is called after the navigation tree mounts.
|
|
329
|
+
*/
|
|
330
|
+
onReady?: () => void;
|
|
289
331
|
/**
|
|
290
332
|
* Callback which is called when an action is not handled.
|
|
291
333
|
*/
|
|
292
|
-
onUnhandledAction?: (action: NavigationAction) => void;
|
|
334
|
+
onUnhandledAction?: (action: Readonly<NavigationAction>) => void;
|
|
293
335
|
/**
|
|
294
|
-
* Whether
|
|
295
|
-
*
|
|
296
|
-
*
|
|
336
|
+
* Whether child navigator should handle a navigation action.
|
|
337
|
+
* The child navigator needs to be mounted before it can handle the action.
|
|
338
|
+
* Defaults to `false`.
|
|
339
|
+
*
|
|
340
|
+
* This will be removed in the next major release.
|
|
341
|
+
*
|
|
342
|
+
* @deprecated Use nested navigation API instead
|
|
297
343
|
*/
|
|
298
|
-
|
|
344
|
+
navigationInChildEnabled?: boolean;
|
|
299
345
|
/**
|
|
300
346
|
* Children elements to render.
|
|
301
347
|
*/
|
|
@@ -335,7 +381,7 @@ export type NavigationProp<
|
|
|
335
381
|
* Update the options for the route.
|
|
336
382
|
* The options object will be shallow merged with default options object.
|
|
337
383
|
*
|
|
338
|
-
* @param
|
|
384
|
+
* @param update Options object or a callback which takes the options from navigator config and returns a new options object.
|
|
339
385
|
*/
|
|
340
386
|
setOptions(options: Partial<ScreenOptions>): void;
|
|
341
387
|
} & EventConsumer<EventMap & EventMapCore<State>> &
|
|
@@ -372,11 +418,9 @@ export type CompositeNavigationProp<
|
|
|
372
418
|
*/
|
|
373
419
|
A extends NavigationProp<any, any, any, infer S> ? S : NavigationState,
|
|
374
420
|
/**
|
|
375
|
-
* Screen options
|
|
376
|
-
* This allows typechecking `setOptions`
|
|
421
|
+
* Screen options should refer to the options specified in the first type
|
|
377
422
|
*/
|
|
378
|
-
|
|
379
|
-
(B extends NavigationProp<any, any, any, any, infer P> ? P : {}),
|
|
423
|
+
A extends NavigationProp<any, any, any, any, infer O> ? O : {},
|
|
380
424
|
/**
|
|
381
425
|
* Event consumer config should refer to the config specified in the first type
|
|
382
426
|
* This allows typechecking `addListener`/`removeListener`
|
|
@@ -527,7 +571,11 @@ export type RouteConfig<
|
|
|
527
571
|
* For a given screen name, there will always be only one screen corresponding to an ID.
|
|
528
572
|
* If `undefined` is returned, it acts same as no `getId` being specified.
|
|
529
573
|
*/
|
|
530
|
-
getId?: ({
|
|
574
|
+
getId?: ({
|
|
575
|
+
params,
|
|
576
|
+
}: {
|
|
577
|
+
params: Readonly<ParamList[RouteName]>;
|
|
578
|
+
}) => string | undefined;
|
|
531
579
|
|
|
532
580
|
/**
|
|
533
581
|
* Initial params object for the route.
|
|
@@ -661,16 +709,13 @@ export type TypedNavigator<
|
|
|
661
709
|
) => null;
|
|
662
710
|
};
|
|
663
711
|
|
|
664
|
-
export type NavigatorScreenParams<
|
|
665
|
-
ParamList,
|
|
666
|
-
State extends NavigationState = NavigationState
|
|
667
|
-
> =
|
|
712
|
+
export type NavigatorScreenParams<ParamList extends {}> =
|
|
668
713
|
| {
|
|
669
714
|
screen?: never;
|
|
670
715
|
params?: never;
|
|
671
716
|
initial?: never;
|
|
672
717
|
path?: string;
|
|
673
|
-
state: PartialState<
|
|
718
|
+
state: PartialState<NavigationState> | NavigationState | undefined;
|
|
674
719
|
}
|
|
675
720
|
| {
|
|
676
721
|
[RouteName in keyof ParamList]: undefined extends ParamList[RouteName]
|
|
@@ -691,18 +736,55 @@ export type NavigatorScreenParams<
|
|
|
691
736
|
}[keyof ParamList];
|
|
692
737
|
|
|
693
738
|
export type PathConfig<ParamList extends {}> = {
|
|
739
|
+
/**
|
|
740
|
+
* Path string to match against.
|
|
741
|
+
* e.g. `/users/:id` will match `/users/1` and extract `id` param as `1`.
|
|
742
|
+
*/
|
|
694
743
|
path?: string;
|
|
744
|
+
/**
|
|
745
|
+
* Whether the path should be consider parent paths or use the exact path.
|
|
746
|
+
* By default, paths are relating to the path config on the parent screen.
|
|
747
|
+
* If `exact` is set to `true`, the parent path configuration is not used.
|
|
748
|
+
*/
|
|
695
749
|
exact?: boolean;
|
|
750
|
+
/**
|
|
751
|
+
* An object mapping the param name to a function which parses the param value.
|
|
752
|
+
*
|
|
753
|
+
* @example
|
|
754
|
+
* ```js
|
|
755
|
+
* parse: {
|
|
756
|
+
* id: Number,
|
|
757
|
+
* date: (value) => new Date(value)
|
|
758
|
+
* }
|
|
759
|
+
* ```
|
|
760
|
+
*/
|
|
696
761
|
parse?: Record<string, (value: string) => any>;
|
|
762
|
+
/**
|
|
763
|
+
* An object mapping the param name to a function which converts the param value to a string.
|
|
764
|
+
* By default, all params are converted to strings using `String(value)`.
|
|
765
|
+
*
|
|
766
|
+
* @example
|
|
767
|
+
* ```js
|
|
768
|
+
* stringify: {
|
|
769
|
+
* date: (value) => value.toISOString()
|
|
770
|
+
* }
|
|
771
|
+
* ```
|
|
772
|
+
*/
|
|
697
773
|
stringify?: Record<string, (value: any) => string>;
|
|
774
|
+
/**
|
|
775
|
+
* Path configuration for child screens.
|
|
776
|
+
*/
|
|
698
777
|
screens?: PathConfigMap<ParamList>;
|
|
778
|
+
/**
|
|
779
|
+
* Name of the initial route to use for the navigator when the path matches.
|
|
780
|
+
*/
|
|
699
781
|
initialRouteName?: keyof ParamList;
|
|
700
782
|
};
|
|
701
783
|
|
|
702
784
|
export type PathConfigMap<ParamList extends {}> = {
|
|
703
785
|
[RouteName in keyof ParamList]?: NonNullable<
|
|
704
786
|
ParamList[RouteName]
|
|
705
|
-
> extends NavigatorScreenParams<infer T
|
|
787
|
+
> extends NavigatorScreenParams<infer T>
|
|
706
788
|
? string | PathConfig<T>
|
|
707
789
|
: string | Omit<PathConfig<{}>, 'screens' | 'initialRouteName'>;
|
|
708
790
|
};
|
package/src/useDescriptors.tsx
CHANGED
|
@@ -99,7 +99,9 @@ export default function useDescriptors<
|
|
|
99
99
|
router,
|
|
100
100
|
emitter,
|
|
101
101
|
}: Options<State, ScreenOptions, EventMap>) {
|
|
102
|
-
const [options, setOptions] = React.useState<Record<string,
|
|
102
|
+
const [options, setOptions] = React.useState<Record<string, ScreenOptions>>(
|
|
103
|
+
{}
|
|
104
|
+
);
|
|
103
105
|
const { onDispatchAction, onOptionsChange, stackRef } = React.useContext(
|
|
104
106
|
NavigationBuilderContext
|
|
105
107
|
);
|
|
@@ -177,6 +179,7 @@ export default function useDescriptors<
|
|
|
177
179
|
(acc, curr) =>
|
|
178
180
|
Object.assign(
|
|
179
181
|
acc,
|
|
182
|
+
// @ts-expect-error: we check for function but TS still complains
|
|
180
183
|
typeof curr !== 'function' ? curr : curr({ route, navigation })
|
|
181
184
|
),
|
|
182
185
|
{} as ScreenOptions
|
|
@@ -205,29 +208,31 @@ export default function useDescriptors<
|
|
|
205
208
|
return o;
|
|
206
209
|
});
|
|
207
210
|
|
|
211
|
+
const element = (
|
|
212
|
+
<NavigationBuilderContext.Provider key={route.key} value={context}>
|
|
213
|
+
<NavigationContext.Provider value={navigation}>
|
|
214
|
+
<NavigationRouteContext.Provider value={route}>
|
|
215
|
+
<SceneView
|
|
216
|
+
navigation={navigation}
|
|
217
|
+
route={route}
|
|
218
|
+
screen={screen}
|
|
219
|
+
routeState={state.routes[i].state}
|
|
220
|
+
getState={getState}
|
|
221
|
+
setState={setState}
|
|
222
|
+
options={mergedOptions}
|
|
223
|
+
clearOptions={clearOptions}
|
|
224
|
+
/>
|
|
225
|
+
</NavigationRouteContext.Provider>
|
|
226
|
+
</NavigationContext.Provider>
|
|
227
|
+
</NavigationBuilderContext.Provider>
|
|
228
|
+
);
|
|
229
|
+
|
|
208
230
|
acc[route.key] = {
|
|
209
231
|
route,
|
|
210
232
|
// @ts-expect-error: it's missing action helpers, fix later
|
|
211
233
|
navigation,
|
|
212
234
|
render() {
|
|
213
|
-
return
|
|
214
|
-
<NavigationBuilderContext.Provider key={route.key} value={context}>
|
|
215
|
-
<NavigationContext.Provider value={navigation}>
|
|
216
|
-
<NavigationRouteContext.Provider value={route}>
|
|
217
|
-
<SceneView
|
|
218
|
-
navigation={navigation}
|
|
219
|
-
route={route}
|
|
220
|
-
screen={screen}
|
|
221
|
-
routeState={state.routes[i].state}
|
|
222
|
-
getState={getState}
|
|
223
|
-
setState={setState}
|
|
224
|
-
options={mergedOptions}
|
|
225
|
-
clearOptions={clearOptions}
|
|
226
|
-
/>
|
|
227
|
-
</NavigationRouteContext.Provider>
|
|
228
|
-
</NavigationContext.Provider>
|
|
229
|
-
</NavigationBuilderContext.Provider>
|
|
230
|
-
);
|
|
235
|
+
return element;
|
|
231
236
|
},
|
|
232
237
|
options: mergedOptions as ScreenOptions,
|
|
233
238
|
};
|
|
@@ -63,9 +63,9 @@ type NavigationBuilderOptions<ScreenOptions extends {}> = {
|
|
|
63
63
|
}) => ScreenOptions);
|
|
64
64
|
};
|
|
65
65
|
|
|
66
|
-
type NavigatorRoute
|
|
66
|
+
type NavigatorRoute = {
|
|
67
67
|
key: string;
|
|
68
|
-
params?: NavigatorScreenParams<ParamListBase
|
|
68
|
+
params?: NavigatorScreenParams<ParamListBase>;
|
|
69
69
|
};
|
|
70
70
|
|
|
71
71
|
const isValidKey = (key: unknown) =>
|
|
@@ -153,7 +153,12 @@ const getRouteConfigsFromChildren = <
|
|
|
153
153
|
? `'${
|
|
154
154
|
typeof child.type === 'string' ? child.type : child.type?.name
|
|
155
155
|
}'${
|
|
156
|
-
child.props
|
|
156
|
+
child.props != null &&
|
|
157
|
+
typeof child.props === 'object' &&
|
|
158
|
+
'name' in child.props &&
|
|
159
|
+
child.props?.name
|
|
160
|
+
? ` for the screen '${child.props.name}'`
|
|
161
|
+
: ''
|
|
157
162
|
}`
|
|
158
163
|
: typeof child === 'object'
|
|
159
164
|
? JSON.stringify(child)
|
|
@@ -267,7 +272,7 @@ export default function useNavigationBuilder<
|
|
|
267
272
|
const navigatorKey = useRegisterNavigator();
|
|
268
273
|
|
|
269
274
|
const route = React.useContext(NavigationRouteContext) as
|
|
270
|
-
| NavigatorRoute
|
|
275
|
+
| NavigatorRoute
|
|
271
276
|
| undefined;
|
|
272
277
|
|
|
273
278
|
const { children, screenListeners, ...rest } = options;
|
|
@@ -417,7 +422,7 @@ export default function useNavigationBuilder<
|
|
|
417
422
|
} else {
|
|
418
423
|
return [
|
|
419
424
|
router.getRehydratedState(
|
|
420
|
-
route?.params?.state ??
|
|
425
|
+
(route?.params?.state ?? currentState) as PartialState<State>,
|
|
421
426
|
{
|
|
422
427
|
routeNames,
|
|
423
428
|
routeParamList: initialRouteParamList,
|
|
@@ -13,6 +13,7 @@ import type { NavigationEventEmitter } from './useEventEmitter';
|
|
|
13
13
|
|
|
14
14
|
type Options<
|
|
15
15
|
State extends NavigationState,
|
|
16
|
+
ScreenOptions extends {},
|
|
16
17
|
EventMap extends Record<string, any>
|
|
17
18
|
> = {
|
|
18
19
|
state: State;
|
|
@@ -20,7 +21,9 @@ type Options<
|
|
|
20
21
|
navigation: NavigationHelpers<ParamListBase> &
|
|
21
22
|
Partial<NavigationProp<ParamListBase, string, any, any, any>>;
|
|
22
23
|
setOptions: (
|
|
23
|
-
cb: (
|
|
24
|
+
cb: (
|
|
25
|
+
options: Record<string, ScreenOptions>
|
|
26
|
+
) => Record<string, ScreenOptions>
|
|
24
27
|
) => void;
|
|
25
28
|
router: Router<State, NavigationAction>;
|
|
26
29
|
emitter: NavigationEventEmitter<EventMap>;
|
|
@@ -58,7 +61,7 @@ export default function useNavigationCache<
|
|
|
58
61
|
setOptions,
|
|
59
62
|
router,
|
|
60
63
|
emitter,
|
|
61
|
-
}: Options<State, EventMap>) {
|
|
64
|
+
}: Options<State, ScreenOptions, EventMap>) {
|
|
62
65
|
const { stackRef } = React.useContext(NavigationBuilderContext);
|
|
63
66
|
|
|
64
67
|
// Cache object which holds navigation objects for each screen
|
|
@@ -149,11 +152,12 @@ export default function useNavigationCache<
|
|
|
149
152
|
|
|
150
153
|
return rest.getParent(id);
|
|
151
154
|
},
|
|
152
|
-
setOptions: (options: object) =>
|
|
155
|
+
setOptions: (options: object) => {
|
|
153
156
|
setOptions((o) => ({
|
|
154
157
|
...o,
|
|
155
158
|
[route.key]: { ...o[route.key], ...options },
|
|
156
|
-
}))
|
|
159
|
+
}));
|
|
160
|
+
},
|
|
157
161
|
isFocused: () => {
|
|
158
162
|
const state = getState();
|
|
159
163
|
|
package/src/useOnAction.tsx
CHANGED
|
@@ -7,6 +7,7 @@ import type {
|
|
|
7
7
|
} from '@react-navigation/routers';
|
|
8
8
|
import * as React from 'react';
|
|
9
9
|
|
|
10
|
+
import DeprecatedNavigationInChildContext from './DeprecatedNavigationInChildContext';
|
|
10
11
|
import NavigationBuilderContext, {
|
|
11
12
|
ChildActionListener,
|
|
12
13
|
ChildBeforeRemoveListener,
|
|
@@ -51,6 +52,9 @@ export default function useOnAction({
|
|
|
51
52
|
addListener: addListenerParent,
|
|
52
53
|
onDispatchAction,
|
|
53
54
|
} = React.useContext(NavigationBuilderContext);
|
|
55
|
+
const navigationInChildEnabled = React.useContext(
|
|
56
|
+
DeprecatedNavigationInChildContext
|
|
57
|
+
);
|
|
54
58
|
|
|
55
59
|
const routerConfigOptionsRef =
|
|
56
60
|
React.useRef<RouterConfigOptions>(routerConfigOptions);
|
|
@@ -126,12 +130,15 @@ export default function useOnAction({
|
|
|
126
130
|
}
|
|
127
131
|
}
|
|
128
132
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
133
|
+
if (typeof action.target === 'string' || navigationInChildEnabled) {
|
|
134
|
+
// If the action wasn't handled by current navigator or a parent navigator, let children handle it
|
|
135
|
+
// Handling this when target isn't specified is deprecated and will be removed in the future
|
|
136
|
+
for (let i = actionListeners.length - 1; i >= 0; i--) {
|
|
137
|
+
const listener = actionListeners[i];
|
|
132
138
|
|
|
133
|
-
|
|
134
|
-
|
|
139
|
+
if (listener(action, visitedNavigators)) {
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
135
142
|
}
|
|
136
143
|
}
|
|
137
144
|
|
|
@@ -142,6 +149,7 @@ export default function useOnAction({
|
|
|
142
149
|
beforeRemoveListeners,
|
|
143
150
|
emitter,
|
|
144
151
|
getState,
|
|
152
|
+
navigationInChildEnabled,
|
|
145
153
|
key,
|
|
146
154
|
onActionParent,
|
|
147
155
|
onDispatchAction,
|