@react-navigation/core 8.0.0-alpha.4 → 8.0.0-alpha.41
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 +17 -14
- package/lib/module/BaseNavigationContainer.js +173 -90
- package/lib/module/BaseNavigationContainer.js.map +1 -1
- package/lib/module/ConsumedParamsContext.js +5 -0
- package/lib/module/ConsumedParamsContext.js.map +1 -0
- package/lib/module/DataLoading.js +129 -0
- package/lib/module/DataLoading.js.map +1 -0
- package/lib/module/NavigationBuilderContext.js +7 -10
- package/lib/module/NavigationBuilderContext.js.map +1 -1
- package/lib/module/NavigationIndependentTree.js +54 -9
- package/lib/module/NavigationIndependentTree.js.map +1 -1
- package/lib/module/NavigationProvider.js +37 -12
- package/lib/module/NavigationProvider.js.map +1 -1
- package/lib/module/NavigationRootContext.js +8 -0
- package/lib/module/NavigationRootContext.js.map +1 -0
- package/lib/module/NavigationStateContext.js +3 -0
- package/lib/module/NavigationStateContext.js.map +1 -1
- package/lib/module/PreventRemoveContext.js.map +1 -1
- package/lib/module/PreventRemoveProvider.js +40 -31
- package/lib/module/PreventRemoveProvider.js.map +1 -1
- package/lib/module/SceneView.js +29 -57
- package/lib/module/SceneView.js.map +1 -1
- package/lib/module/StaticNavigation.js +219 -67
- package/lib/module/StaticNavigation.js.map +1 -1
- package/lib/module/StaticTreeContext.js +5 -0
- package/lib/module/StaticTreeContext.js.map +1 -0
- package/lib/module/createNavigationContainerRef.js +7 -9
- package/lib/module/createNavigationContainerRef.js.map +1 -1
- package/lib/module/createNavigatorFactory.js +27 -5
- package/lib/module/createNavigatorFactory.js.map +1 -1
- package/lib/module/findFocusedRoute.js +7 -4
- package/lib/module/findFocusedRoute.js.map +1 -1
- package/lib/module/getActionFromState.js +45 -20
- package/lib/module/getActionFromState.js.map +1 -1
- package/lib/module/getPathFromState.js +204 -94
- package/lib/module/getPathFromState.js.map +1 -1
- package/lib/module/getPatternParts.js +61 -14
- package/lib/module/getPatternParts.js.map +1 -1
- package/lib/module/getStateFromPath.js +608 -272
- package/lib/module/getStateFromPath.js.map +1 -1
- package/lib/module/getStateFromRouteParams.js +23 -0
- package/lib/module/getStateFromRouteParams.js.map +1 -0
- package/lib/module/index.js +7 -6
- package/lib/module/index.js.map +1 -1
- package/lib/module/internal.js +2 -0
- package/lib/module/internal.js.map +1 -0
- package/lib/module/isRecordEqual.js +1 -1
- package/lib/module/isRecordEqual.js.map +1 -1
- package/lib/module/queryString.js +71 -0
- package/lib/module/queryString.js.map +1 -0
- package/lib/module/theming/useTheme.js +1 -1
- package/lib/module/theming/useTheme.js.map +1 -1
- package/lib/module/types.js +35 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/useDescriptors.js +65 -25
- package/lib/module/useDescriptors.js.map +1 -1
- package/lib/module/useEventEmitter.js +48 -33
- package/lib/module/useEventEmitter.js.map +1 -1
- package/lib/module/useFocusEffect.js +4 -2
- package/lib/module/useFocusEffect.js.map +1 -1
- package/lib/module/useFocusEvents.js +15 -5
- package/lib/module/useFocusEvents.js.map +1 -1
- package/lib/module/useFocusedListenersChildrenAdapter.js +3 -3
- package/lib/module/useFocusedListenersChildrenAdapter.js.map +1 -1
- package/lib/module/useIsFocused.js +8 -12
- package/lib/module/useIsFocused.js.map +1 -1
- package/lib/module/useKeyedChildListeners.js +5 -2
- package/lib/module/useKeyedChildListeners.js.map +1 -1
- package/lib/module/useLazyValue.js.map +1 -1
- package/lib/module/useNavigation.js +4 -17
- package/lib/module/useNavigation.js.map +1 -1
- package/lib/module/useNavigationBuilder.js +244 -147
- package/lib/module/useNavigationBuilder.js.map +1 -1
- package/lib/module/useNavigationCache.js +92 -89
- package/lib/module/useNavigationCache.js.map +1 -1
- package/lib/module/useNavigationHelpers.js +22 -29
- package/lib/module/useNavigationHelpers.js.map +1 -1
- package/lib/module/useNavigationIndependentTree.js +1 -1
- package/lib/module/useNavigationIndependentTree.js.map +1 -1
- package/lib/module/useNavigationState.js +158 -46
- package/lib/module/useNavigationState.js.map +1 -1
- package/lib/module/useOnAction.js +58 -11
- package/lib/module/useOnAction.js.map +1 -1
- package/lib/module/useOnGetNavigation.js +26 -0
- package/lib/module/useOnGetNavigation.js.map +1 -0
- package/lib/module/useOnGetState.js +7 -4
- package/lib/module/useOnGetState.js.map +1 -1
- package/lib/module/useOnPreventRemove.js +40 -31
- package/lib/module/useOnPreventRemove.js.map +1 -1
- package/lib/module/useOnRouteFocus.js +2 -2
- package/lib/module/useOnRouteFocus.js.map +1 -1
- package/lib/module/useOptionsGetters.js +35 -27
- package/lib/module/useOptionsGetters.js.map +1 -1
- package/lib/module/usePreventRemove.js +11 -5
- package/lib/module/usePreventRemove.js.map +1 -1
- package/lib/module/usePreventRemoveContext.js +2 -2
- package/lib/module/usePreventRemoveContext.js.map +1 -1
- package/lib/module/useRegisterNavigator.js +3 -4
- package/lib/module/useRegisterNavigator.js.map +1 -1
- package/lib/module/useRoute.js +2 -0
- package/lib/module/useRoute.js.map +1 -1
- package/lib/module/useRouteCache.js +51 -35
- package/lib/module/useRouteCache.js.map +1 -1
- package/lib/module/useScheduleUpdate.js +12 -10
- package/lib/module/useScheduleUpdate.js.map +1 -1
- package/lib/module/useStateForPath.js +1 -1
- package/lib/module/useStateForPath.js.map +1 -1
- package/lib/module/useSyncState.js +37 -15
- package/lib/module/useSyncState.js.map +1 -1
- package/lib/module/validatePathConfig.js +50 -36
- package/lib/module/validatePathConfig.js.map +1 -1
- package/lib/typescript/src/BaseNavigationContainer.d.ts +6 -3
- package/lib/typescript/src/BaseNavigationContainer.d.ts.map +1 -1
- package/lib/typescript/src/ConsumedParamsContext.d.ts +3 -0
- package/lib/typescript/src/ConsumedParamsContext.d.ts.map +1 -0
- package/lib/typescript/src/DataLoading.d.ts +21 -0
- package/lib/typescript/src/DataLoading.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/Group.d.ts +1 -1
- package/lib/typescript/src/Group.d.ts.map +1 -1
- package/lib/typescript/src/NavigationBuilderContext.d.ts +22 -14
- package/lib/typescript/src/NavigationBuilderContext.d.ts.map +1 -1
- package/lib/typescript/src/NavigationContainerRefContext.d.ts +1 -1
- package/lib/typescript/src/NavigationContainerRefContext.d.ts.map +1 -1
- package/lib/typescript/src/NavigationFocusedRouteStateContext.d.ts +4 -4
- package/lib/typescript/src/NavigationFocusedRouteStateContext.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/NavigationProvider.d.ts +21 -18
- package/lib/typescript/src/NavigationProvider.d.ts.map +1 -1
- package/lib/typescript/src/NavigationRootContext.d.ts +8 -0
- package/lib/typescript/src/NavigationRootContext.d.ts.map +1 -0
- package/lib/typescript/src/NavigationStateContext.d.ts +3 -3
- package/lib/typescript/src/NavigationStateContext.d.ts.map +1 -1
- package/lib/typescript/src/PreventRemoveContext.d.ts +1 -0
- 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 +5 -2
- package/lib/typescript/src/SceneView.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/StaticContainer.d.ts +1 -1
- package/lib/typescript/src/StaticContainer.d.ts.map +1 -1
- package/lib/typescript/src/StaticNavigation.d.ts +189 -111
- package/lib/typescript/src/StaticNavigation.d.ts.map +1 -1
- package/lib/typescript/src/StaticTreeContext.d.ts +4 -0
- package/lib/typescript/src/StaticTreeContext.d.ts.map +1 -0
- package/lib/typescript/src/createNavigationContainerRef.d.ts +1 -1
- package/lib/typescript/src/createNavigationContainerRef.d.ts.map +1 -1
- package/lib/typescript/src/createNavigatorFactory.d.ts +23 -5
- package/lib/typescript/src/createNavigatorFactory.d.ts.map +1 -1
- package/lib/typescript/src/findFocusedRoute.d.ts +3 -8
- package/lib/typescript/src/findFocusedRoute.d.ts.map +1 -1
- package/lib/typescript/src/getActionFromState.d.ts +4 -4
- package/lib/typescript/src/getActionFromState.d.ts.map +1 -1
- package/lib/typescript/src/getPathFromState.d.ts +3 -3
- package/lib/typescript/src/getPathFromState.d.ts.map +1 -1
- package/lib/typescript/src/getPatternParts.d.ts +5 -2
- package/lib/typescript/src/getPatternParts.d.ts.map +1 -1
- package/lib/typescript/src/getStateFromPath.d.ts +4 -7
- package/lib/typescript/src/getStateFromPath.d.ts.map +1 -1
- package/lib/typescript/src/getStateFromRouteParams.d.ts +3 -0
- package/lib/typescript/src/getStateFromRouteParams.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +36 -33
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/internal.d.ts +3 -0
- package/lib/typescript/src/internal.d.ts.map +1 -0
- package/lib/typescript/src/isRecordEqual.d.ts.map +1 -1
- package/lib/typescript/src/queryString.d.ts +5 -0
- package/lib/typescript/src/queryString.d.ts.map +1 -0
- package/lib/typescript/src/theming/ThemeContext.d.ts +1 -1
- package/lib/typescript/src/theming/ThemeContext.d.ts.map +1 -1
- package/lib/typescript/src/theming/ThemeProvider.d.ts +2 -2
- package/lib/typescript/src/theming/ThemeProvider.d.ts.map +1 -1
- package/lib/typescript/src/theming/useTheme.d.ts +1 -1
- package/lib/typescript/src/theming/useTheme.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +265 -167
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/useChildListeners.d.ts +3 -3
- package/lib/typescript/src/useChildListeners.d.ts.map +1 -1
- package/lib/typescript/src/useDescriptors.d.ts +13 -11
- package/lib/typescript/src/useDescriptors.d.ts.map +1 -1
- package/lib/typescript/src/useEventEmitter.d.ts +2 -2
- package/lib/typescript/src/useEventEmitter.d.ts.map +1 -1
- package/lib/typescript/src/useFocusEffect.d.ts.map +1 -1
- package/lib/typescript/src/useFocusEvents.d.ts +2 -2
- package/lib/typescript/src/useFocusEvents.d.ts.map +1 -1
- package/lib/typescript/src/useFocusedListenersChildrenAdapter.d.ts +2 -2
- package/lib/typescript/src/useFocusedListenersChildrenAdapter.d.ts.map +1 -1
- package/lib/typescript/src/useIsFocused.d.ts +4 -0
- package/lib/typescript/src/useIsFocused.d.ts.map +1 -1
- package/lib/typescript/src/useKeyedChildListeners.d.ts +4 -3
- package/lib/typescript/src/useKeyedChildListeners.d.ts.map +1 -1
- package/lib/typescript/src/useLazyValue.d.ts.map +1 -1
- package/lib/typescript/src/useNavigation.d.ts +4 -2
- package/lib/typescript/src/useNavigation.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationBuilder.d.ts +22 -63
- package/lib/typescript/src/useNavigationBuilder.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationCache.d.ts +6 -5
- package/lib/typescript/src/useNavigationCache.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationContainerRef.d.ts +1 -1
- package/lib/typescript/src/useNavigationContainerRef.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationHelpers.d.ts +18 -58
- package/lib/typescript/src/useNavigationHelpers.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationState.d.ts +19 -3
- package/lib/typescript/src/useNavigationState.d.ts.map +1 -1
- package/lib/typescript/src/useOnAction.d.ts +9 -9
- package/lib/typescript/src/useOnAction.d.ts.map +1 -1
- package/lib/typescript/src/useOnGetNavigation.d.ts +12 -0
- package/lib/typescript/src/useOnGetNavigation.d.ts.map +1 -0
- 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 +5 -9
- package/lib/typescript/src/useOnPreventRemove.d.ts.map +1 -1
- package/lib/typescript/src/useOnRouteFocus.d.ts +6 -6
- package/lib/typescript/src/useOnRouteFocus.d.ts.map +1 -1
- package/lib/typescript/src/useOptionsGetters.d.ts +4 -4
- package/lib/typescript/src/useOptionsGetters.d.ts.map +1 -1
- package/lib/typescript/src/usePreventRemove.d.ts.map +1 -1
- package/lib/typescript/src/usePreventRemoveContext.d.ts +2 -1
- package/lib/typescript/src/usePreventRemoveContext.d.ts.map +1 -1
- package/lib/typescript/src/useRegisterNavigator.d.ts.map +1 -1
- package/lib/typescript/src/useRoute.d.ts +7 -3
- package/lib/typescript/src/useRoute.d.ts.map +1 -1
- package/lib/typescript/src/useRouteCache.d.ts +7 -12
- package/lib/typescript/src/useRouteCache.d.ts.map +1 -1
- package/lib/typescript/src/useScheduleUpdate.d.ts +5 -4
- package/lib/typescript/src/useScheduleUpdate.d.ts.map +1 -1
- package/lib/typescript/src/useStateForPath.d.ts +1 -1
- package/lib/typescript/src/useStateForPath.d.ts.map +1 -1
- package/lib/typescript/src/useSyncState.d.ts +1 -0
- package/lib/typescript/src/useSyncState.d.ts.map +1 -1
- package/lib/typescript/src/utilities.d.ts +79 -39
- package/lib/typescript/src/utilities.d.ts.map +1 -1
- package/lib/typescript/src/validatePathConfig.d.ts.map +1 -1
- package/package.json +26 -22
- package/src/BaseNavigationContainer.tsx +459 -332
- package/src/ConsumedParamsContext.tsx +5 -0
- package/src/DataLoading.tsx +206 -0
- package/src/NavigationBuilderContext.tsx +44 -25
- package/src/NavigationFocusedRouteStateContext.tsx +4 -4
- package/src/NavigationIndependentTree.tsx +60 -12
- package/src/NavigationProvider.tsx +59 -21
- package/src/NavigationRootContext.tsx +11 -0
- package/src/NavigationStateContext.tsx +6 -6
- package/src/PreventRemoveContext.tsx +1 -0
- package/src/PreventRemoveProvider.tsx +55 -56
- package/src/SceneView.tsx +31 -57
- package/src/StaticNavigation.tsx +715 -328
- package/src/StaticTreeContext.tsx +7 -0
- package/src/createNavigationContainerRef.tsx +12 -11
- package/src/createNavigatorFactory.tsx +92 -8
- package/src/findFocusedRoute.tsx +16 -16
- package/src/getActionFromState.tsx +87 -51
- package/src/getPathFromState.tsx +310 -134
- package/src/getPatternParts.tsx +98 -16
- package/src/getStateFromPath.tsx +971 -344
- package/src/getStateFromRouteParams.tsx +59 -0
- package/src/index.tsx +57 -6
- package/src/internal.tsx +2 -0
- package/src/isRecordEqual.tsx +3 -1
- package/src/queryString.ts +109 -0
- package/src/theming/useTheme.tsx +1 -1
- package/src/types.tsx +799 -377
- package/src/useDescriptors.tsx +151 -43
- package/src/useEventEmitter.tsx +53 -39
- package/src/useFocusEffect.tsx +5 -2
- package/src/useFocusEvents.tsx +19 -8
- package/src/useFocusedListenersChildrenAdapter.tsx +3 -3
- package/src/useIsFocused.tsx +18 -21
- package/src/useKeyedChildListeners.tsx +5 -2
- package/src/useLazyValue.tsx +2 -2
- package/src/useNavigation.tsx +9 -26
- package/src/useNavigationBuilder.tsx +370 -201
- package/src/useNavigationCache.tsx +148 -123
- package/src/useNavigationHelpers.tsx +27 -37
- package/src/useNavigationIndependentTree.tsx +1 -1
- package/src/useNavigationState.tsx +207 -69
- package/src/useOnAction.tsx +92 -18
- package/src/useOnGetNavigation.tsx +30 -0
- package/src/useOnGetState.tsx +8 -4
- package/src/useOnPreventRemove.tsx +78 -43
- package/src/useOnRouteFocus.tsx +11 -15
- package/src/useOptionsGetters.tsx +44 -30
- package/src/usePreventRemove.tsx +13 -5
- package/src/usePreventRemoveContext.tsx +2 -2
- package/src/useRegisterNavigator.tsx +4 -4
- package/src/useRoute.tsx +20 -6
- package/src/useRouteCache.tsx +57 -35
- package/src/useScheduleUpdate.tsx +13 -11
- package/src/useStateForPath.tsx +1 -1
- package/src/useSyncState.tsx +39 -15
- package/src/utilities.tsx +151 -35
- package/src/validatePathConfig.tsx +86 -57
- package/lib/module/CurrentRenderContext.js +0 -10
- package/lib/module/CurrentRenderContext.js.map +0 -1
- package/lib/module/NavigationMetaContext.js +0 -15
- package/lib/module/NavigationMetaContext.js.map +0 -1
- package/lib/module/checkSerializable.js +0 -46
- package/lib/module/checkSerializable.js.map +0 -1
- package/lib/module/useComponent.js +0 -34
- package/lib/module/useComponent.js.map +0 -1
- package/lib/module/useCurrentRender.js +0 -19
- package/lib/module/useCurrentRender.js.map +0 -1
- package/lib/typescript/src/CurrentRenderContext.d.ts +0 -9
- package/lib/typescript/src/CurrentRenderContext.d.ts.map +0 -1
- package/lib/typescript/src/NavigationMetaContext.d.ts +0 -12
- package/lib/typescript/src/NavigationMetaContext.d.ts.map +0 -1
- package/lib/typescript/src/checkSerializable.d.ts +0 -10
- package/lib/typescript/src/checkSerializable.d.ts.map +0 -1
- package/lib/typescript/src/useComponent.d.ts +0 -7
- package/lib/typescript/src/useComponent.d.ts.map +0 -1
- package/lib/typescript/src/useCurrentRender.d.ts +0 -14
- package/lib/typescript/src/useCurrentRender.d.ts.map +0 -1
- package/src/CurrentRenderContext.tsx +0 -9
- package/src/NavigationMetaContext.tsx +0 -14
- package/src/checkSerializable.tsx +0 -74
- package/src/useComponent.tsx +0 -37
- package/src/useCurrentRender.tsx +0 -31
|
@@ -19,17 +19,17 @@ export function createNavigationContainerRef<
|
|
|
19
19
|
'removeListener',
|
|
20
20
|
'resetRoot',
|
|
21
21
|
'dispatch',
|
|
22
|
-
'isFocused',
|
|
23
22
|
'canGoBack',
|
|
24
23
|
'getRootState',
|
|
25
24
|
'getState',
|
|
26
|
-
'getParent',
|
|
27
25
|
'getCurrentRoute',
|
|
28
26
|
'getCurrentOptions',
|
|
29
27
|
] as const;
|
|
30
28
|
|
|
31
29
|
const listeners: Record<string, ((...args: any[]) => void)[]> = {};
|
|
32
30
|
|
|
31
|
+
let current: NavigationContainerRef<ParamList> | null = null;
|
|
32
|
+
|
|
33
33
|
const removeListener = (
|
|
34
34
|
event: string,
|
|
35
35
|
callback: (...args: any[]) => void
|
|
@@ -37,9 +37,12 @@ export function createNavigationContainerRef<
|
|
|
37
37
|
if (listeners[event]) {
|
|
38
38
|
listeners[event] = listeners[event].filter((cb) => cb !== callback);
|
|
39
39
|
}
|
|
40
|
-
};
|
|
41
40
|
|
|
42
|
-
|
|
41
|
+
current?.removeListener(
|
|
42
|
+
event as keyof NavigationContainerEventMap,
|
|
43
|
+
callback
|
|
44
|
+
);
|
|
45
|
+
};
|
|
43
46
|
|
|
44
47
|
const ref: NavigationContainerRefWithCurrent<ParamList> = {
|
|
45
48
|
get current() {
|
|
@@ -68,7 +71,11 @@ export function createNavigationContainerRef<
|
|
|
68
71
|
},
|
|
69
72
|
...methods.reduce<any>((acc, name) => {
|
|
70
73
|
acc[name] = (...args: any[]) => {
|
|
71
|
-
if (
|
|
74
|
+
if (name === 'removeListener') {
|
|
75
|
+
const [event, callback] = args;
|
|
76
|
+
|
|
77
|
+
removeListener(event, callback);
|
|
78
|
+
} else if (current == null) {
|
|
72
79
|
switch (name) {
|
|
73
80
|
case 'addListener': {
|
|
74
81
|
const [event, callback] = args;
|
|
@@ -78,12 +85,6 @@ export function createNavigationContainerRef<
|
|
|
78
85
|
|
|
79
86
|
return () => removeListener(event, callback);
|
|
80
87
|
}
|
|
81
|
-
case 'removeListener': {
|
|
82
|
-
const [event, callback] = args;
|
|
83
|
-
|
|
84
|
-
removeListener(event, callback);
|
|
85
|
-
break;
|
|
86
|
-
}
|
|
87
88
|
default:
|
|
88
89
|
console.error(NOT_INITIALIZED_ERROR);
|
|
89
90
|
}
|
|
@@ -1,23 +1,107 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type { ParamListBase } from '@react-navigation/routers';
|
|
2
|
+
import * as React from 'react';
|
|
2
3
|
|
|
3
4
|
import { Group } from './Group';
|
|
4
5
|
import { Screen } from './Screen';
|
|
6
|
+
import {
|
|
7
|
+
createComponentForStaticConfig,
|
|
8
|
+
type NoExcessStaticConfig,
|
|
9
|
+
type StaticConfig,
|
|
10
|
+
type StaticParamList,
|
|
11
|
+
} from './StaticNavigation';
|
|
12
|
+
import type {
|
|
13
|
+
NavigatorTypeBagBase,
|
|
14
|
+
NavigatorTypeBagFor,
|
|
15
|
+
NestedNavigatorsForParamList,
|
|
16
|
+
TypedNavigator,
|
|
17
|
+
} from './types';
|
|
18
|
+
import type { KeysOf, NoExcessObject } from './utilities';
|
|
19
|
+
|
|
20
|
+
type NavigatorNesting<ParamList extends ParamListBase, Nesting> = {
|
|
21
|
+
[RouteName in keyof ParamList]?: unknown;
|
|
22
|
+
} & Record<Exclude<KeysOf<Nesting>, keyof ParamList>, never>;
|
|
23
|
+
|
|
24
|
+
type ValidNavigatorNesting<ParamList extends ParamListBase, Nesting> =
|
|
25
|
+
Nesting extends NavigatorNesting<ParamList, Nesting> ? Nesting : never;
|
|
26
|
+
|
|
27
|
+
type AnyStaticConfig<TypeBag extends NavigatorTypeBagBase> = StaticConfig<
|
|
28
|
+
NavigatorTypeBagFor<TypeBag, ParamListBase>
|
|
29
|
+
>;
|
|
30
|
+
|
|
31
|
+
export type TypedNavigatorFactory<in out TypeBag extends NavigatorTypeBagBase> =
|
|
32
|
+
{
|
|
33
|
+
<
|
|
34
|
+
const ParamList extends ParamListBase,
|
|
35
|
+
const Nesting extends NavigatorNesting<ParamList, Nesting> =
|
|
36
|
+
ValidNavigatorNesting<
|
|
37
|
+
ParamList,
|
|
38
|
+
NestedNavigatorsForParamList<ParamList>
|
|
39
|
+
>,
|
|
40
|
+
>(): TypedNavigator<
|
|
41
|
+
NavigatorTypeBagFor<TypeBag, ParamList>,
|
|
42
|
+
undefined,
|
|
43
|
+
Nesting
|
|
44
|
+
>;
|
|
45
|
+
<
|
|
46
|
+
const Config extends AnyStaticConfig<TypeBag> &
|
|
47
|
+
NoExcessObject<Config, AnyStaticConfig<TypeBag>>,
|
|
48
|
+
>(
|
|
49
|
+
config: Config & NoExcessStaticConfig<NoInfer<Config>, TypeBag>
|
|
50
|
+
): TypedNavigator<
|
|
51
|
+
NavigatorTypeBagFor<TypeBag, StaticParamList<{ config: Config }>>,
|
|
52
|
+
Config
|
|
53
|
+
>;
|
|
54
|
+
};
|
|
5
55
|
|
|
6
56
|
/**
|
|
7
|
-
* Higher order
|
|
8
|
-
*
|
|
57
|
+
* Higher order function to create a navigator factory
|
|
58
|
+
* A navigator factory creates a navigator:
|
|
59
|
+
* - `Navigator` and `Screen` pairs for dynamic configuration
|
|
60
|
+
* - Static navigator object for static configuration
|
|
9
61
|
*
|
|
10
62
|
* @param Navigator The navigator component to wrap.
|
|
11
|
-
* @returns Factory method to create a
|
|
63
|
+
* @returns Factory method to create a navigator
|
|
12
64
|
*/
|
|
13
|
-
export function createNavigatorFactory
|
|
65
|
+
export function createNavigatorFactory<TypeBag extends NavigatorTypeBagBase>(
|
|
66
|
+
Navigator: React.ComponentType<any>
|
|
67
|
+
): TypedNavigatorFactory<TypeBag> {
|
|
68
|
+
const displayName = Navigator.displayName ?? Navigator.name ?? 'Navigator';
|
|
69
|
+
|
|
14
70
|
function createNavigator(config?: any): any {
|
|
15
71
|
if (config != null) {
|
|
72
|
+
const NavigatorComponent = createComponentForStaticConfig(
|
|
73
|
+
{
|
|
74
|
+
Navigator,
|
|
75
|
+
Screen,
|
|
76
|
+
Group,
|
|
77
|
+
config,
|
|
78
|
+
},
|
|
79
|
+
displayName
|
|
80
|
+
);
|
|
81
|
+
|
|
16
82
|
return {
|
|
17
|
-
Navigator,
|
|
18
|
-
Screen,
|
|
19
|
-
Group,
|
|
20
83
|
config,
|
|
84
|
+
with(
|
|
85
|
+
DecoratorComponent: React.ComponentType<{
|
|
86
|
+
Navigator: React.ComponentType<any>;
|
|
87
|
+
}>
|
|
88
|
+
) {
|
|
89
|
+
const WithComponent = () => {
|
|
90
|
+
return React.createElement(DecoratorComponent, {
|
|
91
|
+
Navigator: NavigatorComponent,
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
WithComponent.displayName = `${displayName}With`;
|
|
96
|
+
|
|
97
|
+
return {
|
|
98
|
+
config,
|
|
99
|
+
getComponent: () => WithComponent,
|
|
100
|
+
};
|
|
101
|
+
},
|
|
102
|
+
getComponent() {
|
|
103
|
+
return NavigatorComponent;
|
|
104
|
+
},
|
|
21
105
|
};
|
|
22
106
|
}
|
|
23
107
|
|
package/src/findFocusedRoute.tsx
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { NavigationState, PartialState } from '@react-navigation/routers';
|
|
2
2
|
|
|
3
|
-
type
|
|
4
|
-
| {
|
|
5
|
-
key?: string;
|
|
6
|
-
name: string;
|
|
7
|
-
params?: object;
|
|
8
|
-
path?: string;
|
|
9
|
-
}
|
|
10
|
-
| undefined;
|
|
3
|
+
type State = NavigationState | PartialState<NavigationState>;
|
|
11
4
|
|
|
12
|
-
export function findFocusedRoute(
|
|
13
|
-
|
|
5
|
+
export function findFocusedRoute(
|
|
6
|
+
state: State
|
|
7
|
+
): State['routes'][number] | undefined {
|
|
8
|
+
let current: State | undefined = state;
|
|
14
9
|
|
|
15
|
-
while (current
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
while (current != null) {
|
|
11
|
+
const route: State['routes'][number] | undefined =
|
|
12
|
+
current.routes[current.index ?? current.routes.length - 1];
|
|
18
13
|
|
|
19
|
-
|
|
14
|
+
if (route?.state == null) {
|
|
15
|
+
return route;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
current = route.state;
|
|
19
|
+
}
|
|
20
20
|
|
|
21
|
-
return
|
|
21
|
+
return undefined;
|
|
22
22
|
}
|
|
@@ -2,20 +2,18 @@ import type {
|
|
|
2
2
|
CommonActions,
|
|
3
3
|
NavigationState,
|
|
4
4
|
ParamListBase,
|
|
5
|
-
PartialRoute,
|
|
6
5
|
PartialState,
|
|
7
|
-
Route,
|
|
8
6
|
} from '@react-navigation/routers';
|
|
9
7
|
|
|
10
8
|
import type { NavigatorScreenParams, PathConfig, PathConfigMap } from './types';
|
|
11
9
|
|
|
12
10
|
type ConfigItem = {
|
|
13
|
-
initialRouteName?: string;
|
|
14
|
-
screens?: Record<string, ConfigItem
|
|
11
|
+
initialRouteName?: string | undefined;
|
|
12
|
+
screens?: Record<string, ConfigItem> | undefined;
|
|
15
13
|
};
|
|
16
14
|
|
|
17
15
|
type Options = {
|
|
18
|
-
initialRouteName?: string;
|
|
16
|
+
initialRouteName?: string | undefined;
|
|
19
17
|
screens: PathConfigMap<object>;
|
|
20
18
|
};
|
|
21
19
|
|
|
@@ -23,34 +21,60 @@ type NavigateAction<State extends NavigationState> = {
|
|
|
23
21
|
type: 'NAVIGATE';
|
|
24
22
|
payload: {
|
|
25
23
|
name: string;
|
|
26
|
-
params?: NavigatorScreenParams<State
|
|
27
|
-
path?: string;
|
|
24
|
+
params?: NavigatorScreenParams<State> | undefined;
|
|
25
|
+
path?: string | undefined;
|
|
28
26
|
};
|
|
29
27
|
};
|
|
30
28
|
|
|
29
|
+
// Cache the normalized config across calls for the same `options` reference,
|
|
30
|
+
// so we don't re-walk the config tree on every action conversion.
|
|
31
|
+
const cachedNormalizedConfig = new WeakMap<Options, ConfigItem>();
|
|
32
|
+
|
|
31
33
|
export function getActionFromState(
|
|
32
34
|
state: PartialState<NavigationState>,
|
|
33
35
|
options?: Options
|
|
34
36
|
): NavigateAction<NavigationState> | CommonActions.Action | undefined {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
let normalizedConfig;
|
|
38
|
+
|
|
39
|
+
if (options) {
|
|
40
|
+
const cached = cachedNormalizedConfig.get(options);
|
|
41
|
+
|
|
42
|
+
if (cached) {
|
|
43
|
+
normalizedConfig = cached;
|
|
44
|
+
} else {
|
|
45
|
+
normalizedConfig = createNormalizedConfigItem(
|
|
46
|
+
options as PathConfig<object> | string
|
|
47
|
+
);
|
|
48
|
+
cachedNormalizedConfig.set(options, normalizedConfig as ConfigItem);
|
|
49
|
+
}
|
|
50
|
+
} else {
|
|
51
|
+
normalizedConfig = {};
|
|
52
|
+
}
|
|
39
53
|
|
|
40
|
-
const
|
|
41
|
-
state.index
|
|
54
|
+
const routesLength =
|
|
55
|
+
state.index == null || state.index >= state.routes.length
|
|
56
|
+
? state.routes.length
|
|
57
|
+
: state.index + 1;
|
|
42
58
|
|
|
43
|
-
if (
|
|
59
|
+
if (routesLength === 0) {
|
|
44
60
|
return undefined;
|
|
45
61
|
}
|
|
46
62
|
|
|
63
|
+
const firstRoute = state.routes[0];
|
|
64
|
+
|
|
65
|
+
if (firstRoute == null) {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const secondRoute = state.routes[1];
|
|
70
|
+
|
|
47
71
|
if (
|
|
48
72
|
!(
|
|
49
|
-
(
|
|
50
|
-
(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
73
|
+
(routesLength === 1 && firstRoute.key == null) ||
|
|
74
|
+
(routesLength === 2 &&
|
|
75
|
+
firstRoute.key == null &&
|
|
76
|
+
firstRoute.name === normalizedConfig?.initialRouteName &&
|
|
77
|
+
secondRoute?.key == null)
|
|
54
78
|
)
|
|
55
79
|
) {
|
|
56
80
|
return {
|
|
@@ -61,20 +85,21 @@ export function getActionFromState(
|
|
|
61
85
|
|
|
62
86
|
const route = state.routes[state.index ?? state.routes.length - 1];
|
|
63
87
|
|
|
64
|
-
|
|
65
|
-
|
|
88
|
+
if (route == null) {
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
let current: NavigationState | PartialState<NavigationState> | undefined =
|
|
93
|
+
route.state;
|
|
94
|
+
let config: ConfigItem | undefined = normalizedConfig?.screens?.[route.name];
|
|
66
95
|
let params = { ...route.params } as NavigatorScreenParams<ParamListBase>;
|
|
67
96
|
|
|
68
|
-
const payload:
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
| undefined = route
|
|
76
|
-
? { name: route.name, path: route.path, params }
|
|
77
|
-
: undefined;
|
|
97
|
+
const payload: {
|
|
98
|
+
name: string;
|
|
99
|
+
params: NavigatorScreenParams<ParamListBase>;
|
|
100
|
+
path?: string | undefined;
|
|
101
|
+
pop?: boolean | undefined;
|
|
102
|
+
} = { name: route.name, path: route.path, params };
|
|
78
103
|
|
|
79
104
|
// If the screen contains a navigator, pop other screens to navigate to it
|
|
80
105
|
// This avoid pushing multiple instances of navigators onto a stack
|
|
@@ -90,7 +115,7 @@ export function getActionFromState(
|
|
|
90
115
|
// There are 2 ways we can detect if a screen contains a navigator:
|
|
91
116
|
// - The route contains nested state in `route.state`
|
|
92
117
|
// - Nested screens are defined in the config
|
|
93
|
-
if (
|
|
118
|
+
if (config?.screens && Object.keys(config.screens).length) {
|
|
94
119
|
payload.pop = true;
|
|
95
120
|
}
|
|
96
121
|
|
|
@@ -99,13 +124,24 @@ export function getActionFromState(
|
|
|
99
124
|
return undefined;
|
|
100
125
|
}
|
|
101
126
|
|
|
102
|
-
const
|
|
103
|
-
current.index
|
|
104
|
-
? current.routes.
|
|
105
|
-
: current.
|
|
127
|
+
const routesLength =
|
|
128
|
+
current.index == null || current.index >= current.routes.length
|
|
129
|
+
? current.routes.length
|
|
130
|
+
: current.index + 1;
|
|
131
|
+
|
|
132
|
+
const route = current.routes[routesLength - 1];
|
|
133
|
+
|
|
134
|
+
if (route == null) {
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const firstRoute = current.routes[0];
|
|
139
|
+
|
|
140
|
+
if (firstRoute == null) {
|
|
141
|
+
return undefined;
|
|
142
|
+
}
|
|
106
143
|
|
|
107
|
-
const
|
|
108
|
-
routes[routes.length - 1];
|
|
144
|
+
const secondRoute = current.routes[1];
|
|
109
145
|
|
|
110
146
|
// Explicitly set to override existing value when merging params
|
|
111
147
|
Object.assign(params, {
|
|
@@ -115,14 +151,14 @@ export function getActionFromState(
|
|
|
115
151
|
state: undefined,
|
|
116
152
|
});
|
|
117
153
|
|
|
118
|
-
if (
|
|
154
|
+
if (routesLength === 1 && firstRoute.key == null) {
|
|
119
155
|
params.initial = true;
|
|
120
156
|
params.screen = route.name;
|
|
121
157
|
} else if (
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
158
|
+
routesLength === 2 &&
|
|
159
|
+
firstRoute.key == null &&
|
|
160
|
+
firstRoute.name === config?.initialRouteName &&
|
|
161
|
+
secondRoute?.key == null
|
|
126
162
|
) {
|
|
127
163
|
params.initial = false;
|
|
128
164
|
params.screen = route.name;
|
|
@@ -148,14 +184,10 @@ export function getActionFromState(
|
|
|
148
184
|
}
|
|
149
185
|
}
|
|
150
186
|
|
|
151
|
-
if (payload
|
|
187
|
+
if (payload.params.screen || payload.params.state) {
|
|
152
188
|
payload.pop = true;
|
|
153
189
|
}
|
|
154
190
|
|
|
155
|
-
if (!payload) {
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
191
|
// Try to construct payload for a `NAVIGATE` action from the state
|
|
160
192
|
// This lets us preserve the navigation state and not lose it
|
|
161
193
|
return {
|
|
@@ -164,11 +196,16 @@ export function getActionFromState(
|
|
|
164
196
|
};
|
|
165
197
|
}
|
|
166
198
|
|
|
167
|
-
const createNormalizedConfigItem = (
|
|
199
|
+
const createNormalizedConfigItem = (
|
|
200
|
+
config: PathConfig<object> | string
|
|
201
|
+
): ConfigItem =>
|
|
168
202
|
typeof config === 'object' && config != null
|
|
169
203
|
? {
|
|
170
204
|
initialRouteName:
|
|
171
|
-
'initialRouteName' in config
|
|
205
|
+
'initialRouteName' in config &&
|
|
206
|
+
typeof config.initialRouteName === 'string'
|
|
207
|
+
? config.initialRouteName
|
|
208
|
+
: undefined,
|
|
172
209
|
screens:
|
|
173
210
|
'screens' in config && config.screens != null
|
|
174
211
|
? createNormalizedConfigs(config.screens)
|
|
@@ -178,7 +215,6 @@ const createNormalizedConfigItem = (config: PathConfig<object> | string) =>
|
|
|
178
215
|
|
|
179
216
|
const createNormalizedConfigs = (options: PathConfigMap<object>) =>
|
|
180
217
|
Object.entries(options).reduce<Record<string, ConfigItem>>((acc, [k, v]) => {
|
|
181
|
-
// @ts-expect-error -we can't properly type this
|
|
182
218
|
acc[k] = createNormalizedConfigItem(v);
|
|
183
219
|
return acc;
|
|
184
220
|
}, {});
|