@react-navigation/core 7.0.0-alpha.4 → 7.0.0-alpha.6
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 +16 -29
- package/lib/commonjs/BaseNavigationContainer.js.map +1 -1
- package/lib/commonjs/CurrentRenderContext.js +3 -4
- package/lib/commonjs/CurrentRenderContext.js.map +1 -1
- package/lib/commonjs/DeprecatedNavigationInChildContext.js +3 -4
- package/lib/commonjs/DeprecatedNavigationInChildContext.js.map +1 -1
- package/lib/commonjs/EnsureSingleNavigator.js +3 -4
- package/lib/commonjs/EnsureSingleNavigator.js.map +1 -1
- package/lib/commonjs/Group.js.map +1 -1
- package/lib/commonjs/NavigationBuilderContext.js +3 -4
- package/lib/commonjs/NavigationBuilderContext.js.map +1 -1
- package/lib/commonjs/NavigationContainerRefContext.js +3 -4
- package/lib/commonjs/NavigationContainerRefContext.js.map +1 -1
- package/lib/commonjs/NavigationContext.js +3 -4
- package/lib/commonjs/NavigationContext.js.map +1 -1
- package/lib/commonjs/NavigationHelpersContext.js +3 -4
- package/lib/commonjs/NavigationHelpersContext.js.map +1 -1
- package/lib/commonjs/NavigationIndependentTree.js +2 -2
- package/lib/commonjs/NavigationIndependentTree.js.map +1 -1
- package/lib/commonjs/NavigationIndependentTreeContext.js +3 -4
- package/lib/commonjs/NavigationIndependentTreeContext.js.map +1 -1
- package/lib/commonjs/NavigationRouteContext.js +3 -4
- package/lib/commonjs/NavigationRouteContext.js.map +1 -1
- package/lib/commonjs/NavigationStateContext.js +3 -4
- package/lib/commonjs/NavigationStateContext.js.map +1 -1
- package/lib/commonjs/PreventRemoveContext.js +8 -4
- package/lib/commonjs/PreventRemoveContext.js.map +1 -1
- package/lib/commonjs/PreventRemoveProvider.js +8 -10
- package/lib/commonjs/PreventRemoveProvider.js.map +1 -1
- package/lib/commonjs/SceneView.js +2 -2
- package/lib/commonjs/SceneView.js.map +1 -1
- package/lib/commonjs/Screen.js.map +1 -1
- package/lib/commonjs/StaticContainer.js +3 -4
- package/lib/commonjs/StaticContainer.js.map +1 -1
- package/lib/commonjs/StaticNavigation.js +27 -3
- package/lib/commonjs/StaticNavigation.js.map +1 -1
- package/lib/commonjs/UnhandledActionContext.js +3 -4
- package/lib/commonjs/UnhandledActionContext.js.map +1 -1
- package/lib/commonjs/checkDuplicateRouteNames.js +1 -2
- package/lib/commonjs/checkDuplicateRouteNames.js.map +1 -1
- package/lib/commonjs/checkSerializable.js.map +1 -1
- package/lib/commonjs/createNavigationContainerRef.js +1 -2
- package/lib/commonjs/createNavigationContainerRef.js.map +1 -1
- package/lib/commonjs/createNavigatorFactory.js +0 -3
- package/lib/commonjs/createNavigatorFactory.js.map +1 -1
- package/lib/commonjs/findFocusedRoute.js +2 -4
- package/lib/commonjs/findFocusedRoute.js.map +1 -1
- package/lib/commonjs/getActionFromState.js +6 -8
- package/lib/commonjs/getActionFromState.js.map +1 -1
- package/lib/commonjs/getFocusedRouteNameFromRoute.js +1 -1
- package/lib/commonjs/getFocusedRouteNameFromRoute.js.map +1 -1
- package/lib/commonjs/getPathFromState.js +15 -19
- package/lib/commonjs/getPathFromState.js.map +1 -1
- package/lib/commonjs/getStateFromPath.js +11 -19
- 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/types.js.map +1 -1
- package/lib/commonjs/useChildListeners.js +2 -2
- package/lib/commonjs/useChildListeners.js.map +1 -1
- package/lib/commonjs/useComponent.js +2 -2
- package/lib/commonjs/useComponent.js.map +1 -1
- package/lib/commonjs/useCurrentRender.js +2 -2
- package/lib/commonjs/useCurrentRender.js.map +1 -1
- package/lib/commonjs/useDescriptors.js +2 -2
- package/lib/commonjs/useDescriptors.js.map +1 -1
- package/lib/commonjs/useEventEmitter.js +5 -6
- package/lib/commonjs/useEventEmitter.js.map +1 -1
- package/lib/commonjs/useFocusEffect.js +4 -2
- package/lib/commonjs/useFocusEffect.js.map +1 -1
- package/lib/commonjs/useFocusEvents.js +4 -4
- package/lib/commonjs/useFocusEvents.js.map +1 -1
- package/lib/commonjs/useFocusedListenersChildrenAdapter.js +3 -3
- package/lib/commonjs/useFocusedListenersChildrenAdapter.js.map +1 -1
- package/lib/commonjs/useIsFocused.js +5 -4
- package/lib/commonjs/useIsFocused.js.map +1 -1
- package/lib/commonjs/useIsomorphicLayoutEffect.js +12 -0
- package/lib/commonjs/useIsomorphicLayoutEffect.js.map +1 -0
- package/lib/commonjs/useIsomorphicLayoutEffect.native.js +9 -0
- package/lib/commonjs/useIsomorphicLayoutEffect.native.js.map +1 -0
- package/lib/commonjs/useKeyedChildListeners.js +2 -2
- package/lib/commonjs/useKeyedChildListeners.js.map +1 -1
- package/lib/commonjs/useNavigation.js +2 -2
- package/lib/commonjs/useNavigation.js.map +1 -1
- package/lib/commonjs/useNavigationBuilder.js +68 -64
- package/lib/commonjs/useNavigationBuilder.js.map +1 -1
- package/lib/commonjs/useNavigationCache.js +2 -2
- package/lib/commonjs/useNavigationCache.js.map +1 -1
- package/lib/commonjs/useNavigationContainerRef.js +2 -2
- package/lib/commonjs/useNavigationContainerRef.js.map +1 -1
- package/lib/commonjs/useNavigationHelpers.js +4 -5
- package/lib/commonjs/useNavigationHelpers.js.map +1 -1
- package/lib/commonjs/useNavigationIndependentTree.js +2 -2
- package/lib/commonjs/useNavigationIndependentTree.js.map +1 -1
- package/lib/commonjs/useNavigationState.js +2 -2
- package/lib/commonjs/useNavigationState.js.map +1 -1
- package/lib/commonjs/useOnAction.js +3 -3
- package/lib/commonjs/useOnAction.js.map +1 -1
- package/lib/commonjs/useOnGetState.js +4 -5
- package/lib/commonjs/useOnGetState.js.map +1 -1
- package/lib/commonjs/useOnPreventRemove.js +5 -6
- package/lib/commonjs/useOnPreventRemove.js.map +1 -1
- package/lib/commonjs/useOnRouteFocus.js +2 -2
- package/lib/commonjs/useOnRouteFocus.js.map +1 -1
- package/lib/commonjs/useOptionsGetters.js +9 -10
- package/lib/commonjs/useOptionsGetters.js.map +1 -1
- package/lib/commonjs/usePreventRemove.js +3 -3
- package/lib/commonjs/usePreventRemove.js.map +1 -1
- package/lib/commonjs/usePreventRemoveContext.js +2 -2
- package/lib/commonjs/usePreventRemoveContext.js.map +1 -1
- package/lib/commonjs/useRegisterNavigator.js +2 -2
- package/lib/commonjs/useRegisterNavigator.js.map +1 -1
- package/lib/commonjs/useRoute.js +2 -2
- package/lib/commonjs/useRoute.js.map +1 -1
- package/lib/commonjs/useRouteCache.js +3 -4
- package/lib/commonjs/useRouteCache.js.map +1 -1
- package/lib/commonjs/useSyncState.js +27 -56
- package/lib/commonjs/useSyncState.js.map +1 -1
- package/lib/commonjs/validatePathConfig.js.map +1 -1
- package/lib/module/BaseNavigationContainer.js +13 -25
- 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.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.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 +6 -8
- package/lib/module/PreventRemoveProvider.js.map +1 -1
- 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 +20 -1
- package/lib/module/StaticNavigation.js.map +1 -1
- package/lib/module/UnhandledActionContext.js.map +1 -1
- package/lib/module/checkDuplicateRouteNames.js +1 -2
- package/lib/module/checkDuplicateRouteNames.js.map +1 -1
- package/lib/module/checkSerializable.js.map +1 -1
- package/lib/module/createNavigationContainerRef.js.map +1 -1
- package/lib/module/createNavigatorFactory.js +0 -3
- package/lib/module/createNavigatorFactory.js.map +1 -1
- package/lib/module/findFocusedRoute.js +2 -4
- package/lib/module/findFocusedRoute.js.map +1 -1
- package/lib/module/getActionFromState.js +6 -8
- package/lib/module/getActionFromState.js.map +1 -1
- package/lib/module/getFocusedRouteNameFromRoute.js +1 -1
- package/lib/module/getFocusedRouteNameFromRoute.js.map +1 -1
- package/lib/module/getPathFromState.js +13 -17
- package/lib/module/getPathFromState.js.map +1 -1
- package/lib/module/getStateFromPath.js +9 -17
- 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/types.js.map +1 -1
- package/lib/module/useChildListeners.js.map +1 -1
- package/lib/module/useComponent.js.map +1 -1
- package/lib/module/useCurrentRender.js.map +1 -1
- package/lib/module/useDescriptors.js.map +1 -1
- package/lib/module/useEventEmitter.js +3 -4
- package/lib/module/useEventEmitter.js.map +1 -1
- package/lib/module/useFocusEffect.js +2 -0
- package/lib/module/useFocusEffect.js.map +1 -1
- package/lib/module/useFocusEvents.js +2 -2
- package/lib/module/useFocusEvents.js.map +1 -1
- package/lib/module/useFocusedListenersChildrenAdapter.js +1 -1
- package/lib/module/useFocusedListenersChildrenAdapter.js.map +1 -1
- package/lib/module/useIsFocused.js.map +1 -1
- package/lib/module/useIsomorphicLayoutEffect.js +7 -0
- package/lib/module/useIsomorphicLayoutEffect.js.map +1 -0
- package/lib/module/useIsomorphicLayoutEffect.native.js +3 -0
- package/lib/module/useIsomorphicLayoutEffect.native.js.map +1 -0
- package/lib/module/useKeyedChildListeners.js.map +1 -1
- package/lib/module/useNavigation.js.map +1 -1
- package/lib/module/useNavigationBuilder.js +65 -62
- package/lib/module/useNavigationBuilder.js.map +1 -1
- package/lib/module/useNavigationCache.js.map +1 -1
- package/lib/module/useNavigationContainerRef.js.map +1 -1
- package/lib/module/useNavigationHelpers.js +2 -3
- 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 +1 -1
- package/lib/module/useOnAction.js.map +1 -1
- package/lib/module/useOnGetState.js +2 -3
- package/lib/module/useOnGetState.js.map +1 -1
- package/lib/module/useOnPreventRemove.js +3 -4
- package/lib/module/useOnPreventRemove.js.map +1 -1
- package/lib/module/useOnRouteFocus.js.map +1 -1
- package/lib/module/useOptionsGetters.js +7 -8
- package/lib/module/useOptionsGetters.js.map +1 -1
- package/lib/module/usePreventRemove.js +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.map +1 -1
- package/lib/module/useSyncState.js +25 -54
- package/lib/module/useSyncState.js.map +1 -1
- package/lib/module/validatePathConfig.js.map +1 -1
- package/lib/typescript/src/BaseNavigationContainer.d.ts +1 -1
- package/lib/typescript/src/BaseNavigationContainer.d.ts.map +1 -1
- package/lib/typescript/src/EnsureSingleNavigator.d.ts +1 -1
- package/lib/typescript/src/EnsureSingleNavigator.d.ts.map +1 -1
- package/lib/typescript/src/NavigationContext.d.ts +1 -17
- package/lib/typescript/src/NavigationContext.d.ts.map +1 -1
- package/lib/typescript/src/NavigationHelpersContext.d.ts +1 -1
- package/lib/typescript/src/NavigationHelpersContext.d.ts.map +1 -1
- package/lib/typescript/src/NavigationIndependentTree.d.ts +1 -1
- package/lib/typescript/src/NavigationIndependentTree.d.ts.map +1 -1
- package/lib/typescript/src/NavigationRouteContext.d.ts +1 -1
- package/lib/typescript/src/NavigationRouteContext.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 +2 -1
- package/lib/typescript/src/SceneView.d.ts.map +1 -1
- package/lib/typescript/src/StaticNavigation.d.ts +1 -1
- package/lib/typescript/src/StaticNavigation.d.ts.map +1 -1
- package/lib/typescript/src/createNavigatorFactory.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 +25 -0
- 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/useDescriptors.d.ts +3 -2
- package/lib/typescript/src/useDescriptors.d.ts.map +1 -1
- package/lib/typescript/src/useFocusEffect.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/useIsomorphicLayoutEffect.d.ts +6 -0
- package/lib/typescript/src/useIsomorphicLayoutEffect.d.ts.map +1 -0
- package/lib/typescript/src/useIsomorphicLayoutEffect.native.d.ts +3 -0
- package/lib/typescript/src/useIsomorphicLayoutEffect.native.d.ts.map +1 -0
- package/lib/typescript/src/useNavigationBuilder.d.ts +38 -4
- package/lib/typescript/src/useNavigationBuilder.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationCache.d.ts +1 -1
- package/lib/typescript/src/useNavigationCache.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationHelpers.d.ts +35 -18
- package/lib/typescript/src/useNavigationHelpers.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/useRouteCache.d.ts +1 -1
- package/lib/typescript/src/useRouteCache.d.ts.map +1 -1
- package/lib/typescript/src/useSyncState.d.ts +1 -4
- package/lib/typescript/src/useSyncState.d.ts.map +1 -1
- package/lib/typescript/utils/usePrevious.d.ts +6 -0
- package/lib/typescript/utils/usePrevious.d.ts.map +1 -0
- package/package.json +13 -13
- package/src/BaseNavigationContainer.tsx +27 -36
- package/src/Group.tsx +1 -1
- package/src/PreventRemoveProvider.tsx +4 -1
- package/src/SceneView.tsx +1 -1
- package/src/Screen.tsx +1 -1
- package/src/StaticNavigation.tsx +7 -7
- package/src/checkDuplicateRouteNames.tsx +1 -1
- package/src/createNavigationContainerRef.tsx +1 -1
- package/src/createNavigatorFactory.tsx +2 -4
- package/src/getActionFromState.tsx +1 -1
- package/src/getPathFromState.tsx +6 -8
- package/src/getStateFromPath.tsx +6 -3
- package/src/index.tsx +2 -2
- package/src/types.tsx +59 -16
- package/src/useDescriptors.tsx +5 -5
- package/src/useFocusEffect.tsx +1 -0
- package/src/useFocusedListenersChildrenAdapter.tsx +2 -2
- package/src/useIsomorphicLayoutEffect.native.tsx +3 -0
- package/src/useIsomorphicLayoutEffect.tsx +7 -0
- package/src/useNavigation.tsx +1 -1
- package/src/useNavigationBuilder.tsx +99 -77
- package/src/useNavigationCache.tsx +7 -7
- package/src/useNavigationContainerRef.tsx +1 -1
- package/src/useNavigationHelpers.tsx +6 -7
- package/src/useOnAction.tsx +2 -2
- package/src/useOnGetState.tsx +1 -1
- package/src/useOnPreventRemove.tsx +1 -1
- package/src/useOptionsGetters.tsx +2 -2
- package/src/useSyncState.tsx +31 -59
- package/lib/commonjs/useScheduleUpdate.js +0 -37
- package/lib/commonjs/useScheduleUpdate.js.map +0 -1
- package/lib/module/useScheduleUpdate.js +0 -27
- package/lib/module/useScheduleUpdate.js.map +0 -1
- package/lib/typescript/src/useScheduleUpdate.d.ts +0 -14
- package/lib/typescript/src/useScheduleUpdate.d.ts.map +0 -1
- package/src/useScheduleUpdate.tsx +0 -32
package/src/StaticNavigation.tsx
CHANGED
|
@@ -49,7 +49,7 @@ type ParamsForScreen<T> = T extends { screen: StaticNavigation<any, any, any> }
|
|
|
49
49
|
? NavigatorScreenParams<StaticParamList<T>> | undefined
|
|
50
50
|
: UnknownToUndefined<ParamsForScreenComponent<T>>;
|
|
51
51
|
|
|
52
|
-
type ParamListForScreens<Screens
|
|
52
|
+
type ParamListForScreens<Screens> = {
|
|
53
53
|
[Key in KeysOf<Screens>]: ParamsForScreen<Screens[Key]>;
|
|
54
54
|
};
|
|
55
55
|
|
|
@@ -65,7 +65,7 @@ type ParamListForGroups<
|
|
|
65
65
|
>;
|
|
66
66
|
};
|
|
67
67
|
}>
|
|
68
|
-
| undefined
|
|
68
|
+
| undefined,
|
|
69
69
|
> = Groups extends {
|
|
70
70
|
[key: string]: {
|
|
71
71
|
screens: StaticConfigScreens<
|
|
@@ -83,7 +83,7 @@ type StaticConfigScreens<
|
|
|
83
83
|
ParamList extends ParamListBase,
|
|
84
84
|
State extends NavigationState,
|
|
85
85
|
ScreenOptions extends {},
|
|
86
|
-
EventMap extends EventMapBase
|
|
86
|
+
EventMap extends EventMapBase,
|
|
87
87
|
> = {
|
|
88
88
|
[key in keyof ParamList]:
|
|
89
89
|
| React.ComponentType<any>
|
|
@@ -129,7 +129,7 @@ type GroupConfig<
|
|
|
129
129
|
ParamList extends ParamListBase,
|
|
130
130
|
State extends NavigationState,
|
|
131
131
|
ScreenOptions extends {},
|
|
132
|
-
EventMap extends EventMapBase
|
|
132
|
+
EventMap extends EventMapBase,
|
|
133
133
|
> = Omit<RouteGroupConfig<ParamList, ScreenOptions>, 'screens' | 'children'> & {
|
|
134
134
|
/**
|
|
135
135
|
* Callback to determine whether the screens in the group should be rendered or not.
|
|
@@ -147,7 +147,7 @@ export type StaticConfig<
|
|
|
147
147
|
State extends NavigationState,
|
|
148
148
|
ScreenOptions extends {},
|
|
149
149
|
EventMap extends EventMapBase,
|
|
150
|
-
Navigator extends React.ComponentType<{}
|
|
150
|
+
Navigator extends React.ComponentType<{}>,
|
|
151
151
|
> = Omit<
|
|
152
152
|
Omit<
|
|
153
153
|
React.ComponentProps<Navigator>,
|
|
@@ -196,7 +196,7 @@ export type StaticParamList<
|
|
|
196
196
|
};
|
|
197
197
|
};
|
|
198
198
|
};
|
|
199
|
-
}
|
|
199
|
+
},
|
|
200
200
|
> = FlatType<
|
|
201
201
|
ParamListForScreens<T['config']['screens']> &
|
|
202
202
|
ParamListForGroups<T['config']['groups']>
|
|
@@ -263,7 +263,7 @@ const getItemsFromScreens = (
|
|
|
263
263
|
);
|
|
264
264
|
}
|
|
265
265
|
|
|
266
|
-
|
|
266
|
+
const element = isNavigator ? (
|
|
267
267
|
React.createElement(component, {})
|
|
268
268
|
) : (
|
|
269
269
|
<MemoizedScreen component={component} />
|
|
@@ -7,7 +7,7 @@ export function checkDuplicateRouteNames(state: NavigationState) {
|
|
|
7
7
|
location: string,
|
|
8
8
|
state: NavigationState | PartialState<NavigationState>
|
|
9
9
|
) => {
|
|
10
|
-
state.routes.forEach((route: typeof state.routes[0]) => {
|
|
10
|
+
state.routes.forEach((route: (typeof state.routes)[0]) => {
|
|
11
11
|
const currentLocation = location
|
|
12
12
|
? `${location} > ${route.name}`
|
|
13
13
|
: route.name;
|
|
@@ -10,7 +10,7 @@ export const NOT_INITIALIZED_ERROR =
|
|
|
10
10
|
"The 'navigation' object hasn't been initialized yet. This might happen if you don't have a navigator mounted, or if the navigator hasn't finished mounting. See https://reactnavigation.org/docs/navigating-without-navigation-prop#handling-initialization for more details.";
|
|
11
11
|
|
|
12
12
|
export function createNavigationContainerRef<
|
|
13
|
-
ParamList extends {} = ReactNavigation.RootParamList
|
|
13
|
+
ParamList extends {} = ReactNavigation.RootParamList,
|
|
14
14
|
>(): NavigationContainerRefWithCurrent<ParamList> {
|
|
15
15
|
const methods = [
|
|
16
16
|
...Object.keys(CommonActions),
|
|
@@ -17,7 +17,7 @@ export function createNavigatorFactory<
|
|
|
17
17
|
State extends NavigationState,
|
|
18
18
|
ScreenOptions extends {},
|
|
19
19
|
EventMap extends EventMapBase,
|
|
20
|
-
NavigatorComponent extends React.ComponentType<any
|
|
20
|
+
NavigatorComponent extends React.ComponentType<any>,
|
|
21
21
|
>(Navigator: NavigatorComponent) {
|
|
22
22
|
function createNavigator<ParamList extends ParamListBase>(): TypedNavigator<
|
|
23
23
|
ParamList,
|
|
@@ -27,7 +27,6 @@ export function createNavigatorFactory<
|
|
|
27
27
|
typeof Navigator
|
|
28
28
|
>;
|
|
29
29
|
|
|
30
|
-
// eslint-disable-next-line no-redeclare
|
|
31
30
|
function createNavigator<
|
|
32
31
|
ParamList extends ParamListBase,
|
|
33
32
|
Config extends StaticConfig<
|
|
@@ -36,7 +35,7 @@ export function createNavigatorFactory<
|
|
|
36
35
|
ScreenOptions,
|
|
37
36
|
EventMap,
|
|
38
37
|
typeof Navigator
|
|
39
|
-
|
|
38
|
+
>,
|
|
40
39
|
>(
|
|
41
40
|
config: Config
|
|
42
41
|
): TypedNavigator<
|
|
@@ -47,7 +46,6 @@ export function createNavigatorFactory<
|
|
|
47
46
|
typeof Navigator
|
|
48
47
|
> & { config: Config };
|
|
49
48
|
|
|
50
|
-
// eslint-disable-next-line no-redeclare
|
|
51
49
|
function createNavigator(config?: any): any {
|
|
52
50
|
if (config != null) {
|
|
53
51
|
return {
|
|
@@ -65,7 +65,7 @@ export function getActionFromState(
|
|
|
65
65
|
let config: ConfigItem | undefined = normalizedConfig?.screens?.[route?.name];
|
|
66
66
|
let params = { ...route.params } as NavigatorScreenParams<ParamListBase>;
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
const payload = route
|
|
69
69
|
? { name: route.name, path: route.path, params }
|
|
70
70
|
: undefined;
|
|
71
71
|
|
package/src/getPathFromState.tsx
CHANGED
|
@@ -99,11 +99,11 @@ export function getPathFromState<ParamList extends {}>(
|
|
|
99
99
|
let pattern: string | undefined;
|
|
100
100
|
|
|
101
101
|
let focusedParams: Record<string, any> | undefined;
|
|
102
|
-
|
|
102
|
+
const focusedRoute = getActiveRoute(state);
|
|
103
103
|
let currentOptions = configs;
|
|
104
104
|
|
|
105
105
|
// Keep all the route names that appeared during going deeper in config in case the pattern is resolved to undefined
|
|
106
|
-
|
|
106
|
+
const nestedRouteNames = [];
|
|
107
107
|
|
|
108
108
|
let hasNext = true;
|
|
109
109
|
|
|
@@ -213,7 +213,7 @@ export function getPathFromState<ParamList extends {}>(
|
|
|
213
213
|
if (route.state) {
|
|
214
214
|
path += '/';
|
|
215
215
|
} else if (focusedParams) {
|
|
216
|
-
for (
|
|
216
|
+
for (const param in focusedParams) {
|
|
217
217
|
if (focusedParams[param] === 'undefined') {
|
|
218
218
|
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
219
219
|
delete focusedParams[param];
|
|
@@ -262,17 +262,15 @@ const createConfigItem = (
|
|
|
262
262
|
return { pattern };
|
|
263
263
|
}
|
|
264
264
|
|
|
265
|
-
// If an object is specified as the value (e.g. Foo: { ... }),
|
|
266
|
-
// It can have `path` property and `screens` prop which has nested configs
|
|
267
|
-
let pattern: string | undefined;
|
|
268
|
-
|
|
269
265
|
if (config.exact && config.path === undefined) {
|
|
270
266
|
throw new Error(
|
|
271
267
|
"A 'path' needs to be specified when specifying 'exact: true'. If you don't want this screen in the URL, specify it as empty string, e.g. `path: ''`."
|
|
272
268
|
);
|
|
273
269
|
}
|
|
274
270
|
|
|
275
|
-
|
|
271
|
+
// If an object is specified as the value (e.g. Foo: { ... }),
|
|
272
|
+
// It can have `path` property and `screens` prop which has nested configs
|
|
273
|
+
const pattern =
|
|
276
274
|
config.exact !== true
|
|
277
275
|
? joinPaths(parentPattern || '', config.path || '')
|
|
278
276
|
: config.path || '';
|
package/src/getStateFromPath.tsx
CHANGED
|
@@ -71,7 +71,7 @@ export function getStateFromPath<ParamList extends {}>(
|
|
|
71
71
|
validatePathConfig(options);
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
|
|
74
|
+
const initialRoutes: InitialRouteConfig[] = [];
|
|
75
75
|
|
|
76
76
|
if (options?.initialRouteName) {
|
|
77
77
|
initialRoutes.push({
|
|
@@ -523,7 +523,6 @@ const createNestedStateObject = (
|
|
|
523
523
|
initialRoutes: InitialRouteConfig[],
|
|
524
524
|
flatConfig?: RouteConfig[]
|
|
525
525
|
) => {
|
|
526
|
-
let state: InitialState;
|
|
527
526
|
let route = routes.shift() as ParsedRoute;
|
|
528
527
|
const parentScreens: string[] = [];
|
|
529
528
|
|
|
@@ -531,7 +530,11 @@ const createNestedStateObject = (
|
|
|
531
530
|
|
|
532
531
|
parentScreens.push(route.name);
|
|
533
532
|
|
|
534
|
-
state = createStateObject(
|
|
533
|
+
const state: InitialState = createStateObject(
|
|
534
|
+
initialRoute,
|
|
535
|
+
route,
|
|
536
|
+
routes.length === 0
|
|
537
|
+
);
|
|
535
538
|
|
|
536
539
|
if (routes.length > 0) {
|
|
537
540
|
let nestedState = state;
|
package/src/index.tsx
CHANGED
|
@@ -15,11 +15,11 @@ export { NavigationRouteContext } from './NavigationRouteContext';
|
|
|
15
15
|
export { PreventRemoveContext } from './PreventRemoveContext';
|
|
16
16
|
export { PreventRemoveProvider } from './PreventRemoveProvider';
|
|
17
17
|
export {
|
|
18
|
+
createComponentForStaticNavigation,
|
|
19
|
+
createPathConfigForStaticNavigation,
|
|
18
20
|
type StaticNavigation,
|
|
19
21
|
type StaticParamList,
|
|
20
22
|
type StaticScreenProps,
|
|
21
|
-
createComponentForStaticNavigation,
|
|
22
|
-
createPathConfigForStaticNavigation,
|
|
23
23
|
} from './StaticNavigation';
|
|
24
24
|
export * from './types';
|
|
25
25
|
export { useFocusEffect } from './useFocusEffect';
|
package/src/types.tsx
CHANGED
|
@@ -23,7 +23,7 @@ export type DefaultNavigatorOptions<
|
|
|
23
23
|
ParamList extends ParamListBase,
|
|
24
24
|
State extends NavigationState,
|
|
25
25
|
ScreenOptions extends {},
|
|
26
|
-
EventMap extends EventMapBase
|
|
26
|
+
EventMap extends EventMapBase,
|
|
27
27
|
> = DefaultRouterOptions<Keyof<ParamList>> & {
|
|
28
28
|
/**
|
|
29
29
|
* Optional ID for the navigator. Can be used with `navigation.getParent(id)` to refer to a parent.
|
|
@@ -34,6 +34,30 @@ export type DefaultNavigatorOptions<
|
|
|
34
34
|
* Only `Screen`, `Group` and `React.Fragment` are supported as children.
|
|
35
35
|
*/
|
|
36
36
|
children: React.ReactNode;
|
|
37
|
+
/**
|
|
38
|
+
* Layout component for the navigator.
|
|
39
|
+
* Useful for wrapping with a component with access to navigator's state and options.
|
|
40
|
+
*/
|
|
41
|
+
layout?: (props: {
|
|
42
|
+
state: State;
|
|
43
|
+
navigation: NavigationHelpers<ParamList>;
|
|
44
|
+
descriptors: Record<
|
|
45
|
+
string,
|
|
46
|
+
Descriptor<
|
|
47
|
+
ScreenOptions,
|
|
48
|
+
NavigationProp<
|
|
49
|
+
ParamList,
|
|
50
|
+
keyof ParamList,
|
|
51
|
+
string | undefined,
|
|
52
|
+
State,
|
|
53
|
+
ScreenOptions,
|
|
54
|
+
EventMap
|
|
55
|
+
>,
|
|
56
|
+
RouteProp<ParamList>
|
|
57
|
+
>
|
|
58
|
+
>;
|
|
59
|
+
children: React.ReactNode;
|
|
60
|
+
}) => React.ReactElement;
|
|
37
61
|
/**
|
|
38
62
|
* Event listeners for all the screens in the navigator.
|
|
39
63
|
*/
|
|
@@ -52,6 +76,12 @@ export type DefaultNavigatorOptions<
|
|
|
52
76
|
route: RouteProp<ParamList>;
|
|
53
77
|
navigation: any;
|
|
54
78
|
}) => ScreenOptions);
|
|
79
|
+
/**
|
|
80
|
+
A function returning a state, which may be set after modifying the routes name.
|
|
81
|
+
*/
|
|
82
|
+
getStateForRouteNamesChange?: (
|
|
83
|
+
state: NavigationState
|
|
84
|
+
) => PartialState<NavigationState> | undefined;
|
|
55
85
|
};
|
|
56
86
|
|
|
57
87
|
export type EventMapBase = Record<
|
|
@@ -69,7 +99,7 @@ export type EventMapCore<State extends NavigationState> = {
|
|
|
69
99
|
export type EventArg<
|
|
70
100
|
EventName extends string,
|
|
71
101
|
CanPreventDefault extends boolean | undefined = false,
|
|
72
|
-
Data = undefined
|
|
102
|
+
Data = undefined,
|
|
73
103
|
> = {
|
|
74
104
|
/**
|
|
75
105
|
* Type of the event (e.g. `focus`, `blur`)
|
|
@@ -94,7 +124,7 @@ export type EventArg<
|
|
|
94
124
|
|
|
95
125
|
export type EventListenerCallback<
|
|
96
126
|
EventMap extends EventMapBase,
|
|
97
|
-
EventName extends keyof EventMap
|
|
127
|
+
EventName extends keyof EventMap,
|
|
98
128
|
> = (
|
|
99
129
|
e: EventArg<
|
|
100
130
|
Extract<EventName, string>,
|
|
@@ -162,7 +192,7 @@ export class PrivateValueStore<T extends [any, any, any]> {
|
|
|
162
192
|
|
|
163
193
|
type NavigationHelpersCommon<
|
|
164
194
|
ParamList extends ParamListBase,
|
|
165
|
-
State extends NavigationState = NavigationState
|
|
195
|
+
State extends NavigationState = NavigationState,
|
|
166
196
|
> = {
|
|
167
197
|
/**
|
|
168
198
|
* Dispatch an action or an update function to the router.
|
|
@@ -297,11 +327,18 @@ type NavigationHelpersCommon<
|
|
|
297
327
|
* Note that this method doesn't re-render screen when the result changes. So don't use it in `render`.
|
|
298
328
|
*/
|
|
299
329
|
getState(): State;
|
|
330
|
+
/**
|
|
331
|
+
* Schedules the given state to be used as navigation state when the list of screens defined in the navigator changes
|
|
332
|
+
* instead of automatically calculating the new state, e.g. due to conditional rendering or dynamically defining screens.
|
|
333
|
+
*
|
|
334
|
+
* @param state Navigation state object.
|
|
335
|
+
*/
|
|
336
|
+
setStateForNextRouteNamesChange(state: PartialState<State> | State): void;
|
|
300
337
|
} & PrivateValueStore<[ParamList, unknown, unknown]>;
|
|
301
338
|
|
|
302
339
|
export type NavigationHelpers<
|
|
303
340
|
ParamList extends ParamListBase,
|
|
304
|
-
EventMap extends EventMapBase = {}
|
|
341
|
+
EventMap extends EventMapBase = {},
|
|
305
342
|
> = NavigationHelpersCommon<ParamList> &
|
|
306
343
|
EventEmitter<EventMap> & {
|
|
307
344
|
/**
|
|
@@ -354,7 +391,7 @@ export type NavigationProp<
|
|
|
354
391
|
NavigatorID extends string | undefined = undefined,
|
|
355
392
|
State extends NavigationState = NavigationState<ParamList>,
|
|
356
393
|
ScreenOptions extends {} = {},
|
|
357
|
-
EventMap extends EventMapBase = {}
|
|
394
|
+
EventMap extends EventMapBase = {},
|
|
358
395
|
> = Omit<NavigationHelpersCommon<ParamList, State>, 'getParent'> & {
|
|
359
396
|
/**
|
|
360
397
|
* Returns the navigation prop from a parent navigator based on the ID.
|
|
@@ -389,12 +426,12 @@ export type NavigationProp<
|
|
|
389
426
|
|
|
390
427
|
export type RouteProp<
|
|
391
428
|
ParamList extends ParamListBase,
|
|
392
|
-
RouteName extends keyof ParamList = Keyof<ParamList
|
|
429
|
+
RouteName extends keyof ParamList = Keyof<ParamList>,
|
|
393
430
|
> = Route<Extract<RouteName, string>, ParamList[RouteName]>;
|
|
394
431
|
|
|
395
432
|
export type CompositeNavigationProp<
|
|
396
433
|
A extends NavigationProp<ParamListBase, string, any, any, any>,
|
|
397
|
-
B extends NavigationHelpersCommon<ParamListBase, any
|
|
434
|
+
B extends NavigationHelpersCommon<ParamListBase, any>,
|
|
398
435
|
> = Omit<A & B, keyof NavigationProp<any>> &
|
|
399
436
|
NavigationProp<
|
|
400
437
|
/**
|
|
@@ -442,7 +479,7 @@ export type CompositeScreenProps<
|
|
|
442
479
|
},
|
|
443
480
|
B extends {
|
|
444
481
|
navigation: NavigationHelpersCommon<any, any>;
|
|
445
|
-
}
|
|
482
|
+
},
|
|
446
483
|
> = {
|
|
447
484
|
navigation: CompositeNavigationProp<A['navigation'], B['navigation']>;
|
|
448
485
|
route: A['route'];
|
|
@@ -451,7 +488,7 @@ export type CompositeScreenProps<
|
|
|
451
488
|
export type Descriptor<
|
|
452
489
|
ScreenOptions extends {},
|
|
453
490
|
Navigation extends NavigationProp<any, any, any, any, any, any>,
|
|
454
|
-
Route extends RouteProp<any, any
|
|
491
|
+
Route extends RouteProp<any, any>,
|
|
455
492
|
> = {
|
|
456
493
|
/**
|
|
457
494
|
* Render the component associated with this route.
|
|
@@ -476,7 +513,7 @@ export type Descriptor<
|
|
|
476
513
|
|
|
477
514
|
export type ScreenListeners<
|
|
478
515
|
State extends NavigationState,
|
|
479
|
-
EventMap extends EventMapBase
|
|
516
|
+
EventMap extends EventMapBase,
|
|
480
517
|
> = Partial<{
|
|
481
518
|
[EventName in keyof (EventMap & EventMapCore<State>)]: EventListenerCallback<
|
|
482
519
|
EventMap,
|
|
@@ -486,7 +523,7 @@ export type ScreenListeners<
|
|
|
486
523
|
|
|
487
524
|
type ScreenComponentType<
|
|
488
525
|
ParamList extends ParamListBase,
|
|
489
|
-
RouteName extends keyof ParamList
|
|
526
|
+
RouteName extends keyof ParamList,
|
|
490
527
|
> =
|
|
491
528
|
| React.ComponentType<{
|
|
492
529
|
route: RouteProp<ParamList, RouteName>;
|
|
@@ -496,7 +533,7 @@ type ScreenComponentType<
|
|
|
496
533
|
|
|
497
534
|
export type RouteConfigComponent<
|
|
498
535
|
ParamList extends ParamListBase,
|
|
499
|
-
RouteName extends keyof ParamList
|
|
536
|
+
RouteName extends keyof ParamList,
|
|
500
537
|
> =
|
|
501
538
|
| {
|
|
502
539
|
/**
|
|
@@ -531,7 +568,7 @@ export type RouteConfig<
|
|
|
531
568
|
RouteName extends keyof ParamList,
|
|
532
569
|
State extends NavigationState,
|
|
533
570
|
ScreenOptions extends {},
|
|
534
|
-
EventMap extends EventMapBase
|
|
571
|
+
EventMap extends EventMapBase,
|
|
535
572
|
> = {
|
|
536
573
|
/**
|
|
537
574
|
* Optional key for this screen. This doesn't need to be unique.
|
|
@@ -585,7 +622,7 @@ export type RouteConfig<
|
|
|
585
622
|
|
|
586
623
|
export type RouteGroupConfig<
|
|
587
624
|
ParamList extends ParamListBase,
|
|
588
|
-
ScreenOptions extends {}
|
|
625
|
+
ScreenOptions extends {},
|
|
589
626
|
> = {
|
|
590
627
|
/**
|
|
591
628
|
* Optional key for the screens in this group.
|
|
@@ -685,7 +722,7 @@ export type TypedNavigator<
|
|
|
685
722
|
State extends NavigationState,
|
|
686
723
|
ScreenOptions extends {},
|
|
687
724
|
EventMap extends EventMapBase,
|
|
688
|
-
Navigator extends React.ComponentType<any
|
|
725
|
+
Navigator extends React.ComponentType<any>,
|
|
689
726
|
> = {
|
|
690
727
|
/**
|
|
691
728
|
* Navigator component which manages the child screens.
|
|
@@ -779,6 +816,12 @@ export type PathConfig<ParamList extends {}> = {
|
|
|
779
816
|
* Name of the initial route to use for the navigator when the path matches.
|
|
780
817
|
*/
|
|
781
818
|
initialRouteName?: keyof ParamList;
|
|
819
|
+
/**
|
|
820
|
+
* A function returning a state, which may be set after modifying the routes name.
|
|
821
|
+
*/
|
|
822
|
+
getStateForRouteNamesChange?: (
|
|
823
|
+
state: NavigationState
|
|
824
|
+
) => PartialState<NavigationState> | undefined;
|
|
782
825
|
};
|
|
783
826
|
|
|
784
827
|
export type PathConfigMap<ParamList extends {}> = {
|
package/src/useDescriptors.tsx
CHANGED
|
@@ -7,8 +7,8 @@ import type {
|
|
|
7
7
|
import * as React from 'react';
|
|
8
8
|
|
|
9
9
|
import {
|
|
10
|
-
AddKeyedListener,
|
|
11
|
-
AddListener,
|
|
10
|
+
type AddKeyedListener,
|
|
11
|
+
type AddListener,
|
|
12
12
|
NavigationBuilderContext,
|
|
13
13
|
} from './NavigationBuilderContext';
|
|
14
14
|
import { NavigationContext } from './NavigationContext';
|
|
@@ -29,7 +29,7 @@ import { useRouteCache } from './useRouteCache';
|
|
|
29
29
|
export type ScreenConfigWithParent<
|
|
30
30
|
State extends NavigationState,
|
|
31
31
|
ScreenOptions extends {},
|
|
32
|
-
EventMap extends EventMapBase
|
|
32
|
+
EventMap extends EventMapBase,
|
|
33
33
|
> = {
|
|
34
34
|
keys: (string | undefined)[];
|
|
35
35
|
options: (ScreenOptionsOrCallback<ScreenOptions> | undefined)[] | undefined;
|
|
@@ -46,7 +46,7 @@ type ScreenOptionsOrCallback<ScreenOptions extends {}> =
|
|
|
46
46
|
type Options<
|
|
47
47
|
State extends NavigationState,
|
|
48
48
|
ScreenOptions extends {},
|
|
49
|
-
EventMap extends EventMapBase
|
|
49
|
+
EventMap extends EventMapBase,
|
|
50
50
|
> = {
|
|
51
51
|
state: State;
|
|
52
52
|
screens: Record<
|
|
@@ -77,7 +77,7 @@ export function useDescriptors<
|
|
|
77
77
|
State extends NavigationState,
|
|
78
78
|
ActionHelpers extends Record<string, () => void>,
|
|
79
79
|
ScreenOptions extends {},
|
|
80
|
-
EventMap extends EventMapBase
|
|
80
|
+
EventMap extends EventMapBase,
|
|
81
81
|
>({
|
|
82
82
|
state,
|
|
83
83
|
screens,
|
package/src/useFocusEffect.tsx
CHANGED
|
@@ -14,6 +14,7 @@ type EffectCallback = () => undefined | void | (() => void);
|
|
|
14
14
|
export function useFocusEffect(effect: EffectCallback) {
|
|
15
15
|
const navigation = useNavigation();
|
|
16
16
|
|
|
17
|
+
// eslint-disable-next-line prefer-rest-params
|
|
17
18
|
if (arguments[1] !== undefined) {
|
|
18
19
|
const message =
|
|
19
20
|
"You passed a second argument to 'useFocusEffect', but it only accepts one argument. " +
|
|
@@ -2,8 +2,8 @@ import type { ParamListBase } from '@react-navigation/routers';
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
|
-
FocusedNavigationCallback,
|
|
6
|
-
FocusedNavigationListener,
|
|
5
|
+
type FocusedNavigationCallback,
|
|
6
|
+
type FocusedNavigationListener,
|
|
7
7
|
NavigationBuilderContext,
|
|
8
8
|
} from './NavigationBuilderContext';
|
|
9
9
|
import type { NavigationHelpers } from './types';
|
package/src/useNavigation.tsx
CHANGED
|
@@ -10,7 +10,7 @@ import type { NavigationProp } from './types';
|
|
|
10
10
|
* @returns Navigation prop of the parent screen.
|
|
11
11
|
*/
|
|
12
12
|
export function useNavigation<
|
|
13
|
-
T = NavigationProp<ReactNavigation.RootParamList
|
|
13
|
+
T = NavigationProp<ReactNavigation.RootParamList>,
|
|
14
14
|
>(): T {
|
|
15
15
|
const root = React.useContext(NavigationContainerRefContext);
|
|
16
16
|
const navigation = React.useContext(NavigationContext);
|