@react-navigation/core 7.0.0-alpha.8 → 7.0.0-rc.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/lib/commonjs/BaseNavigationContainer.js +18 -19
- package/lib/commonjs/BaseNavigationContainer.js.map +1 -1
- package/lib/commonjs/CurrentRenderContext.js +1 -1
- package/lib/commonjs/CurrentRenderContext.js.map +1 -1
- package/lib/commonjs/DeprecatedNavigationInChildContext.js +1 -1
- package/lib/commonjs/DeprecatedNavigationInChildContext.js.map +1 -1
- package/lib/commonjs/EnsureSingleNavigator.js +4 -5
- package/lib/commonjs/EnsureSingleNavigator.js.map +1 -1
- package/lib/commonjs/Group.js.map +1 -1
- package/lib/commonjs/NavigationBuilderContext.js +1 -1
- package/lib/commonjs/NavigationBuilderContext.js.map +1 -1
- package/lib/commonjs/NavigationContainerRefContext.js +1 -1
- package/lib/commonjs/NavigationContainerRefContext.js.map +1 -1
- package/lib/commonjs/NavigationContext.js +1 -1
- package/lib/commonjs/NavigationContext.js.map +1 -1
- package/lib/commonjs/NavigationHelpersContext.js +1 -1
- package/lib/commonjs/NavigationHelpersContext.js.map +1 -1
- package/lib/commonjs/NavigationIndependentTree.js +4 -5
- package/lib/commonjs/NavigationIndependentTree.js.map +1 -1
- package/lib/commonjs/NavigationIndependentTreeContext.js +1 -1
- package/lib/commonjs/NavigationIndependentTreeContext.js.map +1 -1
- package/lib/commonjs/NavigationRouteContext.js +1 -1
- package/lib/commonjs/NavigationRouteContext.js.map +1 -1
- package/lib/commonjs/NavigationStateContext.js +1 -1
- package/lib/commonjs/NavigationStateContext.js.map +1 -1
- package/lib/commonjs/PreventRemoveContext.js +1 -1
- package/lib/commonjs/PreventRemoveContext.js.map +1 -1
- package/lib/commonjs/PreventRemoveProvider.js +12 -17
- package/lib/commonjs/PreventRemoveProvider.js.map +1 -1
- package/lib/commonjs/SceneView.js +11 -12
- package/lib/commonjs/SceneView.js.map +1 -1
- package/lib/commonjs/Screen.js.map +1 -1
- package/lib/commonjs/StaticContainer.js +1 -1
- package/lib/commonjs/StaticContainer.js.map +1 -1
- package/lib/commonjs/StaticNavigation.js +85 -37
- package/lib/commonjs/StaticNavigation.js.map +1 -1
- package/lib/commonjs/UnhandledActionContext.js +1 -1
- package/lib/commonjs/UnhandledActionContext.js.map +1 -1
- package/lib/commonjs/checkDuplicateRouteNames.js.map +1 -1
- package/lib/commonjs/checkSerializable.js.map +1 -1
- package/lib/commonjs/createNavigationContainerRef.js +2 -6
- package/lib/commonjs/createNavigationContainerRef.js.map +1 -1
- package/lib/commonjs/createNavigatorFactory.js.map +1 -1
- package/lib/commonjs/deepFreeze.js +37 -0
- package/lib/commonjs/deepFreeze.js.map +1 -0
- package/lib/commonjs/findFocusedRoute.js.map +1 -1
- package/lib/commonjs/getActionFromState.js +1 -2
- package/lib/commonjs/getActionFromState.js.map +1 -1
- package/lib/commonjs/getFocusedRouteNameFromRoute.js.map +1 -1
- package/lib/commonjs/getPathFromState.js +8 -14
- package/lib/commonjs/getPathFromState.js.map +1 -1
- package/lib/commonjs/getStateFromPath.js +48 -20
- package/lib/commonjs/getStateFromPath.js.map +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/isArrayEqual.js.map +1 -1
- package/lib/commonjs/isRecordEqual.js.map +1 -1
- package/lib/commonjs/theming/ThemeContext.js +1 -1
- package/lib/commonjs/theming/ThemeContext.js.map +1 -1
- package/lib/commonjs/theming/ThemeProvider.js +5 -6
- package/lib/commonjs/theming/ThemeProvider.js.map +1 -1
- package/lib/commonjs/theming/useTheme.js +1 -1
- package/lib/commonjs/theming/useTheme.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/useChildListeners.js +1 -1
- package/lib/commonjs/useChildListeners.js.map +1 -1
- package/lib/commonjs/useComponent.js +8 -10
- package/lib/commonjs/useComponent.js.map +1 -1
- package/lib/commonjs/useCurrentRender.js +6 -7
- package/lib/commonjs/useCurrentRender.js.map +1 -1
- package/lib/commonjs/useDescriptors.js +16 -17
- package/lib/commonjs/useDescriptors.js.map +1 -1
- package/lib/commonjs/useEventEmitter.js +7 -8
- package/lib/commonjs/useEventEmitter.js.map +1 -1
- package/lib/commonjs/useFocusEffect.js +3 -3
- package/lib/commonjs/useFocusEffect.js.map +1 -1
- package/lib/commonjs/useFocusEvents.js +5 -6
- package/lib/commonjs/useFocusEvents.js.map +1 -1
- package/lib/commonjs/useFocusedListenersChildrenAdapter.js +5 -6
- package/lib/commonjs/useFocusedListenersChildrenAdapter.js.map +1 -1
- package/lib/commonjs/useIsFocused.js +1 -1
- package/lib/commonjs/useIsFocused.js.map +1 -1
- package/lib/commonjs/useIsomorphicLayoutEffect.js.map +1 -1
- package/lib/commonjs/useIsomorphicLayoutEffect.native.js.map +1 -1
- package/lib/commonjs/useKeyedChildListeners.js +1 -1
- package/lib/commonjs/useKeyedChildListeners.js.map +1 -1
- package/lib/commonjs/useLazyValue.js +17 -0
- package/lib/commonjs/useLazyValue.js.map +1 -0
- package/lib/commonjs/useNavigation.js +1 -1
- package/lib/commonjs/useNavigation.js.map +1 -1
- package/lib/commonjs/useNavigationBuilder.js +16 -8
- package/lib/commonjs/useNavigationBuilder.js.map +1 -1
- package/lib/commonjs/useNavigationCache.js +12 -18
- package/lib/commonjs/useNavigationCache.js.map +1 -1
- package/lib/commonjs/useNavigationContainerRef.js +1 -1
- package/lib/commonjs/useNavigationContainerRef.js.map +1 -1
- package/lib/commonjs/useNavigationHelpers.js +9 -12
- package/lib/commonjs/useNavigationHelpers.js.map +1 -1
- package/lib/commonjs/useNavigationIndependentTree.js +1 -1
- package/lib/commonjs/useNavigationIndependentTree.js.map +1 -1
- package/lib/commonjs/useNavigationState.js +1 -1
- package/lib/commonjs/useNavigationState.js.map +1 -1
- package/lib/commonjs/useOnAction.js +12 -14
- package/lib/commonjs/useOnAction.js.map +1 -1
- package/lib/commonjs/useOnGetState.js +5 -6
- package/lib/commonjs/useOnGetState.js.map +1 -1
- package/lib/commonjs/useOnPreventRemove.js +6 -7
- package/lib/commonjs/useOnPreventRemove.js.map +1 -1
- package/lib/commonjs/useOnRouteFocus.js +7 -8
- package/lib/commonjs/useOnRouteFocus.js.map +1 -1
- package/lib/commonjs/useOptionsGetters.js +6 -7
- package/lib/commonjs/useOptionsGetters.js.map +1 -1
- package/lib/commonjs/usePreventRemove.js +2 -2
- package/lib/commonjs/usePreventRemove.js.map +1 -1
- package/lib/commonjs/usePreventRemoveContext.js +1 -1
- package/lib/commonjs/usePreventRemoveContext.js.map +1 -1
- package/lib/commonjs/useRegisterNavigator.js +1 -1
- package/lib/commonjs/useRegisterNavigator.js.map +1 -1
- package/lib/commonjs/useRoute.js +1 -1
- package/lib/commonjs/useRoute.js.map +1 -1
- package/lib/commonjs/useRouteCache.js +16 -2
- package/lib/commonjs/useRouteCache.js.map +1 -1
- package/lib/commonjs/useSyncState.js +13 -4
- package/lib/commonjs/useSyncState.js.map +1 -1
- package/lib/commonjs/validatePathConfig.js +3 -8
- package/lib/commonjs/validatePathConfig.js.map +1 -1
- package/lib/module/BaseNavigationContainer.js +16 -17
- package/lib/module/BaseNavigationContainer.js.map +1 -1
- package/lib/module/CurrentRenderContext.js.map +1 -1
- package/lib/module/DeprecatedNavigationInChildContext.js.map +1 -1
- package/lib/module/EnsureSingleNavigator.js +3 -4
- package/lib/module/EnsureSingleNavigator.js.map +1 -1
- package/lib/module/Group.js.map +1 -1
- package/lib/module/NavigationBuilderContext.js.map +1 -1
- package/lib/module/NavigationContainerRefContext.js.map +1 -1
- package/lib/module/NavigationContext.js.map +1 -1
- package/lib/module/NavigationHelpersContext.js.map +1 -1
- package/lib/module/NavigationIndependentTree.js +3 -4
- package/lib/module/NavigationIndependentTree.js.map +1 -1
- package/lib/module/NavigationIndependentTreeContext.js.map +1 -1
- package/lib/module/NavigationRouteContext.js.map +1 -1
- package/lib/module/NavigationStateContext.js.map +1 -1
- package/lib/module/PreventRemoveContext.js.map +1 -1
- package/lib/module/PreventRemoveProvider.js +10 -15
- package/lib/module/PreventRemoveProvider.js.map +1 -1
- package/lib/module/SceneView.js +10 -11
- package/lib/module/SceneView.js.map +1 -1
- package/lib/module/Screen.js.map +1 -1
- package/lib/module/StaticContainer.js.map +1 -1
- package/lib/module/StaticNavigation.js +84 -36
- package/lib/module/StaticNavigation.js.map +1 -1
- package/lib/module/UnhandledActionContext.js.map +1 -1
- package/lib/module/checkDuplicateRouteNames.js.map +1 -1
- package/lib/module/checkSerializable.js.map +1 -1
- package/lib/module/createNavigationContainerRef.js +2 -6
- package/lib/module/createNavigationContainerRef.js.map +1 -1
- package/lib/module/createNavigatorFactory.js +1 -0
- package/lib/module/createNavigatorFactory.js.map +1 -1
- package/lib/module/deepFreeze.js +29 -0
- package/lib/module/deepFreeze.js.map +1 -0
- package/lib/module/findFocusedRoute.js.map +1 -1
- package/lib/module/getActionFromState.js +1 -2
- package/lib/module/getActionFromState.js.map +1 -1
- package/lib/module/getFocusedRouteNameFromRoute.js.map +1 -1
- package/lib/module/getPathFromState.js +7 -13
- package/lib/module/getPathFromState.js.map +1 -1
- package/lib/module/getStateFromPath.js +46 -18
- package/lib/module/getStateFromPath.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/isArrayEqual.js.map +1 -1
- package/lib/module/isRecordEqual.js.map +1 -1
- package/lib/module/theming/ThemeContext.js.map +1 -1
- package/lib/module/theming/ThemeProvider.js +4 -5
- package/lib/module/theming/ThemeProvider.js.map +1 -1
- package/lib/module/theming/useTheme.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/useChildListeners.js.map +1 -1
- package/lib/module/useComponent.js +7 -9
- package/lib/module/useComponent.js.map +1 -1
- package/lib/module/useCurrentRender.js +5 -6
- package/lib/module/useCurrentRender.js.map +1 -1
- package/lib/module/useDescriptors.js +15 -16
- package/lib/module/useDescriptors.js.map +1 -1
- package/lib/module/useEventEmitter.js +6 -7
- package/lib/module/useEventEmitter.js.map +1 -1
- package/lib/module/useFocusEffect.js +2 -2
- package/lib/module/useFocusEffect.js.map +1 -1
- package/lib/module/useFocusEvents.js +4 -5
- package/lib/module/useFocusEvents.js.map +1 -1
- package/lib/module/useFocusedListenersChildrenAdapter.js +4 -5
- package/lib/module/useFocusedListenersChildrenAdapter.js.map +1 -1
- package/lib/module/useIsFocused.js.map +1 -1
- package/lib/module/useIsomorphicLayoutEffect.js.map +1 -1
- package/lib/module/useIsomorphicLayoutEffect.native.js.map +1 -1
- package/lib/module/useKeyedChildListeners.js.map +1 -1
- package/lib/module/useLazyValue.js +9 -0
- package/lib/module/useLazyValue.js.map +1 -0
- package/lib/module/useNavigation.js.map +1 -1
- package/lib/module/useNavigationBuilder.js +14 -6
- package/lib/module/useNavigationBuilder.js.map +1 -1
- package/lib/module/useNavigationCache.js +11 -17
- package/lib/module/useNavigationCache.js.map +1 -1
- package/lib/module/useNavigationContainerRef.js.map +1 -1
- package/lib/module/useNavigationHelpers.js +8 -11
- package/lib/module/useNavigationHelpers.js.map +1 -1
- package/lib/module/useNavigationIndependentTree.js.map +1 -1
- package/lib/module/useNavigationState.js.map +1 -1
- package/lib/module/useOnAction.js +11 -13
- package/lib/module/useOnAction.js.map +1 -1
- package/lib/module/useOnGetState.js +4 -5
- package/lib/module/useOnGetState.js.map +1 -1
- package/lib/module/useOnPreventRemove.js +5 -6
- package/lib/module/useOnPreventRemove.js.map +1 -1
- package/lib/module/useOnRouteFocus.js +6 -7
- package/lib/module/useOnRouteFocus.js.map +1 -1
- package/lib/module/useOptionsGetters.js +5 -6
- package/lib/module/useOptionsGetters.js.map +1 -1
- package/lib/module/usePreventRemove.js.map +1 -1
- package/lib/module/usePreventRemoveContext.js.map +1 -1
- package/lib/module/useRegisterNavigator.js.map +1 -1
- package/lib/module/useRoute.js.map +1 -1
- package/lib/module/useRouteCache.js +15 -1
- package/lib/module/useRouteCache.js.map +1 -1
- package/lib/module/useSyncState.js +12 -3
- package/lib/module/useSyncState.js.map +1 -1
- package/lib/module/validatePathConfig.js +3 -8
- package/lib/module/validatePathConfig.js.map +1 -1
- package/lib/typescript/src/BaseNavigationContainer.d.ts.map +1 -1
- package/lib/typescript/src/CurrentRenderContext.d.ts +1 -1
- package/lib/typescript/src/CurrentRenderContext.d.ts.map +1 -1
- package/lib/typescript/src/Group.d.ts +1 -1
- package/lib/typescript/src/Group.d.ts.map +1 -1
- package/lib/typescript/src/NavigationBuilderContext.d.ts +5 -5
- package/lib/typescript/src/NavigationBuilderContext.d.ts.map +1 -1
- package/lib/typescript/src/NavigationStateContext.d.ts +3 -19
- package/lib/typescript/src/NavigationStateContext.d.ts.map +1 -1
- package/lib/typescript/src/PreventRemoveContext.d.ts.map +1 -1
- package/lib/typescript/src/Screen.d.ts +1 -1
- package/lib/typescript/src/Screen.d.ts.map +1 -1
- package/lib/typescript/src/StaticNavigation.d.ts +43 -19
- package/lib/typescript/src/StaticNavigation.d.ts.map +1 -1
- package/lib/typescript/src/checkSerializable.d.ts.map +1 -1
- package/lib/typescript/src/createNavigatorFactory.d.ts +1 -9
- package/lib/typescript/src/createNavigatorFactory.d.ts.map +1 -1
- package/lib/typescript/src/deepFreeze.d.ts +3 -0
- package/lib/typescript/src/deepFreeze.d.ts.map +1 -0
- package/lib/typescript/src/findFocusedRoute.d.ts +1 -11
- package/lib/typescript/src/findFocusedRoute.d.ts.map +1 -1
- package/lib/typescript/src/getPathFromState.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +69 -24
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/useChildListeners.d.ts.map +1 -1
- package/lib/typescript/src/useComponent.d.ts.map +1 -1
- package/lib/typescript/src/useDescriptors.d.ts +35 -45
- package/lib/typescript/src/useDescriptors.d.ts.map +1 -1
- package/lib/typescript/src/useKeyedChildListeners.d.ts.map +1 -1
- package/lib/typescript/src/useLazyValue.d.ts +2 -0
- package/lib/typescript/src/useLazyValue.d.ts.map +1 -0
- package/lib/typescript/src/useNavigation.d.ts +4 -1
- package/lib/typescript/src/useNavigation.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationBuilder.d.ts +57 -93
- package/lib/typescript/src/useNavigationBuilder.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationCache.d.ts +17 -22
- package/lib/typescript/src/useNavigationCache.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationHelpers.d.ts +21 -26
- package/lib/typescript/src/useNavigationHelpers.d.ts.map +1 -1
- package/lib/typescript/src/useOnAction.d.ts.map +1 -1
- package/lib/typescript/src/useOnPreventRemove.d.ts.map +1 -1
- package/lib/typescript/src/useRouteCache.d.ts +1 -1
- package/lib/typescript/src/useRouteCache.d.ts.map +1 -1
- package/lib/typescript/src/useSyncState.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/BaseNavigationContainer.tsx +3 -0
- package/src/Group.tsx +2 -1
- package/src/Screen.tsx +11 -1
- package/src/StaticNavigation.tsx +299 -72
- package/src/createNavigatorFactory.tsx +1 -36
- package/src/deepFreeze.tsx +34 -0
- package/src/getPathFromState.tsx +6 -1
- package/src/getStateFromPath.tsx +60 -16
- package/src/index.tsx +1 -0
- package/src/types.tsx +138 -23
- package/src/useDescriptors.tsx +8 -1
- package/src/useFocusEffect.tsx +2 -2
- package/src/useLazyValue.tsx +11 -0
- package/src/useNavigation.tsx +4 -1
- package/src/useNavigationBuilder.tsx +33 -11
- package/src/useRouteCache.tsx +17 -1
- package/src/useSyncState.tsx +16 -3
package/src/types.tsx
CHANGED
|
@@ -24,15 +24,12 @@ type Keyof<T extends {}> = Extract<keyof T, string>;
|
|
|
24
24
|
|
|
25
25
|
export type DefaultNavigatorOptions<
|
|
26
26
|
ParamList extends ParamListBase,
|
|
27
|
+
NavigatorID extends string | undefined,
|
|
27
28
|
State extends NavigationState,
|
|
28
29
|
ScreenOptions extends {},
|
|
29
30
|
EventMap extends EventMapBase,
|
|
31
|
+
Navigation,
|
|
30
32
|
> = DefaultRouterOptions<Keyof<ParamList>> & {
|
|
31
|
-
/**
|
|
32
|
-
* Optional ID for the navigator. Can be used with `navigation.getParent(id)` to refer to a parent.
|
|
33
|
-
*/
|
|
34
|
-
id?: string;
|
|
35
|
-
|
|
36
33
|
/**
|
|
37
34
|
* Children React Elements to extract the route configuration from.
|
|
38
35
|
* Only `Screen`, `Group` and `React.Fragment` are supported as children.
|
|
@@ -71,7 +68,7 @@ export type DefaultNavigatorOptions<
|
|
|
71
68
|
| ScreenListeners<State, EventMap>
|
|
72
69
|
| ((props: {
|
|
73
70
|
route: RouteProp<ParamList>;
|
|
74
|
-
navigation:
|
|
71
|
+
navigation: Navigation;
|
|
75
72
|
}) => ScreenListeners<State, EventMap>);
|
|
76
73
|
|
|
77
74
|
/**
|
|
@@ -81,7 +78,7 @@ export type DefaultNavigatorOptions<
|
|
|
81
78
|
| ScreenOptions
|
|
82
79
|
| ((props: {
|
|
83
80
|
route: RouteProp<ParamList>;
|
|
84
|
-
navigation:
|
|
81
|
+
navigation: Navigation;
|
|
85
82
|
theme: ReactNavigation.Theme;
|
|
86
83
|
}) => ScreenOptions);
|
|
87
84
|
|
|
@@ -90,7 +87,7 @@ export type DefaultNavigatorOptions<
|
|
|
90
87
|
*/
|
|
91
88
|
screenLayout?: (props: {
|
|
92
89
|
route: RouteProp<ParamList, keyof ParamList>;
|
|
93
|
-
navigation:
|
|
90
|
+
navigation: Navigation;
|
|
94
91
|
theme: ReactNavigation.Theme;
|
|
95
92
|
children: React.ReactElement;
|
|
96
93
|
}) => React.ReactElement;
|
|
@@ -98,10 +95,19 @@ export type DefaultNavigatorOptions<
|
|
|
98
95
|
/**
|
|
99
96
|
A function returning a state, which may be set after modifying the routes name.
|
|
100
97
|
*/
|
|
101
|
-
|
|
98
|
+
UNSTABLE_getStateForRouteNamesChange?: (
|
|
102
99
|
state: NavigationState
|
|
103
100
|
) => PartialState<NavigationState> | undefined;
|
|
104
|
-
}
|
|
101
|
+
} & (NavigatorID extends string
|
|
102
|
+
? {
|
|
103
|
+
/**
|
|
104
|
+
* Optional ID for the navigator. Can be used with `navigation.getParent(id)` to refer to a parent.
|
|
105
|
+
*/
|
|
106
|
+
id: NavigatorID;
|
|
107
|
+
}
|
|
108
|
+
: {
|
|
109
|
+
id?: undefined;
|
|
110
|
+
});
|
|
105
111
|
|
|
106
112
|
export type EventMapBase = Record<
|
|
107
113
|
string,
|
|
@@ -555,7 +561,7 @@ export type ScreenListeners<
|
|
|
555
561
|
EventMap extends EventMapBase,
|
|
556
562
|
> = Partial<{
|
|
557
563
|
[EventName in keyof (EventMap & EventMapCore<State>)]: EventListenerCallback<
|
|
558
|
-
EventMap
|
|
564
|
+
EventMap & EventMapCore<State>,
|
|
559
565
|
EventName
|
|
560
566
|
>;
|
|
561
567
|
}>;
|
|
@@ -602,12 +608,13 @@ export type RouteConfigComponent<
|
|
|
602
608
|
getComponent?: never;
|
|
603
609
|
};
|
|
604
610
|
|
|
605
|
-
export type
|
|
611
|
+
export type RouteConfigProps<
|
|
606
612
|
ParamList extends ParamListBase,
|
|
607
613
|
RouteName extends keyof ParamList,
|
|
608
614
|
State extends NavigationState,
|
|
609
615
|
ScreenOptions extends {},
|
|
610
616
|
EventMap extends EventMapBase,
|
|
617
|
+
Navigation,
|
|
611
618
|
> = {
|
|
612
619
|
/**
|
|
613
620
|
* Optional key for this screen. This doesn't need to be unique.
|
|
@@ -628,7 +635,7 @@ export type RouteConfig<
|
|
|
628
635
|
| ScreenOptions
|
|
629
636
|
| ((props: {
|
|
630
637
|
route: RouteProp<ParamList, RouteName>;
|
|
631
|
-
navigation:
|
|
638
|
+
navigation: Navigation;
|
|
632
639
|
theme: ReactNavigation.Theme;
|
|
633
640
|
}) => ScreenOptions);
|
|
634
641
|
|
|
@@ -639,7 +646,7 @@ export type RouteConfig<
|
|
|
639
646
|
| ScreenListeners<State, EventMap>
|
|
640
647
|
| ((props: {
|
|
641
648
|
route: RouteProp<ParamList, RouteName>;
|
|
642
|
-
navigation:
|
|
649
|
+
navigation: Navigation;
|
|
643
650
|
}) => ScreenListeners<State, EventMap>);
|
|
644
651
|
|
|
645
652
|
/**
|
|
@@ -648,8 +655,8 @@ export type RouteConfig<
|
|
|
648
655
|
* e.g. for styling, error boundaries, suspense, etc.
|
|
649
656
|
*/
|
|
650
657
|
layout?: (props: {
|
|
651
|
-
route: RouteProp<ParamList,
|
|
652
|
-
navigation:
|
|
658
|
+
route: RouteProp<ParamList, RouteName>;
|
|
659
|
+
navigation: Navigation;
|
|
653
660
|
theme: ReactNavigation.Theme;
|
|
654
661
|
children: React.ReactElement;
|
|
655
662
|
}) => React.ReactElement;
|
|
@@ -670,11 +677,29 @@ export type RouteConfig<
|
|
|
670
677
|
* Initial params object for the route.
|
|
671
678
|
*/
|
|
672
679
|
initialParams?: Partial<ParamList[RouteName]>;
|
|
673
|
-
}
|
|
680
|
+
};
|
|
681
|
+
|
|
682
|
+
export type RouteConfig<
|
|
683
|
+
ParamList extends ParamListBase,
|
|
684
|
+
RouteName extends keyof ParamList,
|
|
685
|
+
State extends NavigationState,
|
|
686
|
+
ScreenOptions extends {},
|
|
687
|
+
EventMap extends EventMapBase,
|
|
688
|
+
Navigation,
|
|
689
|
+
> = RouteConfigProps<
|
|
690
|
+
ParamList,
|
|
691
|
+
RouteName,
|
|
692
|
+
State,
|
|
693
|
+
ScreenOptions,
|
|
694
|
+
EventMap,
|
|
695
|
+
Navigation
|
|
696
|
+
> &
|
|
697
|
+
RouteConfigComponent<ParamList, RouteName>;
|
|
674
698
|
|
|
675
699
|
export type RouteGroupConfig<
|
|
676
700
|
ParamList extends ParamListBase,
|
|
677
701
|
ScreenOptions extends {},
|
|
702
|
+
Navigation,
|
|
678
703
|
> = {
|
|
679
704
|
/**
|
|
680
705
|
* Optional key for the screens in this group.
|
|
@@ -689,7 +714,7 @@ export type RouteGroupConfig<
|
|
|
689
714
|
| ScreenOptions
|
|
690
715
|
| ((props: {
|
|
691
716
|
route: RouteProp<ParamList, keyof ParamList>;
|
|
692
|
-
navigation:
|
|
717
|
+
navigation: Navigation;
|
|
693
718
|
theme: ReactNavigation.Theme;
|
|
694
719
|
}) => ScreenOptions);
|
|
695
720
|
|
|
@@ -699,7 +724,7 @@ export type RouteGroupConfig<
|
|
|
699
724
|
*/
|
|
700
725
|
screenLayout?: (props: {
|
|
701
726
|
route: RouteProp<ParamList, keyof ParamList>;
|
|
702
|
-
navigation:
|
|
727
|
+
navigation: Navigation;
|
|
703
728
|
theme: ReactNavigation.Theme;
|
|
704
729
|
children: React.ReactElement;
|
|
705
730
|
}) => React.ReactElement;
|
|
@@ -775,6 +800,14 @@ export type NavigationContainerRef<ParamList extends {}> =
|
|
|
775
800
|
* Whether the navigation container is ready to handle actions.
|
|
776
801
|
*/
|
|
777
802
|
isReady(): boolean;
|
|
803
|
+
/**
|
|
804
|
+
* Stub function for setOptions on navigation object for use with useNavigation.
|
|
805
|
+
*/
|
|
806
|
+
setOptions(): never;
|
|
807
|
+
/**
|
|
808
|
+
* Stub function for getParent on navigation object for use with useNavigation.
|
|
809
|
+
*/
|
|
810
|
+
getParent(): undefined;
|
|
778
811
|
};
|
|
779
812
|
|
|
780
813
|
export type NavigationContainerRefWithCurrent<ParamList extends {}> =
|
|
@@ -782,11 +815,77 @@ export type NavigationContainerRefWithCurrent<ParamList extends {}> =
|
|
|
782
815
|
current: NavigationContainerRef<ParamList> | null;
|
|
783
816
|
};
|
|
784
817
|
|
|
818
|
+
export type NavigationListBase<ParamList extends ParamListBase> = {
|
|
819
|
+
[RouteName in keyof ParamList]: unknown;
|
|
820
|
+
};
|
|
821
|
+
|
|
822
|
+
export type TypeBag<
|
|
823
|
+
ParamList extends ParamListBase,
|
|
824
|
+
NavigatorID extends string | undefined,
|
|
825
|
+
State extends NavigationState,
|
|
826
|
+
ScreenOptions extends {},
|
|
827
|
+
EventMap extends EventMapBase,
|
|
828
|
+
NavigationList extends NavigationListBase<ParamList>,
|
|
829
|
+
Navigator extends React.ComponentType<any>,
|
|
830
|
+
> = {
|
|
831
|
+
ParamList: ParamList;
|
|
832
|
+
NavigatorID: NavigatorID;
|
|
833
|
+
State: State;
|
|
834
|
+
ScreenOptions: ScreenOptions;
|
|
835
|
+
EventMap: EventMap;
|
|
836
|
+
NavigationList: NavigationList;
|
|
837
|
+
Navigator: Navigator;
|
|
838
|
+
};
|
|
839
|
+
|
|
840
|
+
export type NavigatorTypeBagBase = {
|
|
841
|
+
ParamList: ParamListBase;
|
|
842
|
+
NavigatorID: string | undefined;
|
|
843
|
+
State: NavigationState;
|
|
844
|
+
ScreenOptions: {};
|
|
845
|
+
EventMap: EventMapBase;
|
|
846
|
+
NavigationList: NavigationListBase<ParamListBase>;
|
|
847
|
+
Navigator: React.ComponentType<any>;
|
|
848
|
+
};
|
|
849
|
+
|
|
850
|
+
export type NavigatorTypeBag<
|
|
851
|
+
ParamList extends ParamListBase,
|
|
852
|
+
NavigatorID extends string | undefined,
|
|
853
|
+
State extends NavigationState,
|
|
854
|
+
ScreenOptions extends {},
|
|
855
|
+
EventMap extends EventMapBase,
|
|
856
|
+
NavigationList extends NavigationListBase<ParamList>,
|
|
857
|
+
Navigator extends React.ComponentType<any>,
|
|
858
|
+
> = {
|
|
859
|
+
ParamList: ParamList;
|
|
860
|
+
NavigatorID: NavigatorID;
|
|
861
|
+
State: State;
|
|
862
|
+
ScreenOptions: ScreenOptions;
|
|
863
|
+
EventMap: EventMap;
|
|
864
|
+
NavigationList: NavigationList;
|
|
865
|
+
Navigator: Navigator;
|
|
866
|
+
};
|
|
867
|
+
|
|
785
868
|
export type TypedNavigator<
|
|
869
|
+
Bag extends NavigatorTypeBagBase,
|
|
870
|
+
Config = unknown,
|
|
871
|
+
> = TypedNavigatorInternal<
|
|
872
|
+
Bag['ParamList'],
|
|
873
|
+
Bag['NavigatorID'],
|
|
874
|
+
Bag['State'],
|
|
875
|
+
Bag['ScreenOptions'],
|
|
876
|
+
Bag['EventMap'],
|
|
877
|
+
Bag['NavigationList'],
|
|
878
|
+
Bag['Navigator']
|
|
879
|
+
> &
|
|
880
|
+
(undefined extends Config ? {} : { config: Config });
|
|
881
|
+
|
|
882
|
+
type TypedNavigatorInternal<
|
|
786
883
|
ParamList extends ParamListBase,
|
|
884
|
+
NavigatorID extends string | undefined,
|
|
787
885
|
State extends NavigationState,
|
|
788
886
|
ScreenOptions extends {},
|
|
789
887
|
EventMap extends EventMapBase,
|
|
888
|
+
NavigationList extends NavigationListBase<ParamList>,
|
|
790
889
|
Navigator extends React.ComponentType<any>,
|
|
791
890
|
> = {
|
|
792
891
|
/**
|
|
@@ -795,19 +894,35 @@ export type TypedNavigator<
|
|
|
795
894
|
Navigator: React.ComponentType<
|
|
796
895
|
Omit<
|
|
797
896
|
React.ComponentProps<Navigator>,
|
|
798
|
-
keyof DefaultNavigatorOptions<any, any, any, any>
|
|
897
|
+
keyof DefaultNavigatorOptions<any, any, any, any, any, any>
|
|
799
898
|
> &
|
|
800
|
-
DefaultNavigatorOptions<
|
|
899
|
+
DefaultNavigatorOptions<
|
|
900
|
+
ParamList,
|
|
901
|
+
NavigatorID,
|
|
902
|
+
State,
|
|
903
|
+
ScreenOptions,
|
|
904
|
+
EventMap,
|
|
905
|
+
NavigationList[keyof ParamList]
|
|
906
|
+
>
|
|
801
907
|
>;
|
|
802
908
|
/**
|
|
803
909
|
* Component used for grouping multiple route configuration.
|
|
804
910
|
*/
|
|
805
|
-
Group: React.ComponentType<
|
|
911
|
+
Group: React.ComponentType<
|
|
912
|
+
RouteGroupConfig<ParamList, ScreenOptions, NavigationList[keyof ParamList]>
|
|
913
|
+
>;
|
|
806
914
|
/**
|
|
807
915
|
* Component used for specifying route configuration.
|
|
808
916
|
*/
|
|
809
917
|
Screen: <RouteName extends keyof ParamList>(
|
|
810
|
-
_: RouteConfig<
|
|
918
|
+
_: RouteConfig<
|
|
919
|
+
ParamList,
|
|
920
|
+
RouteName,
|
|
921
|
+
State,
|
|
922
|
+
ScreenOptions,
|
|
923
|
+
EventMap,
|
|
924
|
+
NavigationList[RouteName]
|
|
925
|
+
>
|
|
811
926
|
) => null;
|
|
812
927
|
};
|
|
813
928
|
|
package/src/useDescriptors.tsx
CHANGED
|
@@ -36,7 +36,14 @@ export type ScreenConfigWithParent<
|
|
|
36
36
|
keys: (string | undefined)[];
|
|
37
37
|
options: (ScreenOptionsOrCallback<ScreenOptions> | undefined)[] | undefined;
|
|
38
38
|
layout: ScreenLayout | undefined;
|
|
39
|
-
props: RouteConfig<
|
|
39
|
+
props: RouteConfig<
|
|
40
|
+
ParamListBase,
|
|
41
|
+
string,
|
|
42
|
+
State,
|
|
43
|
+
ScreenOptions,
|
|
44
|
+
EventMap,
|
|
45
|
+
unknown
|
|
46
|
+
>;
|
|
40
47
|
};
|
|
41
48
|
|
|
42
49
|
type ScreenLayout = (props: {
|
package/src/useFocusEffect.tsx
CHANGED
|
@@ -71,7 +71,7 @@ export function useFocusEffect(effect: EffectCallback) {
|
|
|
71
71
|
}
|
|
72
72
|
};
|
|
73
73
|
|
|
74
|
-
// We need to run the effect on
|
|
74
|
+
// We need to run the effect on initial render/dep changes if the screen is focused
|
|
75
75
|
if (navigation.isFocused()) {
|
|
76
76
|
cleanup = callback();
|
|
77
77
|
isFocused = true;
|
|
@@ -79,7 +79,7 @@ export function useFocusEffect(effect: EffectCallback) {
|
|
|
79
79
|
|
|
80
80
|
const unsubscribeFocus = navigation.addListener('focus', () => {
|
|
81
81
|
// If callback was already called for focus, avoid calling it again
|
|
82
|
-
// The focus event may also fire on
|
|
82
|
+
// The focus event may also fire on initial render, so we guard against running the effect twice
|
|
83
83
|
if (isFocused) {
|
|
84
84
|
return;
|
|
85
85
|
}
|
package/src/useNavigation.tsx
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type NavigationState } from '@react-navigation/routers';
|
|
1
2
|
import * as React from 'react';
|
|
2
3
|
|
|
3
4
|
import { NavigationContainerRefContext } from './NavigationContainerRefContext';
|
|
@@ -10,7 +11,9 @@ import type { NavigationProp } from './types';
|
|
|
10
11
|
* @returns Navigation prop of the parent screen.
|
|
11
12
|
*/
|
|
12
13
|
export function useNavigation<
|
|
13
|
-
T = NavigationProp<ReactNavigation.RootParamList>,
|
|
14
|
+
T = Omit<NavigationProp<ReactNavigation.RootParamList>, 'getState'> & {
|
|
15
|
+
getState(): NavigationState | undefined;
|
|
16
|
+
},
|
|
14
17
|
>(): T {
|
|
15
18
|
const root = React.useContext(NavigationContainerRefContext);
|
|
16
19
|
const navigation = React.useContext(NavigationContext);
|
|
@@ -14,6 +14,7 @@ import * as React from 'react';
|
|
|
14
14
|
import { isValidElementType } from 'react-is';
|
|
15
15
|
import useLatestCallback from 'use-latest-callback';
|
|
16
16
|
|
|
17
|
+
import { deepFreeze } from './deepFreeze';
|
|
17
18
|
import { Group } from './Group';
|
|
18
19
|
import { isArrayEqual } from './isArrayEqual';
|
|
19
20
|
import { isRecordEqual } from './isRecordEqual';
|
|
@@ -39,6 +40,7 @@ import { useFocusedListenersChildrenAdapter } from './useFocusedListenersChildre
|
|
|
39
40
|
import { useFocusEvents } from './useFocusEvents';
|
|
40
41
|
import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect';
|
|
41
42
|
import { useKeyedChildListeners } from './useKeyedChildListeners';
|
|
43
|
+
import { useLazyValue } from './useLazyValue';
|
|
42
44
|
import { useNavigationHelpers } from './useNavigationHelpers';
|
|
43
45
|
import { useOnAction } from './useOnAction';
|
|
44
46
|
import { useOnGetState } from './useOnGetState';
|
|
@@ -102,7 +104,8 @@ const getRouteConfigsFromChildren = <
|
|
|
102
104
|
string,
|
|
103
105
|
State,
|
|
104
106
|
ScreenOptions,
|
|
105
|
-
EventMap
|
|
107
|
+
EventMap,
|
|
108
|
+
unknown
|
|
106
109
|
>,
|
|
107
110
|
});
|
|
108
111
|
|
|
@@ -251,9 +254,11 @@ export function useNavigationBuilder<
|
|
|
251
254
|
createRouter: RouterFactory<State, any, RouterOptions>,
|
|
252
255
|
options: DefaultNavigatorOptions<
|
|
253
256
|
ParamListBase,
|
|
257
|
+
string | undefined,
|
|
254
258
|
State,
|
|
255
259
|
ScreenOptions,
|
|
256
|
-
EventMap
|
|
260
|
+
EventMap,
|
|
261
|
+
any
|
|
257
262
|
> &
|
|
258
263
|
RouterOptions
|
|
259
264
|
) {
|
|
@@ -272,16 +277,27 @@ export function useNavigationBuilder<
|
|
|
272
277
|
...rest
|
|
273
278
|
} = options;
|
|
274
279
|
|
|
275
|
-
const { current: router } = React.useRef<Router<State, any>>(
|
|
276
|
-
createRouter(rest as unknown as RouterOptions)
|
|
277
|
-
);
|
|
278
|
-
|
|
279
280
|
const routeConfigs = getRouteConfigsFromChildren<
|
|
280
281
|
State,
|
|
281
282
|
ScreenOptions,
|
|
282
283
|
EventMap
|
|
283
284
|
>(children);
|
|
284
285
|
|
|
286
|
+
const router = useLazyValue<Router<State, any>>(() => {
|
|
287
|
+
if (
|
|
288
|
+
rest.initialRouteName != null &&
|
|
289
|
+
routeConfigs.every(
|
|
290
|
+
(config) => config.props.name !== rest.initialRouteName
|
|
291
|
+
)
|
|
292
|
+
) {
|
|
293
|
+
throw new Error(
|
|
294
|
+
`Couldn't find a screen named '${rest.initialRouteName}' to use as 'initialRouteName'.`
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
return createRouter(rest as unknown as RouterOptions);
|
|
299
|
+
});
|
|
300
|
+
|
|
285
301
|
const screens = routeConfigs.reduce<
|
|
286
302
|
Record<string, ScreenConfigWithParent<State, ScreenOptions, EventMap>>
|
|
287
303
|
>((acc, config) => {
|
|
@@ -457,7 +473,7 @@ export function useNavigationBuilder<
|
|
|
457
473
|
|
|
458
474
|
let state =
|
|
459
475
|
// If the state isn't initialized, or stale, use the state we initialized instead
|
|
460
|
-
// The state won't update until there's a change needed in the state we have
|
|
476
|
+
// The state won't update until there's a change needed in the state we have initialized locally
|
|
461
477
|
// So it'll be `undefined` or stale until the first navigation event happens
|
|
462
478
|
isStateInitialized(currentState)
|
|
463
479
|
? (currentState as State)
|
|
@@ -470,7 +486,7 @@ export function useNavigationBuilder<
|
|
|
470
486
|
!isRecordEqual(routeKeyList, previousRouteKeyList)
|
|
471
487
|
) {
|
|
472
488
|
const navigatorStateForNextRouteNamesChange =
|
|
473
|
-
options.
|
|
489
|
+
options.UNSTABLE_getStateForRouteNamesChange?.(state);
|
|
474
490
|
// When the list of route names change, the router should handle it to remove invalid routes
|
|
475
491
|
nextState = navigatorStateForNextRouteNamesChange
|
|
476
492
|
? // @ts-expect-error this is ok
|
|
@@ -556,6 +572,10 @@ export function useNavigationBuilder<
|
|
|
556
572
|
state = nextState;
|
|
557
573
|
|
|
558
574
|
React.useEffect(() => {
|
|
575
|
+
// In strict mode, React will double-invoke effects.
|
|
576
|
+
// So we need to reset the flag if component was not unmounted
|
|
577
|
+
stateCleanedUp.current = false;
|
|
578
|
+
|
|
559
579
|
setKey(navigatorKey);
|
|
560
580
|
|
|
561
581
|
if (!getIsInitial()) {
|
|
@@ -578,9 +598,11 @@ export function useNavigationBuilder<
|
|
|
578
598
|
const getState = useLatestCallback((): State => {
|
|
579
599
|
const currentState = shouldUpdate ? nextState : getCurrentState();
|
|
580
600
|
|
|
581
|
-
return (
|
|
582
|
-
isStateInitialized(currentState)
|
|
583
|
-
|
|
601
|
+
return deepFreeze(
|
|
602
|
+
(isStateInitialized(currentState)
|
|
603
|
+
? currentState
|
|
604
|
+
: initializedState) as State
|
|
605
|
+
);
|
|
584
606
|
});
|
|
585
607
|
|
|
586
608
|
const emitter = useEventEmitter<EventMapCore<State>>((e) => {
|
package/src/useRouteCache.tsx
CHANGED
|
@@ -7,7 +7,7 @@ import type { RouteProp } from './types';
|
|
|
7
7
|
type RouteCache = Map<string, RouteProp<ParamListBase>>;
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* Utilities such as `getFocusedRouteNameFromRoute` need to access state.
|
|
11
11
|
* So we need a way to suppress the warning for those use cases.
|
|
12
12
|
* This is fine since they are internal utilities and this is not public API.
|
|
13
13
|
*/
|
|
@@ -41,6 +41,22 @@ export function useRouteCache<State extends NavigationState>(
|
|
|
41
41
|
proxy = routeWithoutState;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
45
|
+
// FIXME: since the state is updated with mutation, the route object cannot be frozen
|
|
46
|
+
// As a workaround, loop through the object and make the properties readonly
|
|
47
|
+
for (const key in proxy) {
|
|
48
|
+
// @ts-expect-error: this is fine since we are looping through the object
|
|
49
|
+
const value = proxy[key];
|
|
50
|
+
|
|
51
|
+
Object.defineProperty(proxy, key, {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
configurable: true,
|
|
54
|
+
writable: false,
|
|
55
|
+
value,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
44
60
|
Object.defineProperty(proxy, CHILD_STATE, {
|
|
45
61
|
enumerable: false,
|
|
46
62
|
configurable: true,
|
package/src/useSyncState.tsx
CHANGED
|
@@ -1,14 +1,27 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
|
|
3
|
+
import { deepFreeze } from './deepFreeze';
|
|
4
|
+
|
|
3
5
|
const createStore = <T,>(getInitialState: () => T) => {
|
|
4
6
|
const listeners: (() => void)[] = [];
|
|
5
7
|
|
|
6
|
-
let
|
|
8
|
+
let initialized = false;
|
|
9
|
+
let state: T;
|
|
10
|
+
|
|
11
|
+
const getState = () => {
|
|
12
|
+
if (initialized) {
|
|
13
|
+
return state;
|
|
14
|
+
}
|
|
7
15
|
|
|
8
|
-
|
|
16
|
+
initialized = true;
|
|
17
|
+
state = deepFreeze(getInitialState());
|
|
18
|
+
|
|
19
|
+
return state;
|
|
20
|
+
};
|
|
9
21
|
|
|
10
22
|
const setState = (newState: T) => {
|
|
11
|
-
state = newState;
|
|
23
|
+
state = deepFreeze(newState);
|
|
24
|
+
|
|
12
25
|
listeners.forEach((listener) => listener());
|
|
13
26
|
};
|
|
14
27
|
|