@react-navigation/core 6.4.5 → 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/types.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/types.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 -57
- 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 +33 -17
- 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 -40
- package/src/useDescriptors.tsx +24 -19
- package/src/useNavigationBuilder.tsx +26 -5
- package/src/useNavigationCache.tsx +8 -4
- package/src/useNavigationIndependentTree.tsx +7 -0
- package/src/useOnAction.tsx +13 -5
package/src/types.tsx
CHANGED
|
@@ -52,17 +52,6 @@ export type DefaultNavigatorOptions<
|
|
|
52
52
|
route: RouteProp<ParamList>;
|
|
53
53
|
navigation: any;
|
|
54
54
|
}) => ScreenOptions);
|
|
55
|
-
/**
|
|
56
|
-
* Default options specified by the navigator.
|
|
57
|
-
* It receives the custom options in the arguments if a function is specified.
|
|
58
|
-
*/
|
|
59
|
-
defaultScreenOptions?:
|
|
60
|
-
| ScreenOptions
|
|
61
|
-
| ((props: {
|
|
62
|
-
route: RouteProp<ParamList>;
|
|
63
|
-
navigation: any;
|
|
64
|
-
options: ScreenOptions;
|
|
65
|
-
}) => ScreenOptions);
|
|
66
55
|
};
|
|
67
56
|
|
|
68
57
|
export type EventMapBase = Record<
|
|
@@ -182,7 +171,7 @@ type NavigationHelpersCommon<
|
|
|
182
171
|
* @param action Action object or update function.
|
|
183
172
|
*/
|
|
184
173
|
dispatch(
|
|
185
|
-
action: NavigationAction | ((state: State) => NavigationAction)
|
|
174
|
+
action: NavigationAction | ((state: Readonly<State>) => NavigationAction)
|
|
186
175
|
): void;
|
|
187
176
|
|
|
188
177
|
/**
|
|
@@ -192,7 +181,7 @@ type NavigationHelpersCommon<
|
|
|
192
181
|
* @param [params] Params object for the route.
|
|
193
182
|
*/
|
|
194
183
|
navigate<RouteName extends keyof ParamList>(
|
|
195
|
-
...args: //
|
|
184
|
+
...args: // This condition allows us to iterate over a union type
|
|
196
185
|
// This is to avoid getting a union of all the params from `ParamList[RouteName]`,
|
|
197
186
|
// which will get our types all mixed up if a union RouteName is passed in.
|
|
198
187
|
RouteName extends unknown
|
|
@@ -209,18 +198,56 @@ type NavigationHelpersCommon<
|
|
|
209
198
|
/**
|
|
210
199
|
* Navigate to a route in current navigation tree.
|
|
211
200
|
*
|
|
212
|
-
* @param route Object with `
|
|
201
|
+
* @param route Object with `name` for the route to navigate to, and a `params` object.
|
|
213
202
|
*/
|
|
214
203
|
navigate<RouteName extends keyof ParamList>(
|
|
215
204
|
options: RouteName extends unknown
|
|
216
|
-
?
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
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
|
+
}
|
|
224
251
|
: never
|
|
225
252
|
): void;
|
|
226
253
|
|
|
@@ -296,17 +323,25 @@ export type NavigationContainerProps = {
|
|
|
296
323
|
/**
|
|
297
324
|
* Callback which is called with the latest navigation state when it changes.
|
|
298
325
|
*/
|
|
299
|
-
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;
|
|
300
331
|
/**
|
|
301
332
|
* Callback which is called when an action is not handled.
|
|
302
333
|
*/
|
|
303
|
-
onUnhandledAction?: (action: NavigationAction) => void;
|
|
334
|
+
onUnhandledAction?: (action: Readonly<NavigationAction>) => void;
|
|
304
335
|
/**
|
|
305
|
-
* Whether
|
|
306
|
-
*
|
|
307
|
-
*
|
|
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
|
|
308
343
|
*/
|
|
309
|
-
|
|
344
|
+
navigationInChildEnabled?: boolean;
|
|
310
345
|
/**
|
|
311
346
|
* Children elements to render.
|
|
312
347
|
*/
|
|
@@ -346,7 +381,7 @@ export type NavigationProp<
|
|
|
346
381
|
* Update the options for the route.
|
|
347
382
|
* The options object will be shallow merged with default options object.
|
|
348
383
|
*
|
|
349
|
-
* @param
|
|
384
|
+
* @param update Options object or a callback which takes the options from navigator config and returns a new options object.
|
|
350
385
|
*/
|
|
351
386
|
setOptions(options: Partial<ScreenOptions>): void;
|
|
352
387
|
} & EventConsumer<EventMap & EventMapCore<State>> &
|
|
@@ -383,11 +418,9 @@ export type CompositeNavigationProp<
|
|
|
383
418
|
*/
|
|
384
419
|
A extends NavigationProp<any, any, any, infer S> ? S : NavigationState,
|
|
385
420
|
/**
|
|
386
|
-
* Screen options
|
|
387
|
-
* This allows typechecking `setOptions`
|
|
421
|
+
* Screen options should refer to the options specified in the first type
|
|
388
422
|
*/
|
|
389
|
-
|
|
390
|
-
(B extends NavigationProp<any, any, any, any, infer P> ? P : {}),
|
|
423
|
+
A extends NavigationProp<any, any, any, any, infer O> ? O : {},
|
|
391
424
|
/**
|
|
392
425
|
* Event consumer config should refer to the config specified in the first type
|
|
393
426
|
* This allows typechecking `addListener`/`removeListener`
|
|
@@ -538,7 +571,11 @@ export type RouteConfig<
|
|
|
538
571
|
* For a given screen name, there will always be only one screen corresponding to an ID.
|
|
539
572
|
* If `undefined` is returned, it acts same as no `getId` being specified.
|
|
540
573
|
*/
|
|
541
|
-
getId?: ({
|
|
574
|
+
getId?: ({
|
|
575
|
+
params,
|
|
576
|
+
}: {
|
|
577
|
+
params: Readonly<ParamList[RouteName]>;
|
|
578
|
+
}) => string | undefined;
|
|
542
579
|
|
|
543
580
|
/**
|
|
544
581
|
* Initial params object for the route.
|
|
@@ -672,16 +709,13 @@ export type TypedNavigator<
|
|
|
672
709
|
) => null;
|
|
673
710
|
};
|
|
674
711
|
|
|
675
|
-
export type NavigatorScreenParams<
|
|
676
|
-
ParamList,
|
|
677
|
-
State extends NavigationState = NavigationState
|
|
678
|
-
> =
|
|
712
|
+
export type NavigatorScreenParams<ParamList extends {}> =
|
|
679
713
|
| {
|
|
680
714
|
screen?: never;
|
|
681
715
|
params?: never;
|
|
682
716
|
initial?: never;
|
|
683
717
|
path?: string;
|
|
684
|
-
state: PartialState<
|
|
718
|
+
state: PartialState<NavigationState> | NavigationState | undefined;
|
|
685
719
|
}
|
|
686
720
|
| {
|
|
687
721
|
[RouteName in keyof ParamList]: undefined extends ParamList[RouteName]
|
|
@@ -702,18 +736,55 @@ export type NavigatorScreenParams<
|
|
|
702
736
|
}[keyof ParamList];
|
|
703
737
|
|
|
704
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
|
+
*/
|
|
705
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
|
+
*/
|
|
706
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
|
+
*/
|
|
707
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
|
+
*/
|
|
708
773
|
stringify?: Record<string, (value: any) => string>;
|
|
774
|
+
/**
|
|
775
|
+
* Path configuration for child screens.
|
|
776
|
+
*/
|
|
709
777
|
screens?: PathConfigMap<ParamList>;
|
|
778
|
+
/**
|
|
779
|
+
* Name of the initial route to use for the navigator when the path matches.
|
|
780
|
+
*/
|
|
710
781
|
initialRouteName?: keyof ParamList;
|
|
711
782
|
};
|
|
712
783
|
|
|
713
784
|
export type PathConfigMap<ParamList extends {}> = {
|
|
714
785
|
[RouteName in keyof ParamList]?: NonNullable<
|
|
715
786
|
ParamList[RouteName]
|
|
716
|
-
> extends NavigatorScreenParams<infer T
|
|
787
|
+
> extends NavigatorScreenParams<infer T>
|
|
717
788
|
? string | PathConfig<T>
|
|
718
789
|
: string | Omit<PathConfig<{}>, 'screens' | 'initialRouteName'>;
|
|
719
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
|
};
|
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
NavigatorScreenParams,
|
|
29
29
|
PrivateValueStore,
|
|
30
30
|
RouteConfig,
|
|
31
|
+
RouteProp,
|
|
31
32
|
} from './types';
|
|
32
33
|
import useChildListeners from './useChildListeners';
|
|
33
34
|
import useComponent from './useComponent';
|
|
@@ -48,9 +49,23 @@ import useScheduleUpdate from './useScheduleUpdate';
|
|
|
48
49
|
// eslint-disable-next-line babel/no-unused-expressions
|
|
49
50
|
PrivateValueStore;
|
|
50
51
|
|
|
51
|
-
type
|
|
52
|
+
type NavigationBuilderOptions<ScreenOptions extends {}> = {
|
|
53
|
+
/**
|
|
54
|
+
* Default options specified by the navigator.
|
|
55
|
+
* It receives the custom options in the arguments if a function is specified.
|
|
56
|
+
*/
|
|
57
|
+
defaultScreenOptions?:
|
|
58
|
+
| ScreenOptions
|
|
59
|
+
| ((props: {
|
|
60
|
+
route: RouteProp<ParamListBase>;
|
|
61
|
+
navigation: any;
|
|
62
|
+
options: ScreenOptions;
|
|
63
|
+
}) => ScreenOptions);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
type NavigatorRoute = {
|
|
52
67
|
key: string;
|
|
53
|
-
params?: NavigatorScreenParams<ParamListBase
|
|
68
|
+
params?: NavigatorScreenParams<ParamListBase>;
|
|
54
69
|
};
|
|
55
70
|
|
|
56
71
|
const isValidKey = (key: unknown) =>
|
|
@@ -138,7 +153,12 @@ const getRouteConfigsFromChildren = <
|
|
|
138
153
|
? `'${
|
|
139
154
|
typeof child.type === 'string' ? child.type : child.type?.name
|
|
140
155
|
}'${
|
|
141
|
-
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
|
+
: ''
|
|
142
162
|
}`
|
|
143
163
|
: typeof child === 'object'
|
|
144
164
|
? JSON.stringify(child)
|
|
@@ -246,12 +266,13 @@ export default function useNavigationBuilder<
|
|
|
246
266
|
ScreenOptions,
|
|
247
267
|
EventMap
|
|
248
268
|
> &
|
|
269
|
+
NavigationBuilderOptions<ScreenOptions> &
|
|
249
270
|
RouterOptions
|
|
250
271
|
) {
|
|
251
272
|
const navigatorKey = useRegisterNavigator();
|
|
252
273
|
|
|
253
274
|
const route = React.useContext(NavigationRouteContext) as
|
|
254
|
-
| NavigatorRoute
|
|
275
|
+
| NavigatorRoute
|
|
255
276
|
| undefined;
|
|
256
277
|
|
|
257
278
|
const { children, screenListeners, ...rest } = options;
|
|
@@ -401,7 +422,7 @@ export default function useNavigationBuilder<
|
|
|
401
422
|
} else {
|
|
402
423
|
return [
|
|
403
424
|
router.getRehydratedState(
|
|
404
|
-
route?.params?.state ??
|
|
425
|
+
(route?.params?.state ?? currentState) as PartialState<State>,
|
|
405
426
|
{
|
|
406
427
|
routeNames,
|
|
407
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,
|