@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
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import type { NavigationState, PartialState } from '@react-navigation/routers';
|
|
2
|
+
|
|
3
|
+
import { getStateFromRouteParams } from './getStateFromRouteParams';
|
|
4
|
+
import type { TreeForPathConfig } from './StaticNavigation';
|
|
5
|
+
|
|
6
|
+
function findScreenInConfig(config: TreeForPathConfig['config'], name: string) {
|
|
7
|
+
const screens = config.screens;
|
|
8
|
+
|
|
9
|
+
if (screens?.[name] != null) {
|
|
10
|
+
return screens[name];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (config.groups) {
|
|
14
|
+
for (const group of Object.values(config.groups)) {
|
|
15
|
+
if (group.screens[name] != null) {
|
|
16
|
+
return group.screens[name];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function findInitialRouteName(
|
|
25
|
+
config: TreeForPathConfig['config']
|
|
26
|
+
): string | undefined {
|
|
27
|
+
if (config.initialRouteName != null) {
|
|
28
|
+
return config.initialRouteName;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
for (const key in config) {
|
|
32
|
+
if (key === 'screens' && config.screens) {
|
|
33
|
+
const name = Object.keys(config.screens)[0];
|
|
34
|
+
|
|
35
|
+
if (name != null) {
|
|
36
|
+
return name;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (key === 'groups' && config.groups) {
|
|
41
|
+
for (const group of Object.values(config.groups)) {
|
|
42
|
+
const name = Object.keys(group.screens)[0];
|
|
43
|
+
|
|
44
|
+
if (name != null) {
|
|
45
|
+
return name;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Get loader for the focused route in a static config tree with given navigation state.
|
|
56
|
+
*
|
|
57
|
+
* @param tree The static navigation config.
|
|
58
|
+
* @param state The navigation state to extract the focused route path from.
|
|
59
|
+
* @returns A function that returns a `Promise<void>`, or `undefined` if no loaders are found.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```js
|
|
63
|
+
* const loader = getLoaderForState(RootStack, {
|
|
64
|
+
* index: 0,
|
|
65
|
+
* routes: [{ name: 'Home' }],
|
|
66
|
+
* });
|
|
67
|
+
* await loader?.();
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export function getLoaderForState(
|
|
71
|
+
tree: TreeForPathConfig,
|
|
72
|
+
state: PartialState<NavigationState> | NavigationState | undefined
|
|
73
|
+
): (() => Promise<void>) | undefined {
|
|
74
|
+
return getLoaderForStateChange(tree, state, undefined, undefined);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function getLoaderForStateChange(
|
|
78
|
+
tree: TreeForPathConfig,
|
|
79
|
+
state: PartialState<NavigationState> | NavigationState | undefined,
|
|
80
|
+
previousState: PartialState<NavigationState> | NavigationState | undefined,
|
|
81
|
+
consumedParams: WeakMap<object, true> | undefined
|
|
82
|
+
): (() => Promise<void>) | undefined {
|
|
83
|
+
const focusedRoute = state?.routes[state.index ?? state.routes.length - 1];
|
|
84
|
+
const previousFocusedRoute =
|
|
85
|
+
previousState?.routes[
|
|
86
|
+
previousState.index ?? previousState.routes.length - 1
|
|
87
|
+
];
|
|
88
|
+
|
|
89
|
+
if (!focusedRoute) {
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const isNewlyFocused =
|
|
94
|
+
previousState === undefined ||
|
|
95
|
+
previousFocusedRoute == null ||
|
|
96
|
+
focusedRoute.name !== previousFocusedRoute.name ||
|
|
97
|
+
(focusedRoute.key != null &&
|
|
98
|
+
previousFocusedRoute.key != null &&
|
|
99
|
+
focusedRoute.key !== previousFocusedRoute.key);
|
|
100
|
+
|
|
101
|
+
const item = findScreenInConfig(tree.config, focusedRoute.name);
|
|
102
|
+
|
|
103
|
+
if (item == null) {
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const initialParams =
|
|
108
|
+
typeof item === 'object' && 'initialParams' in item
|
|
109
|
+
? item.initialParams
|
|
110
|
+
: undefined;
|
|
111
|
+
|
|
112
|
+
const params =
|
|
113
|
+
initialParams != null || focusedRoute.params != null
|
|
114
|
+
? { ...initialParams, ...focusedRoute.params }
|
|
115
|
+
: undefined;
|
|
116
|
+
|
|
117
|
+
const loaders: (() => Promise<void>)[] = [];
|
|
118
|
+
|
|
119
|
+
if (
|
|
120
|
+
isNewlyFocused &&
|
|
121
|
+
'UNSTABLE_loader' in item &&
|
|
122
|
+
typeof item.UNSTABLE_loader === 'function'
|
|
123
|
+
) {
|
|
124
|
+
const loader = item.UNSTABLE_loader;
|
|
125
|
+
|
|
126
|
+
loaders.push(() =>
|
|
127
|
+
loader({
|
|
128
|
+
name: focusedRoute.name,
|
|
129
|
+
params,
|
|
130
|
+
})
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const nested =
|
|
135
|
+
'config' in item
|
|
136
|
+
? item
|
|
137
|
+
: 'screen' in item &&
|
|
138
|
+
// Nested navigators cannot be defined as a getter
|
|
139
|
+
Object.getOwnPropertyDescriptor(item, 'screen')?.get == null &&
|
|
140
|
+
'config' in item.screen
|
|
141
|
+
? item.screen
|
|
142
|
+
: undefined;
|
|
143
|
+
|
|
144
|
+
if (nested) {
|
|
145
|
+
const initialRouteName = findInitialRouteName(nested.config);
|
|
146
|
+
|
|
147
|
+
const stateFromParams =
|
|
148
|
+
focusedRoute.params != null && consumedParams?.has(focusedRoute.params)
|
|
149
|
+
? undefined
|
|
150
|
+
: getStateFromRouteParams(params);
|
|
151
|
+
|
|
152
|
+
let childState =
|
|
153
|
+
previousState !== undefined && stateFromParams != null
|
|
154
|
+
? stateFromParams
|
|
155
|
+
: (focusedRoute.state ?? stateFromParams);
|
|
156
|
+
|
|
157
|
+
if (childState == null && initialRouteName != null) {
|
|
158
|
+
childState = { routes: [{ name: initialRouteName }] };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
let previousChildState:
|
|
162
|
+
| PartialState<NavigationState>
|
|
163
|
+
| NavigationState
|
|
164
|
+
| undefined;
|
|
165
|
+
|
|
166
|
+
if (!isNewlyFocused) {
|
|
167
|
+
const previousRouteParams = previousFocusedRoute?.params;
|
|
168
|
+
const previousParams =
|
|
169
|
+
initialParams != null || previousRouteParams != null
|
|
170
|
+
? { ...initialParams, ...previousRouteParams }
|
|
171
|
+
: undefined;
|
|
172
|
+
const previousStateFromParams =
|
|
173
|
+
previousRouteParams != null && consumedParams?.has(previousRouteParams)
|
|
174
|
+
? undefined
|
|
175
|
+
: getStateFromRouteParams(previousParams);
|
|
176
|
+
|
|
177
|
+
previousChildState =
|
|
178
|
+
previousFocusedRoute?.state ?? previousStateFromParams;
|
|
179
|
+
|
|
180
|
+
if (previousChildState == null && initialRouteName != null) {
|
|
181
|
+
previousChildState = { routes: [{ name: initialRouteName }] };
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const childLoader = getLoaderForStateChange(
|
|
186
|
+
nested,
|
|
187
|
+
childState,
|
|
188
|
+
previousState === undefined
|
|
189
|
+
? undefined
|
|
190
|
+
: (previousChildState ?? { routes: [] }),
|
|
191
|
+
consumedParams
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
if (childLoader) {
|
|
195
|
+
loaders.push(childLoader);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (loaders.length === 0) {
|
|
200
|
+
return undefined;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return async () => {
|
|
204
|
+
await Promise.all(loaders.map((l) => l()));
|
|
205
|
+
};
|
|
206
|
+
}
|
|
@@ -2,6 +2,7 @@ import type {
|
|
|
2
2
|
NavigationAction,
|
|
3
3
|
NavigationState,
|
|
4
4
|
ParamListBase,
|
|
5
|
+
PartialState,
|
|
5
6
|
} from '@react-navigation/routers';
|
|
6
7
|
import * as React from 'react';
|
|
7
8
|
|
|
@@ -14,6 +15,7 @@ export type ListenerMap = {
|
|
|
14
15
|
|
|
15
16
|
export type KeyedListenerMap = {
|
|
16
17
|
getState: GetStateListener;
|
|
18
|
+
getNavigation: GetNavigationListener;
|
|
17
19
|
beforeRemove: ChildBeforeRemoveListener;
|
|
18
20
|
};
|
|
19
21
|
|
|
@@ -46,19 +48,26 @@ export type FocusedNavigationListener = <T>(
|
|
|
46
48
|
|
|
47
49
|
export type GetStateListener = () => NavigationState;
|
|
48
50
|
|
|
49
|
-
export type
|
|
51
|
+
export type GetNavigationListener = () => NavigationHelpers<ParamListBase>;
|
|
50
52
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
53
|
+
export type WithStackTrace = (
|
|
54
|
+
entry: (...args: never[]) => void,
|
|
55
|
+
callback: () => void
|
|
56
|
+
) => void;
|
|
57
|
+
|
|
58
|
+
export type ChildBeforeRemoveListener = (
|
|
59
|
+
action: NavigationAction,
|
|
60
|
+
nextState: NavigationState | PartialState<NavigationState> | undefined
|
|
61
|
+
) => boolean;
|
|
62
|
+
|
|
63
|
+
type NavigationBuilderContextValue = {
|
|
64
|
+
canGoBack?: ((source?: string) => boolean) | undefined;
|
|
65
|
+
onAction?:
|
|
66
|
+
| ((action: NavigationAction, visitedNavigators?: Set<string>) => boolean)
|
|
67
|
+
| undefined;
|
|
68
|
+
addListener?: AddListener | undefined;
|
|
69
|
+
addKeyedListener?: AddKeyedListener | undefined;
|
|
70
|
+
onRouteFocus?: ((key: string) => void) | undefined;
|
|
62
71
|
onDispatchAction: (action: NavigationAction, noop: boolean) => void;
|
|
63
72
|
onEmitEvent: (event: {
|
|
64
73
|
type: string;
|
|
@@ -66,18 +75,28 @@ export const NavigationBuilderContext = React.createContext<{
|
|
|
66
75
|
target: string | undefined;
|
|
67
76
|
data: unknown;
|
|
68
77
|
}) => void;
|
|
69
|
-
onOptionsChange: (
|
|
78
|
+
onOptionsChange: () => void;
|
|
79
|
+
getIsStateEmitted: () => boolean;
|
|
70
80
|
scheduleUpdate: (callback: () => void) => void;
|
|
71
81
|
flushUpdates: () => void;
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
withStackTrace: WithStackTrace;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Context which holds the required helpers needed to build nested navigators.
|
|
87
|
+
*/
|
|
88
|
+
export const NavigationBuilderContext = React.createContext<
|
|
89
|
+
NavigationBuilderContextValue | undefined
|
|
90
|
+
>(undefined);
|
|
91
|
+
|
|
92
|
+
export function useNavigationBuilderContext() {
|
|
93
|
+
const value = React.use(NavigationBuilderContext);
|
|
94
|
+
|
|
95
|
+
if (value == null) {
|
|
96
|
+
throw new Error(
|
|
97
|
+
"Couldn't find a navigation builder context. Is your component inside NavigationContainer?"
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return value;
|
|
102
|
+
}
|
|
@@ -3,11 +3,11 @@ import * as React from 'react';
|
|
|
3
3
|
export type FocusedRouteState = {
|
|
4
4
|
routes: [
|
|
5
5
|
{
|
|
6
|
-
key?: string;
|
|
6
|
+
key?: string | undefined;
|
|
7
7
|
name: string;
|
|
8
|
-
params?: object;
|
|
9
|
-
path?: string;
|
|
10
|
-
state?: FocusedRouteState;
|
|
8
|
+
params?: object | undefined;
|
|
9
|
+
path?: string | undefined;
|
|
10
|
+
state?: FocusedRouteState | undefined;
|
|
11
11
|
},
|
|
12
12
|
];
|
|
13
13
|
};
|
|
@@ -1,12 +1,28 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
|
|
3
|
+
import { NavigationBuilderContext } from './NavigationBuilderContext';
|
|
4
|
+
import { NavigationContainerRefContext } from './NavigationContainerRefContext';
|
|
5
|
+
import { NavigationFocusedRouteStateContext } from './NavigationFocusedRouteStateContext';
|
|
6
|
+
import { NavigationHelpersContext } from './NavigationHelpersContext';
|
|
3
7
|
import { NavigationIndependentTreeContext } from './NavigationIndependentTreeContext';
|
|
4
8
|
import {
|
|
9
|
+
IsScreenContext,
|
|
5
10
|
NamedRouteContextListContext,
|
|
6
11
|
NavigationContext,
|
|
7
12
|
NavigationRouteContext,
|
|
8
|
-
NavigationRouteNameContext,
|
|
9
13
|
} from './NavigationProvider';
|
|
14
|
+
import { NavigationRootContext } from './NavigationRootContext';
|
|
15
|
+
import { PreventRemoveContext } from './PreventRemoveContext';
|
|
16
|
+
import { StaticTreeContext } from './StaticTreeContext';
|
|
17
|
+
import {
|
|
18
|
+
FocusedRouteKeyContext,
|
|
19
|
+
IsFocusedContext,
|
|
20
|
+
IsFocusedGetterContext,
|
|
21
|
+
} from './useIsFocused';
|
|
22
|
+
import {
|
|
23
|
+
NamedNavigationStateListenerListContext,
|
|
24
|
+
NavigationStateListenerContext,
|
|
25
|
+
} from './useNavigationState';
|
|
10
26
|
|
|
11
27
|
/**
|
|
12
28
|
* Component to make the child navigation container independent of parent containers.
|
|
@@ -18,16 +34,48 @@ export function NavigationIndependentTree({
|
|
|
18
34
|
}) {
|
|
19
35
|
return (
|
|
20
36
|
// We need to clear any existing contexts for nested independent container to work correctly
|
|
21
|
-
<
|
|
22
|
-
<
|
|
23
|
-
<
|
|
24
|
-
<
|
|
25
|
-
<
|
|
26
|
-
{
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
37
|
+
<NavigationIndependentTreeContext.Provider value={true}>
|
|
38
|
+
<NavigationContainerRefContext.Provider value={undefined}>
|
|
39
|
+
<NavigationRootContext.Provider value={undefined}>
|
|
40
|
+
<NavigationBuilderContext.Provider value={undefined}>
|
|
41
|
+
<StaticTreeContext.Provider value={undefined}>
|
|
42
|
+
<NavigationHelpersContext.Provider value={undefined}>
|
|
43
|
+
<NavigationStateListenerContext.Provider value={undefined}>
|
|
44
|
+
<FocusedRouteKeyContext.Provider value={undefined}>
|
|
45
|
+
<PreventRemoveContext.Provider value={undefined}>
|
|
46
|
+
<NamedNavigationStateListenerListContext.Provider
|
|
47
|
+
value={undefined}
|
|
48
|
+
>
|
|
49
|
+
<NamedRouteContextListContext.Provider
|
|
50
|
+
value={undefined}
|
|
51
|
+
>
|
|
52
|
+
<NavigationRouteContext.Provider value={undefined}>
|
|
53
|
+
<NavigationContext.Provider value={undefined}>
|
|
54
|
+
<IsFocusedContext.Provider value={undefined}>
|
|
55
|
+
<IsFocusedGetterContext.Provider
|
|
56
|
+
value={undefined}
|
|
57
|
+
>
|
|
58
|
+
<IsScreenContext.Provider value={false}>
|
|
59
|
+
<NavigationFocusedRouteStateContext.Provider
|
|
60
|
+
value={undefined}
|
|
61
|
+
>
|
|
62
|
+
{children}
|
|
63
|
+
</NavigationFocusedRouteStateContext.Provider>
|
|
64
|
+
</IsScreenContext.Provider>
|
|
65
|
+
</IsFocusedGetterContext.Provider>
|
|
66
|
+
</IsFocusedContext.Provider>
|
|
67
|
+
</NavigationContext.Provider>
|
|
68
|
+
</NavigationRouteContext.Provider>
|
|
69
|
+
</NamedRouteContextListContext.Provider>
|
|
70
|
+
</NamedNavigationStateListenerListContext.Provider>
|
|
71
|
+
</PreventRemoveContext.Provider>
|
|
72
|
+
</FocusedRouteKeyContext.Provider>
|
|
73
|
+
</NavigationStateListenerContext.Provider>
|
|
74
|
+
</NavigationHelpersContext.Provider>
|
|
75
|
+
</StaticTreeContext.Provider>
|
|
76
|
+
</NavigationBuilderContext.Provider>
|
|
77
|
+
</NavigationRootContext.Provider>
|
|
78
|
+
</NavigationContainerRefContext.Provider>
|
|
79
|
+
</NavigationIndependentTreeContext.Provider>
|
|
32
80
|
);
|
|
33
81
|
}
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import type { ParamListBase, Route } from '@react-navigation/routers';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
+
import useLatestCallback from 'use-latest-callback';
|
|
3
4
|
|
|
4
5
|
import type { NavigationProp } from './types';
|
|
6
|
+
import {
|
|
7
|
+
FocusedRouteKeyContext,
|
|
8
|
+
IsFocusedContext,
|
|
9
|
+
IsFocusedGetterContext,
|
|
10
|
+
} from './useIsFocused';
|
|
5
11
|
import { useLazyValue } from './useLazyValue';
|
|
12
|
+
import { NamedNavigationStateListenerProvider } from './useNavigationState';
|
|
6
13
|
|
|
7
14
|
/**
|
|
8
15
|
* Context which holds the route prop for a screen.
|
|
@@ -18,15 +25,10 @@ export const NavigationContext = React.createContext<
|
|
|
18
25
|
NavigationProp<ParamListBase> | undefined
|
|
19
26
|
>(undefined);
|
|
20
27
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
type Props = {
|
|
26
|
-
route: Route<string>;
|
|
27
|
-
navigation: NavigationProp<ParamListBase>;
|
|
28
|
-
children: React.ReactNode;
|
|
29
|
-
};
|
|
28
|
+
/**
|
|
29
|
+
* Context which indicates whether the component is inside a screen.
|
|
30
|
+
*/
|
|
31
|
+
export const IsScreenContext = React.createContext(false);
|
|
30
32
|
|
|
31
33
|
/**
|
|
32
34
|
* Component to provide the navigation and route contexts to its children.
|
|
@@ -35,6 +37,12 @@ export const NamedRouteContextListContext = React.createContext<
|
|
|
35
37
|
Record<string, React.Context<Route<string>>> | undefined
|
|
36
38
|
>(undefined);
|
|
37
39
|
|
|
40
|
+
type Props = {
|
|
41
|
+
route: Route<string>;
|
|
42
|
+
navigation: NavigationProp<ParamListBase>;
|
|
43
|
+
children: React.ReactNode;
|
|
44
|
+
};
|
|
45
|
+
|
|
38
46
|
export function NavigationProvider({ route, navigation, children }: Props) {
|
|
39
47
|
const NamedRouteContext = useLazyValue(() => React.createContext(route));
|
|
40
48
|
|
|
@@ -48,17 +56,47 @@ export function NavigationProvider({ route, navigation, children }: Props) {
|
|
|
48
56
|
[NamedRouteContext, parents, route.name]
|
|
49
57
|
);
|
|
50
58
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
const parentIsFocused = React.use(IsFocusedContext);
|
|
60
|
+
const focusedRouteKey = React.use(FocusedRouteKeyContext);
|
|
61
|
+
|
|
62
|
+
// Mark route as focused only if:
|
|
63
|
+
// - It doesn't have a parent navigator
|
|
64
|
+
// - Parent navigator is focused
|
|
65
|
+
const isFocused =
|
|
66
|
+
parentIsFocused == null || parentIsFocused
|
|
67
|
+
? focusedRouteKey === route.key
|
|
68
|
+
: false;
|
|
69
|
+
|
|
70
|
+
const getIsFocused = useLatestCallback(() => isFocused);
|
|
71
|
+
|
|
72
|
+
return React.useMemo(
|
|
73
|
+
() => (
|
|
74
|
+
<NamedNavigationStateListenerProvider name={route.name}>
|
|
75
|
+
<NamedRouteContextListContext.Provider value={NamedRouteContextList}>
|
|
76
|
+
<NamedRouteContext.Provider value={route}>
|
|
77
|
+
<NavigationRouteContext.Provider value={route}>
|
|
78
|
+
<NavigationContext.Provider value={navigation}>
|
|
79
|
+
<IsFocusedContext.Provider value={isFocused}>
|
|
80
|
+
<IsFocusedGetterContext.Provider value={getIsFocused}>
|
|
81
|
+
<IsScreenContext.Provider value={true}>
|
|
82
|
+
{children}
|
|
83
|
+
</IsScreenContext.Provider>
|
|
84
|
+
</IsFocusedGetterContext.Provider>
|
|
85
|
+
</IsFocusedContext.Provider>
|
|
86
|
+
</NavigationContext.Provider>
|
|
87
|
+
</NavigationRouteContext.Provider>
|
|
88
|
+
</NamedRouteContext.Provider>
|
|
89
|
+
</NamedRouteContextListContext.Provider>
|
|
90
|
+
</NamedNavigationStateListenerProvider>
|
|
91
|
+
),
|
|
92
|
+
[
|
|
93
|
+
NamedRouteContext,
|
|
94
|
+
NamedRouteContextList,
|
|
95
|
+
children,
|
|
96
|
+
getIsFocused,
|
|
97
|
+
isFocused,
|
|
98
|
+
navigation,
|
|
99
|
+
route,
|
|
100
|
+
]
|
|
63
101
|
);
|
|
64
102
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ParamListBase } from '@react-navigation/routers';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
|
|
4
|
+
import type { GenericNavigation } from './types';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Context which holds the navigation object for components outside a screen.
|
|
8
|
+
*/
|
|
9
|
+
export const NavigationRootContext = React.createContext<
|
|
10
|
+
GenericNavigation<ParamListBase> | undefined
|
|
11
|
+
>(undefined);
|
|
@@ -5,19 +5,16 @@ const MISSING_CONTEXT_ERROR =
|
|
|
5
5
|
"Couldn't find a navigation context. Have you wrapped your app with 'NavigationContainer'? See https://reactnavigation.org/docs/getting-started for setup instructions.";
|
|
6
6
|
|
|
7
7
|
export const NavigationStateContext = React.createContext<{
|
|
8
|
-
isDefault?: true;
|
|
9
|
-
state?: NavigationState | PartialState<NavigationState
|
|
8
|
+
isDefault?: true | undefined;
|
|
9
|
+
state?: NavigationState | PartialState<NavigationState> | undefined;
|
|
10
10
|
getKey: () => string | undefined;
|
|
11
11
|
setKey: (key: string) => void;
|
|
12
12
|
getState: () => NavigationState | PartialState<NavigationState> | undefined;
|
|
13
13
|
setState: (
|
|
14
14
|
state: NavigationState | PartialState<NavigationState> | undefined
|
|
15
15
|
) => void;
|
|
16
|
+
subscribe: (callback: () => void) => () => void;
|
|
16
17
|
getIsInitial: () => boolean;
|
|
17
|
-
addOptionsGetter?: (
|
|
18
|
-
key: string,
|
|
19
|
-
getter: () => object | undefined | null
|
|
20
|
-
) => void;
|
|
21
18
|
}>({
|
|
22
19
|
isDefault: true,
|
|
23
20
|
|
|
@@ -33,6 +30,9 @@ export const NavigationStateContext = React.createContext<{
|
|
|
33
30
|
get setState(): any {
|
|
34
31
|
throw new Error(MISSING_CONTEXT_ERROR);
|
|
35
32
|
},
|
|
33
|
+
get subscribe(): any {
|
|
34
|
+
throw new Error(MISSING_CONTEXT_ERROR);
|
|
35
|
+
},
|
|
36
36
|
get getIsInitial(): any {
|
|
37
37
|
throw new Error(MISSING_CONTEXT_ERROR);
|
|
38
38
|
},
|