@react-navigation/core 8.0.0-alpha.4 → 8.0.0-alpha.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -14
- package/lib/module/BaseNavigationContainer.js +168 -87
- package/lib/module/BaseNavigationContainer.js.map +1 -1
- package/lib/module/ConsumedParamsContext.js +5 -0
- package/lib/module/ConsumedParamsContext.js.map +1 -0
- package/lib/module/DataLoading.js +129 -0
- package/lib/module/DataLoading.js.map +1 -0
- package/lib/module/NavigationBuilderContext.js +7 -10
- package/lib/module/NavigationBuilderContext.js.map +1 -1
- package/lib/module/NavigationIndependentTree.js +54 -9
- package/lib/module/NavigationIndependentTree.js.map +1 -1
- package/lib/module/NavigationProvider.js +36 -11
- package/lib/module/NavigationProvider.js.map +1 -1
- package/lib/module/NavigationRootContext.js +8 -0
- package/lib/module/NavigationRootContext.js.map +1 -0
- package/lib/module/NavigationStateContext.js +3 -0
- package/lib/module/NavigationStateContext.js.map +1 -1
- package/lib/module/PreventRemoveContext.js.map +1 -1
- package/lib/module/PreventRemoveProvider.js +40 -31
- package/lib/module/PreventRemoveProvider.js.map +1 -1
- package/lib/module/SceneView.js +12 -42
- package/lib/module/SceneView.js.map +1 -1
- package/lib/module/StaticNavigation.js +219 -67
- package/lib/module/StaticNavigation.js.map +1 -1
- package/lib/module/StaticTreeContext.js +5 -0
- package/lib/module/StaticTreeContext.js.map +1 -0
- package/lib/module/createNavigationContainerRef.js +7 -9
- package/lib/module/createNavigationContainerRef.js.map +1 -1
- package/lib/module/createNavigatorFactory.js +27 -5
- package/lib/module/createNavigatorFactory.js.map +1 -1
- package/lib/module/findFocusedRoute.js +7 -4
- package/lib/module/findFocusedRoute.js.map +1 -1
- package/lib/module/getActionFromState.js +45 -20
- package/lib/module/getActionFromState.js.map +1 -1
- package/lib/module/getPathFromState.js +204 -94
- package/lib/module/getPathFromState.js.map +1 -1
- package/lib/module/getPatternParts.js +61 -14
- package/lib/module/getPatternParts.js.map +1 -1
- package/lib/module/getStateFromPath.js +608 -272
- package/lib/module/getStateFromPath.js.map +1 -1
- package/lib/module/getStateFromRouteParams.js +23 -0
- package/lib/module/getStateFromRouteParams.js.map +1 -0
- package/lib/module/index.js +7 -6
- package/lib/module/index.js.map +1 -1
- package/lib/module/internal.js +2 -0
- package/lib/module/internal.js.map +1 -0
- package/lib/module/isRecordEqual.js +1 -1
- package/lib/module/isRecordEqual.js.map +1 -1
- package/lib/module/queryString.js +71 -0
- package/lib/module/queryString.js.map +1 -0
- package/lib/module/theming/useTheme.js +1 -1
- package/lib/module/theming/useTheme.js.map +1 -1
- package/lib/module/types.js +35 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/useDescriptors.js +65 -25
- package/lib/module/useDescriptors.js.map +1 -1
- package/lib/module/useEventEmitter.js +48 -33
- package/lib/module/useEventEmitter.js.map +1 -1
- package/lib/module/useFocusEffect.js +4 -2
- package/lib/module/useFocusEffect.js.map +1 -1
- package/lib/module/useFocusEvents.js +15 -5
- package/lib/module/useFocusEvents.js.map +1 -1
- package/lib/module/useFocusedListenersChildrenAdapter.js +3 -3
- package/lib/module/useFocusedListenersChildrenAdapter.js.map +1 -1
- package/lib/module/useIsFocused.js +8 -12
- package/lib/module/useIsFocused.js.map +1 -1
- package/lib/module/useKeyedChildListeners.js +5 -2
- package/lib/module/useKeyedChildListeners.js.map +1 -1
- package/lib/module/useLazyValue.js.map +1 -1
- package/lib/module/useNavigation.js +4 -17
- package/lib/module/useNavigation.js.map +1 -1
- package/lib/module/useNavigationBuilder.js +244 -147
- package/lib/module/useNavigationBuilder.js.map +1 -1
- package/lib/module/useNavigationCache.js +92 -89
- package/lib/module/useNavigationCache.js.map +1 -1
- package/lib/module/useNavigationHelpers.js +22 -29
- package/lib/module/useNavigationHelpers.js.map +1 -1
- package/lib/module/useNavigationIndependentTree.js +1 -1
- package/lib/module/useNavigationIndependentTree.js.map +1 -1
- package/lib/module/useNavigationState.js +158 -46
- package/lib/module/useNavigationState.js.map +1 -1
- package/lib/module/useOnAction.js +58 -11
- package/lib/module/useOnAction.js.map +1 -1
- package/lib/module/useOnGetNavigation.js +26 -0
- package/lib/module/useOnGetNavigation.js.map +1 -0
- package/lib/module/useOnGetState.js +7 -4
- package/lib/module/useOnGetState.js.map +1 -1
- package/lib/module/useOnPreventRemove.js +40 -31
- package/lib/module/useOnPreventRemove.js.map +1 -1
- package/lib/module/useOnRouteFocus.js +2 -2
- package/lib/module/useOnRouteFocus.js.map +1 -1
- package/lib/module/useOptionsGetters.js +34 -24
- package/lib/module/useOptionsGetters.js.map +1 -1
- package/lib/module/usePreventRemove.js +11 -5
- package/lib/module/usePreventRemove.js.map +1 -1
- package/lib/module/usePreventRemoveContext.js +2 -2
- package/lib/module/usePreventRemoveContext.js.map +1 -1
- package/lib/module/useRegisterNavigator.js +3 -4
- package/lib/module/useRegisterNavigator.js.map +1 -1
- package/lib/module/useRoute.js +2 -0
- package/lib/module/useRoute.js.map +1 -1
- package/lib/module/useRouteCache.js +51 -35
- package/lib/module/useRouteCache.js.map +1 -1
- package/lib/module/useScheduleUpdate.js +12 -10
- package/lib/module/useScheduleUpdate.js.map +1 -1
- package/lib/module/useStateForPath.js +1 -1
- package/lib/module/useStateForPath.js.map +1 -1
- package/lib/module/useSyncState.js +37 -15
- package/lib/module/useSyncState.js.map +1 -1
- package/lib/module/validatePathConfig.js +50 -36
- package/lib/module/validatePathConfig.js.map +1 -1
- package/lib/typescript/src/BaseNavigationContainer.d.ts +6 -3
- package/lib/typescript/src/BaseNavigationContainer.d.ts.map +1 -1
- package/lib/typescript/src/ConsumedParamsContext.d.ts +3 -0
- package/lib/typescript/src/ConsumedParamsContext.d.ts.map +1 -0
- package/lib/typescript/src/DataLoading.d.ts +21 -0
- package/lib/typescript/src/DataLoading.d.ts.map +1 -0
- package/lib/typescript/src/EnsureSingleNavigator.d.ts +1 -1
- package/lib/typescript/src/EnsureSingleNavigator.d.ts.map +1 -1
- package/lib/typescript/src/Group.d.ts +1 -1
- package/lib/typescript/src/Group.d.ts.map +1 -1
- package/lib/typescript/src/NavigationBuilderContext.d.ts +22 -14
- package/lib/typescript/src/NavigationBuilderContext.d.ts.map +1 -1
- package/lib/typescript/src/NavigationContainerRefContext.d.ts +1 -1
- package/lib/typescript/src/NavigationContainerRefContext.d.ts.map +1 -1
- package/lib/typescript/src/NavigationFocusedRouteStateContext.d.ts +4 -4
- package/lib/typescript/src/NavigationFocusedRouteStateContext.d.ts.map +1 -1
- package/lib/typescript/src/NavigationHelpersContext.d.ts +1 -1
- package/lib/typescript/src/NavigationHelpersContext.d.ts.map +1 -1
- package/lib/typescript/src/NavigationIndependentTree.d.ts +1 -1
- package/lib/typescript/src/NavigationIndependentTree.d.ts.map +1 -1
- package/lib/typescript/src/NavigationProvider.d.ts +21 -18
- package/lib/typescript/src/NavigationProvider.d.ts.map +1 -1
- package/lib/typescript/src/NavigationRootContext.d.ts +8 -0
- package/lib/typescript/src/NavigationRootContext.d.ts.map +1 -0
- package/lib/typescript/src/NavigationStateContext.d.ts +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 +5 -2
- package/lib/typescript/src/SceneView.d.ts.map +1 -1
- package/lib/typescript/src/Screen.d.ts +1 -1
- package/lib/typescript/src/Screen.d.ts.map +1 -1
- package/lib/typescript/src/StaticContainer.d.ts +1 -1
- package/lib/typescript/src/StaticContainer.d.ts.map +1 -1
- package/lib/typescript/src/StaticNavigation.d.ts +189 -111
- package/lib/typescript/src/StaticNavigation.d.ts.map +1 -1
- package/lib/typescript/src/StaticTreeContext.d.ts +4 -0
- package/lib/typescript/src/StaticTreeContext.d.ts.map +1 -0
- package/lib/typescript/src/createNavigationContainerRef.d.ts +1 -1
- package/lib/typescript/src/createNavigationContainerRef.d.ts.map +1 -1
- package/lib/typescript/src/createNavigatorFactory.d.ts +23 -5
- package/lib/typescript/src/createNavigatorFactory.d.ts.map +1 -1
- package/lib/typescript/src/findFocusedRoute.d.ts +3 -8
- package/lib/typescript/src/findFocusedRoute.d.ts.map +1 -1
- package/lib/typescript/src/getActionFromState.d.ts +4 -4
- package/lib/typescript/src/getActionFromState.d.ts.map +1 -1
- package/lib/typescript/src/getPathFromState.d.ts +3 -3
- package/lib/typescript/src/getPathFromState.d.ts.map +1 -1
- package/lib/typescript/src/getPatternParts.d.ts +5 -2
- package/lib/typescript/src/getPatternParts.d.ts.map +1 -1
- package/lib/typescript/src/getStateFromPath.d.ts +4 -7
- package/lib/typescript/src/getStateFromPath.d.ts.map +1 -1
- package/lib/typescript/src/getStateFromRouteParams.d.ts +3 -0
- package/lib/typescript/src/getStateFromRouteParams.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +36 -33
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/internal.d.ts +3 -0
- package/lib/typescript/src/internal.d.ts.map +1 -0
- package/lib/typescript/src/isRecordEqual.d.ts.map +1 -1
- package/lib/typescript/src/queryString.d.ts +5 -0
- package/lib/typescript/src/queryString.d.ts.map +1 -0
- package/lib/typescript/src/theming/ThemeContext.d.ts +1 -1
- package/lib/typescript/src/theming/ThemeContext.d.ts.map +1 -1
- package/lib/typescript/src/theming/ThemeProvider.d.ts +2 -2
- package/lib/typescript/src/theming/ThemeProvider.d.ts.map +1 -1
- package/lib/typescript/src/theming/useTheme.d.ts +1 -1
- package/lib/typescript/src/theming/useTheme.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +265 -167
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/useChildListeners.d.ts +3 -3
- package/lib/typescript/src/useChildListeners.d.ts.map +1 -1
- package/lib/typescript/src/useDescriptors.d.ts +13 -11
- package/lib/typescript/src/useDescriptors.d.ts.map +1 -1
- package/lib/typescript/src/useEventEmitter.d.ts +2 -2
- package/lib/typescript/src/useEventEmitter.d.ts.map +1 -1
- package/lib/typescript/src/useFocusEffect.d.ts.map +1 -1
- package/lib/typescript/src/useFocusEvents.d.ts +2 -2
- package/lib/typescript/src/useFocusEvents.d.ts.map +1 -1
- package/lib/typescript/src/useFocusedListenersChildrenAdapter.d.ts +2 -2
- package/lib/typescript/src/useFocusedListenersChildrenAdapter.d.ts.map +1 -1
- package/lib/typescript/src/useIsFocused.d.ts +4 -0
- package/lib/typescript/src/useIsFocused.d.ts.map +1 -1
- package/lib/typescript/src/useKeyedChildListeners.d.ts +4 -3
- package/lib/typescript/src/useKeyedChildListeners.d.ts.map +1 -1
- package/lib/typescript/src/useLazyValue.d.ts.map +1 -1
- package/lib/typescript/src/useNavigation.d.ts +4 -2
- package/lib/typescript/src/useNavigation.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationBuilder.d.ts +22 -63
- package/lib/typescript/src/useNavigationBuilder.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationCache.d.ts +6 -5
- package/lib/typescript/src/useNavigationCache.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationContainerRef.d.ts +1 -1
- package/lib/typescript/src/useNavigationContainerRef.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationHelpers.d.ts +18 -58
- package/lib/typescript/src/useNavigationHelpers.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationState.d.ts +19 -3
- package/lib/typescript/src/useNavigationState.d.ts.map +1 -1
- package/lib/typescript/src/useOnAction.d.ts +9 -9
- package/lib/typescript/src/useOnAction.d.ts.map +1 -1
- package/lib/typescript/src/useOnGetNavigation.d.ts +12 -0
- package/lib/typescript/src/useOnGetNavigation.d.ts.map +1 -0
- package/lib/typescript/src/useOnGetState.d.ts +1 -1
- package/lib/typescript/src/useOnGetState.d.ts.map +1 -1
- package/lib/typescript/src/useOnPreventRemove.d.ts +5 -9
- package/lib/typescript/src/useOnPreventRemove.d.ts.map +1 -1
- package/lib/typescript/src/useOnRouteFocus.d.ts +6 -6
- package/lib/typescript/src/useOnRouteFocus.d.ts.map +1 -1
- package/lib/typescript/src/useOptionsGetters.d.ts +2 -4
- package/lib/typescript/src/useOptionsGetters.d.ts.map +1 -1
- package/lib/typescript/src/usePreventRemove.d.ts.map +1 -1
- package/lib/typescript/src/usePreventRemoveContext.d.ts +2 -1
- package/lib/typescript/src/usePreventRemoveContext.d.ts.map +1 -1
- package/lib/typescript/src/useRegisterNavigator.d.ts.map +1 -1
- package/lib/typescript/src/useRoute.d.ts +7 -3
- package/lib/typescript/src/useRoute.d.ts.map +1 -1
- package/lib/typescript/src/useRouteCache.d.ts +7 -12
- package/lib/typescript/src/useRouteCache.d.ts.map +1 -1
- package/lib/typescript/src/useScheduleUpdate.d.ts +5 -4
- package/lib/typescript/src/useScheduleUpdate.d.ts.map +1 -1
- package/lib/typescript/src/useStateForPath.d.ts +1 -1
- package/lib/typescript/src/useStateForPath.d.ts.map +1 -1
- package/lib/typescript/src/useSyncState.d.ts +1 -0
- package/lib/typescript/src/useSyncState.d.ts.map +1 -1
- package/lib/typescript/src/utilities.d.ts +79 -39
- package/lib/typescript/src/utilities.d.ts.map +1 -1
- package/lib/typescript/src/validatePathConfig.d.ts.map +1 -1
- package/package.json +26 -22
- package/src/BaseNavigationContainer.tsx +468 -333
- package/src/ConsumedParamsContext.tsx +5 -0
- package/src/DataLoading.tsx +206 -0
- package/src/NavigationBuilderContext.tsx +44 -25
- package/src/NavigationFocusedRouteStateContext.tsx +4 -4
- package/src/NavigationIndependentTree.tsx +60 -12
- package/src/NavigationProvider.tsx +47 -20
- package/src/NavigationRootContext.tsx +11 -0
- package/src/NavigationStateContext.tsx +9 -6
- package/src/PreventRemoveContext.tsx +1 -0
- package/src/PreventRemoveProvider.tsx +55 -56
- package/src/SceneView.tsx +14 -40
- package/src/StaticNavigation.tsx +715 -328
- package/src/StaticTreeContext.tsx +7 -0
- package/src/createNavigationContainerRef.tsx +12 -11
- package/src/createNavigatorFactory.tsx +92 -8
- package/src/findFocusedRoute.tsx +16 -16
- package/src/getActionFromState.tsx +87 -51
- package/src/getPathFromState.tsx +310 -134
- package/src/getPatternParts.tsx +98 -16
- package/src/getStateFromPath.tsx +971 -344
- package/src/getStateFromRouteParams.tsx +59 -0
- package/src/index.tsx +57 -6
- package/src/internal.tsx +2 -0
- package/src/isRecordEqual.tsx +3 -1
- package/src/queryString.ts +109 -0
- package/src/theming/useTheme.tsx +1 -1
- package/src/types.tsx +799 -377
- package/src/useDescriptors.tsx +151 -43
- package/src/useEventEmitter.tsx +53 -39
- package/src/useFocusEffect.tsx +5 -2
- package/src/useFocusEvents.tsx +19 -8
- package/src/useFocusedListenersChildrenAdapter.tsx +3 -3
- package/src/useIsFocused.tsx +18 -21
- package/src/useKeyedChildListeners.tsx +5 -2
- package/src/useLazyValue.tsx +2 -2
- package/src/useNavigation.tsx +9 -26
- package/src/useNavigationBuilder.tsx +370 -201
- package/src/useNavigationCache.tsx +148 -123
- package/src/useNavigationHelpers.tsx +27 -37
- package/src/useNavigationIndependentTree.tsx +1 -1
- package/src/useNavigationState.tsx +207 -69
- package/src/useOnAction.tsx +92 -18
- package/src/useOnGetNavigation.tsx +30 -0
- package/src/useOnGetState.tsx +8 -4
- package/src/useOnPreventRemove.tsx +78 -43
- package/src/useOnRouteFocus.tsx +11 -15
- package/src/useOptionsGetters.tsx +41 -28
- package/src/usePreventRemove.tsx +13 -5
- package/src/usePreventRemoveContext.tsx +2 -2
- package/src/useRegisterNavigator.tsx +4 -4
- package/src/useRoute.tsx +20 -6
- package/src/useRouteCache.tsx +57 -35
- package/src/useScheduleUpdate.tsx +13 -11
- package/src/useStateForPath.tsx +1 -1
- package/src/useSyncState.tsx +39 -15
- package/src/utilities.tsx +151 -35
- package/src/validatePathConfig.tsx +86 -57
- package/lib/module/CurrentRenderContext.js +0 -10
- package/lib/module/CurrentRenderContext.js.map +0 -1
- package/lib/module/NavigationMetaContext.js +0 -15
- package/lib/module/NavigationMetaContext.js.map +0 -1
- package/lib/module/checkSerializable.js +0 -46
- package/lib/module/checkSerializable.js.map +0 -1
- package/lib/module/useComponent.js +0 -34
- package/lib/module/useComponent.js.map +0 -1
- package/lib/module/useCurrentRender.js +0 -19
- package/lib/module/useCurrentRender.js.map +0 -1
- package/lib/typescript/src/CurrentRenderContext.d.ts +0 -9
- package/lib/typescript/src/CurrentRenderContext.d.ts.map +0 -1
- package/lib/typescript/src/NavigationMetaContext.d.ts +0 -12
- package/lib/typescript/src/NavigationMetaContext.d.ts.map +0 -1
- package/lib/typescript/src/checkSerializable.d.ts +0 -10
- package/lib/typescript/src/checkSerializable.d.ts.map +0 -1
- package/lib/typescript/src/useComponent.d.ts +0 -7
- package/lib/typescript/src/useComponent.d.ts.map +0 -1
- package/lib/typescript/src/useCurrentRender.d.ts +0 -14
- package/lib/typescript/src/useCurrentRender.d.ts.map +0 -1
- package/src/CurrentRenderContext.tsx +0 -9
- package/src/NavigationMetaContext.tsx +0 -14
- package/src/checkSerializable.tsx +0 -74
- package/src/useComponent.tsx +0 -37
- package/src/useCurrentRender.tsx +0 -31
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from '@react-navigation/routers';
|
|
8
8
|
import * as React from 'react';
|
|
9
9
|
|
|
10
|
-
import {
|
|
10
|
+
import { useNavigationBuilderContext } from './NavigationBuilderContext';
|
|
11
11
|
import { NavigationContext } from './NavigationProvider';
|
|
12
12
|
import type { NavigationHelpers, NavigationProp } from './types';
|
|
13
13
|
import type { NavigationEventEmitter } from './useEventEmitter';
|
|
@@ -19,12 +19,13 @@ type Options<
|
|
|
19
19
|
> = {
|
|
20
20
|
routes: State['routes'];
|
|
21
21
|
getState: () => State;
|
|
22
|
-
navigation: NavigationHelpers<ParamListBase> &
|
|
22
|
+
navigation: NavigationHelpers<ParamListBase, State> &
|
|
23
23
|
Partial<NavigationProp<ParamListBase, string, any, any, any>>;
|
|
24
|
+
canGoBack: (source?: string) => boolean;
|
|
24
25
|
setOptions: (
|
|
25
26
|
cb: (
|
|
26
|
-
options: Record<string, ScreenOptions>
|
|
27
|
-
) => Record<string, ScreenOptions>
|
|
27
|
+
options: Record<string, Partial<ScreenOptions> | undefined>
|
|
28
|
+
) => Record<string, Partial<ScreenOptions> | undefined>
|
|
28
29
|
) => void;
|
|
29
30
|
router: Router<State, NavigationAction>;
|
|
30
31
|
emitter: NavigationEventEmitter<EventMap>;
|
|
@@ -68,134 +69,158 @@ export function useNavigationCache<
|
|
|
68
69
|
routes,
|
|
69
70
|
getState,
|
|
70
71
|
navigation,
|
|
72
|
+
canGoBack,
|
|
71
73
|
setOptions,
|
|
72
74
|
router,
|
|
73
75
|
emitter,
|
|
74
76
|
}: Options<State, ScreenOptions, EventMap>) {
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
+
const { withStackTrace } = useNavigationBuilderContext();
|
|
78
|
+
|
|
79
|
+
const parentNavigation = React.use(NavigationContext);
|
|
77
80
|
|
|
78
81
|
// Cache object which holds navigation objects for each screen
|
|
79
82
|
// We use `React.useMemo` instead of `React.useRef` coz we want to invalidate it when deps change
|
|
80
83
|
// In reality, these deps will rarely change, if ever
|
|
81
|
-
const cache = React.useMemo
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
EventMap,
|
|
87
|
-
ActionHelpers
|
|
88
|
-
>,
|
|
89
|
-
}),
|
|
84
|
+
const cache = React.useMemo<{
|
|
85
|
+
current: NavigationCache<State, ScreenOptions, EventMap, ActionHelpers>;
|
|
86
|
+
routeNames: Record<string, string>;
|
|
87
|
+
}>(
|
|
88
|
+
() => ({ current: {}, routeNames: {} }),
|
|
90
89
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
91
|
-
[
|
|
90
|
+
[
|
|
91
|
+
getState,
|
|
92
|
+
parentNavigation,
|
|
93
|
+
navigation,
|
|
94
|
+
canGoBack,
|
|
95
|
+
setOptions,
|
|
96
|
+
router,
|
|
97
|
+
emitter,
|
|
98
|
+
withStackTrace,
|
|
99
|
+
]
|
|
92
100
|
);
|
|
93
101
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
102
|
+
const next = React.useMemo(() => {
|
|
103
|
+
return routes.reduce<
|
|
104
|
+
NavigationCache<State, ScreenOptions, EventMap, ActionHelpers>
|
|
105
|
+
>((acc, route) => {
|
|
106
|
+
const previous =
|
|
107
|
+
cache.routeNames[route.key] === route.name
|
|
108
|
+
? cache.current[route.key]
|
|
109
|
+
: undefined;
|
|
110
|
+
|
|
111
|
+
if (previous) {
|
|
112
|
+
// If a cached navigation object already exists, reuse it
|
|
113
|
+
acc[route.key] = previous;
|
|
114
|
+
} else {
|
|
115
|
+
const dispatch = (
|
|
116
|
+
thunk:
|
|
117
|
+
| NavigationAction
|
|
118
|
+
| ((state: State) => NavigationAction | null | undefined)
|
|
119
|
+
) => {
|
|
120
|
+
withStackTrace(dispatch, () => {
|
|
121
|
+
React.startTransition(() => {
|
|
122
|
+
const action =
|
|
123
|
+
typeof thunk === 'function' ? thunk(getState()) : thunk;
|
|
124
|
+
|
|
125
|
+
if (action != null) {
|
|
126
|
+
navigation.dispatch({ source: route.key, ...action });
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const actions = {
|
|
133
|
+
...router.actionCreators,
|
|
134
|
+
...CommonActions,
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const helpers = Object.keys(actions).reduce<Record<string, () => void>>(
|
|
138
|
+
(acc, name) => {
|
|
139
|
+
const helper = (...args: any) =>
|
|
140
|
+
withStackTrace(helper, () =>
|
|
141
|
+
// @ts-expect-error: name is a valid key, but TypeScript is dumb
|
|
142
|
+
dispatch(actions[name](...args))
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
acc[name] = helper;
|
|
146
|
+
|
|
147
|
+
return acc;
|
|
148
|
+
},
|
|
149
|
+
{}
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
153
|
+
const { emit, ...rest } = navigation;
|
|
154
|
+
|
|
155
|
+
acc[route.key] = {
|
|
156
|
+
...rest,
|
|
157
|
+
...helpers,
|
|
158
|
+
// FIXME: too much work to fix the types for now
|
|
159
|
+
...(emitter.create(route.key) as any),
|
|
160
|
+
dispatch,
|
|
161
|
+
canGoBack: () => canGoBack(route.key),
|
|
162
|
+
getParent: (routeName) => {
|
|
163
|
+
if (routeName === route.name) {
|
|
164
|
+
// If the passed route name is the same as the current route's name,
|
|
165
|
+
// we return the cached navigation object for the route
|
|
166
|
+
return acc[route.key];
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (routeName !== undefined) {
|
|
170
|
+
const parent = parentNavigation?.getParent(routeName);
|
|
171
|
+
|
|
172
|
+
if (parent === undefined) {
|
|
173
|
+
throw new Error(
|
|
174
|
+
`Couldn't find a navigation object for '${routeName}' in current or any parent screens. Is your component inside the correct screen?`
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return parent;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return parentNavigation;
|
|
182
|
+
},
|
|
183
|
+
setOptions: (options: Partial<ScreenOptions>) => {
|
|
184
|
+
setOptions((o) => ({
|
|
185
|
+
...o,
|
|
186
|
+
[route.key]: { ...o[route.key], ...options },
|
|
187
|
+
}));
|
|
188
|
+
},
|
|
189
|
+
isFocused: () => {
|
|
190
|
+
const state = rest.getState();
|
|
191
|
+
|
|
192
|
+
if (state.routes[state.index]?.key !== route.key) {
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// If the current screen is focused, we also need to check if parent navigator is focused
|
|
197
|
+
// This makes sure that we return the focus state in the whole tree, not just this navigator
|
|
198
|
+
return navigation ? navigation.isFocused() : true;
|
|
199
|
+
},
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return acc;
|
|
204
|
+
}, {});
|
|
205
|
+
}, [
|
|
206
|
+
cache,
|
|
207
|
+
routes,
|
|
208
|
+
getState,
|
|
209
|
+
navigation,
|
|
210
|
+
canGoBack,
|
|
211
|
+
router,
|
|
212
|
+
withStackTrace,
|
|
213
|
+
emitter,
|
|
214
|
+
parentNavigation,
|
|
215
|
+
setOptions,
|
|
216
|
+
]);
|
|
217
|
+
|
|
218
|
+
React.useInsertionEffect(() => {
|
|
219
|
+
cache.current = next;
|
|
220
|
+
cache.routeNames = Object.fromEntries(
|
|
221
|
+
routes.map((route) => [route.key, route.name])
|
|
222
|
+
);
|
|
223
|
+
}, [cache, next, routes]);
|
|
224
|
+
|
|
225
|
+
return next;
|
|
201
226
|
}
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
} from '@react-navigation/routers';
|
|
8
8
|
import * as React from 'react';
|
|
9
9
|
|
|
10
|
+
import { useNavigationBuilderContext } from './NavigationBuilderContext';
|
|
10
11
|
import { NavigationContext } from './NavigationProvider';
|
|
11
12
|
import { type NavigationHelpers, PrivateValueStore } from './types';
|
|
12
13
|
import type { NavigationEventEmitter } from './useEventEmitter';
|
|
@@ -18,10 +19,10 @@ PrivateValueStore;
|
|
|
18
19
|
type Options<State extends NavigationState, Action extends NavigationAction> = {
|
|
19
20
|
onAction: (action: NavigationAction) => boolean;
|
|
20
21
|
onUnhandledAction: (action: NavigationAction) => void;
|
|
22
|
+
canGoBack: (source?: string) => boolean;
|
|
21
23
|
getState: () => State;
|
|
22
24
|
emitter: NavigationEventEmitter<any>;
|
|
23
25
|
router: Router<State, Action>;
|
|
24
|
-
stateRef: React.RefObject<State | null>;
|
|
25
26
|
};
|
|
26
27
|
|
|
27
28
|
/**
|
|
@@ -36,22 +37,26 @@ export function useNavigationHelpers<
|
|
|
36
37
|
>({
|
|
37
38
|
onAction,
|
|
38
39
|
onUnhandledAction,
|
|
40
|
+
canGoBack,
|
|
39
41
|
getState,
|
|
40
42
|
emitter,
|
|
41
43
|
router,
|
|
42
|
-
stateRef,
|
|
43
44
|
}: Options<State, Action>) {
|
|
44
|
-
const parentNavigationHelpers = React.
|
|
45
|
+
const parentNavigationHelpers = React.use(NavigationContext);
|
|
46
|
+
|
|
47
|
+
const { withStackTrace } = useNavigationBuilderContext();
|
|
45
48
|
|
|
46
49
|
return React.useMemo(() => {
|
|
47
50
|
const dispatch = (op: Action | ((state: State) => Action)) => {
|
|
48
|
-
|
|
51
|
+
withStackTrace(dispatch, () => {
|
|
52
|
+
const action = typeof op === 'function' ? op(getState()) : op;
|
|
49
53
|
|
|
50
|
-
|
|
54
|
+
const handled = onAction(action);
|
|
51
55
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
56
|
+
if (!handled) {
|
|
57
|
+
onUnhandledAction?.(action);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
55
60
|
};
|
|
56
61
|
|
|
57
62
|
const actions = {
|
|
@@ -60,8 +65,15 @@ export function useNavigationHelpers<
|
|
|
60
65
|
};
|
|
61
66
|
|
|
62
67
|
const helpers = Object.keys(actions).reduce((acc, name) => {
|
|
68
|
+
const helper = (...args: any) =>
|
|
69
|
+
withStackTrace(helper, () =>
|
|
70
|
+
// @ts-expect-error: name is a valid key, but TypeScript is dumb
|
|
71
|
+
dispatch(actions[name](...args))
|
|
72
|
+
);
|
|
73
|
+
|
|
63
74
|
// @ts-expect-error: name is a valid key, but TypeScript is dumb
|
|
64
|
-
acc[name] =
|
|
75
|
+
acc[name] = helper;
|
|
76
|
+
|
|
65
77
|
return acc;
|
|
66
78
|
}, {} as ActionHelpers);
|
|
67
79
|
|
|
@@ -73,41 +85,19 @@ export function useNavigationHelpers<
|
|
|
73
85
|
isFocused: parentNavigationHelpers
|
|
74
86
|
? parentNavigationHelpers.isFocused
|
|
75
87
|
: () => true,
|
|
76
|
-
canGoBack: () =>
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return (
|
|
80
|
-
router.getStateForAction(state, CommonActions.goBack() as Action, {
|
|
81
|
-
routeNames: state.routeNames,
|
|
82
|
-
routeParamList: {},
|
|
83
|
-
routeGetIdList: {},
|
|
84
|
-
}) !== null ||
|
|
85
|
-
parentNavigationHelpers?.canGoBack() ||
|
|
86
|
-
false
|
|
87
|
-
);
|
|
88
|
-
},
|
|
89
|
-
getState: (): State => {
|
|
90
|
-
// FIXME: Workaround for when the state is read during render
|
|
91
|
-
// By this time, we haven't committed the new state yet
|
|
92
|
-
// Without this `useSyncExternalStore` will keep reading the old state
|
|
93
|
-
// This may result in `useNavigationState` or `useIsFocused` returning wrong values
|
|
94
|
-
// Apart from `useSyncExternalStore`, `getState` should never be called during render
|
|
95
|
-
if (stateRef.current != null) {
|
|
96
|
-
return stateRef.current;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return getState();
|
|
100
|
-
},
|
|
101
|
-
} as NavigationHelpers<ParamListBase, EventMap> & ActionHelpers;
|
|
88
|
+
canGoBack: () => canGoBack(),
|
|
89
|
+
getState,
|
|
90
|
+
} as NavigationHelpers<ParamListBase, State, EventMap> & ActionHelpers;
|
|
102
91
|
|
|
103
92
|
return navigationHelpers;
|
|
104
93
|
}, [
|
|
105
|
-
router,
|
|
94
|
+
router.actionCreators,
|
|
106
95
|
parentNavigationHelpers,
|
|
107
96
|
emitter.emit,
|
|
97
|
+
canGoBack,
|
|
108
98
|
getState,
|
|
109
99
|
onAction,
|
|
110
100
|
onUnhandledAction,
|
|
111
|
-
|
|
101
|
+
withStackTrace,
|
|
112
102
|
]);
|
|
113
103
|
}
|
|
@@ -3,5 +3,5 @@ import * as React from 'react';
|
|
|
3
3
|
import { NavigationIndependentTreeContext } from './NavigationIndependentTreeContext';
|
|
4
4
|
|
|
5
5
|
export function useNavigationIndependentTree() {
|
|
6
|
-
return React.
|
|
6
|
+
return React.use(NavigationIndependentTreeContext);
|
|
7
7
|
}
|