@react-navigation/core 8.0.0-alpha.4 → 8.0.0-alpha.41
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 +173 -90
- 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 +37 -12
- 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 +29 -57
- 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 +35 -27
- 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 +3 -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 +4 -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 +459 -332
- 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 +59 -21
- package/src/NavigationRootContext.tsx +11 -0
- package/src/NavigationStateContext.tsx +6 -6
- package/src/PreventRemoveContext.tsx +1 -0
- package/src/PreventRemoveProvider.tsx +55 -56
- package/src/SceneView.tsx +31 -57
- 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 +44 -30
- 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
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { DefaultRouterOptions, InitialState, NavigationAction, NavigationState, ParamListBase, PartialState, Route, Router } from '@react-navigation/routers';
|
|
2
2
|
import type * as React from 'react';
|
|
3
|
-
import type {
|
|
3
|
+
import type { Theme as InternalTheme } from './internal.js';
|
|
4
|
+
import type { FlatType, KeyOf, NotUndefined, StandardSchemaV1, UnionToIntersection } from './utilities.js';
|
|
4
5
|
/**
|
|
5
6
|
* Root navigator used in the app.
|
|
6
7
|
* It's used for the global types in the app.
|
|
@@ -33,9 +34,14 @@ export interface RootNavigator {
|
|
|
33
34
|
* }
|
|
34
35
|
* ```
|
|
35
36
|
*/
|
|
36
|
-
export interface Theme {
|
|
37
|
+
export interface Theme extends InternalTheme {
|
|
37
38
|
}
|
|
38
|
-
export type RootParamList = RootNavigator extends
|
|
39
|
+
export type RootParamList = RootNavigator extends PrivateValueStore<[
|
|
40
|
+
infer ParamList extends {},
|
|
41
|
+
any,
|
|
42
|
+
any,
|
|
43
|
+
any
|
|
44
|
+
]> ? ParamList : {};
|
|
39
45
|
export type DefaultNavigatorOptions<ParamList extends ParamListBase, State extends NavigationState, ScreenOptions extends {}, EventMap extends EventMapBase, Navigation> = DefaultRouterOptions<KeyOf<ParamList>> & {
|
|
40
46
|
/**
|
|
41
47
|
* Children React Elements to extract the route configuration from.
|
|
@@ -46,31 +52,31 @@ export type DefaultNavigatorOptions<ParamList extends ParamListBase, State exten
|
|
|
46
52
|
* Layout for the navigator.
|
|
47
53
|
* Useful for wrapping with a component with access to navigator's state and options.
|
|
48
54
|
*/
|
|
49
|
-
layout?: (props: {
|
|
55
|
+
layout?: ((props: {
|
|
50
56
|
state: State;
|
|
51
|
-
navigation: NavigationHelpers<ParamList>;
|
|
52
|
-
descriptors: Record<string, Descriptor<ScreenOptions, NavigationProp<ParamList, keyof ParamList, State, ScreenOptions, EventMap>,
|
|
57
|
+
navigation: NavigationHelpers<ParamList, State>;
|
|
58
|
+
descriptors: Record<string, Descriptor<ScreenOptions, NavigationProp<ParamList, keyof ParamList, State, ScreenOptions, EventMap>, ScreenRouteProp<ParamList>>>;
|
|
53
59
|
children: React.ReactNode;
|
|
54
|
-
}) => React.ReactElement;
|
|
60
|
+
}) => React.ReactElement) | undefined;
|
|
55
61
|
/**
|
|
56
62
|
* Event listeners for all the screens in the navigator.
|
|
57
63
|
*/
|
|
58
|
-
screenListeners?: ScreenListeners<State, EventMap> | ((props: {
|
|
59
|
-
route:
|
|
64
|
+
screenListeners?: (ScreenListeners<State, EventMap> | ((props: {
|
|
65
|
+
route: ScreenRouteProp<ParamList>;
|
|
60
66
|
navigation: Navigation;
|
|
61
|
-
}) => ScreenListeners<State, EventMap>);
|
|
67
|
+
}) => ScreenListeners<State, EventMap>)) | undefined;
|
|
62
68
|
/**
|
|
63
69
|
* Default options for all screens under this navigator.
|
|
64
70
|
*/
|
|
65
|
-
screenOptions?: ScreenOptions | ((props: {
|
|
66
|
-
route:
|
|
71
|
+
screenOptions?: (ScreenOptions | ((props: {
|
|
72
|
+
route: ScreenRouteProp<ParamList>;
|
|
67
73
|
navigation: Navigation;
|
|
68
74
|
theme: Theme;
|
|
69
|
-
}) => ScreenOptions);
|
|
75
|
+
}) => ScreenOptions)) | undefined;
|
|
70
76
|
/**
|
|
71
77
|
* Layout for all screens under this navigator.
|
|
72
78
|
*/
|
|
73
|
-
screenLayout?: (props: ScreenLayoutArgs<ParamList, keyof ParamList, ScreenOptions, Navigation>) => React.ReactElement;
|
|
79
|
+
screenLayout?: ((props: ScreenLayoutArgs<ParamList, keyof ParamList, ScreenOptions, Navigation>) => React.ReactElement) | undefined;
|
|
74
80
|
/**
|
|
75
81
|
* A function returning overrides for the underlying router used by the navigator.
|
|
76
82
|
* The overrides will be shallow merged onto the original router.
|
|
@@ -78,7 +84,7 @@ export type DefaultNavigatorOptions<ParamList extends ParamListBase, State exten
|
|
|
78
84
|
*
|
|
79
85
|
* This must be a pure function and cannot reference outside dynamic variables.
|
|
80
86
|
*/
|
|
81
|
-
router?: <Action extends NavigationAction>(original: Router<State, Action>) => Partial<Router<State, Action
|
|
87
|
+
router?: (<Action extends NavigationAction>(original: Router<State, Action>) => Partial<Router<State, Action>>) | undefined;
|
|
82
88
|
/**
|
|
83
89
|
* What should happen when the available route names change.
|
|
84
90
|
* e.g. when different screens are rendered based on a condition.
|
|
@@ -98,13 +104,13 @@ export type DefaultNavigatorOptions<ParamList extends ParamListBase, State exten
|
|
|
98
104
|
* - Direct navigation is only handled for `NAVIGATE` actions.
|
|
99
105
|
* - Unhandled state is restored only if the current state becomes invalid, i.e. it doesn't contain any currently defined screens.
|
|
100
106
|
*/
|
|
101
|
-
routeNamesChangeBehavior?: 'firstMatch' | 'lastUnhandled';
|
|
107
|
+
routeNamesChangeBehavior?: ('firstMatch' | 'lastUnhandled') | undefined;
|
|
102
108
|
};
|
|
103
109
|
export type EventMapBase = Record<string, {
|
|
104
110
|
data?: any;
|
|
105
|
-
canPreventDefault?: boolean;
|
|
111
|
+
canPreventDefault?: boolean | undefined;
|
|
106
112
|
}>;
|
|
107
|
-
export type EventMapCore<State extends NavigationState> = {
|
|
113
|
+
export type EventMapCore<in out State extends NavigationState> = {
|
|
108
114
|
focus: {
|
|
109
115
|
data: undefined;
|
|
110
116
|
};
|
|
@@ -131,7 +137,7 @@ export type EventArg<EventName, CanPreventDefault extends boolean | undefined =
|
|
|
131
137
|
/**
|
|
132
138
|
* Key of the route which received the event.
|
|
133
139
|
*/
|
|
134
|
-
readonly target?: string;
|
|
140
|
+
readonly target?: string | undefined;
|
|
135
141
|
} & (CanPreventDefault extends true ? {
|
|
136
142
|
/**
|
|
137
143
|
* Whether `event.preventDefault()` was called on this event object.
|
|
@@ -142,12 +148,12 @@ export type EventArg<EventName, CanPreventDefault extends boolean | undefined =
|
|
|
142
148
|
*/
|
|
143
149
|
preventDefault(): void;
|
|
144
150
|
} : {}) & (undefined extends Data ? {
|
|
145
|
-
readonly data?: Readonly<Data
|
|
151
|
+
readonly data?: Readonly<Data> | undefined;
|
|
146
152
|
} : {
|
|
147
153
|
readonly data: Readonly<Data>;
|
|
148
154
|
});
|
|
149
|
-
export type EventListenerCallback<EventMap extends EventMapBase, EventName extends keyof EventMap, EventCanPreventDefault extends boolean | undefined = EventMap[EventName]['canPreventDefault']> = (e: EventArg<EventName, undefined extends EventCanPreventDefault ? false : EventCanPreventDefault, EventMap[EventName]['data']>) => void;
|
|
150
|
-
export type EventConsumer<EventMap extends EventMapBase> = {
|
|
155
|
+
export type EventListenerCallback<in out EventMap extends EventMapBase, in out EventName extends keyof EventMap, in out EventCanPreventDefault extends boolean | undefined = EventMap[EventName]['canPreventDefault']> = (e: EventArg<EventName, undefined extends EventCanPreventDefault ? false : EventCanPreventDefault, EventMap[EventName]['data']>) => void;
|
|
156
|
+
export type EventConsumer<in out EventMap extends EventMapBase> = {
|
|
151
157
|
/**
|
|
152
158
|
* Subscribe to events from the parent navigator.
|
|
153
159
|
*
|
|
@@ -157,7 +163,7 @@ export type EventConsumer<EventMap extends EventMapBase> = {
|
|
|
157
163
|
addListener<EventName extends KeyOf<EventMap>>(type: EventName, callback: EventListenerCallback<EventMap, EventName>): () => void;
|
|
158
164
|
removeListener<EventName extends KeyOf<EventMap>>(type: EventName, callback: EventListenerCallback<EventMap, EventName>): void;
|
|
159
165
|
};
|
|
160
|
-
export type EventEmitter<EventMap extends EventMapBase> = {
|
|
166
|
+
export type EventEmitter<in out EventMap extends EventMapBase> = {
|
|
161
167
|
/**
|
|
162
168
|
* Emit an event to child screens.
|
|
163
169
|
*
|
|
@@ -168,7 +174,7 @@ export type EventEmitter<EventMap extends EventMapBase> = {
|
|
|
168
174
|
*/
|
|
169
175
|
emit<EventName extends KeyOf<EventMap>>(options: {
|
|
170
176
|
type: EventName;
|
|
171
|
-
target?: string;
|
|
177
|
+
target?: string | undefined;
|
|
172
178
|
} & (EventMap[EventName]['canPreventDefault'] extends true ? {
|
|
173
179
|
canPreventDefault: true;
|
|
174
180
|
} : {}) & (undefined extends EventMap[EventName]['data'] ? {
|
|
@@ -177,7 +183,7 @@ export type EventEmitter<EventMap extends EventMapBase> = {
|
|
|
177
183
|
data: EventMap[EventName]['data'];
|
|
178
184
|
})): EventArg<EventName, EventMap[EventName]['canPreventDefault'], EventMap[EventName]['data']>;
|
|
179
185
|
};
|
|
180
|
-
export declare class PrivateValueStore<T extends [any, any, any]> {
|
|
186
|
+
export declare class PrivateValueStore<T extends [any, any, any, any]> {
|
|
181
187
|
/**
|
|
182
188
|
* UGLY HACK! DO NOT USE THE TYPE!!!
|
|
183
189
|
*
|
|
@@ -190,6 +196,25 @@ export declare class PrivateValueStore<T extends [any, any, any]> {
|
|
|
190
196
|
*/
|
|
191
197
|
protected ''?: T;
|
|
192
198
|
}
|
|
199
|
+
type NavigatorLike = {
|
|
200
|
+
Navigator: React.ComponentType<any>;
|
|
201
|
+
Screen: unknown;
|
|
202
|
+
Group: unknown;
|
|
203
|
+
} | {
|
|
204
|
+
config: unknown;
|
|
205
|
+
getComponent: () => React.ComponentType<any>;
|
|
206
|
+
};
|
|
207
|
+
export type ParamListForNavigator<T extends {}> = T extends NavigatorLike ? T extends PrivateValueStore<[infer ParamList extends {}, any, any, any]> ? ParamList : T : T;
|
|
208
|
+
type NestedNavigatorForScreenParams<T, Params = NotUndefined<T>> = [
|
|
209
|
+
Params
|
|
210
|
+
] extends [never] ? never : Params extends NavigatorScreenParams<infer Navigator> ? Navigator extends PrivateValueStore<[any, any, any, any]> ? Navigator extends NavigatorLike ? Navigator : never : never : never;
|
|
211
|
+
export type NestedNavigatorsForParamList<ParamList extends {}> = {
|
|
212
|
+
[RouteName in keyof ParamList as NestedNavigatorForScreenParams<ParamList[RouteName]> extends never ? never : RouteName]: NestedNavigatorForScreenParams<ParamList[RouteName]>;
|
|
213
|
+
};
|
|
214
|
+
type NavigateOptions = {
|
|
215
|
+
merge?: boolean | undefined;
|
|
216
|
+
pop?: boolean | undefined;
|
|
217
|
+
};
|
|
193
218
|
type NavigationHelpersCommon<ParamList extends ParamListBase, State extends NavigationState = NavigationState> = {
|
|
194
219
|
/**
|
|
195
220
|
* Dispatch an action or an update function to the router.
|
|
@@ -210,34 +235,12 @@ type NavigationHelpersCommon<ParamList extends ParamListBase, State extends Navi
|
|
|
210
235
|
navigate<RouteName extends keyof ParamList>(...args: RouteName extends unknown ? undefined extends ParamList[RouteName] ? [
|
|
211
236
|
screen: RouteName,
|
|
212
237
|
params?: ParamList[RouteName],
|
|
213
|
-
options?:
|
|
214
|
-
merge?: boolean;
|
|
215
|
-
pop?: boolean;
|
|
216
|
-
}
|
|
238
|
+
options?: NavigateOptions
|
|
217
239
|
] : [
|
|
218
240
|
screen: RouteName,
|
|
219
241
|
params: ParamList[RouteName],
|
|
220
|
-
options?:
|
|
221
|
-
merge?: boolean;
|
|
222
|
-
pop?: boolean;
|
|
223
|
-
}
|
|
242
|
+
options?: NavigateOptions
|
|
224
243
|
] : never): void;
|
|
225
|
-
/**
|
|
226
|
-
* Navigate to a route in current navigation tree.
|
|
227
|
-
*
|
|
228
|
-
* @param options.name Name of the route to navigate to.
|
|
229
|
-
* @param [options.params] Params object for the route.
|
|
230
|
-
* @param [options.path] Path to associate the route with (e.g. for deep links).
|
|
231
|
-
* @param [options.merge] Whether to merge the params onto the route. Defaults to `false`.
|
|
232
|
-
* @param [options.pop] Whether to pop routes in a stack to go back to the matching route. Defaults to `false`.
|
|
233
|
-
*/
|
|
234
|
-
navigate<RouteName extends keyof ParamList>(options: RouteName extends unknown ? {
|
|
235
|
-
name: RouteName;
|
|
236
|
-
params: ParamList[RouteName];
|
|
237
|
-
path?: string;
|
|
238
|
-
merge?: boolean;
|
|
239
|
-
pop?: boolean;
|
|
240
|
-
} : never): void;
|
|
241
244
|
/**
|
|
242
245
|
* Preloads the route in current navigation tree.
|
|
243
246
|
*
|
|
@@ -277,9 +280,9 @@ type NavigationHelpersCommon<ParamList extends ParamListBase, State extends Navi
|
|
|
277
280
|
* So don't use it in `render`.
|
|
278
281
|
*/
|
|
279
282
|
getState(): State;
|
|
280
|
-
}
|
|
281
|
-
type ParamType<ParamList extends {}, RouteName
|
|
282
|
-
type NavigationHelpersRoute<ParamList extends {}, RouteName extends keyof ParamList = KeyOf<ParamList>> = {
|
|
283
|
+
};
|
|
284
|
+
type ParamType<ParamList extends {}, RouteName, IsPartial extends boolean = false> = RouteName extends keyof ParamList ? ParamList[RouteName] extends undefined ? undefined : IsPartial extends true ? Partial<ParamList[RouteName]> : ParamList[RouteName] : unknown;
|
|
285
|
+
type NavigationHelpersRoute<in out ParamList extends {}, in out RouteName extends keyof ParamList = KeyOf<ParamList>> = {
|
|
283
286
|
/**
|
|
284
287
|
* Update the param object for the route.
|
|
285
288
|
* The new params will be shallow merged with the old one.
|
|
@@ -302,34 +305,34 @@ type NavigationHelpersRoute<ParamList extends {}, RouteName extends keyof ParamL
|
|
|
302
305
|
*/
|
|
303
306
|
pushParams(params: ParamType<ParamList, RouteName>): void;
|
|
304
307
|
};
|
|
305
|
-
export type NavigationHelpers<ParamList extends ParamListBase, EventMap extends EventMapBase = {}> = NavigationHelpersCommon<ParamList> & EventEmitter<EventMap> & NavigationHelpersRoute<ParamList, keyof ParamList>;
|
|
308
|
+
export type NavigationHelpers<ParamList extends ParamListBase, State extends NavigationState = NavigationState<ParamList>, EventMap extends EventMapBase = {}> = NavigationHelpersCommon<ParamList, State> & EventEmitter<EventMap> & NavigationHelpersRoute<ParamList, keyof ParamList> & PrivateValueStore<[ParamList, unknown, unknown, unknown]>;
|
|
306
309
|
export type NavigationContainerProps = {
|
|
307
310
|
/**
|
|
308
311
|
* Initial state object for the navigation tree.
|
|
309
312
|
*/
|
|
310
|
-
initialState?: InitialState;
|
|
313
|
+
initialState?: InitialState | undefined;
|
|
311
314
|
/**
|
|
312
315
|
* Callback which is called with the latest navigation state when it changes.
|
|
313
316
|
*/
|
|
314
|
-
onStateChange?: (state: Readonly<NavigationState> | undefined) => void;
|
|
317
|
+
onStateChange?: ((state: Readonly<NavigationState> | undefined) => void) | undefined;
|
|
315
318
|
/**
|
|
316
319
|
* Callback which is called after the navigation tree mounts.
|
|
317
320
|
*/
|
|
318
|
-
onReady?: () => void;
|
|
321
|
+
onReady?: (() => void) | undefined;
|
|
319
322
|
/**
|
|
320
323
|
* Callback which is called when an action is not handled.
|
|
321
324
|
*/
|
|
322
|
-
onUnhandledAction?: (action: Readonly<NavigationAction>) => void;
|
|
325
|
+
onUnhandledAction?: ((action: Readonly<NavigationAction>) => void) | undefined;
|
|
323
326
|
/**
|
|
324
327
|
* Theme object for the UI elements.
|
|
325
328
|
*/
|
|
326
|
-
theme?: Theme;
|
|
329
|
+
theme?: Theme | undefined;
|
|
327
330
|
/**
|
|
328
331
|
* Children elements to render.
|
|
329
332
|
*/
|
|
330
333
|
children: React.ReactNode;
|
|
331
334
|
};
|
|
332
|
-
|
|
335
|
+
type NavigationPropBase<ParamList extends {}, RouteName extends keyof ParamList = KeyOf<ParamList>, State extends NavigationState = NavigationState<ParamList>, ScreenOptions extends {} = {}, EventMap extends EventMapBase = {}, ActionHelpers extends Record<string, (...args: any) => void> = {}> = NavigationHelpersCommon<ParamList, State> & {
|
|
333
336
|
/**
|
|
334
337
|
* Update the options for the route.
|
|
335
338
|
* The options object will be shallow merged with default options object.
|
|
@@ -337,6 +340,8 @@ export type NavigationProp<ParamList extends {}, RouteName extends keyof ParamLi
|
|
|
337
340
|
* @param options Partial options object for the current screen.
|
|
338
341
|
*/
|
|
339
342
|
setOptions(options: Partial<ScreenOptions>): void;
|
|
343
|
+
} & NavigationHelpersRoute<ParamList, RouteName> & ActionHelpers & EventConsumer<EventMap & EventMapCore<State>>;
|
|
344
|
+
export type NavigationProp<ParamList extends {}, RouteName extends keyof ParamList = KeyOf<ParamList>, State extends NavigationState = NavigationState<ParamList>, ScreenOptions extends {} = {}, EventMap extends EventMapBase = {}, ActionHelpers extends Record<string, (...args: any) => void> = {}> = NavigationPropBase<ParamList, RouteName, State, ScreenOptions, EventMap, ActionHelpers> & {
|
|
340
345
|
/**
|
|
341
346
|
* Returns the navigation prop of the parent screen.
|
|
342
347
|
* If a route name is provided, the navigation prop from the parent screen with matching route name (including current) will be returned.
|
|
@@ -346,51 +351,62 @@ export type NavigationProp<ParamList extends {}, RouteName extends keyof ParamLi
|
|
|
346
351
|
*/
|
|
347
352
|
getParent(routeName: RouteName): NavigationProp<ParamList, RouteName, State, ScreenOptions, EventMap, ActionHelpers>;
|
|
348
353
|
getParent(): NavigationProp<ParamListBase> | undefined;
|
|
349
|
-
} &
|
|
350
|
-
export type RouteProp<ParamList extends ParamListBase, RouteName extends keyof ParamList = KeyOf<ParamList>> = Route<Extract<RouteName, string>, ParamList[RouteName]>;
|
|
351
|
-
|
|
354
|
+
} & PrivateValueStore<[ParamList, RouteName, EventMap, ActionHelpers]>;
|
|
355
|
+
export type RouteProp<in out ParamList extends ParamListBase, in out RouteName extends keyof ParamList = KeyOf<ParamList>> = Route<Extract<RouteName, string>, ParamList[RouteName]>;
|
|
356
|
+
type ScreenRouteProp<ParamList extends ParamListBase, RouteName extends keyof ParamList = KeyOf<ParamList>> = {
|
|
357
|
+
[Name in Extract<RouteName, string>]: RouteProp<ParamList, Name>;
|
|
358
|
+
}[Extract<RouteName, string>];
|
|
359
|
+
export type CompositeNavigationProp<A extends NavigationProp<ParamListBase, any, any, any, any>, B extends NavigationProp<ParamListBase, any, any, any, any>> = CompositeNavigationPropInternal<A, B,
|
|
352
360
|
/**
|
|
353
361
|
* Param list from both navigation objects needs to be combined
|
|
354
362
|
* For example, we should be able to navigate to screens in both A and B
|
|
355
363
|
*/
|
|
356
|
-
|
|
364
|
+
ParamListOfNavigationProp<A> & ParamListOfNavigationProp<B>,
|
|
357
365
|
/**
|
|
358
366
|
* The route name should refer to the route name specified in the first type
|
|
359
|
-
* Ideally it should work for any of them, but it's not possible to infer that way
|
|
360
367
|
*/
|
|
361
|
-
A
|
|
368
|
+
RouteNameOfNavigationProp<A>,
|
|
362
369
|
/**
|
|
363
|
-
*
|
|
370
|
+
* Event map should refer to the config specified in the first type
|
|
364
371
|
*/
|
|
365
|
-
A
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
*/
|
|
369
|
-
A extends NavigationProp<any, any, any, infer O> ? O : {},
|
|
370
|
-
/**
|
|
371
|
-
* Event consumer config should refer to the config specified in the first type
|
|
372
|
-
* This allows typechecking `addListener`/`removeListener`
|
|
373
|
-
*/
|
|
374
|
-
A extends NavigationProp<any, any, any, any, infer E> ? E : {}>, 'getParent'> & {
|
|
372
|
+
EventMapOfNavigationProp<A>>;
|
|
373
|
+
type CompositeNavigationPropInternal<A extends NavigationProp<ParamListBase, any, any, any, any>, B extends NavigationProp<ParamListBase, any, any, any, any>, ParamList extends {}, RouteName extends keyof ParamList, EventMap extends EventMapBase> = // Action helpers are read from the private brand (4th slot) instead of
|
|
374
|
+
ActionHelpersOfNavigationProp<A> & ActionHelpersOfNavigationProp<B> & NavigationPropBase<ParamList, RouteName, StateOfNavigationProp<A>, ScreenOptionsOfNavigationProp<A>, EventMap> & {
|
|
375
375
|
getParent: A['getParent'] & B['getParent'];
|
|
376
|
-
}
|
|
377
|
-
|
|
376
|
+
} & PrivateValueStore<[
|
|
377
|
+
ParamList,
|
|
378
|
+
RouteName,
|
|
379
|
+
EventMap,
|
|
380
|
+
ActionHelpersOfNavigationProp<A> & ActionHelpersOfNavigationProp<B>
|
|
381
|
+
]>;
|
|
382
|
+
type PrivateValueOfNavigationProp<T> = T extends PrivateValueStore<infer Value> ? Value : [never, unknown, {}, {}];
|
|
383
|
+
type ParamListOfNavigationProp<T> = PrivateValueOfNavigationProp<T>[0];
|
|
384
|
+
type RouteNameOfNavigationProp<T> = PrivateValueOfNavigationProp<T>[1];
|
|
385
|
+
type ActionHelpersOfNavigationProp<T> = PrivateValueOfNavigationProp<T>[3];
|
|
386
|
+
type StateOfNavigationProp<T> = T extends {
|
|
387
|
+
getState: () => infer State extends NavigationState;
|
|
388
|
+
} ? State : NavigationState;
|
|
389
|
+
type ScreenOptionsOfNavigationProp<T> = T extends {
|
|
390
|
+
setOptions: (options: Partial<infer ScreenOptions>) => void;
|
|
391
|
+
} ? ScreenOptions : {};
|
|
392
|
+
type EventMapOfNavigationProp<T> = PrivateValueOfNavigationProp<T>[2];
|
|
393
|
+
export type CompositeScreenProps<in out A extends {
|
|
378
394
|
navigation: NavigationProp<ParamListBase, string, any, any, any>;
|
|
379
395
|
route: RouteProp<ParamListBase>;
|
|
380
|
-
}, B extends {
|
|
396
|
+
}, in out B extends {
|
|
381
397
|
navigation: NavigationProp<ParamListBase, string, any, any, any>;
|
|
382
398
|
}> = {
|
|
383
399
|
navigation: CompositeNavigationProp<A['navigation'], B['navigation']>;
|
|
384
400
|
route: A['route'];
|
|
385
401
|
};
|
|
386
|
-
export type ScreenLayoutArgs<ParamList extends ParamListBase, RouteName extends keyof ParamList, ScreenOptions extends {}, Navigation> = {
|
|
387
|
-
route:
|
|
402
|
+
export type ScreenLayoutArgs<in out ParamList extends ParamListBase, in out RouteName extends keyof ParamList, in out ScreenOptions extends {}, in out Navigation> = {
|
|
403
|
+
route: ScreenRouteProp<ParamList, RouteName>;
|
|
388
404
|
options: ScreenOptions;
|
|
389
405
|
navigation: Navigation;
|
|
390
406
|
theme: Theme;
|
|
391
407
|
children: React.ReactElement;
|
|
392
408
|
};
|
|
393
|
-
export type Descriptor<ScreenOptions extends {}, Navigation extends NavigationProp<
|
|
409
|
+
export type Descriptor<out ScreenOptions extends {}, out Navigation extends NavigationProp<ParamListBase, any, any, any, any>, out Route extends RouteProp<any, any>> = {
|
|
394
410
|
/**
|
|
395
411
|
* Render the component associated with this route.
|
|
396
412
|
*/
|
|
@@ -408,7 +424,7 @@ export type Descriptor<ScreenOptions extends {}, Navigation extends NavigationPr
|
|
|
408
424
|
*/
|
|
409
425
|
navigation: Navigation;
|
|
410
426
|
};
|
|
411
|
-
export type ScreenListeners<State extends NavigationState, EventMap extends EventMapBase> = Partial<{
|
|
427
|
+
export type ScreenListeners<in out State extends NavigationState, in out EventMap extends EventMapBase> = Partial<{
|
|
412
428
|
[EventName in keyof (EventMap & EventMapCore<State>)]: EventListenerCallback<EventMap & EventMapCore<State>, EventName>;
|
|
413
429
|
}>;
|
|
414
430
|
type ScreenComponentType<ParamList extends ParamListBase, RouteName extends keyof ParamList> = React.ComponentType<{
|
|
@@ -440,13 +456,13 @@ export type RouteConfigComponent<ParamList extends ParamListBase, RouteName exte
|
|
|
440
456
|
component?: never;
|
|
441
457
|
getComponent?: never;
|
|
442
458
|
};
|
|
443
|
-
export type RouteConfigProps<ParamList extends ParamListBase, RouteName extends keyof ParamList, State extends NavigationState, ScreenOptions extends {}, EventMap extends EventMapBase, Navigation> = {
|
|
459
|
+
export type RouteConfigProps<in out ParamList extends ParamListBase, in out RouteName extends keyof ParamList, in out State extends NavigationState, in out ScreenOptions extends {}, in out EventMap extends EventMapBase, in out Navigation> = {
|
|
444
460
|
/**
|
|
445
461
|
* Optional key for this screen. This doesn't need to be unique.
|
|
446
462
|
* If the key changes, existing screens with this name will be removed or reset.
|
|
447
463
|
* Useful when we have some common screens and have conditional rendering.
|
|
448
464
|
*/
|
|
449
|
-
navigationKey?: string;
|
|
465
|
+
navigationKey?: string | undefined;
|
|
450
466
|
/**
|
|
451
467
|
* Route name of this screen.
|
|
452
468
|
*/
|
|
@@ -454,58 +470,58 @@ export type RouteConfigProps<ParamList extends ParamListBase, RouteName extends
|
|
|
454
470
|
/**
|
|
455
471
|
* Navigator options for this screen.
|
|
456
472
|
*/
|
|
457
|
-
options?: ScreenOptions | ((props: {
|
|
473
|
+
options?: (ScreenOptions | ((props: {
|
|
458
474
|
route: RouteProp<ParamList, RouteName>;
|
|
459
475
|
navigation: Navigation;
|
|
460
476
|
theme: Theme;
|
|
461
|
-
}) => ScreenOptions);
|
|
477
|
+
}) => ScreenOptions)) | undefined;
|
|
462
478
|
/**
|
|
463
479
|
* Event listeners for this screen.
|
|
464
480
|
*/
|
|
465
|
-
listeners?: ScreenListeners<State, EventMap> | ((props: {
|
|
481
|
+
listeners?: (ScreenListeners<State, EventMap> | ((props: {
|
|
466
482
|
route: RouteProp<ParamList, RouteName>;
|
|
467
483
|
navigation: Navigation;
|
|
468
|
-
}) => ScreenListeners<State, EventMap>);
|
|
484
|
+
}) => ScreenListeners<State, EventMap>)) | undefined;
|
|
469
485
|
/**
|
|
470
486
|
* Layout for this screen.
|
|
471
487
|
* Useful for wrapping the screen with custom containers.
|
|
472
488
|
* e.g. for styling, error boundaries, suspense, etc.
|
|
473
489
|
*/
|
|
474
|
-
layout?: (props: ScreenLayoutArgs<ParamList, RouteName, ScreenOptions, Navigation>) => React.ReactElement;
|
|
490
|
+
layout?: ((props: ScreenLayoutArgs<ParamList, RouteName, ScreenOptions, Navigation>) => React.ReactElement) | undefined;
|
|
475
491
|
/**
|
|
476
492
|
* Function to return an unique ID for this screen.
|
|
477
493
|
* Receives an object with the route params.
|
|
478
494
|
* For a given screen name, there will always be only one screen corresponding to an ID.
|
|
479
495
|
* If `undefined` is returned, it acts same as no `getId` being specified.
|
|
480
496
|
*/
|
|
481
|
-
getId?: ({ params, }: {
|
|
497
|
+
getId?: (({ params, }: {
|
|
482
498
|
params: Readonly<ParamList[RouteName]>;
|
|
483
|
-
}) => string | undefined;
|
|
499
|
+
}) => string | undefined) | undefined;
|
|
484
500
|
/**
|
|
485
501
|
* Initial params object for the route.
|
|
486
502
|
*/
|
|
487
|
-
initialParams?: Partial<ParamList[RouteName]
|
|
503
|
+
initialParams?: Partial<ParamList[RouteName]> | undefined;
|
|
488
504
|
};
|
|
489
505
|
export type RouteConfig<ParamList extends ParamListBase, RouteName extends keyof ParamList, State extends NavigationState, ScreenOptions extends {}, EventMap extends EventMapBase, Navigation> = RouteConfigProps<ParamList, RouteName, State, ScreenOptions, EventMap, Navigation> & RouteConfigComponent<ParamList, RouteName>;
|
|
490
|
-
export type RouteGroupConfig<ParamList extends ParamListBase, ScreenOptions extends {}, Navigation> = {
|
|
506
|
+
export type RouteGroupConfig<in out ParamList extends ParamListBase, in out ScreenOptions extends {}, in out Navigation> = {
|
|
491
507
|
/**
|
|
492
508
|
* Optional key for the screens in this group.
|
|
493
509
|
* If the key changes, all existing screens in this group will be removed or reset.
|
|
494
510
|
*/
|
|
495
|
-
navigationKey?: string;
|
|
511
|
+
navigationKey?: string | undefined;
|
|
496
512
|
/**
|
|
497
513
|
* Navigator options for this screen.
|
|
498
514
|
*/
|
|
499
|
-
screenOptions?: ScreenOptions | ((props: {
|
|
500
|
-
route:
|
|
515
|
+
screenOptions?: (ScreenOptions | ((props: {
|
|
516
|
+
route: ScreenRouteProp<ParamList>;
|
|
501
517
|
navigation: Navigation;
|
|
502
518
|
theme: Theme;
|
|
503
|
-
}) => ScreenOptions);
|
|
519
|
+
}) => ScreenOptions)) | undefined;
|
|
504
520
|
/**
|
|
505
521
|
* Layout for the screens inside the group.
|
|
506
522
|
* This will override the `screenLayout` of parent group or navigator.
|
|
507
523
|
*/
|
|
508
|
-
screenLayout?: ((props: ScreenLayoutArgs<ParamList, keyof ParamList, ScreenOptions, Navigation>) => React.ReactElement) | {};
|
|
524
|
+
screenLayout?: (((props: ScreenLayoutArgs<ParamList, keyof ParamList, ScreenOptions, Navigation>) => React.ReactElement) | {}) | undefined;
|
|
509
525
|
/**
|
|
510
526
|
* Children React Elements to extract the route configuration from.
|
|
511
527
|
* Only `Screen`, `Group` and `React.Fragment` are supported as children.
|
|
@@ -573,15 +589,19 @@ export type NavigationContainerEventMap = {
|
|
|
573
589
|
/**
|
|
574
590
|
* The data object passed when emitting the event.
|
|
575
591
|
*/
|
|
576
|
-
data
|
|
592
|
+
data?: unknown;
|
|
577
593
|
/**
|
|
578
594
|
* The key of the target route which received the event.
|
|
579
595
|
*/
|
|
580
|
-
target
|
|
596
|
+
target?: string | undefined;
|
|
581
597
|
/**
|
|
582
598
|
* Whether `event.preventDefault()` was called on this event.
|
|
583
599
|
*/
|
|
584
|
-
defaultPrevented
|
|
600
|
+
defaultPrevented?: boolean | undefined;
|
|
601
|
+
/**
|
|
602
|
+
* Prevent the default action which happens on this event.
|
|
603
|
+
*/
|
|
604
|
+
preventDefault?: (() => void) | undefined;
|
|
585
605
|
};
|
|
586
606
|
};
|
|
587
607
|
};
|
|
@@ -628,46 +648,74 @@ export type GenericNavigation<ParamList extends {}> = Omit<NavigationProp<ParamL
|
|
|
628
648
|
*/
|
|
629
649
|
setOptions(options: unknown): void;
|
|
630
650
|
};
|
|
631
|
-
export type RouteForName<ParamList extends {}, RouteName extends string> =
|
|
632
|
-
|
|
633
|
-
}
|
|
651
|
+
export type RouteForName<ParamList extends {}, RouteName extends string> = string extends RouteName ? ParamListRoute<ParamList> : RouteForNameInternal<ParamList, RouteName>;
|
|
652
|
+
type RouteForNameInternal<ParamList extends {}, RouteName extends string> = (RouteName extends KeyOf<ParamList> ? RouteProp<ParamList, RouteName> : never) | RouteForNameNested<NestedParamLists<ParamList>, RouteName>;
|
|
653
|
+
type RouteForNameNested<ParamLists, RouteName extends string> = ParamLists extends {} ? RouteForNameInternal<ParamLists, RouteName> : never;
|
|
654
|
+
/**
|
|
655
|
+
* Union of param lists of the nested navigators in a param list.
|
|
656
|
+
*/
|
|
657
|
+
export type NestedParamLists<ParamList extends {}> = {
|
|
658
|
+
[RouteName in keyof ParamList]: NavigatorScreenParams<{}> extends ParamList[RouteName] ? NotUndefined<ParamList[RouteName]> extends NavigatorScreenParams<infer T> ? ParamListForNavigator<T> : never : never;
|
|
659
|
+
}[keyof ParamList];
|
|
634
660
|
type ParamListRoute<ParamList extends {}> = {
|
|
635
|
-
[RouteName in keyof ParamList]: NavigatorScreenParams<{}> extends ParamList[RouteName] ? NotUndefined<ParamList[RouteName]> extends NavigatorScreenParams<infer T> ? ParamListRoute<T
|
|
661
|
+
[RouteName in keyof ParamList]: NavigatorScreenParams<{}> extends ParamList[RouteName] ? NotUndefined<ParamList[RouteName]> extends NavigatorScreenParams<infer T> ? ParamListRoute<ParamListForNavigator<T>> | RouteProp<ParamList, RouteName> : RouteProp<ParamList, RouteName> : RouteProp<ParamList, RouteName>;
|
|
636
662
|
}[keyof ParamList];
|
|
637
663
|
type MaybeParamListRoute<ParamList extends {}> = ParamList extends ParamListBase ? ParamListRoute<ParamList> : Route<string>;
|
|
638
|
-
type BasicNavigationComposite<Navigation extends NavigationProp<any, any, any, any, any>, Parent
|
|
664
|
+
type BasicNavigationComposite<Navigation extends NavigationProp<any, any, any, any, any>, Parent extends NavigationProp<any, any, any, any, any> | undefined> = Parent extends undefined ? Navigation : CompositeNavigationProp<Navigation, NonNullable<Parent>>;
|
|
639
665
|
type BasicNavigationList<ParamList extends {}, ExcludedRouteNames, Parent extends NavigationProp<any, any, any, any, any> | undefined> = UnionToIntersection<{
|
|
640
|
-
[RouteName in keyof ParamList]: (NavigatorScreenParams<{}> extends ParamList[RouteName] ? NotUndefined<ParamList[RouteName]> extends NavigatorScreenParams<infer T> ? BasicNavigationList<
|
|
666
|
+
[RouteName in keyof ParamList]: (NavigatorScreenParams<{}> extends ParamList[RouteName] ? NotUndefined<ParamList[RouteName]> extends NavigatorScreenParams<infer T> ? ParamListForNavigator<T> extends infer NestedParamList extends {} ? keyof NestedParamList extends ExcludedRouteNames ? {} : BasicNavigationList<NestedParamList, ExcludedRouteNames, NavigationProp<ParamList, RouteName>> : {} : {} : {}) & (RouteName extends ExcludedRouteNames ? {} : {
|
|
641
667
|
[Key in RouteName]: BasicNavigationComposite<NavigationProp<ParamList, RouteName>, Parent>;
|
|
642
668
|
});
|
|
643
669
|
}[keyof ParamList]>;
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
type NavigationListForNestedInternal<Navigator> = NavigationListForNavigator<Navigator> & NavigationListForStaticConfig<NavigationListForNavigator<Navigator>, Navigator>;
|
|
647
|
-
type NavigationListWithComposite<Parent extends NavigationProp<any, any, any, any, any>, NavigatorList extends Record<string, any>> = {
|
|
648
|
-
[K in keyof NavigatorList]: CompositeNavigationProp<NavigatorList[K], Parent>;
|
|
670
|
+
type InheritedParentParams<ParentParamList, ParamList> = {
|
|
671
|
+
[K in keyof ParentParamList as K extends keyof ParamList ? never : string extends K ? never : K]: ParentParamList[K];
|
|
649
672
|
};
|
|
650
|
-
type
|
|
673
|
+
type GenericNavigationComposite<ParamList extends ParamListBase, RouteName extends keyof ParamList, Parent> = Parent extends NavigationProp<any, any, any, any, any> ? ParamListOfNavigationProp<Parent> extends infer ParentParamList ? NavigationProp<ParamList & InheritedParentParams<ParentParamList, ParamList>, RouteName> & {
|
|
674
|
+
getParent: Parent['getParent'];
|
|
675
|
+
} : never : NavigationProp<ParamList, RouteName>;
|
|
676
|
+
type NavigationListForScreenParams<T extends {}, ParamList extends ParamListBase, RouteName extends keyof ParamList, ExcludedRouteNames, Parent extends NavigationProp<any, any, any, any, any> | undefined> = T extends PrivateValueStore<[any, any, any, any]> & NavigatorLike ? NavigationListForNestedInternal<T, GenericNavigationComposite<ParamList, RouteName, Parent>> : NavigationListForParamListScreenParams<T, ParamList, RouteName, ExcludedRouteNames, Parent>;
|
|
677
|
+
type NavigationListForParamListScreenParams<T extends {}, ParamList extends ParamListBase, RouteName extends keyof ParamList, ExcludedRouteNames, Parent extends NavigationProp<any, any, any, any, any> | undefined> = T extends ParamListBase ? BasicNavigationListForParamList<T, ExcludedRouteNames, GenericNavigationComposite<ParamList, RouteName, Parent>> : {};
|
|
678
|
+
type BasicNavigationListForParamList<ParamList extends ParamListBase, ExcludedRouteNames, Parent extends NavigationProp<any, any, any, any, any> | undefined> = UnionToIntersection<{
|
|
679
|
+
[RouteName in keyof ParamList]: (NavigatorScreenParams<{}> extends ParamList[RouteName] ? NotUndefined<ParamList[RouteName]> extends NavigatorScreenParams<infer T> ? NavigationListForScreenParams<T, ParamList, RouteName, ExcludedRouteNames, Parent> : {} : {}) & (RouteName extends ExcludedRouteNames ? {} : {
|
|
680
|
+
[Key in RouteName]: GenericNavigationComposite<ParamList, RouteName, Parent>;
|
|
681
|
+
});
|
|
682
|
+
}[keyof ParamList]>;
|
|
683
|
+
export type NavigationListForNavigator<Navigator> = Navigator extends PrivateValueStore<infer Value> ? Value[1] : {};
|
|
684
|
+
export type NavigationListForNested<Navigator> = NavigationListForNestedInternal<Navigator> extends infer NavigationList ? Navigator extends PrivateValueStore<[infer ParamList, any, any, any]> ? ParamList extends {} ? NavigationList & BasicNavigationList<ParamList, keyof NavigationList, undefined> : NavigationList : NavigationList : never;
|
|
685
|
+
type NavigationListForNestedInternal<Navigator, Parent = undefined, NavigatorList extends Record<string, any> = NavigationListForNavigator<Navigator>, Navigators = NestedNavigatorsOf<Navigator>, ComposedList = ComposeNavigationList<NavigatorList, Parent>> = (Navigator extends {
|
|
651
686
|
readonly config: {
|
|
652
|
-
screens?:
|
|
653
|
-
groups?:
|
|
687
|
+
readonly screens?: infer Screens;
|
|
688
|
+
readonly groups?: infer Groups;
|
|
654
689
|
};
|
|
655
|
-
} ? NavigationListForScreens<
|
|
656
|
-
type
|
|
657
|
-
|
|
690
|
+
} ? ComposedList & NavigationListForScreens<ComposedList, Screens> & NavigationListForGroups<ComposedList, Groups> : ComposedList) & NavigationListForNestedNavigators<ComposedList, Navigators> & NavigationListForDynamicNestedParamLists<Navigator, ComposedList, Navigators>;
|
|
691
|
+
type NavigationListForDynamicNestedParamLists<Navigator, ParentList, Navigators> = Navigator extends {
|
|
692
|
+
readonly config: unknown;
|
|
693
|
+
} ? {} : Navigator extends PrivateValueStore<[infer ParamList, any, any, any]> ? NavigationListForNestedParamLists<ParentList, ParamList, Navigators> : {};
|
|
694
|
+
type NestedNavigatorsOf<Navigator> = Navigator extends PrivateValueStore<[any, any, any, infer Nesting]> ? Nesting extends Record<string, any> ? Nesting : {} : {};
|
|
695
|
+
type NavigationListForNestedNavigators<ParentList, Navigators> = UnionToIntersection<{
|
|
696
|
+
[K in keyof Navigators]: K extends keyof ParentList ? NavigationListForNestedInternal<Navigators[K], ParentList[K]> : {};
|
|
697
|
+
}[keyof Navigators]>;
|
|
698
|
+
type NavigationListForNestedParamLists<ParentList, ParamList, Navigators> = ParentList extends Record<string, any> ? ParamList extends ParamListBase ? UnionToIntersection<{
|
|
699
|
+
[K in keyof ParamList]: K extends keyof Navigators ? {} : K extends keyof ParentList ? NavigatorScreenParams<{}> extends ParamList[K] ? NotUndefined<ParamList[K]> extends NavigatorScreenParams<infer T> ? NavigationListForScreenParams<T, ParamList, K, keyof ParentList, ParentList[K]> : {} : {} : {};
|
|
700
|
+
}[keyof ParamList]> : {} : {};
|
|
701
|
+
type ComposeNavigationList<NavigatorList extends Record<string, any>, Parent> = Parent extends NavigationProp<any, any, any, any, any> ? {
|
|
702
|
+
[K in keyof NavigatorList]: CompositeNavigationProp<NavigatorList[K], Parent>;
|
|
703
|
+
} : NavigatorList;
|
|
704
|
+
type NavigationListForScreens<ParentList, Screens> = Screens extends {} ? UnionToIntersection<{
|
|
705
|
+
[K in keyof Screens]: Screens[K] extends {
|
|
658
706
|
config: any;
|
|
659
|
-
} ?
|
|
707
|
+
} ? K extends keyof ParentList ? NavigationListForNestedInternal<Screens[K], ParentList[K]> : never : Screens[K] extends {
|
|
660
708
|
screen: {
|
|
661
709
|
config: any;
|
|
662
710
|
};
|
|
663
|
-
} ?
|
|
664
|
-
}[keyof Screens]
|
|
665
|
-
type NavigationListForGroups<ParentList, Groups> = Groups extends
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
711
|
+
} ? K extends keyof ParentList ? NavigationListForNestedInternal<Screens[K]['screen'], ParentList[K]> : never : never;
|
|
712
|
+
}[keyof Screens]> : {};
|
|
713
|
+
type NavigationListForGroups<ParentList, Groups> = Groups extends {} ? UnionToIntersection<{
|
|
714
|
+
[K in keyof Groups]: Groups[K] extends {
|
|
715
|
+
screens: any;
|
|
716
|
+
} ? NavigationListForScreens<ParentList, Groups[K]['screens']> : never;
|
|
669
717
|
}[keyof Groups]> : {};
|
|
670
|
-
export type NavigationContainerRef<ParamList extends {}> = NavigationHelpers<ParamList> & EventConsumer<NavigationContainerEventMap> & {
|
|
718
|
+
export type NavigationContainerRef<ParamList extends {}> = Omit<NavigationHelpers<ParamList>, keyof NavigationHelpersRoute<{}> | 'isFocused'> & NavigationHelpersRoute<{}> & EventConsumer<NavigationContainerEventMap> & {
|
|
671
719
|
/**
|
|
672
720
|
* Reset the navigation state of the root navigator to the provided state.
|
|
673
721
|
*
|
|
@@ -677,7 +725,7 @@ export type NavigationContainerRef<ParamList extends {}> = NavigationHelpers<Par
|
|
|
677
725
|
/**
|
|
678
726
|
* Get the rehydrated navigation state of the navigation tree.
|
|
679
727
|
*/
|
|
680
|
-
getRootState(): NavigationState;
|
|
728
|
+
getRootState(): NavigationState | undefined;
|
|
681
729
|
/**
|
|
682
730
|
* Get the currently focused navigation route.
|
|
683
731
|
*/
|
|
@@ -690,37 +738,61 @@ export type NavigationContainerRef<ParamList extends {}> = NavigationHelpers<Par
|
|
|
690
738
|
* Whether the navigation container is ready to handle actions.
|
|
691
739
|
*/
|
|
692
740
|
isReady(): boolean;
|
|
693
|
-
/**
|
|
694
|
-
* Stub function for setOptions on navigation object for use with useNavigation.
|
|
695
|
-
*/
|
|
696
|
-
setOptions(): never;
|
|
697
|
-
/**
|
|
698
|
-
* Stub function for getParent on navigation object for use with useNavigation.
|
|
699
|
-
*/
|
|
700
|
-
getParent(): undefined;
|
|
701
741
|
};
|
|
702
742
|
export type NavigationContainerRefWithCurrent<ParamList extends {}> = NavigationContainerRef<ParamList> & {
|
|
703
743
|
current: NavigationContainerRef<ParamList> | null;
|
|
704
744
|
};
|
|
705
|
-
export type NavigationListBase<ParamList extends ParamListBase> = {
|
|
745
|
+
export type NavigationListBase<in out ParamList extends ParamListBase> = {
|
|
706
746
|
[RouteName in keyof ParamList]: unknown;
|
|
707
747
|
};
|
|
708
|
-
|
|
748
|
+
type ActionHelpersOf<T> = T extends Record<string, (...args: any) => void> ? T : {};
|
|
749
|
+
export interface NavigatorTypeBagBase {
|
|
709
750
|
ParamList: {};
|
|
710
751
|
State: NavigationState;
|
|
711
752
|
ScreenOptions: {};
|
|
712
753
|
EventMap: {};
|
|
713
|
-
|
|
754
|
+
ActionHelpers: {};
|
|
755
|
+
NavigationList: {
|
|
756
|
+
[RouteName in keyof this['ParamList']]: NavigationProp<this['ParamList'], RouteName, this['State'], this['ScreenOptions'], this['EventMap'], ActionHelpersOf<this['ActionHelpers']>>;
|
|
757
|
+
};
|
|
714
758
|
Navigator: React.ComponentType<any>;
|
|
759
|
+
}
|
|
760
|
+
/**
|
|
761
|
+
* Adds a proper `ParamList` to a type bag interface
|
|
762
|
+
* So it can be used as `this['ParamList']`
|
|
763
|
+
*/
|
|
764
|
+
export type NavigatorTypeBagFor<TypeBag extends NavigatorTypeBagBase, ParamList extends {}> = TypeBag & {
|
|
765
|
+
ParamList: ParamList;
|
|
715
766
|
};
|
|
716
|
-
export type
|
|
767
|
+
export type NavigatorProps<ParamList extends ParamListBase, State extends NavigationState, ScreenOptions extends {}, EventMap extends EventMapBase, Navigation, Navigator extends React.ComponentType<any>> = Omit<React.ComponentProps<Navigator>, keyof DefaultNavigatorOptions<any, any, any, any, any>> & DefaultNavigatorOptions<ParamList, State, ScreenOptions, EventMap, Navigation>;
|
|
768
|
+
type TypedNavigatorStaticComponent<Bag extends NavigatorTypeBagBase> = React.ComponentType<Partial<Omit<NavigatorProps<Bag['ParamList'], Bag['State'], Bag['ScreenOptions'], Bag['EventMap'], Bag['NavigationList'][keyof Bag['ParamList']], Bag['Navigator']>, 'children'>>>;
|
|
769
|
+
type TypedNavigatorStaticDecorated<Bag extends NavigatorTypeBagBase, Config> = {
|
|
770
|
+
getComponent: () => React.ComponentType<{}>;
|
|
717
771
|
config: Config;
|
|
718
|
-
}
|
|
719
|
-
|
|
772
|
+
} & PrivateValueStore<[
|
|
773
|
+
Bag['ParamList'],
|
|
774
|
+
Bag['NavigationList'],
|
|
775
|
+
unknown,
|
|
776
|
+
unknown
|
|
777
|
+
]>;
|
|
778
|
+
type TypedNavigatorStatic<in out Bag extends NavigatorTypeBagBase, in out Config> = {
|
|
779
|
+
config: Config;
|
|
780
|
+
with: (Component: React.ComponentType<{
|
|
781
|
+
Navigator: TypedNavigatorStaticComponent<Bag>;
|
|
782
|
+
}>) => TypedNavigatorStaticDecorated<Bag, Config>;
|
|
783
|
+
getComponent: () => TypedNavigatorStaticComponent<Bag>;
|
|
784
|
+
};
|
|
785
|
+
export type TypedNavigator<Bag extends NavigatorTypeBagBase, Config = unknown, Nesting = unknown> = (undefined extends Config ? TypedNavigatorInternal<Bag['ParamList'], Bag['State'], Bag['ScreenOptions'], Bag['EventMap'], Bag['NavigationList'], Bag['Navigator']> : TypedNavigatorStatic<Bag, Config>) & PrivateValueStore<[
|
|
786
|
+
Bag['ParamList'],
|
|
787
|
+
Bag['NavigationList'],
|
|
788
|
+
unknown,
|
|
789
|
+
Nesting
|
|
790
|
+
]>;
|
|
791
|
+
type TypedNavigatorInternal<in out ParamList extends ParamListBase, in out State extends NavigationState, in out ScreenOptions extends {}, in out EventMap extends EventMapBase, in out NavigationList extends NavigationListBase<ParamList>, in out Navigator extends React.ComponentType<any>> = {
|
|
720
792
|
/**
|
|
721
793
|
* Navigator component which manages the child screens.
|
|
722
794
|
*/
|
|
723
|
-
Navigator: React.ComponentType<
|
|
795
|
+
Navigator: React.ComponentType<NavigatorProps<ParamList, State, ScreenOptions, EventMap, NavigationList[keyof ParamList], Navigator>>;
|
|
724
796
|
/**
|
|
725
797
|
* Component used for grouping multiple route configuration.
|
|
726
798
|
*/
|
|
@@ -730,35 +802,45 @@ type TypedNavigatorInternal<ParamList extends ParamListBase, State extends Navig
|
|
|
730
802
|
*/
|
|
731
803
|
Screen: <RouteName extends keyof ParamList>(_: RouteConfig<ParamList, RouteName, State, ScreenOptions, EventMap, NavigationList[RouteName]>) => null;
|
|
732
804
|
};
|
|
733
|
-
|
|
805
|
+
declare const NavigatorScreenParamsSymbol: unique symbol;
|
|
806
|
+
type NavigatorScreenParamsBrand<T extends {}> = {
|
|
807
|
+
readonly [NavigatorScreenParamsSymbol]?: any & {
|
|
808
|
+
readonly type: T;
|
|
809
|
+
};
|
|
810
|
+
};
|
|
811
|
+
type NavigatorScreenParamsForParamList<ParamList extends {}> = {
|
|
734
812
|
screen?: never;
|
|
735
813
|
params?: never;
|
|
736
814
|
merge?: never;
|
|
737
815
|
initial?: never;
|
|
738
816
|
pop?: never;
|
|
739
|
-
|
|
817
|
+
preload?: never;
|
|
818
|
+
path?: string | undefined;
|
|
740
819
|
state: PartialState<NavigationState> | NavigationState | undefined;
|
|
741
820
|
} | {
|
|
742
821
|
[RouteName in keyof ParamList]: undefined extends ParamList[RouteName] ? {
|
|
743
822
|
screen: RouteName;
|
|
744
|
-
params?: ParamList[RouteName];
|
|
745
|
-
merge?: boolean;
|
|
746
|
-
initial?: boolean;
|
|
747
|
-
path?: string;
|
|
748
|
-
pop?: boolean;
|
|
823
|
+
params?: ParamList[RouteName] | undefined;
|
|
824
|
+
merge?: boolean | undefined;
|
|
825
|
+
initial?: boolean | undefined;
|
|
826
|
+
path?: string | undefined;
|
|
827
|
+
pop?: boolean | undefined;
|
|
828
|
+
preload?: boolean | undefined;
|
|
749
829
|
state?: never;
|
|
750
830
|
} : {
|
|
751
831
|
screen: RouteName;
|
|
752
832
|
params: ParamList[RouteName];
|
|
753
|
-
merge?: boolean;
|
|
754
|
-
initial?: boolean;
|
|
755
|
-
path?: string;
|
|
756
|
-
pop?: boolean;
|
|
833
|
+
merge?: boolean | undefined;
|
|
834
|
+
initial?: boolean | undefined;
|
|
835
|
+
path?: string | undefined;
|
|
836
|
+
pop?: boolean | undefined;
|
|
837
|
+
preload?: boolean | undefined;
|
|
757
838
|
state?: never;
|
|
758
839
|
};
|
|
759
840
|
}[keyof ParamList];
|
|
841
|
+
export type NavigatorScreenParams<ParamList extends {}> = NavigatorScreenParamsForParamList<ParamListForNavigator<ParamList>> & NavigatorScreenParamsBrand<ParamList>;
|
|
760
842
|
type ParseConfig<Params> = {
|
|
761
|
-
[K in keyof Params]?: (value: string) => Params[K]
|
|
843
|
+
[K in keyof Params]?: ((value: string) => Params[K]) | StandardSchemaV1<string | string[] | null | undefined, Params[K]>;
|
|
762
844
|
};
|
|
763
845
|
type StringifyConfig<Params> = {
|
|
764
846
|
[K in keyof Params]?: (value: Params[K]) => string;
|
|
@@ -774,9 +856,9 @@ type PathConfigAlias<Params> = {
|
|
|
774
856
|
* By default, paths are relating to the path config on the parent screen.
|
|
775
857
|
* If `exact` is set to `true`, the parent path configuration is not used.
|
|
776
858
|
*/
|
|
777
|
-
exact?: boolean;
|
|
859
|
+
exact?: boolean | undefined;
|
|
778
860
|
/**
|
|
779
|
-
* An object mapping the param name to a function
|
|
861
|
+
* An object mapping the param name to a parser function or a Standard Schema.
|
|
780
862
|
*
|
|
781
863
|
* @example
|
|
782
864
|
* ```js
|
|
@@ -786,12 +868,28 @@ type PathConfigAlias<Params> = {
|
|
|
786
868
|
* }
|
|
787
869
|
* ```
|
|
788
870
|
*/
|
|
789
|
-
parse?: ParseConfig<Params
|
|
871
|
+
parse?: ParseConfig<Params> | undefined;
|
|
872
|
+
/**
|
|
873
|
+
* Whether this path can resolve to multiple routes.
|
|
874
|
+
* Both routes should specify `shared: true` for this to work.
|
|
875
|
+
* By default, a path can only resolve to one route.
|
|
876
|
+
*
|
|
877
|
+
* This is useful when same screen used in multiple navigators,
|
|
878
|
+
* e.g. tabs with stacks containing profile screen in each stack.
|
|
879
|
+
*
|
|
880
|
+
* The path defined first will be the canonical path.
|
|
881
|
+
*/
|
|
882
|
+
shared?: boolean | undefined;
|
|
790
883
|
};
|
|
791
|
-
export type PathConfig<Params> = FlatType<Partial<PathConfigAlias<Params>> & {
|
|
884
|
+
export type PathConfig<Params> = FlatType<Partial<Omit<PathConfigAlias<Params>, 'path'>> & {
|
|
885
|
+
/**
|
|
886
|
+
* Path string to match against.
|
|
887
|
+
* e.g. `/users/:id` will match `/users/1` and extract `id` param as `1`.
|
|
888
|
+
*/
|
|
889
|
+
path?: string | undefined;
|
|
792
890
|
/**
|
|
793
891
|
* An object mapping the param name to a function which converts the param value to a string.
|
|
794
|
-
* By default,
|
|
892
|
+
* By default, arrays and null are preserved for query params, and other values are converted using `String(value)`.
|
|
795
893
|
* Keys are constrained to valid param names when Params type is provided.
|
|
796
894
|
*
|
|
797
895
|
* @example
|
|
@@ -801,23 +899,23 @@ export type PathConfig<Params> = FlatType<Partial<PathConfigAlias<Params>> & {
|
|
|
801
899
|
* }
|
|
802
900
|
* ```
|
|
803
901
|
*/
|
|
804
|
-
stringify?: StringifyConfig<Params
|
|
902
|
+
stringify?: StringifyConfig<Params> | undefined;
|
|
805
903
|
/**
|
|
806
904
|
* Additional path alias that will be matched to the same screen.
|
|
807
905
|
*/
|
|
808
|
-
alias?: (string | PathConfigAlias<Params>)[];
|
|
809
|
-
} & (NonNullable<Params> extends NavigatorScreenParams<infer ParamList> ? {
|
|
906
|
+
alias?: (string | PathConfigAlias<Params>)[] | undefined;
|
|
907
|
+
} & (NonNullable<Params> extends NavigatorScreenParams<infer ParamList> ? ParamListForNavigator<ParamList> extends infer ChildParamList extends {} ? {
|
|
810
908
|
/**
|
|
811
909
|
* Path configuration for child screens.
|
|
812
910
|
*/
|
|
813
|
-
screens?: PathConfigMap<
|
|
911
|
+
screens?: PathConfigMap<ChildParamList> | undefined;
|
|
814
912
|
/**
|
|
815
913
|
* Name of the initial route to use for the navigator when the path matches.
|
|
816
914
|
*/
|
|
817
|
-
initialRouteName?: keyof
|
|
818
|
-
} : {})>;
|
|
915
|
+
initialRouteName?: Extract<keyof ChildParamList, string> | undefined;
|
|
916
|
+
} : {} : {})>;
|
|
819
917
|
export type PathConfigMap<ParamList extends {}> = {
|
|
820
|
-
[RouteName in keyof ParamList]?: string | PathConfig<ParamList[RouteName]
|
|
918
|
+
[RouteName in keyof ParamList]?: string | PathConfig<ParamList[RouteName]> | undefined;
|
|
821
919
|
};
|
|
822
920
|
export {};
|
|
823
921
|
//# sourceMappingURL=types.d.ts.map
|