@react-navigation/core 8.0.0-alpha.2 → 8.0.0-alpha.21
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 +20 -9
- 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/NavigationBuilderContext.js +1 -0
- package/lib/module/NavigationBuilderContext.js.map +1 -1
- package/lib/module/NavigationIndependentTree.js +8 -4
- package/lib/module/NavigationIndependentTree.js.map +1 -1
- package/lib/module/NavigationProvider.js +14 -3
- package/lib/module/NavigationProvider.js.map +1 -1
- package/lib/module/NavigationStateContext.js.map +1 -1
- package/lib/module/PreventRemoveProvider.js +3 -3
- package/lib/module/PreventRemoveProvider.js.map +1 -1
- package/lib/module/SceneView.js +46 -56
- package/lib/module/SceneView.js.map +1 -1
- package/lib/module/StaticNavigation.js +166 -46
- package/lib/module/StaticNavigation.js.map +1 -1
- package/lib/module/checkSerializable.js +11 -4
- package/lib/module/checkSerializable.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 +40 -14
- package/lib/module/getActionFromState.js.map +1 -1
- package/lib/module/getPathFromState.js +48 -11
- package/lib/module/getPathFromState.js.map +1 -1
- package/lib/module/getPatternParts.js +3 -0
- package/lib/module/getPatternParts.js.map +1 -1
- package/lib/module/getStateFromPath.js +353 -166
- package/lib/module/getStateFromPath.js.map +1 -1
- package/lib/module/getStateFromRouteParams.js +24 -0
- package/lib/module/getStateFromRouteParams.js.map +1 -0
- package/lib/module/index.js +3 -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 +15 -0
- package/lib/module/types.js.map +1 -1
- package/lib/module/useDescriptors.js +18 -9
- package/lib/module/useDescriptors.js.map +1 -1
- package/lib/module/useEventEmitter.js +43 -31
- package/lib/module/useEventEmitter.js.map +1 -1
- package/lib/module/useFocusEvents.js +6 -2
- 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/useNavigation.js.map +1 -1
- package/lib/module/useNavigationBuilder.js +144 -86
- package/lib/module/useNavigationBuilder.js.map +1 -1
- package/lib/module/useNavigationCache.js +3 -3
- package/lib/module/useNavigationCache.js.map +1 -1
- package/lib/module/useNavigationHelpers.js +1 -1
- 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 +6 -4
- package/lib/module/useNavigationState.js.map +1 -1
- package/lib/module/useOnAction.js +3 -3
- 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 +3 -3
- 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 +7 -4
- package/lib/module/useOptionsGetters.js.map +1 -1
- package/lib/module/usePreventRemove.js +1 -1
- package/lib/module/usePreventRemove.js.map +1 -1
- package/lib/module/usePreventRemoveContext.js +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.map +1 -1
- package/lib/module/useRouteCache.js +2 -1
- package/lib/module/useRouteCache.js.map +1 -1
- package/lib/module/useScheduleUpdate.js +1 -1
- 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/validatePathConfig.js +2 -1
- 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 +8 -0
- package/lib/typescript/src/ConsumedParamsContext.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 +12 -6
- 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 +10 -10
- package/lib/typescript/src/NavigationProvider.d.ts.map +1 -1
- package/lib/typescript/src/NavigationStateContext.d.ts +3 -3
- package/lib/typescript/src/NavigationStateContext.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 +3 -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 +123 -92
- package/lib/typescript/src/StaticNavigation.d.ts.map +1 -1
- package/lib/typescript/src/checkSerializable.d.ts +5 -3
- 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 +17 -5
- package/lib/typescript/src/createNavigatorFactory.d.ts.map +1 -1
- package/lib/typescript/src/findFocusedRoute.d.ts +3 -3
- 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 +5 -5
- 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 +34 -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 +215 -131
- 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 +7 -7
- package/lib/typescript/src/useDescriptors.d.ts.map +1 -1
- package/lib/typescript/src/useEventEmitter.d.ts +1 -1
- 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/useNavigation.d.ts +4 -2
- package/lib/typescript/src/useNavigation.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationBuilder.d.ts +24 -24
- 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 -19
- package/lib/typescript/src/useNavigationHelpers.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationState.d.ts +2 -2
- 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 +3 -3
- 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/usePreventRemoveContext.d.ts +1 -1
- package/lib/typescript/src/useRoute.d.ts +2 -2
- package/lib/typescript/src/useRoute.d.ts.map +1 -1
- package/lib/typescript/src/useRouteCache.d.ts +4 -4
- package/lib/typescript/src/useRouteCache.d.ts.map +1 -1
- 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/utilities.d.ts +45 -5
- package/lib/typescript/src/utilities.d.ts.map +1 -1
- package/lib/typescript/src/validatePathConfig.d.ts.map +1 -1
- package/package.json +23 -20
- package/src/BaseNavigationContainer.tsx +337 -326
- package/src/ConsumedParamsContext.tsx +10 -0
- package/src/NavigationBuilderContext.tsx +14 -8
- package/src/NavigationFocusedRouteStateContext.tsx +4 -4
- package/src/NavigationIndependentTree.tsx +8 -5
- package/src/NavigationProvider.tsx +17 -3
- package/src/NavigationStateContext.tsx +5 -6
- package/src/PreventRemoveProvider.tsx +3 -3
- package/src/SceneView.tsx +58 -56
- package/src/StaticNavigation.tsx +488 -250
- package/src/checkSerializable.tsx +22 -12
- package/src/createNavigatorFactory.tsx +83 -8
- package/src/findFocusedRoute.tsx +13 -8
- package/src/getActionFromState.tsx +68 -39
- package/src/getPathFromState.tsx +91 -27
- package/src/getPatternParts.tsx +8 -0
- package/src/getStateFromPath.tsx +555 -180
- package/src/getStateFromRouteParams.tsx +60 -0
- package/src/index.tsx +47 -5
- package/src/theming/useTheme.tsx +1 -1
- package/src/types.tsx +541 -338
- package/src/useDescriptors.tsx +27 -12
- package/src/useEventEmitter.tsx +45 -36
- package/src/useFocusEvents.tsx +8 -2
- package/src/useFocusedListenersChildrenAdapter.tsx +2 -2
- package/src/useIsFocused.tsx +14 -21
- package/src/useNavigation.tsx +5 -3
- package/src/useNavigationBuilder.tsx +220 -132
- package/src/useNavigationCache.tsx +6 -6
- package/src/useNavigationHelpers.tsx +1 -1
- package/src/useNavigationIndependentTree.tsx +1 -1
- package/src/useNavigationState.tsx +11 -7
- package/src/useOnAction.tsx +10 -10
- package/src/useOnGetState.tsx +5 -3
- package/src/useOnPreventRemove.tsx +3 -3
- package/src/useOnRouteFocus.tsx +10 -12
- package/src/useOptionsGetters.tsx +7 -4
- package/src/usePreventRemove.tsx +1 -1
- package/src/usePreventRemoveContext.tsx +1 -1
- package/src/useRegisterNavigator.tsx +2 -2
- package/src/useRoute.tsx +4 -2
- package/src/useRouteCache.tsx +2 -1
- package/src/useScheduleUpdate.tsx +1 -3
- package/src/useStateForPath.tsx +1 -1
- package/src/utilities.tsx +101 -5
- package/src/validatePathConfig.tsx +1 -0
- 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
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
type ConsumedParamsContextValue = {
|
|
4
|
+
isConsumed: (params: object) => boolean;
|
|
5
|
+
setConsumed: (params: object) => void;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const ConsumedParamsContext = React.createContext<
|
|
9
|
+
ConsumedParamsContextValue | undefined
|
|
10
|
+
>(undefined);
|
|
@@ -52,20 +52,26 @@ export type ChildBeforeRemoveListener = (action: NavigationAction) => boolean;
|
|
|
52
52
|
* Context which holds the required helpers needed to build nested navigators.
|
|
53
53
|
*/
|
|
54
54
|
export const NavigationBuilderContext = React.createContext<{
|
|
55
|
-
onAction?:
|
|
56
|
-
action: NavigationAction,
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
onRouteFocus?: (key: string) => void;
|
|
55
|
+
onAction?:
|
|
56
|
+
| ((action: NavigationAction, visitedNavigators?: Set<string>) => boolean)
|
|
57
|
+
| undefined;
|
|
58
|
+
addListener?: AddListener | undefined;
|
|
59
|
+
addKeyedListener?: AddKeyedListener | undefined;
|
|
60
|
+
onRouteFocus?: ((key: string) => void) | undefined;
|
|
62
61
|
onDispatchAction: (action: NavigationAction, noop: boolean) => void;
|
|
62
|
+
onEmitEvent: (event: {
|
|
63
|
+
type: string;
|
|
64
|
+
defaultPrevented: boolean | undefined;
|
|
65
|
+
target: string | undefined;
|
|
66
|
+
data: unknown;
|
|
67
|
+
}) => void;
|
|
63
68
|
onOptionsChange: (options: object) => void;
|
|
64
69
|
scheduleUpdate: (callback: () => void) => void;
|
|
65
70
|
flushUpdates: () => void;
|
|
66
|
-
stackRef?: React.MutableRefObject<string | undefined
|
|
71
|
+
stackRef?: React.MutableRefObject<string | undefined> | undefined;
|
|
67
72
|
}>({
|
|
68
73
|
onDispatchAction: () => undefined,
|
|
74
|
+
onEmitEvent: () => undefined,
|
|
69
75
|
onOptionsChange: () => undefined,
|
|
70
76
|
scheduleUpdate: () => {
|
|
71
77
|
throw new Error("Couldn't find a context for scheduling updates.");
|
|
@@ -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
|
};
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
NavigationRouteContext,
|
|
8
8
|
NavigationRouteNameContext,
|
|
9
9
|
} from './NavigationProvider';
|
|
10
|
+
import { IsFocusedContext } from './useIsFocused';
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* Component to make the child navigation container independent of parent containers.
|
|
@@ -21,11 +22,13 @@ export function NavigationIndependentTree({
|
|
|
21
22
|
<NamedRouteContextListContext.Provider value={undefined}>
|
|
22
23
|
<NavigationRouteContext.Provider value={undefined}>
|
|
23
24
|
<NavigationContext.Provider value={undefined}>
|
|
24
|
-
<
|
|
25
|
-
<
|
|
26
|
-
{
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
<IsFocusedContext.Provider value={undefined}>
|
|
26
|
+
<NavigationRouteNameContext.Provider value={undefined}>
|
|
27
|
+
<NavigationIndependentTreeContext.Provider value={true}>
|
|
28
|
+
{children}
|
|
29
|
+
</NavigationIndependentTreeContext.Provider>
|
|
30
|
+
</NavigationRouteNameContext.Provider>
|
|
31
|
+
</IsFocusedContext.Provider>
|
|
29
32
|
</NavigationContext.Provider>
|
|
30
33
|
</NavigationRouteContext.Provider>
|
|
31
34
|
</NamedRouteContextListContext.Provider>
|
|
@@ -2,6 +2,7 @@ import type { ParamListBase, Route } from '@react-navigation/routers';
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
|
|
4
4
|
import type { NavigationProp } from './types';
|
|
5
|
+
import { FocusedRouteKeyContext, IsFocusedContext } from './useIsFocused';
|
|
5
6
|
import { useLazyValue } from './useLazyValue';
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -48,14 +49,27 @@ export function NavigationProvider({ route, navigation, children }: Props) {
|
|
|
48
49
|
[NamedRouteContext, parents, route.name]
|
|
49
50
|
);
|
|
50
51
|
|
|
52
|
+
const parentIsFocused = React.use(IsFocusedContext);
|
|
53
|
+
const focusedRouteKey = React.use(FocusedRouteKeyContext);
|
|
54
|
+
|
|
55
|
+
// Mark route as focused only if:
|
|
56
|
+
// - It doesn't have a parent navigator
|
|
57
|
+
// - Parent navigator is focused
|
|
58
|
+
const isFocused =
|
|
59
|
+
parentIsFocused == null || parentIsFocused
|
|
60
|
+
? focusedRouteKey === route.key
|
|
61
|
+
: false;
|
|
62
|
+
|
|
51
63
|
return (
|
|
52
64
|
<NamedRouteContextListContext.Provider value={NamedRouteContextList}>
|
|
53
65
|
<NamedRouteContext.Provider value={route}>
|
|
54
66
|
<NavigationRouteContext.Provider value={route}>
|
|
55
67
|
<NavigationContext.Provider value={navigation}>
|
|
56
|
-
<
|
|
57
|
-
{
|
|
58
|
-
|
|
68
|
+
<IsFocusedContext.Provider value={isFocused}>
|
|
69
|
+
<NavigationRouteNameContext.Provider value={route.name}>
|
|
70
|
+
{children}
|
|
71
|
+
</NavigationRouteNameContext.Provider>
|
|
72
|
+
</IsFocusedContext.Provider>
|
|
59
73
|
</NavigationContext.Provider>
|
|
60
74
|
</NavigationRouteContext.Provider>
|
|
61
75
|
</NamedRouteContext.Provider>
|
|
@@ -5,8 +5,8 @@ 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;
|
|
@@ -14,10 +14,9 @@ export const NavigationStateContext = React.createContext<{
|
|
|
14
14
|
state: NavigationState | PartialState<NavigationState> | undefined
|
|
15
15
|
) => void;
|
|
16
16
|
getIsInitial: () => boolean;
|
|
17
|
-
addOptionsGetter?:
|
|
18
|
-
key: string,
|
|
19
|
-
|
|
20
|
-
) => void;
|
|
17
|
+
addOptionsGetter?:
|
|
18
|
+
| ((key: string, getter: () => object | undefined | null) => void)
|
|
19
|
+
| undefined;
|
|
21
20
|
}>({
|
|
22
21
|
isDefault: true,
|
|
23
22
|
|
|
@@ -50,10 +50,10 @@ export function PreventRemoveProvider({ children }: Props) {
|
|
|
50
50
|
const [preventedRoutesMap, setPreventedRoutesMap] =
|
|
51
51
|
React.useState<PreventedRoutesMap>(() => new Map());
|
|
52
52
|
|
|
53
|
-
const navigation = React.
|
|
54
|
-
const route = React.
|
|
53
|
+
const navigation = React.use(NavigationHelpersContext);
|
|
54
|
+
const route = React.use(NavigationRouteContext);
|
|
55
55
|
|
|
56
|
-
const preventRemoveContextValue = React.
|
|
56
|
+
const preventRemoveContextValue = React.use(PreventRemoveContext);
|
|
57
57
|
// take `setPreventRemove` from parent context - if exist it means we're in a nested context
|
|
58
58
|
const setParentPrevented = preventRemoveContextValue?.setPreventRemove;
|
|
59
59
|
|
package/src/SceneView.tsx
CHANGED
|
@@ -6,6 +6,7 @@ import type {
|
|
|
6
6
|
} from '@react-navigation/routers';
|
|
7
7
|
import * as React from 'react';
|
|
8
8
|
|
|
9
|
+
import { ConsumedParamsContext } from './ConsumedParamsContext';
|
|
9
10
|
import { EnsureSingleNavigator } from './EnsureSingleNavigator';
|
|
10
11
|
import { isArrayEqual } from './isArrayEqual';
|
|
11
12
|
import {
|
|
@@ -70,46 +71,16 @@ export function SceneView<
|
|
|
70
71
|
const state = getState();
|
|
71
72
|
|
|
72
73
|
const routes = state.routes.map((r) => {
|
|
73
|
-
if (r.key
|
|
74
|
-
return
|
|
74
|
+
if (r.key === route.key && r.state !== child) {
|
|
75
|
+
return {
|
|
76
|
+
...r,
|
|
77
|
+
state: child,
|
|
78
|
+
};
|
|
75
79
|
}
|
|
76
80
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
// Before updating the state, cleanup any nested screen and state
|
|
80
|
-
// This will avoid the navigator trying to handle them again
|
|
81
|
-
if (
|
|
82
|
-
nextRoute.params &&
|
|
83
|
-
(('state' in nextRoute.params &&
|
|
84
|
-
typeof nextRoute.params.state === 'object' &&
|
|
85
|
-
nextRoute.params.state !== null) ||
|
|
86
|
-
('screen' in nextRoute.params &&
|
|
87
|
-
typeof nextRoute.params.screen === 'string'))
|
|
88
|
-
) {
|
|
89
|
-
// @ts-expect-error: we don't have correct type for params
|
|
90
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
91
|
-
const { state, screen, params, initial, ...rest } = nextRoute.params;
|
|
92
|
-
|
|
93
|
-
if (Object.keys(rest).length) {
|
|
94
|
-
return { ...nextRoute, params: rest };
|
|
95
|
-
} else {
|
|
96
|
-
const {
|
|
97
|
-
// We destructure the params to omit them
|
|
98
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
99
|
-
params,
|
|
100
|
-
...restRoute
|
|
101
|
-
} = nextRoute;
|
|
102
|
-
|
|
103
|
-
return restRoute;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return nextRoute;
|
|
81
|
+
return r;
|
|
108
82
|
});
|
|
109
83
|
|
|
110
|
-
// Make sure not to update state if routes haven't changed
|
|
111
|
-
// Otherwise this will result in params cleanup as well
|
|
112
|
-
// We only want to cleanup params when state changes - after they are used
|
|
113
84
|
if (!isArrayEqual(state.routes, routes)) {
|
|
114
85
|
setState({
|
|
115
86
|
...state,
|
|
@@ -134,10 +105,39 @@ export function SceneView<
|
|
|
134
105
|
|
|
135
106
|
const getIsInitial = React.useCallback(() => isInitialRef.current, []);
|
|
136
107
|
|
|
137
|
-
const
|
|
138
|
-
|
|
108
|
+
const [consumedParams, setConsumedParams] = React.useState<WeakMap<
|
|
109
|
+
object,
|
|
110
|
+
true
|
|
111
|
+
> | null>(null);
|
|
112
|
+
|
|
113
|
+
const consumedParamsContext = React.useMemo(
|
|
114
|
+
() => ({
|
|
115
|
+
isConsumed: (params: object) => {
|
|
116
|
+
if (consumedParams) {
|
|
117
|
+
return consumedParams.has(params);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return false;
|
|
121
|
+
},
|
|
122
|
+
setConsumed: (params: object) => {
|
|
123
|
+
setConsumedParams((prev) => {
|
|
124
|
+
if (prev && prev.has(params)) {
|
|
125
|
+
return prev;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const map = new WeakMap<object, true>();
|
|
129
|
+
|
|
130
|
+
map.set(params, true);
|
|
131
|
+
|
|
132
|
+
return map;
|
|
133
|
+
});
|
|
134
|
+
},
|
|
135
|
+
}),
|
|
136
|
+
[consumedParams]
|
|
139
137
|
);
|
|
140
138
|
|
|
139
|
+
const parentFocusedRouteState = React.use(NavigationFocusedRouteStateContext);
|
|
140
|
+
|
|
141
141
|
const focusedRouteState = React.useMemo(() => {
|
|
142
142
|
const state: FocusedRouteState = {
|
|
143
143
|
routes: [
|
|
@@ -205,23 +205,25 @@ export function SceneView<
|
|
|
205
205
|
: screen.component;
|
|
206
206
|
|
|
207
207
|
return (
|
|
208
|
-
<
|
|
209
|
-
<
|
|
210
|
-
<
|
|
211
|
-
<
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
screen.children
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
208
|
+
<ConsumedParamsContext.Provider value={consumedParamsContext}>
|
|
209
|
+
<NavigationStateContext.Provider value={context}>
|
|
210
|
+
<NavigationFocusedRouteStateContext.Provider value={focusedRouteState}>
|
|
211
|
+
<EnsureSingleNavigator>
|
|
212
|
+
<StaticContainer
|
|
213
|
+
name={screen.name}
|
|
214
|
+
render={ScreenComponent || screen.children}
|
|
215
|
+
navigation={navigation}
|
|
216
|
+
route={route}
|
|
217
|
+
>
|
|
218
|
+
{ScreenComponent !== undefined ? (
|
|
219
|
+
<ScreenComponent navigation={navigation} route={route} />
|
|
220
|
+
) : screen.children !== undefined ? (
|
|
221
|
+
screen.children({ navigation, route })
|
|
222
|
+
) : null}
|
|
223
|
+
</StaticContainer>
|
|
224
|
+
</EnsureSingleNavigator>
|
|
225
|
+
</NavigationFocusedRouteStateContext.Provider>
|
|
226
|
+
</NavigationStateContext.Provider>
|
|
227
|
+
</ConsumedParamsContext.Provider>
|
|
226
228
|
);
|
|
227
229
|
}
|