@react-navigation/core 6.0.2
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/LICENSE +21 -0
- package/README.md +38 -0
- package/lib/commonjs/BaseNavigationContainer.js +393 -0
- package/lib/commonjs/BaseNavigationContainer.js.map +1 -0
- package/lib/commonjs/CurrentRenderContext.js +21 -0
- package/lib/commonjs/CurrentRenderContext.js.map +1 -0
- package/lib/commonjs/EnsureSingleNavigator.js +53 -0
- package/lib/commonjs/EnsureSingleNavigator.js.map +1 -0
- package/lib/commonjs/Group.js +15 -0
- package/lib/commonjs/Group.js.map +1 -0
- package/lib/commonjs/NavigationBuilderContext.js +23 -0
- package/lib/commonjs/NavigationBuilderContext.js.map +1 -0
- package/lib/commonjs/NavigationContainerRefContext.js +20 -0
- package/lib/commonjs/NavigationContainerRefContext.js.map +1 -0
- package/lib/commonjs/NavigationContext.js +20 -0
- package/lib/commonjs/NavigationContext.js.map +1 -0
- package/lib/commonjs/NavigationHelpersContext.js +21 -0
- package/lib/commonjs/NavigationHelpersContext.js.map +1 -0
- package/lib/commonjs/NavigationRouteContext.js +20 -0
- package/lib/commonjs/NavigationRouteContext.js.map +1 -0
- package/lib/commonjs/NavigationStateContext.js +42 -0
- package/lib/commonjs/NavigationStateContext.js.map +1 -0
- package/lib/commonjs/SceneView.js +97 -0
- package/lib/commonjs/SceneView.js.map +1 -0
- package/lib/commonjs/Screen.js +15 -0
- package/lib/commonjs/Screen.js.map +1 -0
- package/lib/commonjs/StaticContainer.js +43 -0
- package/lib/commonjs/StaticContainer.js.map +1 -0
- package/lib/commonjs/UnhandledActionContext.js +17 -0
- package/lib/commonjs/UnhandledActionContext.js.map +1 -0
- package/lib/commonjs/checkDuplicateRouteNames.js +31 -0
- package/lib/commonjs/checkDuplicateRouteNames.js.map +1 -0
- package/lib/commonjs/checkSerializable.js +59 -0
- package/lib/commonjs/checkSerializable.js.map +1 -0
- package/lib/commonjs/createNavigationContainerRef.js +82 -0
- package/lib/commonjs/createNavigationContainerRef.js.map +1 -0
- package/lib/commonjs/createNavigatorFactory.js +34 -0
- package/lib/commonjs/createNavigatorFactory.js.map +1 -0
- package/lib/commonjs/findFocusedRoute.js +22 -0
- package/lib/commonjs/findFocusedRoute.js.map +1 -0
- package/lib/commonjs/fromEntries.js +19 -0
- package/lib/commonjs/fromEntries.js.map +1 -0
- package/lib/commonjs/getActionFromState.js +99 -0
- package/lib/commonjs/getActionFromState.js.map +1 -0
- package/lib/commonjs/getFocusedRouteNameFromRoute.js +23 -0
- package/lib/commonjs/getFocusedRouteNameFromRoute.js.map +1 -0
- package/lib/commonjs/getPathFromState.js +238 -0
- package/lib/commonjs/getPathFromState.js.map +1 -0
- package/lib/commonjs/getStateFromPath.js +450 -0
- package/lib/commonjs/getStateFromPath.js.map +1 -0
- package/lib/commonjs/index.js +227 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/isArrayEqual.js +15 -0
- package/lib/commonjs/isArrayEqual.js.map +1 -0
- package/lib/commonjs/types.js +18 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/commonjs/useChildListeners.js +38 -0
- package/lib/commonjs/useChildListeners.js.map +1 -0
- package/lib/commonjs/useComponent.js +36 -0
- package/lib/commonjs/useComponent.js.map +1 -0
- package/lib/commonjs/useCurrentRender.js +33 -0
- package/lib/commonjs/useCurrentRender.js.map +1 -0
- package/lib/commonjs/useDescriptors.js +141 -0
- package/lib/commonjs/useDescriptors.js.map +1 -0
- package/lib/commonjs/useEventEmitter.js +118 -0
- package/lib/commonjs/useEventEmitter.js.map +1 -0
- package/lib/commonjs/useFocusEffect.js +97 -0
- package/lib/commonjs/useFocusEffect.js.map +1 -0
- package/lib/commonjs/useFocusEvents.js +77 -0
- package/lib/commonjs/useFocusEvents.js.map +1 -0
- package/lib/commonjs/useFocusedListenersChildrenAdapter.js +57 -0
- package/lib/commonjs/useFocusedListenersChildrenAdapter.js.map +1 -0
- package/lib/commonjs/useIsFocused.js +47 -0
- package/lib/commonjs/useIsFocused.js.map +1 -0
- package/lib/commonjs/useKeyedChildListeners.js +35 -0
- package/lib/commonjs/useKeyedChildListeners.js.map +1 -0
- package/lib/commonjs/useNavigation.js +36 -0
- package/lib/commonjs/useNavigation.js.map +1 -0
- package/lib/commonjs/useNavigationBuilder.js +480 -0
- package/lib/commonjs/useNavigationBuilder.js.map +1 -0
- package/lib/commonjs/useNavigationCache.js +122 -0
- package/lib/commonjs/useNavigationCache.js.map +1 -0
- package/lib/commonjs/useNavigationContainerRef.js +27 -0
- package/lib/commonjs/useNavigationContainerRef.js.map +1 -0
- package/lib/commonjs/useNavigationHelpers.js +77 -0
- package/lib/commonjs/useNavigationHelpers.js.map +1 -0
- package/lib/commonjs/useNavigationState.js +41 -0
- package/lib/commonjs/useNavigationState.js.map +1 -0
- package/lib/commonjs/useOnAction.js +118 -0
- package/lib/commonjs/useOnAction.js.map +1 -0
- package/lib/commonjs/useOnGetState.js +60 -0
- package/lib/commonjs/useOnGetState.js.map +1 -0
- package/lib/commonjs/useOnPreventRemove.js +89 -0
- package/lib/commonjs/useOnPreventRemove.js.map +1 -0
- package/lib/commonjs/useOnRouteFocus.js +45 -0
- package/lib/commonjs/useOnRouteFocus.js.map +1 -0
- package/lib/commonjs/useOptionsGetters.js +99 -0
- package/lib/commonjs/useOptionsGetters.js.map +1 -0
- package/lib/commonjs/useRegisterNavigator.js +40 -0
- package/lib/commonjs/useRegisterNavigator.js.map +1 -0
- package/lib/commonjs/useRoute.js +32 -0
- package/lib/commonjs/useRoute.js.map +1 -0
- package/lib/commonjs/useRouteCache.js +61 -0
- package/lib/commonjs/useRouteCache.js.map +1 -0
- package/lib/commonjs/useScheduleUpdate.js +44 -0
- package/lib/commonjs/useScheduleUpdate.js.map +1 -0
- package/lib/commonjs/useSyncState.js +76 -0
- package/lib/commonjs/useSyncState.js.map +1 -0
- package/lib/commonjs/validatePathConfig.js +31 -0
- package/lib/commonjs/validatePathConfig.js.map +1 -0
- package/lib/module/BaseNavigationContainer.js +360 -0
- package/lib/module/BaseNavigationContainer.js.map +1 -0
- package/lib/module/CurrentRenderContext.js +9 -0
- package/lib/module/CurrentRenderContext.js.map +1 -0
- package/lib/module/EnsureSingleNavigator.js +38 -0
- package/lib/module/EnsureSingleNavigator.js.map +1 -0
- package/lib/module/Group.js +8 -0
- package/lib/module/Group.js.map +1 -0
- package/lib/module/NavigationBuilderContext.js +11 -0
- package/lib/module/NavigationBuilderContext.js.map +1 -0
- package/lib/module/NavigationContainerRefContext.js +8 -0
- package/lib/module/NavigationContainerRefContext.js.map +1 -0
- package/lib/module/NavigationContext.js +8 -0
- package/lib/module/NavigationContext.js.map +1 -0
- package/lib/module/NavigationHelpersContext.js +9 -0
- package/lib/module/NavigationHelpersContext.js.map +1 -0
- package/lib/module/NavigationRouteContext.js +8 -0
- package/lib/module/NavigationRouteContext.js.map +1 -0
- package/lib/module/NavigationStateContext.js +27 -0
- package/lib/module/NavigationStateContext.js.map +1 -0
- package/lib/module/SceneView.js +80 -0
- package/lib/module/SceneView.js.map +1 -0
- package/lib/module/Screen.js +8 -0
- package/lib/module/Screen.js.map +1 -0
- package/lib/module/StaticContainer.js +30 -0
- package/lib/module/StaticContainer.js.map +1 -0
- package/lib/module/UnhandledActionContext.js +4 -0
- package/lib/module/UnhandledActionContext.js.map +1 -0
- package/lib/module/checkDuplicateRouteNames.js +24 -0
- package/lib/module/checkDuplicateRouteNames.js.map +1 -0
- package/lib/module/checkSerializable.js +52 -0
- package/lib/module/checkSerializable.js.map +1 -0
- package/lib/module/createNavigationContainerRef.js +71 -0
- package/lib/module/createNavigationContainerRef.js.map +1 -0
- package/lib/module/createNavigatorFactory.js +24 -0
- package/lib/module/createNavigatorFactory.js.map +1 -0
- package/lib/module/findFocusedRoute.js +15 -0
- package/lib/module/findFocusedRoute.js.map +1 -0
- package/lib/module/fromEntries.js +12 -0
- package/lib/module/fromEntries.js.map +1 -0
- package/lib/module/getActionFromState.js +92 -0
- package/lib/module/getActionFromState.js.map +1 -0
- package/lib/module/getFocusedRouteNameFromRoute.js +15 -0
- package/lib/module/getFocusedRouteNameFromRoute.js.map +1 -0
- package/lib/module/getPathFromState.js +223 -0
- package/lib/module/getPathFromState.js.map +1 -0
- package/lib/module/getStateFromPath.js +434 -0
- package/lib/module/getStateFromPath.js.map +1 -0
- package/lib/module/index.js +24 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/isArrayEqual.js +8 -0
- package/lib/module/isArrayEqual.js.map +1 -0
- package/lib/module/types.js +9 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/useChildListeners.js +27 -0
- package/lib/module/useChildListeners.js.map +1 -0
- package/lib/module/useComponent.js +24 -0
- package/lib/module/useComponent.js.map +1 -0
- package/lib/module/useCurrentRender.js +19 -0
- package/lib/module/useCurrentRender.js.map +1 -0
- package/lib/module/useDescriptors.js +122 -0
- package/lib/module/useDescriptors.js.map +1 -0
- package/lib/module/useEventEmitter.js +107 -0
- package/lib/module/useEventEmitter.js.map +1 -0
- package/lib/module/useFocusEffect.js +83 -0
- package/lib/module/useFocusEffect.js.map +1 -0
- package/lib/module/useFocusEvents.js +63 -0
- package/lib/module/useFocusEvents.js.map +1 -0
- package/lib/module/useFocusedListenersChildrenAdapter.js +43 -0
- package/lib/module/useFocusedListenersChildrenAdapter.js.map +1 -0
- package/lib/module/useIsFocused.js +34 -0
- package/lib/module/useIsFocused.js.map +1 -0
- package/lib/module/useKeyedChildListeners.js +24 -0
- package/lib/module/useKeyedChildListeners.js.map +1 -0
- package/lib/module/useNavigation.js +21 -0
- package/lib/module/useNavigation.js.map +1 -0
- package/lib/module/useNavigationBuilder.js +443 -0
- package/lib/module/useNavigationBuilder.js.map +1 -0
- package/lib/module/useNavigationCache.js +107 -0
- package/lib/module/useNavigationCache.js.map +1 -0
- package/lib/module/useNavigationContainerRef.js +12 -0
- package/lib/module/useNavigationContainerRef.js.map +1 -0
- package/lib/module/useNavigationHelpers.js +59 -0
- package/lib/module/useNavigationHelpers.js.map +1 -0
- package/lib/module/useNavigationState.js +27 -0
- package/lib/module/useNavigationState.js.map +1 -0
- package/lib/module/useOnAction.js +103 -0
- package/lib/module/useOnAction.js.map +1 -0
- package/lib/module/useOnGetState.js +43 -0
- package/lib/module/useOnGetState.js.map +1 -0
- package/lib/module/useOnPreventRemove.js +68 -0
- package/lib/module/useOnPreventRemove.js.map +1 -0
- package/lib/module/useOnRouteFocus.js +31 -0
- package/lib/module/useOnRouteFocus.js.map +1 -0
- package/lib/module/useOptionsGetters.js +83 -0
- package/lib/module/useOptionsGetters.js.map +1 -0
- package/lib/module/useRegisterNavigator.js +27 -0
- package/lib/module/useRegisterNavigator.js.map +1 -0
- package/lib/module/useRoute.js +18 -0
- package/lib/module/useRoute.js.map +1 -0
- package/lib/module/useRouteCache.js +47 -0
- package/lib/module/useRouteCache.js.map +1 -0
- package/lib/module/useScheduleUpdate.js +29 -0
- package/lib/module/useScheduleUpdate.js.map +1 -0
- package/lib/module/useSyncState.js +64 -0
- package/lib/module/useSyncState.js.map +1 -0
- package/lib/module/validatePathConfig.js +24 -0
- package/lib/module/validatePathConfig.js.map +1 -0
- package/lib/typescript/src/BaseNavigationContainer.d.ts +14 -0
- package/lib/typescript/src/CurrentRenderContext.d.ts +9 -0
- package/lib/typescript/src/EnsureSingleNavigator.d.ts +13 -0
- package/lib/typescript/src/Group.d.ts +6 -0
- package/lib/typescript/src/NavigationBuilderContext.d.ts +34 -0
- package/lib/typescript/src/NavigationContainerRefContext.d.ts +8 -0
- package/lib/typescript/src/NavigationContext.d.ts +24 -0
- package/lib/typescript/src/NavigationHelpersContext.d.ts +9 -0
- package/lib/typescript/src/NavigationRouteContext.d.ts +7 -0
- package/lib/typescript/src/NavigationStateContext.d.ts +45 -0
- package/lib/typescript/src/SceneView.d.ts +21 -0
- package/lib/typescript/src/Screen.d.ts +6 -0
- package/lib/typescript/src/StaticContainer.d.ts +7 -0
- package/lib/typescript/src/UnhandledActionContext.d.ts +4 -0
- package/lib/typescript/src/checkDuplicateRouteNames.d.ts +2 -0
- package/lib/typescript/src/checkSerializable.d.ts +9 -0
- package/lib/typescript/src/createNavigationContainerRef.d.ts +3 -0
- package/lib/typescript/src/createNavigatorFactory.d.ts +11 -0
- package/lib/typescript/src/findFocusedRoute.d.ts +22 -0
- package/lib/typescript/src/fromEntries.d.ts +1 -0
- package/lib/typescript/src/getActionFromState.d.ts +16 -0
- package/lib/typescript/src/getFocusedRouteNameFromRoute.d.ts +2 -0
- package/lib/typescript/src/getPathFromState.d.ts +38 -0
- package/lib/typescript/src/getStateFromPath.d.ts +32 -0
- package/lib/typescript/src/index.d.ts +23 -0
- package/lib/typescript/src/isArrayEqual.d.ts +5 -0
- package/lib/typescript/src/types.d.ts +485 -0
- package/lib/typescript/src/useChildListeners.d.ts +11 -0
- package/lib/typescript/src/useComponent.d.ts +2 -0
- package/lib/typescript/src/useCurrentRender.d.ts +13 -0
- package/lib/typescript/src/useDescriptors.d.ts +89 -0
- package/lib/typescript/src/useEventEmitter.d.ts +8 -0
- package/lib/typescript/src/useFocusEffect.d.ts +10 -0
- package/lib/typescript/src/useFocusEvents.d.ts +12 -0
- package/lib/typescript/src/useFocusedListenersChildrenAdapter.d.ts +12 -0
- package/lib/typescript/src/useIsFocused.d.ts +5 -0
- package/lib/typescript/src/useKeyedChildListeners.d.ts +11 -0
- package/lib/typescript/src/useNavigation.d.ts +7 -0
- package/lib/typescript/src/useNavigationBuilder.d.ts +223 -0
- package/lib/typescript/src/useNavigationCache.d.ts +19 -0
- package/lib/typescript/src/useNavigationContainerRef.d.ts +2 -0
- package/lib/typescript/src/useNavigationHelpers.d.ts +174 -0
- package/lib/typescript/src/useNavigationState.d.ts +9 -0
- package/lib/typescript/src/useOnAction.d.ts +25 -0
- package/lib/typescript/src/useOnGetState.d.ts +8 -0
- package/lib/typescript/src/useOnPreventRemove.d.ts +16 -0
- package/lib/typescript/src/useOnRouteFocus.d.ts +14 -0
- package/lib/typescript/src/useOptionsGetters.d.ts +12 -0
- package/lib/typescript/src/useRegisterNavigator.d.ts +5 -0
- package/lib/typescript/src/useRoute.d.ts +8 -0
- package/lib/typescript/src/useRouteCache.d.ts +13 -0
- package/lib/typescript/src/useScheduleUpdate.d.ts +13 -0
- package/lib/typescript/src/useSyncState.d.ts +4 -0
- package/lib/typescript/src/validatePathConfig.d.ts +1 -0
- package/package.json +73 -0
- package/src/BaseNavigationContainer.tsx +453 -0
- package/src/CurrentRenderContext.tsx +10 -0
- package/src/EnsureSingleNavigator.tsx +53 -0
- package/src/Group.tsx +14 -0
- package/src/NavigationBuilderContext.tsx +70 -0
- package/src/NavigationContainerRefContext.tsx +14 -0
- package/src/NavigationContext.tsx +12 -0
- package/src/NavigationHelpersContext.tsx +13 -0
- package/src/NavigationRouteContext.tsx +10 -0
- package/src/NavigationStateContext.tsx +39 -0
- package/src/SceneView.tsx +134 -0
- package/src/Screen.tsx +17 -0
- package/src/StaticContainer.tsx +29 -0
- package/src/UnhandledActionContext.tsx +9 -0
- package/src/checkDuplicateRouteNames.tsx +33 -0
- package/src/checkSerializable.tsx +74 -0
- package/src/createNavigationContainerRef.tsx +97 -0
- package/src/createNavigatorFactory.tsx +40 -0
- package/src/findFocusedRoute.tsx +13 -0
- package/src/fromEntries.tsx +13 -0
- package/src/getActionFromState.tsx +154 -0
- package/src/getFocusedRouteNameFromRoute.tsx +28 -0
- package/src/getPathFromState.tsx +297 -0
- package/src/getStateFromPath.tsx +575 -0
- package/src/index.tsx +23 -0
- package/src/isArrayEqual.tsx +7 -0
- package/src/types.tsx +645 -0
- package/src/useChildListeners.tsx +37 -0
- package/src/useComponent.tsx +30 -0
- package/src/useCurrentRender.tsx +35 -0
- package/src/useDescriptors.tsx +229 -0
- package/src/useEventEmitter.tsx +130 -0
- package/src/useFocusEffect.tsx +112 -0
- package/src/useFocusEvents.tsx +73 -0
- package/src/useFocusedListenersChildrenAdapter.tsx +47 -0
- package/src/useIsFocused.tsx +43 -0
- package/src/useKeyedChildListeners.tsx +40 -0
- package/src/useNavigation.tsx +26 -0
- package/src/useNavigationBuilder.tsx +640 -0
- package/src/useNavigationCache.tsx +159 -0
- package/src/useNavigationContainerRef.tsx +17 -0
- package/src/useNavigationHelpers.tsx +98 -0
- package/src/useNavigationState.tsx +41 -0
- package/src/useOnAction.tsx +166 -0
- package/src/useOnGetState.tsx +47 -0
- package/src/useOnPreventRemove.tsx +99 -0
- package/src/useOnRouteFocus.tsx +47 -0
- package/src/useOptionsGetters.tsx +98 -0
- package/src/useRegisterNavigator.tsx +29 -0
- package/src/useRoute.tsx +22 -0
- package/src/useRouteCache.tsx +55 -0
- package/src/useScheduleUpdate.tsx +32 -0
- package/src/useSyncState.tsx +74 -0
- package/src/validatePathConfig.tsx +32 -0
|
@@ -0,0 +1,453 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CommonActions,
|
|
3
|
+
InitialState,
|
|
4
|
+
NavigationAction,
|
|
5
|
+
NavigationState,
|
|
6
|
+
ParamListBase,
|
|
7
|
+
PartialState,
|
|
8
|
+
Route,
|
|
9
|
+
} from '@react-navigation/routers';
|
|
10
|
+
import * as React from 'react';
|
|
11
|
+
|
|
12
|
+
import checkDuplicateRouteNames from './checkDuplicateRouteNames';
|
|
13
|
+
import checkSerializable from './checkSerializable';
|
|
14
|
+
import { NOT_INITIALIZED_ERROR } from './createNavigationContainerRef';
|
|
15
|
+
import EnsureSingleNavigator from './EnsureSingleNavigator';
|
|
16
|
+
import findFocusedRoute from './findFocusedRoute';
|
|
17
|
+
import NavigationBuilderContext from './NavigationBuilderContext';
|
|
18
|
+
import NavigationContainerRefContext from './NavigationContainerRefContext';
|
|
19
|
+
import NavigationContext from './NavigationContext';
|
|
20
|
+
import NavigationRouteContext from './NavigationRouteContext';
|
|
21
|
+
import NavigationStateContext from './NavigationStateContext';
|
|
22
|
+
import type {
|
|
23
|
+
NavigationContainerEventMap,
|
|
24
|
+
NavigationContainerProps,
|
|
25
|
+
NavigationContainerRef,
|
|
26
|
+
} from './types';
|
|
27
|
+
import UnhandledActionContext from './UnhandledActionContext';
|
|
28
|
+
import useChildListeners from './useChildListeners';
|
|
29
|
+
import useEventEmitter from './useEventEmitter';
|
|
30
|
+
import useKeyedChildListeners from './useKeyedChildListeners';
|
|
31
|
+
import useOptionsGetters from './useOptionsGetters';
|
|
32
|
+
import { ScheduleUpdateContext } from './useScheduleUpdate';
|
|
33
|
+
import useSyncState from './useSyncState';
|
|
34
|
+
|
|
35
|
+
type State = NavigationState | PartialState<NavigationState> | undefined;
|
|
36
|
+
|
|
37
|
+
const serializableWarnings: string[] = [];
|
|
38
|
+
const duplicateNameWarnings: string[] = [];
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Remove `key` and `routeNames` from the state objects recursively to get partial state.
|
|
42
|
+
*
|
|
43
|
+
* @param state Initial state object.
|
|
44
|
+
*/
|
|
45
|
+
const getPartialState = (
|
|
46
|
+
state: InitialState | undefined
|
|
47
|
+
): PartialState<NavigationState> | undefined => {
|
|
48
|
+
if (state === undefined) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
53
|
+
const { key, routeNames, ...partialState } = state;
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
...partialState,
|
|
57
|
+
stale: true,
|
|
58
|
+
routes: state.routes.map((route) => {
|
|
59
|
+
if (route.state === undefined) {
|
|
60
|
+
return route as Route<string> & {
|
|
61
|
+
state?: PartialState<NavigationState>;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return { ...route, state: getPartialState(route.state) };
|
|
66
|
+
}),
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Container component which holds the navigation state.
|
|
72
|
+
* This should be rendered at the root wrapping the whole app.
|
|
73
|
+
*
|
|
74
|
+
* @param props.initialState Initial state object for the navigation tree.
|
|
75
|
+
* @param props.onStateChange Callback which is called with the latest navigation state when it changes.
|
|
76
|
+
* @param props.children Child elements to render the content.
|
|
77
|
+
* @param props.ref Ref object which refers to the navigation object containing helper methods.
|
|
78
|
+
*/
|
|
79
|
+
const BaseNavigationContainer = React.forwardRef(
|
|
80
|
+
function BaseNavigationContainer(
|
|
81
|
+
{
|
|
82
|
+
initialState,
|
|
83
|
+
onStateChange,
|
|
84
|
+
onUnhandledAction,
|
|
85
|
+
independent,
|
|
86
|
+
children,
|
|
87
|
+
}: NavigationContainerProps,
|
|
88
|
+
ref?: React.Ref<NavigationContainerRef<ParamListBase>>
|
|
89
|
+
) {
|
|
90
|
+
const parent = React.useContext(NavigationStateContext);
|
|
91
|
+
|
|
92
|
+
if (!parent.isDefault && !independent) {
|
|
93
|
+
throw new Error(
|
|
94
|
+
"Looks like you have nested a 'NavigationContainer' inside another. Normally you need only one container at the root of the app, so this was probably an error. If this was intentional, pass 'independent={true}' explicitly. Note that this will make the child navigators disconnected from the parent and you won't be able to navigate between them."
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const [state, getState, setState, scheduleUpdate, flushUpdates] =
|
|
99
|
+
useSyncState<State>(() =>
|
|
100
|
+
getPartialState(initialState == null ? undefined : initialState)
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
const isFirstMountRef = React.useRef<boolean>(true);
|
|
104
|
+
|
|
105
|
+
const navigatorKeyRef = React.useRef<string | undefined>();
|
|
106
|
+
|
|
107
|
+
const getKey = React.useCallback(() => navigatorKeyRef.current, []);
|
|
108
|
+
|
|
109
|
+
const setKey = React.useCallback((key: string) => {
|
|
110
|
+
navigatorKeyRef.current = key;
|
|
111
|
+
}, []);
|
|
112
|
+
|
|
113
|
+
const { listeners, addListener } = useChildListeners();
|
|
114
|
+
|
|
115
|
+
const { keyedListeners, addKeyedListener } = useKeyedChildListeners();
|
|
116
|
+
|
|
117
|
+
const dispatch = React.useCallback(
|
|
118
|
+
(
|
|
119
|
+
action:
|
|
120
|
+
| NavigationAction
|
|
121
|
+
| ((state: NavigationState) => NavigationAction)
|
|
122
|
+
) => {
|
|
123
|
+
if (listeners.focus[0] == null) {
|
|
124
|
+
console.error(NOT_INITIALIZED_ERROR);
|
|
125
|
+
} else {
|
|
126
|
+
listeners.focus[0]((navigation) => navigation.dispatch(action));
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
[listeners.focus]
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
const canGoBack = React.useCallback(() => {
|
|
133
|
+
if (listeners.focus[0] == null) {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const { result, handled } = listeners.focus[0]((navigation) =>
|
|
138
|
+
navigation.canGoBack()
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
if (handled) {
|
|
142
|
+
return result;
|
|
143
|
+
} else {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
}, [listeners.focus]);
|
|
147
|
+
|
|
148
|
+
const resetRoot = React.useCallback(
|
|
149
|
+
(state?: PartialState<NavigationState> | NavigationState) => {
|
|
150
|
+
const target = state?.key ?? keyedListeners.getState.root?.().key;
|
|
151
|
+
|
|
152
|
+
if (target == null) {
|
|
153
|
+
console.error(NOT_INITIALIZED_ERROR);
|
|
154
|
+
} else {
|
|
155
|
+
listeners.focus[0]((navigation) =>
|
|
156
|
+
navigation.dispatch({
|
|
157
|
+
...CommonActions.reset(state),
|
|
158
|
+
target,
|
|
159
|
+
})
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
[keyedListeners.getState, listeners.focus]
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
const getRootState = React.useCallback(() => {
|
|
167
|
+
return keyedListeners.getState.root?.();
|
|
168
|
+
}, [keyedListeners.getState]);
|
|
169
|
+
|
|
170
|
+
const getCurrentRoute = React.useCallback(() => {
|
|
171
|
+
const state = getRootState();
|
|
172
|
+
|
|
173
|
+
if (state == null) {
|
|
174
|
+
return undefined;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const route = findFocusedRoute(state);
|
|
178
|
+
|
|
179
|
+
return route as Route<string> | undefined;
|
|
180
|
+
}, [getRootState]);
|
|
181
|
+
|
|
182
|
+
const emitter = useEventEmitter<NavigationContainerEventMap>();
|
|
183
|
+
|
|
184
|
+
const { addOptionsGetter, getCurrentOptions } = useOptionsGetters({});
|
|
185
|
+
|
|
186
|
+
const navigation: NavigationContainerRef<ParamListBase> = React.useMemo(
|
|
187
|
+
() => ({
|
|
188
|
+
...Object.keys(CommonActions).reduce<any>((acc, name) => {
|
|
189
|
+
acc[name] = (...args: any[]) =>
|
|
190
|
+
// @ts-expect-error: this is ok
|
|
191
|
+
dispatch(CommonActions[name](...args));
|
|
192
|
+
return acc;
|
|
193
|
+
}, {}),
|
|
194
|
+
...emitter.create('root'),
|
|
195
|
+
dispatch,
|
|
196
|
+
resetRoot,
|
|
197
|
+
isFocused: () => true,
|
|
198
|
+
canGoBack,
|
|
199
|
+
getParent: () => undefined,
|
|
200
|
+
getState: () => stateRef.current,
|
|
201
|
+
getRootState,
|
|
202
|
+
getCurrentRoute,
|
|
203
|
+
getCurrentOptions,
|
|
204
|
+
isReady: () => listeners.focus[0] != null,
|
|
205
|
+
}),
|
|
206
|
+
[
|
|
207
|
+
canGoBack,
|
|
208
|
+
dispatch,
|
|
209
|
+
emitter,
|
|
210
|
+
getCurrentOptions,
|
|
211
|
+
getCurrentRoute,
|
|
212
|
+
getRootState,
|
|
213
|
+
listeners.focus,
|
|
214
|
+
resetRoot,
|
|
215
|
+
]
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
React.useImperativeHandle(ref, () => navigation, [navigation]);
|
|
219
|
+
|
|
220
|
+
const onDispatchAction = React.useCallback(
|
|
221
|
+
(action: NavigationAction, noop: boolean) => {
|
|
222
|
+
emitter.emit({
|
|
223
|
+
type: '__unsafe_action__',
|
|
224
|
+
data: { action, noop, stack: stackRef.current },
|
|
225
|
+
});
|
|
226
|
+
},
|
|
227
|
+
[emitter]
|
|
228
|
+
);
|
|
229
|
+
|
|
230
|
+
const lastEmittedOptionsRef = React.useRef<object | undefined>();
|
|
231
|
+
|
|
232
|
+
const onOptionsChange = React.useCallback(
|
|
233
|
+
(options) => {
|
|
234
|
+
if (lastEmittedOptionsRef.current === options) {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
lastEmittedOptionsRef.current = options;
|
|
239
|
+
|
|
240
|
+
emitter.emit({
|
|
241
|
+
type: 'options',
|
|
242
|
+
data: { options },
|
|
243
|
+
});
|
|
244
|
+
},
|
|
245
|
+
[emitter]
|
|
246
|
+
);
|
|
247
|
+
|
|
248
|
+
const stackRef = React.useRef<string | undefined>();
|
|
249
|
+
|
|
250
|
+
const builderContext = React.useMemo(
|
|
251
|
+
() => ({
|
|
252
|
+
addListener,
|
|
253
|
+
addKeyedListener,
|
|
254
|
+
onDispatchAction,
|
|
255
|
+
onOptionsChange,
|
|
256
|
+
stackRef,
|
|
257
|
+
}),
|
|
258
|
+
[addListener, addKeyedListener, onDispatchAction, onOptionsChange]
|
|
259
|
+
);
|
|
260
|
+
|
|
261
|
+
const scheduleContext = React.useMemo(
|
|
262
|
+
() => ({ scheduleUpdate, flushUpdates }),
|
|
263
|
+
[scheduleUpdate, flushUpdates]
|
|
264
|
+
);
|
|
265
|
+
|
|
266
|
+
const isInitialRef = React.useRef(true);
|
|
267
|
+
|
|
268
|
+
const getIsInitial = React.useCallback(() => isInitialRef.current, []);
|
|
269
|
+
|
|
270
|
+
const context = React.useMemo(
|
|
271
|
+
() => ({
|
|
272
|
+
state,
|
|
273
|
+
getState,
|
|
274
|
+
setState,
|
|
275
|
+
getKey,
|
|
276
|
+
setKey,
|
|
277
|
+
getIsInitial,
|
|
278
|
+
addOptionsGetter,
|
|
279
|
+
}),
|
|
280
|
+
[
|
|
281
|
+
state,
|
|
282
|
+
getState,
|
|
283
|
+
setState,
|
|
284
|
+
getKey,
|
|
285
|
+
setKey,
|
|
286
|
+
getIsInitial,
|
|
287
|
+
addOptionsGetter,
|
|
288
|
+
]
|
|
289
|
+
);
|
|
290
|
+
|
|
291
|
+
const onStateChangeRef = React.useRef(onStateChange);
|
|
292
|
+
const stateRef = React.useRef(state);
|
|
293
|
+
|
|
294
|
+
React.useEffect(() => {
|
|
295
|
+
isInitialRef.current = false;
|
|
296
|
+
onStateChangeRef.current = onStateChange;
|
|
297
|
+
stateRef.current = state;
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
React.useEffect(() => {
|
|
301
|
+
const hydratedState = getRootState();
|
|
302
|
+
|
|
303
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
304
|
+
if (hydratedState !== undefined) {
|
|
305
|
+
const serializableResult = checkSerializable(hydratedState);
|
|
306
|
+
|
|
307
|
+
if (!serializableResult.serializable) {
|
|
308
|
+
const { location, reason } = serializableResult;
|
|
309
|
+
|
|
310
|
+
let path = '';
|
|
311
|
+
let pointer: Record<any, any> = hydratedState;
|
|
312
|
+
let params = false;
|
|
313
|
+
|
|
314
|
+
for (let i = 0; i < location.length; i++) {
|
|
315
|
+
const curr = location[i];
|
|
316
|
+
const prev = location[i - 1];
|
|
317
|
+
|
|
318
|
+
pointer = pointer[curr];
|
|
319
|
+
|
|
320
|
+
if (!params && curr === 'state') {
|
|
321
|
+
continue;
|
|
322
|
+
} else if (!params && curr === 'routes') {
|
|
323
|
+
if (path) {
|
|
324
|
+
path += ' > ';
|
|
325
|
+
}
|
|
326
|
+
} else if (
|
|
327
|
+
!params &&
|
|
328
|
+
typeof curr === 'number' &&
|
|
329
|
+
prev === 'routes'
|
|
330
|
+
) {
|
|
331
|
+
path += pointer?.name;
|
|
332
|
+
} else if (!params) {
|
|
333
|
+
path += ` > ${curr}`;
|
|
334
|
+
params = true;
|
|
335
|
+
} else {
|
|
336
|
+
if (typeof curr === 'number' || /^[0-9]+$/.test(curr)) {
|
|
337
|
+
path += `[${curr}]`;
|
|
338
|
+
} else if (/^[a-z$_]+$/i.test(curr)) {
|
|
339
|
+
path += `.${curr}`;
|
|
340
|
+
} else {
|
|
341
|
+
path += `[${JSON.stringify(curr)}]`;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
const message = `Non-serializable values were found in the navigation state. Check:\n\n${path} (${reason})\n\nThis can break usage such as persisting and restoring state. This might happen if you passed non-serializable values such as function, class instances etc. in params. If you need to use components with callbacks in your options, you can use 'navigation.setOptions' instead. See https://reactnavigation.org/docs/troubleshooting#i-get-the-warning-non-serializable-values-were-found-in-the-navigation-state for more details.`;
|
|
347
|
+
|
|
348
|
+
if (!serializableWarnings.includes(message)) {
|
|
349
|
+
serializableWarnings.push(message);
|
|
350
|
+
console.warn(message);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
const duplicateRouteNamesResult =
|
|
355
|
+
checkDuplicateRouteNames(hydratedState);
|
|
356
|
+
|
|
357
|
+
if (duplicateRouteNamesResult.length) {
|
|
358
|
+
const message = `Found screens with the same name nested inside one another. Check:\n${duplicateRouteNamesResult.map(
|
|
359
|
+
(locations) => `\n${locations.join(', ')}`
|
|
360
|
+
)}\n\nThis can cause confusing behavior during navigation. Consider using unique names for each screen instead.`;
|
|
361
|
+
|
|
362
|
+
if (!duplicateNameWarnings.includes(message)) {
|
|
363
|
+
duplicateNameWarnings.push(message);
|
|
364
|
+
console.warn(message);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
emitter.emit({ type: 'state', data: { state } });
|
|
371
|
+
|
|
372
|
+
if (!isFirstMountRef.current && onStateChangeRef.current) {
|
|
373
|
+
onStateChangeRef.current(hydratedState);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
isFirstMountRef.current = false;
|
|
377
|
+
}, [getRootState, emitter, state]);
|
|
378
|
+
|
|
379
|
+
const defaultOnUnhandledAction = React.useCallback(
|
|
380
|
+
(action: NavigationAction) => {
|
|
381
|
+
if (process.env.NODE_ENV === 'production') {
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
const payload: Record<string, any> | undefined = action.payload;
|
|
386
|
+
|
|
387
|
+
let message = `The action '${action.type}'${
|
|
388
|
+
payload ? ` with payload ${JSON.stringify(action.payload)}` : ''
|
|
389
|
+
} was not handled by any navigator.`;
|
|
390
|
+
|
|
391
|
+
switch (action.type) {
|
|
392
|
+
case 'NAVIGATE':
|
|
393
|
+
case 'PUSH':
|
|
394
|
+
case 'REPLACE':
|
|
395
|
+
case 'JUMP_TO':
|
|
396
|
+
if (payload?.name) {
|
|
397
|
+
message += `\n\nDo you have a screen named '${payload.name}'?\n\nIf you're trying to navigate to a screen in a nested navigator, see https://reactnavigation.org/docs/nesting-navigators#navigating-to-a-screen-in-a-nested-navigator.`;
|
|
398
|
+
} else {
|
|
399
|
+
message += `\n\nYou need to pass the name of the screen to navigate to.\n\nSee https://reactnavigation.org/docs/navigation-actions for usage.`;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
break;
|
|
403
|
+
case 'GO_BACK':
|
|
404
|
+
case 'POP':
|
|
405
|
+
case 'POP_TO_TOP':
|
|
406
|
+
message += `\n\nIs there any screen to go back to?`;
|
|
407
|
+
break;
|
|
408
|
+
case 'OPEN_DRAWER':
|
|
409
|
+
case 'CLOSE_DRAWER':
|
|
410
|
+
case 'TOGGLE_DRAWER':
|
|
411
|
+
message += `\n\nIs your screen inside a Drawer navigator?`;
|
|
412
|
+
break;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
message += `\n\nThis is a development-only warning and won't be shown in production.`;
|
|
416
|
+
|
|
417
|
+
console.error(message);
|
|
418
|
+
},
|
|
419
|
+
[]
|
|
420
|
+
);
|
|
421
|
+
|
|
422
|
+
let element = (
|
|
423
|
+
<NavigationContainerRefContext.Provider value={navigation}>
|
|
424
|
+
<ScheduleUpdateContext.Provider value={scheduleContext}>
|
|
425
|
+
<NavigationBuilderContext.Provider value={builderContext}>
|
|
426
|
+
<NavigationStateContext.Provider value={context}>
|
|
427
|
+
<UnhandledActionContext.Provider
|
|
428
|
+
value={onUnhandledAction ?? defaultOnUnhandledAction}
|
|
429
|
+
>
|
|
430
|
+
<EnsureSingleNavigator>{children}</EnsureSingleNavigator>
|
|
431
|
+
</UnhandledActionContext.Provider>
|
|
432
|
+
</NavigationStateContext.Provider>
|
|
433
|
+
</NavigationBuilderContext.Provider>
|
|
434
|
+
</ScheduleUpdateContext.Provider>
|
|
435
|
+
</NavigationContainerRefContext.Provider>
|
|
436
|
+
);
|
|
437
|
+
|
|
438
|
+
if (independent) {
|
|
439
|
+
// We need to clear any existing contexts for nested independent container to work correctly
|
|
440
|
+
element = (
|
|
441
|
+
<NavigationRouteContext.Provider value={undefined}>
|
|
442
|
+
<NavigationContext.Provider value={undefined}>
|
|
443
|
+
{element}
|
|
444
|
+
</NavigationContext.Provider>
|
|
445
|
+
</NavigationRouteContext.Provider>
|
|
446
|
+
);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
return element;
|
|
450
|
+
}
|
|
451
|
+
);
|
|
452
|
+
|
|
453
|
+
export default BaseNavigationContainer;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Context which holds the values for the current navigation tree.
|
|
5
|
+
* Intended for use in SSR. This is not safe to use on the client.
|
|
6
|
+
*/
|
|
7
|
+
const CurrentRenderContext =
|
|
8
|
+
React.createContext<{ options?: object } | undefined>(undefined);
|
|
9
|
+
|
|
10
|
+
export default CurrentRenderContext;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
type Props = {
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
const MULTIPLE_NAVIGATOR_ERROR = `Another navigator is already registered for this container. You likely have multiple navigators under a single "NavigationContainer" or "Screen". Make sure each navigator is under a separate "Screen" container. See https://reactnavigation.org/docs/nesting-navigators for a guide on nesting.`;
|
|
8
|
+
|
|
9
|
+
export const SingleNavigatorContext =
|
|
10
|
+
React.createContext<
|
|
11
|
+
| {
|
|
12
|
+
register(key: string): void;
|
|
13
|
+
unregister(key: string): void;
|
|
14
|
+
}
|
|
15
|
+
| undefined
|
|
16
|
+
>(undefined);
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Component which ensures that there's only one navigator nested under it.
|
|
20
|
+
*/
|
|
21
|
+
export default function EnsureSingleNavigator({ children }: Props) {
|
|
22
|
+
const navigatorKeyRef = React.useRef<string | undefined>();
|
|
23
|
+
|
|
24
|
+
const value = React.useMemo(
|
|
25
|
+
() => ({
|
|
26
|
+
register(key: string) {
|
|
27
|
+
const currentKey = navigatorKeyRef.current;
|
|
28
|
+
|
|
29
|
+
if (currentKey !== undefined && key !== currentKey) {
|
|
30
|
+
throw new Error(MULTIPLE_NAVIGATOR_ERROR);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
navigatorKeyRef.current = key;
|
|
34
|
+
},
|
|
35
|
+
unregister(key: string) {
|
|
36
|
+
const currentKey = navigatorKeyRef.current;
|
|
37
|
+
|
|
38
|
+
if (key !== currentKey) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
navigatorKeyRef.current = undefined;
|
|
43
|
+
},
|
|
44
|
+
}),
|
|
45
|
+
[]
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<SingleNavigatorContext.Provider value={value}>
|
|
50
|
+
{children}
|
|
51
|
+
</SingleNavigatorContext.Provider>
|
|
52
|
+
);
|
|
53
|
+
}
|
package/src/Group.tsx
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ParamListBase } from '@react-navigation/routers';
|
|
2
|
+
|
|
3
|
+
import type { RouteGroupConfig } from './types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Empty component used for grouping screen configs.
|
|
7
|
+
*/
|
|
8
|
+
export default function Group<
|
|
9
|
+
ParamList extends ParamListBase,
|
|
10
|
+
ScreenOptions extends {}
|
|
11
|
+
>(_: RouteGroupConfig<ParamList, ScreenOptions>) {
|
|
12
|
+
/* istanbul ignore next */
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
NavigationAction,
|
|
3
|
+
NavigationState,
|
|
4
|
+
ParamListBase,
|
|
5
|
+
} from '@react-navigation/routers';
|
|
6
|
+
import * as React from 'react';
|
|
7
|
+
|
|
8
|
+
import type { NavigationHelpers } from './types';
|
|
9
|
+
|
|
10
|
+
export type ListenerMap = {
|
|
11
|
+
action: ChildActionListener;
|
|
12
|
+
focus: FocusedNavigationListener;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type KeyedListenerMap = {
|
|
16
|
+
getState: GetStateListener;
|
|
17
|
+
beforeRemove: ChildBeforeRemoveListener;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type AddListener = <T extends keyof ListenerMap>(
|
|
21
|
+
type: T,
|
|
22
|
+
listener: ListenerMap[T]
|
|
23
|
+
) => void;
|
|
24
|
+
|
|
25
|
+
export type AddKeyedListener = <T extends keyof KeyedListenerMap>(
|
|
26
|
+
type: T,
|
|
27
|
+
key: string,
|
|
28
|
+
listener: KeyedListenerMap[T]
|
|
29
|
+
) => void;
|
|
30
|
+
|
|
31
|
+
export type ChildActionListener = (
|
|
32
|
+
action: NavigationAction,
|
|
33
|
+
visitedNavigators?: Set<string>
|
|
34
|
+
) => boolean;
|
|
35
|
+
|
|
36
|
+
export type FocusedNavigationCallback<T> = (
|
|
37
|
+
navigation: NavigationHelpers<ParamListBase>
|
|
38
|
+
) => T;
|
|
39
|
+
|
|
40
|
+
export type FocusedNavigationListener = <T>(
|
|
41
|
+
callback: FocusedNavigationCallback<T>
|
|
42
|
+
) => {
|
|
43
|
+
handled: boolean;
|
|
44
|
+
result: T;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export type GetStateListener = () => NavigationState;
|
|
48
|
+
|
|
49
|
+
export type ChildBeforeRemoveListener = (action: NavigationAction) => boolean;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Context which holds the required helpers needed to build nested navigators.
|
|
53
|
+
*/
|
|
54
|
+
const NavigationBuilderContext = React.createContext<{
|
|
55
|
+
onAction?: (
|
|
56
|
+
action: NavigationAction,
|
|
57
|
+
visitedNavigators?: Set<string>
|
|
58
|
+
) => boolean;
|
|
59
|
+
addListener?: AddListener;
|
|
60
|
+
addKeyedListener?: AddKeyedListener;
|
|
61
|
+
onRouteFocus?: (key: string) => void;
|
|
62
|
+
onDispatchAction: (action: NavigationAction, noop: boolean) => void;
|
|
63
|
+
onOptionsChange: (options: object) => void;
|
|
64
|
+
stackRef?: React.MutableRefObject<string | undefined>;
|
|
65
|
+
}>({
|
|
66
|
+
onDispatchAction: () => undefined,
|
|
67
|
+
onOptionsChange: () => undefined,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
export default NavigationBuilderContext;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ParamListBase } from '@react-navigation/routers';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
|
|
4
|
+
import type { NavigationContainerRef } from './types';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Context which holds the route prop for a screen.
|
|
8
|
+
*/
|
|
9
|
+
const NavigationContainerRefContext =
|
|
10
|
+
React.createContext<NavigationContainerRef<ParamListBase> | undefined>(
|
|
11
|
+
undefined
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
export default NavigationContainerRefContext;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ParamListBase } from '@react-navigation/routers';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
|
|
4
|
+
import type { NavigationProp } from './types';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Context which holds the navigation prop for a screen.
|
|
8
|
+
*/
|
|
9
|
+
const NavigationContext =
|
|
10
|
+
React.createContext<NavigationProp<ParamListBase> | undefined>(undefined);
|
|
11
|
+
|
|
12
|
+
export default NavigationContext;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ParamListBase } from '@react-navigation/routers';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
|
|
4
|
+
import type { NavigationHelpers } from './types';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Context which holds the navigation helpers of the parent navigator.
|
|
8
|
+
* Navigators should use this context in their view component.
|
|
9
|
+
*/
|
|
10
|
+
const NavigationHelpersContext =
|
|
11
|
+
React.createContext<NavigationHelpers<ParamListBase> | undefined>(undefined);
|
|
12
|
+
|
|
13
|
+
export default NavigationHelpersContext;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Route } from '@react-navigation/routers';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Context which holds the route prop for a screen.
|
|
6
|
+
*/
|
|
7
|
+
const NavigationRouteContext =
|
|
8
|
+
React.createContext<Route<string> | undefined>(undefined);
|
|
9
|
+
|
|
10
|
+
export default NavigationRouteContext;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { NavigationState, PartialState } from '@react-navigation/routers';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
|
|
4
|
+
const MISSING_CONTEXT_ERROR =
|
|
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
|
+
|
|
7
|
+
export default React.createContext<{
|
|
8
|
+
isDefault?: true;
|
|
9
|
+
state?: NavigationState | PartialState<NavigationState>;
|
|
10
|
+
getKey: () => string | undefined;
|
|
11
|
+
setKey: (key: string) => void;
|
|
12
|
+
getState: () => NavigationState | PartialState<NavigationState> | undefined;
|
|
13
|
+
setState: (
|
|
14
|
+
state: NavigationState | PartialState<NavigationState> | undefined
|
|
15
|
+
) => void;
|
|
16
|
+
getIsInitial: () => boolean;
|
|
17
|
+
addOptionsGetter?: (
|
|
18
|
+
key: string,
|
|
19
|
+
getter: () => object | undefined | null
|
|
20
|
+
) => void;
|
|
21
|
+
}>({
|
|
22
|
+
isDefault: true,
|
|
23
|
+
|
|
24
|
+
get getKey(): any {
|
|
25
|
+
throw new Error(MISSING_CONTEXT_ERROR);
|
|
26
|
+
},
|
|
27
|
+
get setKey(): any {
|
|
28
|
+
throw new Error(MISSING_CONTEXT_ERROR);
|
|
29
|
+
},
|
|
30
|
+
get getState(): any {
|
|
31
|
+
throw new Error(MISSING_CONTEXT_ERROR);
|
|
32
|
+
},
|
|
33
|
+
get setState(): any {
|
|
34
|
+
throw new Error(MISSING_CONTEXT_ERROR);
|
|
35
|
+
},
|
|
36
|
+
get getIsInitial(): any {
|
|
37
|
+
throw new Error(MISSING_CONTEXT_ERROR);
|
|
38
|
+
},
|
|
39
|
+
});
|