@react-navigation/core 8.0.0-alpha.3 → 8.0.0-alpha.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/module/BaseNavigationContainer.js +38 -19
- 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 +127 -0
- package/lib/module/DataLoading.js.map +1 -0
- package/lib/module/NavigationBuilderContext.js +1 -0
- package/lib/module/NavigationBuilderContext.js.map +1 -1
- package/lib/module/NavigationIndependentTree.js +20 -8
- package/lib/module/NavigationIndependentTree.js.map +1 -1
- package/lib/module/NavigationProvider.js +22 -11
- package/lib/module/NavigationProvider.js.map +1 -1
- 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 +37 -27
- package/lib/module/PreventRemoveProvider.js.map +1 -1
- package/lib/module/SceneView.js +10 -41
- package/lib/module/SceneView.js.map +1 -1
- package/lib/module/StaticNavigation.js +179 -50
- 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/checkSerializable.js +18 -13
- package/lib/module/checkSerializable.js.map +1 -1
- package/lib/module/createNavigationContainerRef.js +6 -8
- 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 +171 -90
- package/lib/module/getPathFromState.js.map +1 -1
- package/lib/module/getPatternParts.js +20 -4
- package/lib/module/getPatternParts.js.map +1 -1
- package/lib/module/getStateFromPath.js +487 -217
- 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 +5 -4
- package/lib/module/index.js.map +1 -1
- package/lib/module/theming/useTheme.js +1 -1
- package/lib/module/theming/useTheme.js.map +1 -1
- package/lib/module/types.js +35 -0
- package/lib/module/types.js.map +1 -1
- package/lib/module/useDescriptors.js +21 -11
- 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/useFocusEvents.js +12 -4
- package/lib/module/useFocusEvents.js.map +1 -1
- package/lib/module/useFocusedListenersChildrenAdapter.js +2 -2
- package/lib/module/useFocusedListenersChildrenAdapter.js.map +1 -1
- package/lib/module/useIsFocused.js +7 -12
- package/lib/module/useIsFocused.js.map +1 -1
- package/lib/module/useKeyedChildListeners.js +4 -2
- package/lib/module/useKeyedChildListeners.js.map +1 -1
- package/lib/module/useLazyValue.js.map +1 -1
- package/lib/module/useNavigation.js +2 -15
- package/lib/module/useNavigation.js.map +1 -1
- package/lib/module/useNavigationBuilder.js +204 -131
- package/lib/module/useNavigationBuilder.js.map +1 -1
- package/lib/module/useNavigationCache.js +22 -17
- package/lib/module/useNavigationCache.js.map +1 -1
- package/lib/module/useNavigationHelpers.js +28 -10
- 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 +125 -45
- package/lib/module/useNavigationState.js.map +1 -1
- package/lib/module/useOnAction.js +37 -7
- package/lib/module/useOnAction.js.map +1 -1
- package/lib/module/useOnGetState.js +6 -3
- package/lib/module/useOnGetState.js.map +1 -1
- package/lib/module/useOnPreventRemove.js +39 -30
- package/lib/module/useOnPreventRemove.js.map +1 -1
- package/lib/module/useOnRouteFocus.js +1 -1
- package/lib/module/useOnRouteFocus.js.map +1 -1
- package/lib/module/useOptionsGetters.js +10 -5
- package/lib/module/useOptionsGetters.js.map +1 -1
- package/lib/module/usePreventRemove.js +10 -3
- package/lib/module/usePreventRemove.js.map +1 -1
- package/lib/module/usePreventRemoveContext.js +1 -1
- package/lib/module/usePreventRemoveContext.js.map +1 -1
- package/lib/module/useRegisterNavigator.js +2 -2
- 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 +17 -11
- package/lib/module/useRouteCache.js.map +1 -1
- package/lib/module/useScheduleUpdate.js +9 -9
- 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 +32 -9
- 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 +9 -8
- 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 +12 -13
- package/lib/typescript/src/NavigationProvider.d.ts.map +1 -1
- package/lib/typescript/src/NavigationStateContext.d.ts +4 -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 +4 -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 -109
- 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/checkSerializable.d.ts +8 -4
- package/lib/typescript/src/checkSerializable.d.ts.map +1 -1
- 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 +1 -0
- 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/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 +260 -159
- 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/useComponent.d.ts +1 -1
- package/lib/typescript/src/useComponent.d.ts.map +1 -1
- package/lib/typescript/src/useDescriptors.d.ts +10 -9
- 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/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 +3 -0
- package/lib/typescript/src/useIsFocused.d.ts.map +1 -1
- package/lib/typescript/src/useKeyedChildListeners.d.ts +3 -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 +23 -30
- package/lib/typescript/src/useNavigationBuilder.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationCache.d.ts +3 -3
- 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 +19 -27
- package/lib/typescript/src/useNavigationHelpers.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationState.d.ts +17 -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/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 +1 -1
- 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/useRoute.d.ts +7 -3
- package/lib/typescript/src/useRoute.d.ts.map +1 -1
- package/lib/typescript/src/useRouteCache.d.ts +5 -5
- 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 +74 -37
- package/lib/typescript/src/utilities.d.ts.map +1 -1
- package/lib/typescript/src/validatePathConfig.d.ts.map +1 -1
- package/package.json +23 -22
- package/src/BaseNavigationContainer.tsx +362 -334
- package/src/ConsumedParamsContext.tsx +5 -0
- package/src/DataLoading.tsx +203 -0
- package/src/NavigationBuilderContext.tsx +14 -9
- package/src/NavigationFocusedRouteStateContext.tsx +4 -4
- package/src/NavigationIndependentTree.tsx +23 -12
- package/src/NavigationProvider.tsx +26 -15
- package/src/NavigationStateContext.tsx +9 -6
- package/src/PreventRemoveContext.tsx +1 -0
- package/src/PreventRemoveProvider.tsx +51 -46
- package/src/SceneView.tsx +11 -39
- package/src/StaticNavigation.tsx +659 -307
- package/src/StaticTreeContext.tsx +7 -0
- package/src/checkSerializable.tsx +35 -19
- package/src/createNavigationContainerRef.tsx +12 -9
- package/src/createNavigatorFactory.tsx +92 -8
- package/src/findFocusedRoute.tsx +16 -16
- package/src/getActionFromState.tsx +87 -51
- package/src/getPathFromState.tsx +254 -128
- package/src/getPatternParts.tsx +25 -4
- package/src/getStateFromPath.tsx +821 -331
- package/src/getStateFromRouteParams.tsx +59 -0
- package/src/index.tsx +55 -5
- package/src/theming/useTheme.tsx +1 -1
- package/src/types.tsx +798 -373
- package/src/useDescriptors.tsx +31 -14
- package/src/useEventEmitter.tsx +52 -38
- package/src/useFocusEvents.tsx +15 -7
- package/src/useFocusedListenersChildrenAdapter.tsx +2 -2
- package/src/useIsFocused.tsx +14 -21
- package/src/useKeyedChildListeners.tsx +4 -2
- package/src/useLazyValue.tsx +2 -2
- package/src/useNavigation.tsx +7 -24
- package/src/useNavigationBuilder.tsx +314 -186
- package/src/useNavigationCache.tsx +32 -25
- package/src/useNavigationHelpers.tsx +27 -10
- package/src/useNavigationIndependentTree.tsx +1 -1
- package/src/useNavigationState.tsx +168 -69
- package/src/useOnAction.tsx +61 -13
- package/src/useOnGetState.tsx +5 -3
- package/src/useOnPreventRemove.tsx +75 -42
- package/src/useOnRouteFocus.tsx +10 -12
- package/src/useOptionsGetters.tsx +11 -5
- package/src/usePreventRemove.tsx +12 -3
- package/src/usePreventRemoveContext.tsx +1 -1
- package/src/useRegisterNavigator.tsx +2 -2
- package/src/useRoute.tsx +20 -6
- package/src/useRouteCache.tsx +22 -16
- package/src/useScheduleUpdate.tsx +9 -10
- package/src/useStateForPath.tsx +1 -1
- package/src/useSyncState.tsx +35 -9
- package/src/utilities.tsx +144 -31
- package/src/validatePathConfig.tsx +86 -57
- package/lib/module/CurrentRenderContext.js +0 -10
- package/lib/module/CurrentRenderContext.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/useCurrentRender.d.ts +0 -14
- package/lib/typescript/src/useCurrentRender.d.ts.map +0 -1
- package/src/CurrentRenderContext.tsx +0 -9
- package/src/useCurrentRender.tsx +0 -31
|
@@ -3,7 +3,6 @@ import {
|
|
|
3
3
|
type InitialState,
|
|
4
4
|
type NavigationAction,
|
|
5
5
|
type NavigationState,
|
|
6
|
-
type ParamListBase,
|
|
7
6
|
type PartialState,
|
|
8
7
|
type Route,
|
|
9
8
|
} from '@react-navigation/routers';
|
|
@@ -12,6 +11,7 @@ import useLatestCallback from 'use-latest-callback';
|
|
|
12
11
|
|
|
13
12
|
import { checkDuplicateRouteNames } from './checkDuplicateRouteNames';
|
|
14
13
|
import { checkSerializable } from './checkSerializable';
|
|
14
|
+
import { ConsumedParamsContext } from './ConsumedParamsContext';
|
|
15
15
|
import { NOT_INITIALIZED_ERROR } from './createNavigationContainerRef';
|
|
16
16
|
import { EnsureSingleNavigator } from './EnsureSingleNavigator';
|
|
17
17
|
import { findFocusedRoute } from './findFocusedRoute';
|
|
@@ -24,11 +24,13 @@ import type {
|
|
|
24
24
|
NavigationContainerEventMap,
|
|
25
25
|
NavigationContainerProps,
|
|
26
26
|
NavigationContainerRef,
|
|
27
|
+
RootParamList,
|
|
27
28
|
} from './types';
|
|
28
29
|
import { UnhandledActionContext } from './UnhandledActionContext';
|
|
29
30
|
import { useChildListeners } from './useChildListeners';
|
|
30
31
|
import { useEventEmitter } from './useEventEmitter';
|
|
31
32
|
import { useKeyedChildListeners } from './useKeyedChildListeners';
|
|
33
|
+
import { useLazyValue } from './useLazyValue';
|
|
32
34
|
import { useNavigationIndependentTree } from './useNavigationIndependentTree';
|
|
33
35
|
import { useOptionsGetters } from './useOptionsGetters';
|
|
34
36
|
import { useSyncState } from './useSyncState';
|
|
@@ -38,6 +40,10 @@ type State = NavigationState | PartialState<NavigationState> | undefined;
|
|
|
38
40
|
const serializableWarnings: string[] = [];
|
|
39
41
|
const duplicateNameWarnings: string[] = [];
|
|
40
42
|
|
|
43
|
+
type Props<ParamList extends {}> = NavigationContainerProps & {
|
|
44
|
+
ref?: React.Ref<NavigationContainerRef<ParamList>>;
|
|
45
|
+
};
|
|
46
|
+
|
|
41
47
|
/**
|
|
42
48
|
* Remove `key` and `routeNames` from the state objects recursively to get partial state.
|
|
43
49
|
*
|
|
@@ -80,387 +86,409 @@ const getPartialState = (
|
|
|
80
86
|
* @param props.children Child elements to render the content.
|
|
81
87
|
* @param props.ref Ref object which refers to the navigation object containing helper methods.
|
|
82
88
|
*/
|
|
83
|
-
export
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
"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, wrap the container in 'NavigationIndependentTree' explicitly. Note that this will make the child navigators disconnected from the parent and you won't be able to navigate between them."
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const { state, getState, setState, scheduleUpdate, flushUpdates } =
|
|
105
|
-
useSyncState<State>(() =>
|
|
106
|
-
getPartialState(initialState == null ? undefined : initialState)
|
|
107
|
-
);
|
|
89
|
+
export function BaseNavigationContainer<ParamList extends {} = RootParamList>({
|
|
90
|
+
initialState,
|
|
91
|
+
onStateChange,
|
|
92
|
+
onReady,
|
|
93
|
+
onUnhandledAction,
|
|
94
|
+
theme,
|
|
95
|
+
children,
|
|
96
|
+
ref,
|
|
97
|
+
}: Props<ParamList>) {
|
|
98
|
+
const parent = React.use(NavigationStateContext);
|
|
99
|
+
const independent = useNavigationIndependentTree();
|
|
100
|
+
|
|
101
|
+
if (!parent.isDefault && !independent) {
|
|
102
|
+
throw new Error(
|
|
103
|
+
"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, wrap the container in 'NavigationIndependentTree' explicitly. Note that this will make the child navigators disconnected from the parent and you won't be able to navigate between them."
|
|
104
|
+
);
|
|
105
|
+
}
|
|
108
106
|
|
|
109
|
-
|
|
107
|
+
const { state, getState, setState, subscribe, scheduleUpdate, flushUpdates } =
|
|
108
|
+
useSyncState<State>(() =>
|
|
109
|
+
getPartialState(initialState == null ? undefined : initialState)
|
|
110
|
+
);
|
|
110
111
|
|
|
111
|
-
|
|
112
|
+
const consumedParams = useLazyValue(() => new WeakMap<object, true>());
|
|
112
113
|
|
|
113
|
-
|
|
114
|
+
const isFirstMountRef = React.useRef<boolean>(true);
|
|
114
115
|
|
|
115
|
-
|
|
116
|
-
navigatorKeyRef.current = key;
|
|
117
|
-
}, []);
|
|
116
|
+
const navigatorKeyRef = React.useRef<string | undefined>(undefined);
|
|
118
117
|
|
|
119
|
-
|
|
118
|
+
const getKey = React.useCallback(() => navigatorKeyRef.current, []);
|
|
120
119
|
|
|
121
|
-
|
|
120
|
+
const setKey = React.useCallback((key: string) => {
|
|
121
|
+
navigatorKeyRef.current = key;
|
|
122
|
+
}, []);
|
|
122
123
|
|
|
123
|
-
|
|
124
|
-
(
|
|
125
|
-
action:
|
|
126
|
-
| NavigationAction
|
|
127
|
-
| ((state: NavigationState) => NavigationAction)
|
|
128
|
-
) => {
|
|
129
|
-
if (listeners.focus[0] == null) {
|
|
130
|
-
console.error(NOT_INITIALIZED_ERROR);
|
|
131
|
-
} else {
|
|
132
|
-
listeners.focus[0]((navigation) => navigation.dispatch(action));
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
);
|
|
124
|
+
const { listeners, addListener } = useChildListeners();
|
|
136
125
|
|
|
137
|
-
|
|
138
|
-
if (listeners.focus[0] == null) {
|
|
139
|
-
return false;
|
|
140
|
-
}
|
|
126
|
+
const { keyedListeners, addKeyedListener } = useKeyedChildListeners();
|
|
141
127
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
)
|
|
128
|
+
const dispatch = useLatestCallback(
|
|
129
|
+
(
|
|
130
|
+
action: NavigationAction | ((state: NavigationState) => NavigationAction)
|
|
131
|
+
) => {
|
|
132
|
+
const listener = listeners.focus[0];
|
|
145
133
|
|
|
146
|
-
if (
|
|
147
|
-
|
|
134
|
+
if (listener == null) {
|
|
135
|
+
console.error(NOT_INITIALIZED_ERROR);
|
|
148
136
|
} else {
|
|
149
|
-
|
|
137
|
+
listener((navigation) =>
|
|
138
|
+
React.startTransition(() => {
|
|
139
|
+
navigation.dispatch(action);
|
|
140
|
+
})
|
|
141
|
+
);
|
|
150
142
|
}
|
|
151
|
-
}
|
|
143
|
+
}
|
|
144
|
+
);
|
|
152
145
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
listeners.focus[0]((navigation) =>
|
|
161
|
-
navigation.dispatch({
|
|
162
|
-
...CommonActions.reset(state),
|
|
163
|
-
target,
|
|
164
|
-
})
|
|
165
|
-
);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
146
|
+
const canGoBack = useLatestCallback(() => {
|
|
147
|
+
if (listeners.focus[0] == null) {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const { result, handled } = listeners.focus[0]((navigation) =>
|
|
152
|
+
navigation.canGoBack()
|
|
168
153
|
);
|
|
169
154
|
|
|
170
|
-
|
|
171
|
-
return
|
|
172
|
-
}
|
|
155
|
+
if (handled) {
|
|
156
|
+
return result;
|
|
157
|
+
} else {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
});
|
|
173
161
|
|
|
174
|
-
|
|
175
|
-
|
|
162
|
+
const resetRoot = useLatestCallback(
|
|
163
|
+
(state: PartialState<NavigationState> | NavigationState) => {
|
|
164
|
+
const target = keyedListeners.getState.root?.().key;
|
|
165
|
+
const listener = listeners.focus[0];
|
|
176
166
|
|
|
177
|
-
if (
|
|
178
|
-
|
|
167
|
+
if (target == null || listener == null) {
|
|
168
|
+
console.error(NOT_INITIALIZED_ERROR);
|
|
169
|
+
} else {
|
|
170
|
+
listener((navigation) =>
|
|
171
|
+
navigation.dispatch({
|
|
172
|
+
...CommonActions.reset(state),
|
|
173
|
+
target,
|
|
174
|
+
})
|
|
175
|
+
);
|
|
179
176
|
}
|
|
177
|
+
}
|
|
178
|
+
);
|
|
180
179
|
|
|
181
|
-
|
|
180
|
+
const getRootState = useLatestCallback(() => {
|
|
181
|
+
return keyedListeners.getState.root?.();
|
|
182
|
+
});
|
|
182
183
|
|
|
183
|
-
|
|
184
|
-
|
|
184
|
+
const getCurrentRoute = useLatestCallback(() => {
|
|
185
|
+
const state = getRootState();
|
|
185
186
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
const { addOptionsGetter, getCurrentOptions } = useOptionsGetters({});
|
|
191
|
-
|
|
192
|
-
const navigation: NavigationContainerRef<ParamListBase> = React.useMemo(
|
|
193
|
-
() => ({
|
|
194
|
-
...Object.keys(CommonActions).reduce<any>((acc, name) => {
|
|
195
|
-
acc[name] = (...args: any[]) =>
|
|
196
|
-
// @ts-expect-error: this is ok
|
|
197
|
-
dispatch(CommonActions[name](...args));
|
|
198
|
-
return acc;
|
|
199
|
-
}, {}),
|
|
200
|
-
...emitter.create('root'),
|
|
201
|
-
dispatch,
|
|
202
|
-
resetRoot,
|
|
203
|
-
isFocused: () => true,
|
|
204
|
-
canGoBack,
|
|
205
|
-
getParent: () => undefined,
|
|
206
|
-
getState,
|
|
207
|
-
getRootState,
|
|
208
|
-
getCurrentRoute,
|
|
209
|
-
getCurrentOptions,
|
|
210
|
-
isReady,
|
|
211
|
-
setOptions: () => {
|
|
212
|
-
throw new Error('Cannot call setOptions outside a screen');
|
|
213
|
-
},
|
|
214
|
-
}),
|
|
215
|
-
[
|
|
216
|
-
canGoBack,
|
|
217
|
-
dispatch,
|
|
218
|
-
emitter,
|
|
219
|
-
getCurrentOptions,
|
|
220
|
-
getCurrentRoute,
|
|
221
|
-
getRootState,
|
|
222
|
-
getState,
|
|
223
|
-
isReady,
|
|
224
|
-
resetRoot,
|
|
225
|
-
]
|
|
226
|
-
);
|
|
187
|
+
if (state == null) {
|
|
188
|
+
return undefined;
|
|
189
|
+
}
|
|
227
190
|
|
|
228
|
-
|
|
191
|
+
const route = findFocusedRoute(state);
|
|
192
|
+
|
|
193
|
+
return route as Route<string> | undefined;
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
const isReady = useLatestCallback(() => listeners.focus[0] != null);
|
|
197
|
+
|
|
198
|
+
const emitter = useEventEmitter<NavigationContainerEventMap>();
|
|
199
|
+
|
|
200
|
+
const { addOptionsGetter, getCurrentOptions } = useOptionsGetters({});
|
|
201
|
+
|
|
202
|
+
const navigation: NavigationContainerRef<ParamList> = React.useMemo(
|
|
203
|
+
() => ({
|
|
204
|
+
...Object.keys(CommonActions).reduce<any>((acc, name) => {
|
|
205
|
+
acc[name] = (...args: any[]) =>
|
|
206
|
+
// @ts-expect-error: this is ok
|
|
207
|
+
dispatch(CommonActions[name](...args));
|
|
208
|
+
|
|
209
|
+
return acc;
|
|
210
|
+
}, {}),
|
|
211
|
+
...emitter.create('root'),
|
|
212
|
+
dispatch,
|
|
213
|
+
resetRoot,
|
|
214
|
+
isFocused: () => true,
|
|
215
|
+
canGoBack,
|
|
216
|
+
getParent: () => undefined,
|
|
217
|
+
getState,
|
|
218
|
+
getRootState,
|
|
219
|
+
getCurrentRoute,
|
|
220
|
+
getCurrentOptions,
|
|
221
|
+
isReady,
|
|
222
|
+
setOptions: () => {
|
|
223
|
+
throw new Error('Cannot call setOptions outside a screen');
|
|
224
|
+
},
|
|
225
|
+
}),
|
|
226
|
+
[
|
|
227
|
+
canGoBack,
|
|
228
|
+
dispatch,
|
|
229
|
+
emitter,
|
|
230
|
+
getCurrentOptions,
|
|
231
|
+
getCurrentRoute,
|
|
232
|
+
getRootState,
|
|
233
|
+
getState,
|
|
234
|
+
isReady,
|
|
235
|
+
resetRoot,
|
|
236
|
+
]
|
|
237
|
+
);
|
|
238
|
+
|
|
239
|
+
React.useImperativeHandle(ref, () => navigation, [navigation]);
|
|
240
|
+
|
|
241
|
+
const onDispatchAction = useLatestCallback(
|
|
242
|
+
(action: NavigationAction, noop: boolean) => {
|
|
243
|
+
emitter.emit({
|
|
244
|
+
type: '__unsafe_action__',
|
|
245
|
+
data: { action, noop, stack: stackRef.current },
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
);
|
|
249
|
+
|
|
250
|
+
const onEmitEvent = useLatestCallback(
|
|
251
|
+
(event: {
|
|
252
|
+
type: string;
|
|
253
|
+
defaultPrevented: boolean | undefined;
|
|
254
|
+
target: string | undefined;
|
|
255
|
+
data: unknown;
|
|
256
|
+
}) => {
|
|
257
|
+
emitter.emit({
|
|
258
|
+
type: '__unsafe_event__',
|
|
259
|
+
data: event,
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
);
|
|
229
263
|
|
|
230
|
-
|
|
231
|
-
(action: NavigationAction, noop: boolean) => {
|
|
232
|
-
emitter.emit({
|
|
233
|
-
type: '__unsafe_action__',
|
|
234
|
-
data: { action, noop, stack: stackRef.current },
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
);
|
|
264
|
+
const lastEmittedOptionsRef = React.useRef<object | undefined>(undefined);
|
|
238
265
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
target: string | undefined;
|
|
244
|
-
data: unknown;
|
|
245
|
-
}) => {
|
|
246
|
-
emitter.emit({
|
|
247
|
-
type: '__unsafe_event__',
|
|
248
|
-
data: event,
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
);
|
|
266
|
+
const onOptionsChange = useLatestCallback((options: object) => {
|
|
267
|
+
if (lastEmittedOptionsRef.current === options) {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
252
270
|
|
|
253
|
-
|
|
271
|
+
lastEmittedOptionsRef.current = options;
|
|
254
272
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
273
|
+
emitter.emit({
|
|
274
|
+
type: 'options',
|
|
275
|
+
data: { options },
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
const stackRef = React.useRef<string | undefined>(undefined);
|
|
280
|
+
|
|
281
|
+
const lastEmittedStateRef = React.useRef<State>(undefined);
|
|
282
|
+
|
|
283
|
+
const getIsStateEmitted = useLatestCallback(
|
|
284
|
+
() => !isFirstMountRef.current && lastEmittedStateRef.current === getState()
|
|
285
|
+
);
|
|
286
|
+
|
|
287
|
+
const builderContext = React.useMemo(
|
|
288
|
+
() => ({
|
|
289
|
+
addListener,
|
|
290
|
+
addKeyedListener,
|
|
291
|
+
onDispatchAction,
|
|
292
|
+
onEmitEvent,
|
|
293
|
+
onOptionsChange,
|
|
294
|
+
getIsStateEmitted,
|
|
295
|
+
scheduleUpdate,
|
|
296
|
+
flushUpdates,
|
|
297
|
+
stackRef,
|
|
298
|
+
}),
|
|
299
|
+
[
|
|
300
|
+
addListener,
|
|
301
|
+
addKeyedListener,
|
|
302
|
+
onDispatchAction,
|
|
303
|
+
onEmitEvent,
|
|
304
|
+
onOptionsChange,
|
|
305
|
+
getIsStateEmitted,
|
|
306
|
+
scheduleUpdate,
|
|
307
|
+
flushUpdates,
|
|
308
|
+
]
|
|
309
|
+
);
|
|
310
|
+
|
|
311
|
+
const isInitialRef = React.useRef(true);
|
|
312
|
+
|
|
313
|
+
const getIsInitial = React.useCallback(() => isInitialRef.current, []);
|
|
314
|
+
|
|
315
|
+
const context = React.useMemo(
|
|
316
|
+
() => ({
|
|
317
|
+
state,
|
|
318
|
+
getState,
|
|
319
|
+
setState,
|
|
320
|
+
subscribe,
|
|
321
|
+
getKey,
|
|
322
|
+
setKey,
|
|
323
|
+
getIsInitial,
|
|
324
|
+
addOptionsGetter,
|
|
325
|
+
}),
|
|
326
|
+
[
|
|
327
|
+
state,
|
|
328
|
+
getState,
|
|
329
|
+
setState,
|
|
330
|
+
subscribe,
|
|
331
|
+
getKey,
|
|
332
|
+
setKey,
|
|
333
|
+
getIsInitial,
|
|
334
|
+
addOptionsGetter,
|
|
335
|
+
]
|
|
336
|
+
);
|
|
337
|
+
|
|
338
|
+
const onReadyRef = React.useRef(onReady);
|
|
339
|
+
const onStateChangeRef = React.useRef(onStateChange);
|
|
340
|
+
|
|
341
|
+
React.useEffect(() => {
|
|
342
|
+
isInitialRef.current = false;
|
|
343
|
+
onStateChangeRef.current = onStateChange;
|
|
344
|
+
onReadyRef.current = onReady;
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
const onReadyCalledRef = React.useRef(false);
|
|
348
|
+
|
|
349
|
+
React.useEffect(() => {
|
|
350
|
+
if (!onReadyCalledRef.current && isReady()) {
|
|
351
|
+
onReadyCalledRef.current = true;
|
|
352
|
+
onReadyRef.current?.();
|
|
353
|
+
emitter.emit({ type: 'ready' });
|
|
354
|
+
}
|
|
355
|
+
}, [state, isReady, emitter]);
|
|
259
356
|
|
|
260
|
-
|
|
357
|
+
React.useEffect(() => {
|
|
358
|
+
const hydratedState = getRootState();
|
|
261
359
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
});
|
|
266
|
-
});
|
|
360
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
361
|
+
if (hydratedState !== undefined) {
|
|
362
|
+
const serializableResult = checkSerializable(hydratedState);
|
|
267
363
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
const builderContext = React.useMemo(
|
|
271
|
-
() => ({
|
|
272
|
-
addListener,
|
|
273
|
-
addKeyedListener,
|
|
274
|
-
onDispatchAction,
|
|
275
|
-
onEmitEvent,
|
|
276
|
-
onOptionsChange,
|
|
277
|
-
scheduleUpdate,
|
|
278
|
-
flushUpdates,
|
|
279
|
-
stackRef,
|
|
280
|
-
}),
|
|
281
|
-
[
|
|
282
|
-
addListener,
|
|
283
|
-
addKeyedListener,
|
|
284
|
-
onDispatchAction,
|
|
285
|
-
onEmitEvent,
|
|
286
|
-
onOptionsChange,
|
|
287
|
-
scheduleUpdate,
|
|
288
|
-
flushUpdates,
|
|
289
|
-
]
|
|
290
|
-
);
|
|
364
|
+
if (!serializableResult.serializable) {
|
|
365
|
+
const { location, reason } = serializableResult;
|
|
291
366
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
const context = React.useMemo(
|
|
297
|
-
() => ({
|
|
298
|
-
state,
|
|
299
|
-
getState,
|
|
300
|
-
setState,
|
|
301
|
-
getKey,
|
|
302
|
-
setKey,
|
|
303
|
-
getIsInitial,
|
|
304
|
-
addOptionsGetter,
|
|
305
|
-
}),
|
|
306
|
-
[
|
|
307
|
-
state,
|
|
308
|
-
getState,
|
|
309
|
-
setState,
|
|
310
|
-
getKey,
|
|
311
|
-
setKey,
|
|
312
|
-
getIsInitial,
|
|
313
|
-
addOptionsGetter,
|
|
314
|
-
]
|
|
315
|
-
);
|
|
367
|
+
let path = '';
|
|
368
|
+
let pointer: Record<any, any> = hydratedState;
|
|
369
|
+
let params = false;
|
|
316
370
|
|
|
317
|
-
|
|
318
|
-
|
|
371
|
+
for (let i = 0; i < location.length; i++) {
|
|
372
|
+
const curr = location[i];
|
|
373
|
+
const prev = location[i - 1];
|
|
319
374
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
onReadyRef.current = onReady;
|
|
324
|
-
});
|
|
375
|
+
if (curr == null) {
|
|
376
|
+
continue;
|
|
377
|
+
}
|
|
325
378
|
|
|
326
|
-
|
|
379
|
+
pointer = pointer[curr];
|
|
327
380
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
let params = false;
|
|
349
|
-
|
|
350
|
-
for (let i = 0; i < location.length; i++) {
|
|
351
|
-
const curr = location[i];
|
|
352
|
-
const prev = location[i - 1];
|
|
353
|
-
|
|
354
|
-
pointer = pointer[curr];
|
|
355
|
-
|
|
356
|
-
if (!params && curr === 'state') {
|
|
357
|
-
continue;
|
|
358
|
-
} else if (!params && curr === 'routes') {
|
|
359
|
-
if (path) {
|
|
360
|
-
path += ' > ';
|
|
361
|
-
}
|
|
362
|
-
} else if (
|
|
363
|
-
!params &&
|
|
364
|
-
typeof curr === 'number' &&
|
|
365
|
-
prev === 'routes'
|
|
366
|
-
) {
|
|
367
|
-
path += pointer?.name;
|
|
368
|
-
} else if (!params) {
|
|
369
|
-
path += ` > ${curr}`;
|
|
370
|
-
params = true;
|
|
381
|
+
if (!params && curr === 'state') {
|
|
382
|
+
continue;
|
|
383
|
+
} else if (!params && curr === 'routes') {
|
|
384
|
+
if (path) {
|
|
385
|
+
path += ' > ';
|
|
386
|
+
}
|
|
387
|
+
} else if (
|
|
388
|
+
!params &&
|
|
389
|
+
typeof curr === 'number' &&
|
|
390
|
+
prev === 'routes'
|
|
391
|
+
) {
|
|
392
|
+
path += pointer?.name;
|
|
393
|
+
} else if (!params) {
|
|
394
|
+
path += ` > ${curr}`;
|
|
395
|
+
params = true;
|
|
396
|
+
} else {
|
|
397
|
+
if (typeof curr === 'number' || /^[0-9]+$/.test(curr)) {
|
|
398
|
+
path += `[${curr}]`;
|
|
399
|
+
} else if (/^[a-z$_]+$/i.test(curr)) {
|
|
400
|
+
path += `.${curr}`;
|
|
371
401
|
} else {
|
|
372
|
-
|
|
373
|
-
path += `[${curr}]`;
|
|
374
|
-
} else if (/^[a-z$_]+$/i.test(curr)) {
|
|
375
|
-
path += `.${curr}`;
|
|
376
|
-
} else {
|
|
377
|
-
path += `[${JSON.stringify(curr)}]`;
|
|
378
|
-
}
|
|
402
|
+
path += `[${JSON.stringify(curr)}]`;
|
|
379
403
|
}
|
|
380
404
|
}
|
|
405
|
+
}
|
|
381
406
|
|
|
382
|
-
|
|
407
|
+
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.`;
|
|
383
408
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
}
|
|
409
|
+
if (!serializableWarnings.includes(message)) {
|
|
410
|
+
serializableWarnings.push(message);
|
|
411
|
+
console.warn(message);
|
|
388
412
|
}
|
|
413
|
+
}
|
|
389
414
|
|
|
390
|
-
|
|
391
|
-
|
|
415
|
+
const duplicateRouteNamesResult =
|
|
416
|
+
checkDuplicateRouteNames(hydratedState);
|
|
392
417
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
418
|
+
if (duplicateRouteNamesResult.length) {
|
|
419
|
+
const message = `Found screens with the same name nested inside one another. Check:\n${duplicateRouteNamesResult.map(
|
|
420
|
+
(locations) => `\n${locations.join(', ')}`
|
|
421
|
+
)}\n\nThis can cause confusing behavior during navigation. Consider using unique names for each screen instead.`;
|
|
397
422
|
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
}
|
|
423
|
+
if (!duplicateNameWarnings.includes(message)) {
|
|
424
|
+
duplicateNameWarnings.push(message);
|
|
425
|
+
console.warn(message);
|
|
402
426
|
}
|
|
403
427
|
}
|
|
404
428
|
}
|
|
429
|
+
}
|
|
405
430
|
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
if (!isFirstMountRef.current && onStateChangeRef.current) {
|
|
409
|
-
onStateChangeRef.current(hydratedState);
|
|
410
|
-
}
|
|
431
|
+
lastEmittedStateRef.current = state;
|
|
411
432
|
|
|
412
|
-
|
|
413
|
-
}, [getRootState, emitter, state]);
|
|
433
|
+
emitter.emit({ type: 'state', data: { state } });
|
|
414
434
|
|
|
415
|
-
|
|
416
|
-
(
|
|
417
|
-
|
|
418
|
-
return;
|
|
419
|
-
}
|
|
435
|
+
if (!isFirstMountRef.current && onStateChangeRef.current) {
|
|
436
|
+
onStateChangeRef.current(hydratedState);
|
|
437
|
+
}
|
|
420
438
|
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
let message = `The action '${action.type}'${
|
|
424
|
-
payload ? ` with payload ${JSON.stringify(action.payload)}` : ''
|
|
425
|
-
} was not handled by any navigator.`;
|
|
426
|
-
|
|
427
|
-
switch (action.type) {
|
|
428
|
-
case 'PRELOAD':
|
|
429
|
-
case 'NAVIGATE':
|
|
430
|
-
case 'PUSH':
|
|
431
|
-
case 'REPLACE':
|
|
432
|
-
case 'POP_TO':
|
|
433
|
-
case 'JUMP_TO':
|
|
434
|
-
if (payload?.name) {
|
|
435
|
-
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.\n\nIf you're using conditional rendering, navigation will happen automatically and you shouldn't navigate manually, see.`;
|
|
436
|
-
} else {
|
|
437
|
-
message += `\n\nYou need to pass the name of the screen to navigate to.\n\nSee https://reactnavigation.org/docs/navigation-actions for usage.`;
|
|
438
|
-
}
|
|
439
|
+
isFirstMountRef.current = false;
|
|
440
|
+
}, [getRootState, emitter, state]);
|
|
439
441
|
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
break;
|
|
446
|
-
case 'OPEN_DRAWER':
|
|
447
|
-
case 'CLOSE_DRAWER':
|
|
448
|
-
case 'TOGGLE_DRAWER':
|
|
449
|
-
message += `\n\nIs your screen inside a Drawer navigator?`;
|
|
450
|
-
break;
|
|
451
|
-
}
|
|
442
|
+
const defaultOnUnhandledAction = useLatestCallback(
|
|
443
|
+
(action: NavigationAction) => {
|
|
444
|
+
if (process.env.NODE_ENV === 'production') {
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
452
447
|
|
|
453
|
-
|
|
448
|
+
const payload: Record<string, any> | undefined = action.payload;
|
|
449
|
+
|
|
450
|
+
let message = `The action '${action.type}'${
|
|
451
|
+
payload ? ` with payload ${JSON.stringify(action.payload)}` : ''
|
|
452
|
+
} was not handled by any navigator.`;
|
|
453
|
+
|
|
454
|
+
switch (action.type) {
|
|
455
|
+
case 'PRELOAD':
|
|
456
|
+
case 'NAVIGATE':
|
|
457
|
+
case 'PUSH':
|
|
458
|
+
case 'REPLACE':
|
|
459
|
+
case 'POP_TO':
|
|
460
|
+
case 'JUMP_TO':
|
|
461
|
+
if (payload?.name) {
|
|
462
|
+
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.\n\nIf you're using conditional rendering, navigation will happen automatically and you shouldn't navigate manually, see.`;
|
|
463
|
+
} else {
|
|
464
|
+
message += `\n\nYou need to pass the name of the screen to navigate to.\n\nSee https://reactnavigation.org/docs/navigation-actions for usage.`;
|
|
465
|
+
}
|
|
454
466
|
|
|
455
|
-
|
|
467
|
+
break;
|
|
468
|
+
case 'GO_BACK':
|
|
469
|
+
case 'POP':
|
|
470
|
+
case 'POP_TO_TOP':
|
|
471
|
+
message += `\n\nIs there any screen to go back to?`;
|
|
472
|
+
break;
|
|
473
|
+
case 'OPEN_DRAWER':
|
|
474
|
+
case 'CLOSE_DRAWER':
|
|
475
|
+
case 'TOGGLE_DRAWER':
|
|
476
|
+
message += `\n\nIs your screen inside a Drawer navigator?`;
|
|
477
|
+
break;
|
|
456
478
|
}
|
|
457
|
-
);
|
|
458
479
|
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
480
|
+
message += `\n\nThis is a development-only warning and won't be shown in production.`;
|
|
481
|
+
|
|
482
|
+
console.error(message);
|
|
483
|
+
}
|
|
484
|
+
);
|
|
485
|
+
|
|
486
|
+
return (
|
|
487
|
+
<NavigationIndependentTreeContext.Provider value={false}>
|
|
488
|
+
<NavigationContainerRefContext.Provider value={navigation}>
|
|
489
|
+
<NavigationBuilderContext.Provider value={builderContext}>
|
|
490
|
+
<NavigationStateContext.Provider value={context}>
|
|
491
|
+
<ConsumedParamsContext.Provider value={consumedParams}>
|
|
464
492
|
<UnhandledActionContext.Provider
|
|
465
493
|
value={onUnhandledAction ?? defaultOnUnhandledAction}
|
|
466
494
|
>
|
|
@@ -468,10 +496,10 @@ export const BaseNavigationContainer = React.forwardRef(
|
|
|
468
496
|
<ThemeProvider value={theme}>{children}</ThemeProvider>
|
|
469
497
|
</EnsureSingleNavigator>
|
|
470
498
|
</UnhandledActionContext.Provider>
|
|
471
|
-
</
|
|
472
|
-
</
|
|
473
|
-
</
|
|
474
|
-
</
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
499
|
+
</ConsumedParamsContext.Provider>
|
|
500
|
+
</NavigationStateContext.Provider>
|
|
501
|
+
</NavigationBuilderContext.Provider>
|
|
502
|
+
</NavigationContainerRefContext.Provider>
|
|
503
|
+
</NavigationIndependentTreeContext.Provider>
|
|
504
|
+
);
|
|
505
|
+
}
|