@react-navigation/core 7.0.0-alpha.1 → 7.0.0-alpha.10
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/commonjs/BaseNavigationContainer.js +25 -30
- package/lib/commonjs/BaseNavigationContainer.js.map +1 -1
- package/lib/commonjs/CurrentRenderContext.js +3 -4
- package/lib/commonjs/CurrentRenderContext.js.map +1 -1
- package/lib/commonjs/DeprecatedNavigationInChildContext.js +3 -4
- package/lib/commonjs/DeprecatedNavigationInChildContext.js.map +1 -1
- package/lib/commonjs/EnsureSingleNavigator.js +3 -4
- package/lib/commonjs/EnsureSingleNavigator.js.map +1 -1
- package/lib/commonjs/Group.js.map +1 -1
- package/lib/commonjs/NavigationBuilderContext.js +3 -4
- package/lib/commonjs/NavigationBuilderContext.js.map +1 -1
- package/lib/commonjs/NavigationContainerRefContext.js +3 -4
- package/lib/commonjs/NavigationContainerRefContext.js.map +1 -1
- package/lib/commonjs/NavigationContext.js +3 -4
- package/lib/commonjs/NavigationContext.js.map +1 -1
- package/lib/commonjs/NavigationHelpersContext.js +3 -4
- package/lib/commonjs/NavigationHelpersContext.js.map +1 -1
- package/lib/commonjs/NavigationIndependentTree.js +2 -2
- package/lib/commonjs/NavigationIndependentTree.js.map +1 -1
- package/lib/commonjs/NavigationIndependentTreeContext.js +3 -4
- package/lib/commonjs/NavigationIndependentTreeContext.js.map +1 -1
- package/lib/commonjs/NavigationRouteContext.js +3 -4
- package/lib/commonjs/NavigationRouteContext.js.map +1 -1
- package/lib/commonjs/NavigationStateContext.js +3 -4
- package/lib/commonjs/NavigationStateContext.js.map +1 -1
- package/lib/commonjs/PreventRemoveContext.js +8 -4
- package/lib/commonjs/PreventRemoveContext.js.map +1 -1
- package/lib/commonjs/PreventRemoveProvider.js +8 -10
- package/lib/commonjs/PreventRemoveProvider.js.map +1 -1
- package/lib/commonjs/SceneView.js +2 -2
- package/lib/commonjs/SceneView.js.map +1 -1
- package/lib/commonjs/Screen.js.map +1 -1
- package/lib/commonjs/StaticContainer.js +3 -4
- package/lib/commonjs/StaticContainer.js.map +1 -1
- package/lib/commonjs/StaticNavigation.js +34 -7
- package/lib/commonjs/StaticNavigation.js.map +1 -1
- package/lib/commonjs/UnhandledActionContext.js +3 -4
- package/lib/commonjs/UnhandledActionContext.js.map +1 -1
- package/lib/commonjs/checkDuplicateRouteNames.js +1 -2
- package/lib/commonjs/checkDuplicateRouteNames.js.map +1 -1
- package/lib/commonjs/checkSerializable.js.map +1 -1
- package/lib/commonjs/createNavigationContainerRef.js +1 -2
- package/lib/commonjs/createNavigationContainerRef.js.map +1 -1
- package/lib/commonjs/createNavigatorFactory.js +0 -3
- package/lib/commonjs/createNavigatorFactory.js.map +1 -1
- package/lib/commonjs/findFocusedRoute.js +2 -4
- package/lib/commonjs/findFocusedRoute.js.map +1 -1
- package/lib/commonjs/getActionFromState.js +6 -8
- package/lib/commonjs/getActionFromState.js.map +1 -1
- package/lib/commonjs/getFocusedRouteNameFromRoute.js +1 -1
- package/lib/commonjs/getFocusedRouteNameFromRoute.js.map +1 -1
- package/lib/commonjs/getPathFromState.js +21 -21
- package/lib/commonjs/getPathFromState.js.map +1 -1
- package/lib/commonjs/getStateFromPath.js +24 -17
- package/lib/commonjs/getStateFromPath.js.map +1 -1
- package/lib/commonjs/index.js +27 -3
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/isArrayEqual.js.map +1 -1
- package/lib/commonjs/isRecordEqual.js.map +1 -1
- package/lib/commonjs/theming/ThemeContext.js +12 -0
- package/lib/commonjs/theming/ThemeContext.js.map +1 -0
- package/lib/commonjs/theming/ThemeProvider.js +20 -0
- package/lib/commonjs/theming/ThemeProvider.js.map +1 -0
- package/lib/commonjs/theming/useTheme.js +18 -0
- package/lib/commonjs/theming/useTheme.js.map +1 -0
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/useChildListeners.js +2 -2
- package/lib/commonjs/useChildListeners.js.map +1 -1
- package/lib/commonjs/useComponent.js +2 -2
- package/lib/commonjs/useComponent.js.map +1 -1
- package/lib/commonjs/useCurrentRender.js +2 -2
- package/lib/commonjs/useCurrentRender.js.map +1 -1
- package/lib/commonjs/useDescriptors.js +83 -31
- package/lib/commonjs/useDescriptors.js.map +1 -1
- package/lib/commonjs/useEventEmitter.js +5 -6
- package/lib/commonjs/useEventEmitter.js.map +1 -1
- package/lib/commonjs/useFocusEffect.js +4 -2
- package/lib/commonjs/useFocusEffect.js.map +1 -1
- package/lib/commonjs/useFocusEvents.js +4 -4
- package/lib/commonjs/useFocusEvents.js.map +1 -1
- package/lib/commonjs/useFocusedListenersChildrenAdapter.js +3 -3
- package/lib/commonjs/useFocusedListenersChildrenAdapter.js.map +1 -1
- package/lib/commonjs/useIsFocused.js +5 -4
- package/lib/commonjs/useIsFocused.js.map +1 -1
- package/lib/commonjs/useIsomorphicLayoutEffect.js +12 -0
- package/lib/commonjs/useIsomorphicLayoutEffect.js.map +1 -0
- package/lib/commonjs/useIsomorphicLayoutEffect.native.js +9 -0
- package/lib/commonjs/useIsomorphicLayoutEffect.native.js.map +1 -0
- package/lib/commonjs/useKeyedChildListeners.js +2 -2
- package/lib/commonjs/useKeyedChildListeners.js.map +1 -1
- package/lib/commonjs/useNavigation.js +2 -2
- package/lib/commonjs/useNavigation.js.map +1 -1
- package/lib/commonjs/useNavigationBuilder.js +78 -68
- package/lib/commonjs/useNavigationBuilder.js.map +1 -1
- package/lib/commonjs/useNavigationCache.js +57 -16
- package/lib/commonjs/useNavigationCache.js.map +1 -1
- package/lib/commonjs/useNavigationContainerRef.js +2 -2
- package/lib/commonjs/useNavigationContainerRef.js.map +1 -1
- package/lib/commonjs/useNavigationHelpers.js +4 -5
- package/lib/commonjs/useNavigationHelpers.js.map +1 -1
- package/lib/commonjs/useNavigationIndependentTree.js +2 -2
- package/lib/commonjs/useNavigationIndependentTree.js.map +1 -1
- package/lib/commonjs/useNavigationState.js +2 -2
- package/lib/commonjs/useNavigationState.js.map +1 -1
- package/lib/commonjs/useOnAction.js +6 -4
- package/lib/commonjs/useOnAction.js.map +1 -1
- package/lib/commonjs/useOnGetState.js +4 -5
- package/lib/commonjs/useOnGetState.js.map +1 -1
- package/lib/commonjs/useOnPreventRemove.js +5 -6
- package/lib/commonjs/useOnPreventRemove.js.map +1 -1
- package/lib/commonjs/useOnRouteFocus.js +2 -2
- package/lib/commonjs/useOnRouteFocus.js.map +1 -1
- package/lib/commonjs/useOptionsGetters.js +9 -10
- package/lib/commonjs/useOptionsGetters.js.map +1 -1
- package/lib/commonjs/usePreventRemove.js +5 -5
- package/lib/commonjs/usePreventRemove.js.map +1 -1
- package/lib/commonjs/usePreventRemoveContext.js +2 -2
- package/lib/commonjs/usePreventRemoveContext.js.map +1 -1
- package/lib/commonjs/useRegisterNavigator.js +2 -2
- package/lib/commonjs/useRegisterNavigator.js.map +1 -1
- package/lib/commonjs/useRoute.js +2 -2
- package/lib/commonjs/useRoute.js.map +1 -1
- package/lib/commonjs/useRouteCache.js +19 -16
- package/lib/commonjs/useRouteCache.js.map +1 -1
- package/lib/commonjs/useSyncState.js +27 -56
- package/lib/commonjs/useSyncState.js.map +1 -1
- package/lib/commonjs/validatePathConfig.js +37 -10
- package/lib/commonjs/validatePathConfig.js.map +1 -1
- package/lib/module/BaseNavigationContainer.js +22 -26
- package/lib/module/BaseNavigationContainer.js.map +1 -1
- package/lib/module/CurrentRenderContext.js.map +1 -1
- package/lib/module/DeprecatedNavigationInChildContext.js.map +1 -1
- package/lib/module/EnsureSingleNavigator.js.map +1 -1
- package/lib/module/Group.js.map +1 -1
- package/lib/module/NavigationBuilderContext.js.map +1 -1
- package/lib/module/NavigationContainerRefContext.js.map +1 -1
- package/lib/module/NavigationContext.js.map +1 -1
- package/lib/module/NavigationHelpersContext.js.map +1 -1
- package/lib/module/NavigationIndependentTree.js.map +1 -1
- package/lib/module/NavigationIndependentTreeContext.js.map +1 -1
- package/lib/module/NavigationRouteContext.js.map +1 -1
- package/lib/module/NavigationStateContext.js.map +1 -1
- package/lib/module/PreventRemoveContext.js.map +1 -1
- package/lib/module/PreventRemoveProvider.js +6 -8
- package/lib/module/PreventRemoveProvider.js.map +1 -1
- package/lib/module/SceneView.js.map +1 -1
- package/lib/module/Screen.js.map +1 -1
- package/lib/module/StaticContainer.js.map +1 -1
- package/lib/module/StaticNavigation.js +27 -5
- package/lib/module/StaticNavigation.js.map +1 -1
- package/lib/module/UnhandledActionContext.js.map +1 -1
- package/lib/module/checkDuplicateRouteNames.js +1 -2
- package/lib/module/checkDuplicateRouteNames.js.map +1 -1
- package/lib/module/checkSerializable.js.map +1 -1
- package/lib/module/createNavigationContainerRef.js.map +1 -1
- package/lib/module/createNavigatorFactory.js +0 -3
- package/lib/module/createNavigatorFactory.js.map +1 -1
- package/lib/module/findFocusedRoute.js +2 -4
- package/lib/module/findFocusedRoute.js.map +1 -1
- package/lib/module/getActionFromState.js +6 -8
- package/lib/module/getActionFromState.js.map +1 -1
- package/lib/module/getFocusedRouteNameFromRoute.js +1 -1
- package/lib/module/getFocusedRouteNameFromRoute.js.map +1 -1
- package/lib/module/getPathFromState.js +19 -19
- package/lib/module/getPathFromState.js.map +1 -1
- package/lib/module/getStateFromPath.js +22 -15
- package/lib/module/getStateFromPath.js.map +1 -1
- package/lib/module/index.js +4 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/isArrayEqual.js.map +1 -1
- package/lib/module/isRecordEqual.js.map +1 -1
- package/lib/module/theming/ThemeContext.js +4 -0
- package/lib/module/theming/ThemeContext.js.map +1 -0
- package/lib/module/theming/ThemeProvider.js +12 -0
- package/lib/module/theming/ThemeProvider.js.map +1 -0
- package/lib/module/theming/useTheme.js +10 -0
- package/lib/module/theming/useTheme.js.map +1 -0
- package/lib/module/types.js.map +1 -1
- package/lib/module/useChildListeners.js.map +1 -1
- package/lib/module/useComponent.js.map +1 -1
- package/lib/module/useCurrentRender.js.map +1 -1
- package/lib/module/useDescriptors.js +81 -29
- package/lib/module/useDescriptors.js.map +1 -1
- package/lib/module/useEventEmitter.js +3 -4
- package/lib/module/useEventEmitter.js.map +1 -1
- package/lib/module/useFocusEffect.js +2 -0
- package/lib/module/useFocusEffect.js.map +1 -1
- package/lib/module/useFocusEvents.js +2 -2
- package/lib/module/useFocusEvents.js.map +1 -1
- package/lib/module/useFocusedListenersChildrenAdapter.js +1 -1
- package/lib/module/useFocusedListenersChildrenAdapter.js.map +1 -1
- package/lib/module/useIsFocused.js.map +1 -1
- package/lib/module/useIsomorphicLayoutEffect.js +7 -0
- package/lib/module/useIsomorphicLayoutEffect.js.map +1 -0
- package/lib/module/useIsomorphicLayoutEffect.native.js +3 -0
- package/lib/module/useIsomorphicLayoutEffect.native.js.map +1 -0
- package/lib/module/useKeyedChildListeners.js.map +1 -1
- package/lib/module/useNavigation.js.map +1 -1
- package/lib/module/useNavigationBuilder.js +75 -66
- package/lib/module/useNavigationBuilder.js.map +1 -1
- package/lib/module/useNavigationCache.js +55 -14
- package/lib/module/useNavigationCache.js.map +1 -1
- package/lib/module/useNavigationContainerRef.js.map +1 -1
- package/lib/module/useNavigationHelpers.js +2 -3
- package/lib/module/useNavigationHelpers.js.map +1 -1
- package/lib/module/useNavigationIndependentTree.js.map +1 -1
- package/lib/module/useNavigationState.js.map +1 -1
- package/lib/module/useOnAction.js +4 -2
- package/lib/module/useOnAction.js.map +1 -1
- package/lib/module/useOnGetState.js +2 -3
- package/lib/module/useOnGetState.js.map +1 -1
- package/lib/module/useOnPreventRemove.js +3 -4
- package/lib/module/useOnPreventRemove.js.map +1 -1
- package/lib/module/useOnRouteFocus.js.map +1 -1
- package/lib/module/useOptionsGetters.js +7 -8
- package/lib/module/useOptionsGetters.js.map +1 -1
- package/lib/module/usePreventRemove.js +2 -2
- package/lib/module/usePreventRemove.js.map +1 -1
- package/lib/module/usePreventRemoveContext.js.map +1 -1
- package/lib/module/useRegisterNavigator.js.map +1 -1
- package/lib/module/useRoute.js.map +1 -1
- package/lib/module/useRouteCache.js +16 -12
- package/lib/module/useRouteCache.js.map +1 -1
- package/lib/module/useSyncState.js +25 -54
- package/lib/module/useSyncState.js.map +1 -1
- package/lib/module/validatePathConfig.js +37 -10
- package/lib/module/validatePathConfig.js.map +1 -1
- package/lib/typescript/src/BaseNavigationContainer.d.ts +2 -1
- package/lib/typescript/src/BaseNavigationContainer.d.ts.map +1 -1
- package/lib/typescript/src/EnsureSingleNavigator.d.ts +1 -1
- package/lib/typescript/src/EnsureSingleNavigator.d.ts.map +1 -1
- package/lib/typescript/src/NavigationContext.d.ts +1 -17
- package/lib/typescript/src/NavigationContext.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/NavigationRouteContext.d.ts +1 -1
- package/lib/typescript/src/NavigationRouteContext.d.ts.map +1 -1
- package/lib/typescript/src/NavigationStateContext.d.ts +2 -18
- 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 +2 -2
- package/lib/typescript/src/SceneView.d.ts.map +1 -1
- package/lib/typescript/src/StaticNavigation.d.ts +12 -5
- package/lib/typescript/src/StaticNavigation.d.ts.map +1 -1
- package/lib/typescript/src/createNavigatorFactory.d.ts.map +1 -1
- package/lib/typescript/src/findFocusedRoute.d.ts +1 -9
- package/lib/typescript/src/findFocusedRoute.d.ts.map +1 -1
- package/lib/typescript/src/getPathFromState.d.ts +1 -0
- package/lib/typescript/src/getPathFromState.d.ts.map +1 -1
- package/lib/typescript/src/getStateFromPath.d.ts +1 -0
- package/lib/typescript/src/getStateFromPath.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +5 -2
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/theming/ThemeContext.d.ts +3 -0
- package/lib/typescript/src/theming/ThemeContext.d.ts.map +1 -0
- package/lib/typescript/src/theming/ThemeProvider.d.ts +8 -0
- package/lib/typescript/src/theming/ThemeProvider.d.ts.map +1 -0
- package/lib/typescript/src/theming/useTheme.d.ts +2 -0
- package/lib/typescript/src/theming/useTheme.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +80 -1
- package/lib/typescript/src/types.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 +107 -59
- package/lib/typescript/src/useDescriptors.d.ts.map +1 -1
- package/lib/typescript/src/useFocusEffect.d.ts.map +1 -1
- package/lib/typescript/src/useFocusedListenersChildrenAdapter.d.ts +1 -1
- package/lib/typescript/src/useFocusedListenersChildrenAdapter.d.ts.map +1 -1
- package/lib/typescript/src/useIsomorphicLayoutEffect.d.ts +6 -0
- package/lib/typescript/src/useIsomorphicLayoutEffect.d.ts.map +1 -0
- package/lib/typescript/src/useIsomorphicLayoutEffect.native.d.ts +3 -0
- package/lib/typescript/src/useIsomorphicLayoutEffect.native.d.ts.map +1 -0
- package/lib/typescript/src/useNavigation.d.ts +4 -1
- package/lib/typescript/src/useNavigation.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationBuilder.d.ts +99 -63
- package/lib/typescript/src/useNavigationBuilder.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationCache.d.ts +53 -3
- package/lib/typescript/src/useNavigationCache.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationHelpers.d.ts +25 -55
- package/lib/typescript/src/useNavigationHelpers.d.ts.map +1 -1
- package/lib/typescript/src/useOnAction.d.ts +1 -1
- 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 +1 -1
- package/lib/typescript/src/useOnPreventRemove.d.ts.map +1 -1
- package/lib/typescript/src/usePreventRemove.d.ts +1 -1
- package/lib/typescript/src/usePreventRemove.d.ts.map +1 -1
- package/lib/typescript/src/useRouteCache.d.ts +1 -1
- package/lib/typescript/src/useRouteCache.d.ts.map +1 -1
- package/lib/typescript/src/useSyncState.d.ts +1 -4
- package/lib/typescript/src/useSyncState.d.ts.map +1 -1
- package/lib/typescript/src/validatePathConfig.d.ts +1 -1
- package/lib/typescript/src/validatePathConfig.d.ts.map +1 -1
- package/lib/typescript/utils/usePrevious.d.ts +6 -0
- package/lib/typescript/utils/usePrevious.d.ts.map +1 -0
- package/package.json +14 -14
- package/src/BaseNavigationContainer.tsx +35 -36
- package/src/Group.tsx +1 -1
- package/src/PreventRemoveProvider.tsx +4 -1
- package/src/SceneView.tsx +1 -1
- package/src/Screen.tsx +1 -1
- package/src/StaticNavigation.tsx +34 -32
- package/src/checkDuplicateRouteNames.tsx +1 -1
- package/src/createNavigationContainerRef.tsx +1 -1
- package/src/createNavigatorFactory.tsx +2 -4
- package/src/getActionFromState.tsx +1 -1
- package/src/getFocusedRouteNameFromRoute.tsx +3 -3
- package/src/getPathFromState.tsx +14 -11
- package/src/getStateFromPath.tsx +22 -3
- package/src/index.tsx +6 -3
- package/src/theming/ThemeContext.tsx +7 -0
- package/src/theming/ThemeProvider.tsx +14 -0
- package/src/theming/useTheme.tsx +15 -0
- package/src/types.tsx +133 -17
- package/src/useDescriptors.tsx +153 -59
- package/src/useFocusEffect.tsx +1 -0
- package/src/useFocusedListenersChildrenAdapter.tsx +2 -2
- package/src/useIsomorphicLayoutEffect.native.tsx +3 -0
- package/src/useIsomorphicLayoutEffect.tsx +7 -0
- package/src/useNavigation.tsx +4 -1
- package/src/useNavigationBuilder.tsx +119 -100
- package/src/useNavigationCache.tsx +91 -30
- package/src/useNavigationContainerRef.tsx +1 -1
- package/src/useNavigationHelpers.tsx +6 -7
- package/src/useOnAction.tsx +8 -3
- package/src/useOnGetState.tsx +1 -1
- package/src/useOnPreventRemove.tsx +1 -1
- package/src/useOptionsGetters.tsx +2 -2
- package/src/usePreventRemove.tsx +1 -1
- package/src/useRouteCache.tsx +17 -16
- package/src/useSyncState.tsx +31 -59
- package/src/validatePathConfig.tsx +58 -14
- package/lib/commonjs/fromEntries.js +0 -18
- package/lib/commonjs/fromEntries.js.map +0 -1
- package/lib/commonjs/useScheduleUpdate.js +0 -37
- package/lib/commonjs/useScheduleUpdate.js.map +0 -1
- package/lib/module/fromEntries.js +0 -12
- package/lib/module/fromEntries.js.map +0 -1
- package/lib/module/useScheduleUpdate.js +0 -27
- package/lib/module/useScheduleUpdate.js.map +0 -1
- package/lib/typescript/src/fromEntries.d.ts +0 -2
- package/lib/typescript/src/fromEntries.d.ts.map +0 -1
- package/lib/typescript/src/useScheduleUpdate.d.ts +0 -14
- package/lib/typescript/src/useScheduleUpdate.d.ts.map +0 -1
- package/src/fromEntries.tsx +0 -11
- package/src/useScheduleUpdate.tsx +0 -32
package/src/useNavigation.tsx
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type NavigationState } from '@react-navigation/routers';
|
|
1
2
|
import * as React from 'react';
|
|
2
3
|
|
|
3
4
|
import { NavigationContainerRefContext } from './NavigationContainerRefContext';
|
|
@@ -10,7 +11,9 @@ import type { NavigationProp } from './types';
|
|
|
10
11
|
* @returns Navigation prop of the parent screen.
|
|
11
12
|
*/
|
|
12
13
|
export function useNavigation<
|
|
13
|
-
T = NavigationProp<ReactNavigation.RootParamList>
|
|
14
|
+
T = Omit<NavigationProp<ReactNavigation.RootParamList>, 'getState'> & {
|
|
15
|
+
getState(): NavigationState | undefined;
|
|
16
|
+
},
|
|
14
17
|
>(): T {
|
|
15
18
|
const root = React.useContext(NavigationContainerRefContext);
|
|
16
19
|
const navigation = React.useContext(NavigationContext);
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CommonActions,
|
|
3
|
-
DefaultRouterOptions,
|
|
4
|
-
NavigationAction,
|
|
5
|
-
NavigationState,
|
|
6
|
-
ParamListBase,
|
|
7
|
-
PartialState,
|
|
8
|
-
Route,
|
|
9
|
-
Router,
|
|
10
|
-
RouterConfigOptions,
|
|
11
|
-
RouterFactory,
|
|
3
|
+
type DefaultRouterOptions,
|
|
4
|
+
type NavigationAction,
|
|
5
|
+
type NavigationState,
|
|
6
|
+
type ParamListBase,
|
|
7
|
+
type PartialState,
|
|
8
|
+
type Route,
|
|
9
|
+
type Router,
|
|
10
|
+
type RouterConfigOptions,
|
|
11
|
+
type RouterFactory,
|
|
12
12
|
} from '@react-navigation/routers';
|
|
13
13
|
import * as React from 'react';
|
|
14
14
|
import { isValidElementType } from 'react-is';
|
|
15
|
+
import useLatestCallback from 'use-latest-callback';
|
|
15
16
|
|
|
16
17
|
import { Group } from './Group';
|
|
17
18
|
import { isArrayEqual } from './isArrayEqual';
|
|
@@ -22,47 +23,31 @@ import { NavigationStateContext } from './NavigationStateContext';
|
|
|
22
23
|
import { PreventRemoveProvider } from './PreventRemoveProvider';
|
|
23
24
|
import { Screen } from './Screen';
|
|
24
25
|
import {
|
|
25
|
-
DefaultNavigatorOptions,
|
|
26
|
-
EventMapBase,
|
|
27
|
-
EventMapCore,
|
|
28
|
-
NavigatorScreenParams,
|
|
26
|
+
type DefaultNavigatorOptions,
|
|
27
|
+
type EventMapBase,
|
|
28
|
+
type EventMapCore,
|
|
29
|
+
type NavigatorScreenParams,
|
|
29
30
|
PrivateValueStore,
|
|
30
|
-
RouteConfig,
|
|
31
|
-
RouteProp,
|
|
31
|
+
type RouteConfig,
|
|
32
32
|
} from './types';
|
|
33
33
|
import { useChildListeners } from './useChildListeners';
|
|
34
34
|
import { useComponent } from './useComponent';
|
|
35
35
|
import { useCurrentRender } from './useCurrentRender';
|
|
36
|
-
import { ScreenConfigWithParent, useDescriptors } from './useDescriptors';
|
|
36
|
+
import { type ScreenConfigWithParent, useDescriptors } from './useDescriptors';
|
|
37
37
|
import { useEventEmitter } from './useEventEmitter';
|
|
38
38
|
import { useFocusedListenersChildrenAdapter } from './useFocusedListenersChildrenAdapter';
|
|
39
39
|
import { useFocusEvents } from './useFocusEvents';
|
|
40
|
+
import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect';
|
|
40
41
|
import { useKeyedChildListeners } from './useKeyedChildListeners';
|
|
41
42
|
import { useNavigationHelpers } from './useNavigationHelpers';
|
|
42
43
|
import { useOnAction } from './useOnAction';
|
|
43
44
|
import { useOnGetState } from './useOnGetState';
|
|
44
45
|
import { useOnRouteFocus } from './useOnRouteFocus';
|
|
45
46
|
import { useRegisterNavigator } from './useRegisterNavigator';
|
|
46
|
-
import { useScheduleUpdate } from './useScheduleUpdate';
|
|
47
47
|
|
|
48
48
|
// This is to make TypeScript compiler happy
|
|
49
|
-
// eslint-disable-next-line babel/no-unused-expressions
|
|
50
49
|
PrivateValueStore;
|
|
51
50
|
|
|
52
|
-
type NavigationBuilderOptions<ScreenOptions extends {}> = {
|
|
53
|
-
/**
|
|
54
|
-
* Default options specified by the navigator.
|
|
55
|
-
* It receives the custom options in the arguments if a function is specified.
|
|
56
|
-
*/
|
|
57
|
-
defaultScreenOptions?:
|
|
58
|
-
| ScreenOptions
|
|
59
|
-
| ((props: {
|
|
60
|
-
route: RouteProp<ParamListBase>;
|
|
61
|
-
navigation: any;
|
|
62
|
-
options: ScreenOptions;
|
|
63
|
-
}) => ScreenOptions);
|
|
64
|
-
};
|
|
65
|
-
|
|
66
51
|
type NavigatorRoute = {
|
|
67
52
|
key: string;
|
|
68
53
|
params?: NavigatorScreenParams<ParamListBase>;
|
|
@@ -79,7 +64,7 @@ const isValidKey = (key: unknown) =>
|
|
|
79
64
|
const getRouteConfigsFromChildren = <
|
|
80
65
|
State extends NavigationState,
|
|
81
66
|
ScreenOptions extends {},
|
|
82
|
-
EventMap extends EventMapBase
|
|
67
|
+
EventMap extends EventMapBase,
|
|
83
68
|
>(
|
|
84
69
|
children: React.ReactNode,
|
|
85
70
|
groupKey?: string,
|
|
@@ -87,7 +72,8 @@ const getRouteConfigsFromChildren = <
|
|
|
87
72
|
State,
|
|
88
73
|
ScreenOptions,
|
|
89
74
|
EventMap
|
|
90
|
-
>['options']
|
|
75
|
+
>['options'],
|
|
76
|
+
groupLayout?: ScreenConfigWithParent<State, ScreenOptions, EventMap>['layout']
|
|
91
77
|
) => {
|
|
92
78
|
const configs = React.Children.toArray(children).reduce<
|
|
93
79
|
ScreenConfigWithParent<State, ScreenOptions, EventMap>[]
|
|
@@ -110,6 +96,7 @@ const getRouteConfigsFromChildren = <
|
|
|
110
96
|
acc.push({
|
|
111
97
|
keys: [groupKey, child.props.navigationKey],
|
|
112
98
|
options: groupOptions,
|
|
99
|
+
layout: groupLayout,
|
|
113
100
|
props: child.props as RouteConfig<
|
|
114
101
|
ParamListBase,
|
|
115
102
|
string,
|
|
@@ -118,6 +105,7 @@ const getRouteConfigsFromChildren = <
|
|
|
118
105
|
EventMap
|
|
119
106
|
>,
|
|
120
107
|
});
|
|
108
|
+
|
|
121
109
|
return acc;
|
|
122
110
|
}
|
|
123
111
|
|
|
@@ -139,8 +127,9 @@ const getRouteConfigsFromChildren = <
|
|
|
139
127
|
child.type !== Group
|
|
140
128
|
? groupOptions
|
|
141
129
|
: groupOptions != null
|
|
142
|
-
|
|
143
|
-
|
|
130
|
+
? [...groupOptions, child.props.screenOptions]
|
|
131
|
+
: [child.props.screenOptions],
|
|
132
|
+
child.props.screenLayout ?? groupLayout
|
|
144
133
|
)
|
|
145
134
|
);
|
|
146
135
|
return acc;
|
|
@@ -161,8 +150,8 @@ const getRouteConfigsFromChildren = <
|
|
|
161
150
|
: ''
|
|
162
151
|
}`
|
|
163
152
|
: typeof child === 'object'
|
|
164
|
-
|
|
165
|
-
|
|
153
|
+
? JSON.stringify(child)
|
|
154
|
+
: `'${String(child)}'`
|
|
166
155
|
}). To render this component in the navigator, pass it in the 'component' prop to 'Screen'.`
|
|
167
156
|
);
|
|
168
157
|
}, []);
|
|
@@ -257,7 +246,7 @@ export function useNavigationBuilder<
|
|
|
257
246
|
RouterOptions extends DefaultRouterOptions,
|
|
258
247
|
ActionHelpers extends Record<string, () => void>,
|
|
259
248
|
ScreenOptions extends {},
|
|
260
|
-
EventMap extends Record<string, any
|
|
249
|
+
EventMap extends Record<string, any>,
|
|
261
250
|
>(
|
|
262
251
|
createRouter: RouterFactory<State, any, RouterOptions>,
|
|
263
252
|
options: DefaultNavigatorOptions<
|
|
@@ -266,7 +255,6 @@ export function useNavigationBuilder<
|
|
|
266
255
|
ScreenOptions,
|
|
267
256
|
EventMap
|
|
268
257
|
> &
|
|
269
|
-
NavigationBuilderOptions<ScreenOptions> &
|
|
270
258
|
RouterOptions
|
|
271
259
|
) {
|
|
272
260
|
const navigatorKey = useRegisterNavigator();
|
|
@@ -275,17 +263,17 @@ export function useNavigationBuilder<
|
|
|
275
263
|
| NavigatorRoute
|
|
276
264
|
| undefined;
|
|
277
265
|
|
|
278
|
-
const {
|
|
266
|
+
const {
|
|
267
|
+
children,
|
|
268
|
+
layout,
|
|
269
|
+
screenOptions,
|
|
270
|
+
screenLayout,
|
|
271
|
+
screenListeners,
|
|
272
|
+
...rest
|
|
273
|
+
} = options;
|
|
274
|
+
|
|
279
275
|
const { current: router } = React.useRef<Router<State, any>>(
|
|
280
|
-
createRouter(
|
|
281
|
-
...(rest as unknown as RouterOptions),
|
|
282
|
-
...(route?.params &&
|
|
283
|
-
route.params.state == null &&
|
|
284
|
-
route.params.initial !== false &&
|
|
285
|
-
typeof route.params.screen === 'string'
|
|
286
|
-
? { initialRouteName: route.params.screen }
|
|
287
|
-
: null),
|
|
288
|
-
})
|
|
276
|
+
createRouter(rest as unknown as RouterOptions)
|
|
289
277
|
);
|
|
290
278
|
|
|
291
279
|
const routeConfigs = getRouteConfigsFromChildren<
|
|
@@ -362,12 +350,7 @@ export function useNavigationBuilder<
|
|
|
362
350
|
|
|
363
351
|
const stateCleanedUp = React.useRef(false);
|
|
364
352
|
|
|
365
|
-
const
|
|
366
|
-
setCurrentState(undefined);
|
|
367
|
-
stateCleanedUp.current = true;
|
|
368
|
-
}, [setCurrentState]);
|
|
369
|
-
|
|
370
|
-
const setState = React.useCallback(
|
|
353
|
+
const setState = useLatestCallback(
|
|
371
354
|
(state: NavigationState | PartialState<NavigationState> | undefined) => {
|
|
372
355
|
if (stateCleanedUp.current) {
|
|
373
356
|
// State might have been already cleaned up due to unmount
|
|
@@ -375,9 +358,9 @@ export function useNavigationBuilder<
|
|
|
375
358
|
// This would lead to old data preservation on main navigator unmount
|
|
376
359
|
return;
|
|
377
360
|
}
|
|
361
|
+
|
|
378
362
|
setCurrentState(state);
|
|
379
|
-
}
|
|
380
|
-
[setCurrentState]
|
|
363
|
+
}
|
|
381
364
|
);
|
|
382
365
|
|
|
383
366
|
const [initializedState, isFirstStateInitialization] = React.useMemo(() => {
|
|
@@ -409,7 +392,11 @@ export function useNavigationBuilder<
|
|
|
409
392
|
// So we need to rehydrate it to make it usable
|
|
410
393
|
if (
|
|
411
394
|
(currentState === undefined || !isStateValid(currentState)) &&
|
|
412
|
-
route?.params?.state == null
|
|
395
|
+
route?.params?.state == null &&
|
|
396
|
+
!(
|
|
397
|
+
typeof route?.params?.screen === 'string' &&
|
|
398
|
+
route?.params?.initial !== false
|
|
399
|
+
)
|
|
413
400
|
) {
|
|
414
401
|
return [
|
|
415
402
|
router.getInitialState({
|
|
@@ -420,9 +407,29 @@ export function useNavigationBuilder<
|
|
|
420
407
|
true,
|
|
421
408
|
];
|
|
422
409
|
} else {
|
|
410
|
+
let stateFromParams;
|
|
411
|
+
|
|
412
|
+
if (route?.params?.state != null) {
|
|
413
|
+
stateFromParams = route.params.state;
|
|
414
|
+
} else if (
|
|
415
|
+
typeof route?.params?.screen === 'string' &&
|
|
416
|
+
route?.params?.initial !== false
|
|
417
|
+
) {
|
|
418
|
+
stateFromParams = {
|
|
419
|
+
index: 0,
|
|
420
|
+
routes: [
|
|
421
|
+
{
|
|
422
|
+
name: route.params.screen,
|
|
423
|
+
params: route.params.params,
|
|
424
|
+
path: route.params.path,
|
|
425
|
+
},
|
|
426
|
+
],
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
|
|
423
430
|
return [
|
|
424
431
|
router.getRehydratedState(
|
|
425
|
-
(
|
|
432
|
+
(stateFromParams ?? currentState) as PartialState<State>,
|
|
426
433
|
{
|
|
427
434
|
routeNames,
|
|
428
435
|
routeParamList: initialRouteParamList,
|
|
@@ -462,17 +469,26 @@ export function useNavigationBuilder<
|
|
|
462
469
|
!isArrayEqual(state.routeNames, routeNames) ||
|
|
463
470
|
!isRecordEqual(routeKeyList, previousRouteKeyList)
|
|
464
471
|
) {
|
|
472
|
+
const navigatorStateForNextRouteNamesChange =
|
|
473
|
+
options.getStateForRouteNamesChange?.(state);
|
|
465
474
|
// When the list of route names change, the router should handle it to remove invalid routes
|
|
466
|
-
nextState =
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
475
|
+
nextState = navigatorStateForNextRouteNamesChange
|
|
476
|
+
? // @ts-expect-error this is ok
|
|
477
|
+
router.getRehydratedState(navigatorStateForNextRouteNamesChange, {
|
|
478
|
+
routeNames,
|
|
479
|
+
routeParamList,
|
|
480
|
+
routeGetIdList,
|
|
481
|
+
})
|
|
482
|
+
: router.getStateForRouteNamesChange(state, {
|
|
483
|
+
routeNames,
|
|
484
|
+
routeParamList,
|
|
485
|
+
routeGetIdList,
|
|
486
|
+
routeKeyChanges: Object.keys(routeKeyList).filter(
|
|
487
|
+
(name) =>
|
|
488
|
+
name in previousRouteKeyList &&
|
|
489
|
+
routeKeyList[name] !== previousRouteKeyList[name]
|
|
490
|
+
),
|
|
491
|
+
});
|
|
476
492
|
}
|
|
477
493
|
|
|
478
494
|
const previousNestedParamsRef = React.useRef(route?.params);
|
|
@@ -527,7 +543,7 @@ export function useNavigationBuilder<
|
|
|
527
543
|
|
|
528
544
|
const shouldUpdate = state !== nextState;
|
|
529
545
|
|
|
530
|
-
|
|
546
|
+
useIsomorphicLayoutEffect(() => {
|
|
531
547
|
if (shouldUpdate) {
|
|
532
548
|
// If the state needs to be updated, we'll schedule an update
|
|
533
549
|
setState(nextState);
|
|
@@ -551,34 +567,24 @@ export function useNavigationBuilder<
|
|
|
551
567
|
|
|
552
568
|
return () => {
|
|
553
569
|
// We need to clean up state for this navigator on unmount
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
if (getCurrentState() !== undefined && getKey() === navigatorKey) {
|
|
559
|
-
cleanUpState();
|
|
560
|
-
}
|
|
561
|
-
}, 0);
|
|
570
|
+
if (getCurrentState() !== undefined && getKey() === navigatorKey) {
|
|
571
|
+
setCurrentState(undefined);
|
|
572
|
+
stateCleanedUp.current = true;
|
|
573
|
+
}
|
|
562
574
|
};
|
|
563
575
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
564
576
|
}, []);
|
|
565
577
|
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
// latest initializedState, but don't need it to change when that happens
|
|
569
|
-
const initializedStateRef = React.useRef<State>();
|
|
570
|
-
initializedStateRef.current = initializedState;
|
|
571
|
-
|
|
572
|
-
const getState = React.useCallback((): State => {
|
|
573
|
-
const currentState = getCurrentState();
|
|
578
|
+
const getState = useLatestCallback((): State => {
|
|
579
|
+
const currentState = shouldUpdate ? nextState : getCurrentState();
|
|
574
580
|
|
|
575
|
-
return
|
|
576
|
-
?
|
|
577
|
-
|
|
578
|
-
}
|
|
581
|
+
return (
|
|
582
|
+
isStateInitialized(currentState) ? currentState : initializedState
|
|
583
|
+
) as State;
|
|
584
|
+
});
|
|
579
585
|
|
|
580
586
|
const emitter = useEventEmitter<EventMapCore<State>>((e) => {
|
|
581
|
-
|
|
587
|
+
const routeNames = [];
|
|
582
588
|
|
|
583
589
|
let route: Route<string> | undefined;
|
|
584
590
|
|
|
@@ -685,7 +691,7 @@ export function useNavigationBuilder<
|
|
|
685
691
|
getStateListeners: keyedListeners.getState,
|
|
686
692
|
});
|
|
687
693
|
|
|
688
|
-
const descriptors = useDescriptors<
|
|
694
|
+
const { describe, descriptors } = useDescriptors<
|
|
689
695
|
State,
|
|
690
696
|
ActionHelpers,
|
|
691
697
|
ScreenOptions,
|
|
@@ -694,8 +700,8 @@ export function useNavigationBuilder<
|
|
|
694
700
|
state,
|
|
695
701
|
screens,
|
|
696
702
|
navigation,
|
|
697
|
-
screenOptions
|
|
698
|
-
|
|
703
|
+
screenOptions,
|
|
704
|
+
screenLayout,
|
|
699
705
|
onAction,
|
|
700
706
|
getState,
|
|
701
707
|
setState,
|
|
@@ -713,15 +719,28 @@ export function useNavigationBuilder<
|
|
|
713
719
|
descriptors,
|
|
714
720
|
});
|
|
715
721
|
|
|
716
|
-
const NavigationContent = useComponent((children: React.ReactNode) =>
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
722
|
+
const NavigationContent = useComponent((children: React.ReactNode) => {
|
|
723
|
+
const element =
|
|
724
|
+
layout != null
|
|
725
|
+
? layout({
|
|
726
|
+
state,
|
|
727
|
+
descriptors,
|
|
728
|
+
navigation,
|
|
729
|
+
children,
|
|
730
|
+
})
|
|
731
|
+
: children;
|
|
732
|
+
|
|
733
|
+
return (
|
|
734
|
+
<NavigationHelpersContext.Provider value={navigation}>
|
|
735
|
+
<PreventRemoveProvider>{element}</PreventRemoveProvider>
|
|
736
|
+
</NavigationHelpersContext.Provider>
|
|
737
|
+
);
|
|
738
|
+
});
|
|
721
739
|
|
|
722
740
|
return {
|
|
723
741
|
state,
|
|
724
742
|
navigation,
|
|
743
|
+
describe,
|
|
725
744
|
descriptors,
|
|
726
745
|
NavigationContent,
|
|
727
746
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CommonActions,
|
|
3
|
-
NavigationAction,
|
|
4
|
-
NavigationState,
|
|
5
|
-
ParamListBase,
|
|
6
|
-
Router,
|
|
3
|
+
type NavigationAction,
|
|
4
|
+
type NavigationState,
|
|
5
|
+
type ParamListBase,
|
|
6
|
+
type Router,
|
|
7
7
|
} from '@react-navigation/routers';
|
|
8
8
|
import * as React from 'react';
|
|
9
9
|
|
|
@@ -14,7 +14,7 @@ import type { NavigationEventEmitter } from './useEventEmitter';
|
|
|
14
14
|
type Options<
|
|
15
15
|
State extends NavigationState,
|
|
16
16
|
ScreenOptions extends {},
|
|
17
|
-
EventMap extends Record<string, any
|
|
17
|
+
EventMap extends Record<string, any>,
|
|
18
18
|
> = {
|
|
19
19
|
state: State;
|
|
20
20
|
getState: () => State;
|
|
@@ -29,22 +29,25 @@ type Options<
|
|
|
29
29
|
emitter: NavigationEventEmitter<EventMap>;
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
-
type
|
|
32
|
+
type NavigationItem<
|
|
33
33
|
State extends NavigationState,
|
|
34
34
|
ScreenOptions extends {},
|
|
35
|
-
EventMap extends Record<string, any
|
|
36
|
-
> =
|
|
35
|
+
EventMap extends Record<string, any>,
|
|
36
|
+
> = NavigationProp<
|
|
37
|
+
ParamListBase,
|
|
37
38
|
string,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
State,
|
|
43
|
-
ScreenOptions,
|
|
44
|
-
EventMap
|
|
45
|
-
>
|
|
39
|
+
string | undefined,
|
|
40
|
+
State,
|
|
41
|
+
ScreenOptions,
|
|
42
|
+
EventMap
|
|
46
43
|
>;
|
|
47
44
|
|
|
45
|
+
type NavigationCache<
|
|
46
|
+
State extends NavigationState,
|
|
47
|
+
ScreenOptions extends {},
|
|
48
|
+
EventMap extends Record<string, any>,
|
|
49
|
+
> = Record<string, NavigationItem<State, ScreenOptions, EventMap>>;
|
|
50
|
+
|
|
48
51
|
/**
|
|
49
52
|
* Hook to cache navigation objects for each screen in the navigator.
|
|
50
53
|
* It's important to cache them to make sure navigation objects don't change between renders.
|
|
@@ -53,7 +56,8 @@ type NavigationCache<
|
|
|
53
56
|
export function useNavigationCache<
|
|
54
57
|
State extends NavigationState,
|
|
55
58
|
ScreenOptions extends {},
|
|
56
|
-
EventMap extends Record<string, any
|
|
59
|
+
EventMap extends Record<string, any>,
|
|
60
|
+
ActionHelpers extends Record<string, () => void>,
|
|
57
61
|
>({
|
|
58
62
|
state,
|
|
59
63
|
getState,
|
|
@@ -64,20 +68,72 @@ export function useNavigationCache<
|
|
|
64
68
|
}: Options<State, ScreenOptions, EventMap>) {
|
|
65
69
|
const { stackRef } = React.useContext(NavigationBuilderContext);
|
|
66
70
|
|
|
71
|
+
const base = React.useMemo((): NavigationItem<
|
|
72
|
+
State,
|
|
73
|
+
ScreenOptions,
|
|
74
|
+
EventMap
|
|
75
|
+
> &
|
|
76
|
+
ActionHelpers => {
|
|
77
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
78
|
+
const { emit, ...rest } = navigation;
|
|
79
|
+
|
|
80
|
+
const actions = {
|
|
81
|
+
...router.actionCreators,
|
|
82
|
+
...CommonActions,
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const dispatch = () => {
|
|
86
|
+
throw new Error(
|
|
87
|
+
'Actions cannot be dispatched from a placeholder screen.'
|
|
88
|
+
);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const helpers = Object.keys(actions).reduce<Record<string, () => void>>(
|
|
92
|
+
(acc, name) => {
|
|
93
|
+
acc[name] = dispatch;
|
|
94
|
+
|
|
95
|
+
return acc;
|
|
96
|
+
},
|
|
97
|
+
{}
|
|
98
|
+
) as ActionHelpers;
|
|
99
|
+
|
|
100
|
+
return {
|
|
101
|
+
...rest,
|
|
102
|
+
...helpers,
|
|
103
|
+
addListener: () => {
|
|
104
|
+
// Event listeners are not supported for placeholder screens
|
|
105
|
+
|
|
106
|
+
return () => {
|
|
107
|
+
// Empty function
|
|
108
|
+
};
|
|
109
|
+
},
|
|
110
|
+
removeListener: () => {
|
|
111
|
+
// Event listeners are not supported for placeholder screens
|
|
112
|
+
},
|
|
113
|
+
dispatch,
|
|
114
|
+
getParent: (id?: string) => {
|
|
115
|
+
if (id !== undefined && id === rest.getId()) {
|
|
116
|
+
return base;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return rest.getParent(id);
|
|
120
|
+
},
|
|
121
|
+
setOptions: () => {
|
|
122
|
+
throw new Error('Options cannot be set from a placeholder screen.');
|
|
123
|
+
},
|
|
124
|
+
isFocused: () => false,
|
|
125
|
+
};
|
|
126
|
+
}, [navigation, router.actionCreators]);
|
|
127
|
+
|
|
67
128
|
// Cache object which holds navigation objects for each screen
|
|
68
129
|
// We use `React.useMemo` instead of `React.useRef` coz we want to invalidate it when deps change
|
|
69
130
|
// In reality, these deps will rarely change, if ever
|
|
70
131
|
const cache = React.useMemo(
|
|
71
132
|
() => ({ current: {} as NavigationCache<State, ScreenOptions, EventMap> }),
|
|
72
133
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
73
|
-
[getState, navigation, setOptions,
|
|
134
|
+
[base, getState, navigation, setOptions, emitter]
|
|
74
135
|
);
|
|
75
136
|
|
|
76
|
-
const actions = {
|
|
77
|
-
...router.actionCreators,
|
|
78
|
-
...CommonActions,
|
|
79
|
-
};
|
|
80
|
-
|
|
81
137
|
cache.current = state.routes.reduce<
|
|
82
138
|
NavigationCache<State, ScreenOptions, EventMap>
|
|
83
139
|
>((acc, route) => {
|
|
@@ -91,9 +147,6 @@ export function useNavigationCache<
|
|
|
91
147
|
// If a cached navigation object already exists, reuse it
|
|
92
148
|
acc[route.key] = previous;
|
|
93
149
|
} else {
|
|
94
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
95
|
-
const { emit, ...rest } = navigation;
|
|
96
|
-
|
|
97
150
|
const dispatch = (thunk: Thunk) => {
|
|
98
151
|
const action = typeof thunk === 'function' ? thunk(getState()) : thunk;
|
|
99
152
|
|
|
@@ -124,6 +177,11 @@ export function useNavigationCache<
|
|
|
124
177
|
}
|
|
125
178
|
};
|
|
126
179
|
|
|
180
|
+
const actions = {
|
|
181
|
+
...router.actionCreators,
|
|
182
|
+
...CommonActions,
|
|
183
|
+
};
|
|
184
|
+
|
|
127
185
|
const helpers = Object.keys(actions).reduce<Record<string, () => void>>(
|
|
128
186
|
(acc, name) => {
|
|
129
187
|
acc[name] = (...args: any) =>
|
|
@@ -138,19 +196,19 @@ export function useNavigationCache<
|
|
|
138
196
|
);
|
|
139
197
|
|
|
140
198
|
acc[route.key] = {
|
|
141
|
-
...
|
|
199
|
+
...base,
|
|
142
200
|
...helpers,
|
|
143
201
|
// FIXME: too much work to fix the types for now
|
|
144
202
|
...(emitter.create(route.key) as any),
|
|
145
203
|
dispatch: (thunk: Thunk) => withStack(() => dispatch(thunk)),
|
|
146
204
|
getParent: (id?: string) => {
|
|
147
|
-
if (id !== undefined && id ===
|
|
205
|
+
if (id !== undefined && id === base.getId()) {
|
|
148
206
|
// If the passed id is the same as the current navigation id,
|
|
149
207
|
// we return the cached navigation object for the relevant route
|
|
150
208
|
return acc[route.key];
|
|
151
209
|
}
|
|
152
210
|
|
|
153
|
-
return
|
|
211
|
+
return base.getParent(id);
|
|
154
212
|
},
|
|
155
213
|
setOptions: (options: object) => {
|
|
156
214
|
setOptions((o) => ({
|
|
@@ -175,5 +233,8 @@ export function useNavigationCache<
|
|
|
175
233
|
return acc;
|
|
176
234
|
}, {});
|
|
177
235
|
|
|
178
|
-
return
|
|
236
|
+
return {
|
|
237
|
+
base,
|
|
238
|
+
navigations: cache.current,
|
|
239
|
+
};
|
|
179
240
|
}
|
|
@@ -4,7 +4,7 @@ import { createNavigationContainerRef } from './createNavigationContainerRef';
|
|
|
4
4
|
import type { NavigationContainerRefWithCurrent } from './types';
|
|
5
5
|
|
|
6
6
|
export function useNavigationContainerRef<
|
|
7
|
-
ParamList extends {} = ReactNavigation.RootParamList
|
|
7
|
+
ParamList extends {} = ReactNavigation.RootParamList,
|
|
8
8
|
>(): NavigationContainerRefWithCurrent<ParamList> {
|
|
9
9
|
const navigation =
|
|
10
10
|
React.useRef<NavigationContainerRefWithCurrent<ParamList> | null>(null);
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CommonActions,
|
|
3
|
-
NavigationAction,
|
|
4
|
-
NavigationState,
|
|
5
|
-
ParamListBase,
|
|
6
|
-
Router,
|
|
3
|
+
type NavigationAction,
|
|
4
|
+
type NavigationState,
|
|
5
|
+
type ParamListBase,
|
|
6
|
+
type Router,
|
|
7
7
|
} from '@react-navigation/routers';
|
|
8
8
|
import * as React from 'react';
|
|
9
9
|
|
|
10
10
|
import { NavigationContext } from './NavigationContext';
|
|
11
|
-
import { NavigationHelpers, PrivateValueStore } from './types';
|
|
11
|
+
import { type NavigationHelpers, PrivateValueStore } from './types';
|
|
12
12
|
import { UnhandledActionContext } from './UnhandledActionContext';
|
|
13
13
|
import type { NavigationEventEmitter } from './useEventEmitter';
|
|
14
14
|
|
|
15
15
|
// This is to make TypeScript compiler happy
|
|
16
|
-
// eslint-disable-next-line babel/no-unused-expressions
|
|
17
16
|
PrivateValueStore;
|
|
18
17
|
|
|
19
18
|
type Options<State extends NavigationState, Action extends NavigationAction> = {
|
|
@@ -32,7 +31,7 @@ export function useNavigationHelpers<
|
|
|
32
31
|
State extends NavigationState,
|
|
33
32
|
ActionHelpers extends Record<string, () => void>,
|
|
34
33
|
Action extends NavigationAction,
|
|
35
|
-
EventMap extends Record<string, any
|
|
34
|
+
EventMap extends Record<string, any>,
|
|
36
35
|
>({
|
|
37
36
|
id: navigatorId,
|
|
38
37
|
onAction,
|
package/src/useOnAction.tsx
CHANGED
|
@@ -9,8 +9,8 @@ import * as React from 'react';
|
|
|
9
9
|
|
|
10
10
|
import { DeprecatedNavigationInChildContext } from './DeprecatedNavigationInChildContext';
|
|
11
11
|
import {
|
|
12
|
-
ChildActionListener,
|
|
13
|
-
ChildBeforeRemoveListener,
|
|
12
|
+
type ChildActionListener,
|
|
13
|
+
type ChildBeforeRemoveListener,
|
|
14
14
|
NavigationBuilderContext,
|
|
15
15
|
} from './NavigationBuilderContext';
|
|
16
16
|
import type { EventMapCore } from './types';
|
|
@@ -131,7 +131,12 @@ export function useOnAction({
|
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
-
if (
|
|
134
|
+
if (
|
|
135
|
+
typeof action.target === 'string' ||
|
|
136
|
+
// For backward compatibility
|
|
137
|
+
action.type === 'NAVIGATE_DEPRECATED' ||
|
|
138
|
+
navigationInChildEnabled
|
|
139
|
+
) {
|
|
135
140
|
// If the action wasn't handled by current navigator or a parent navigator, let children handle it
|
|
136
141
|
// Handling this when target isn't specified is deprecated and will be removed in the future
|
|
137
142
|
for (let i = actionListeners.length - 1; i >= 0; i--) {
|
package/src/useOnGetState.tsx
CHANGED
|
@@ -3,7 +3,7 @@ import * as React from 'react';
|
|
|
3
3
|
|
|
4
4
|
import { isArrayEqual } from './isArrayEqual';
|
|
5
5
|
import {
|
|
6
|
-
GetStateListener,
|
|
6
|
+
type GetStateListener,
|
|
7
7
|
NavigationBuilderContext,
|
|
8
8
|
} from './NavigationBuilderContext';
|
|
9
9
|
import { NavigationRouteContext } from './NavigationRouteContext';
|