@react-navigation/core 8.0.0-alpha.2 → 8.0.0-alpha.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/module/BaseNavigationContainer.js +20 -9
- package/lib/module/BaseNavigationContainer.js.map +1 -1
- package/lib/module/ConsumedParamsContext.js +5 -0
- package/lib/module/ConsumedParamsContext.js.map +1 -0
- package/lib/module/NavigationBuilderContext.js +1 -0
- package/lib/module/NavigationBuilderContext.js.map +1 -1
- package/lib/module/NavigationIndependentTree.js +8 -4
- package/lib/module/NavigationIndependentTree.js.map +1 -1
- package/lib/module/NavigationProvider.js +14 -3
- package/lib/module/NavigationProvider.js.map +1 -1
- package/lib/module/NavigationStateContext.js.map +1 -1
- package/lib/module/PreventRemoveProvider.js +3 -3
- package/lib/module/PreventRemoveProvider.js.map +1 -1
- package/lib/module/SceneView.js +46 -56
- package/lib/module/SceneView.js.map +1 -1
- package/lib/module/StaticNavigation.js +166 -46
- package/lib/module/StaticNavigation.js.map +1 -1
- package/lib/module/checkSerializable.js +11 -4
- package/lib/module/checkSerializable.js.map +1 -1
- package/lib/module/createNavigatorFactory.js +27 -5
- package/lib/module/createNavigatorFactory.js.map +1 -1
- package/lib/module/findFocusedRoute.js +7 -4
- package/lib/module/findFocusedRoute.js.map +1 -1
- package/lib/module/getActionFromState.js +40 -14
- package/lib/module/getActionFromState.js.map +1 -1
- package/lib/module/getPathFromState.js +48 -11
- package/lib/module/getPathFromState.js.map +1 -1
- package/lib/module/getPatternParts.js +3 -0
- package/lib/module/getPatternParts.js.map +1 -1
- package/lib/module/getStateFromPath.js +353 -166
- package/lib/module/getStateFromPath.js.map +1 -1
- package/lib/module/getStateFromRouteParams.js +24 -0
- package/lib/module/getStateFromRouteParams.js.map +1 -0
- package/lib/module/index.js +3 -4
- package/lib/module/index.js.map +1 -1
- package/lib/module/theming/useTheme.js +1 -1
- package/lib/module/theming/useTheme.js.map +1 -1
- package/lib/module/types.js +15 -0
- package/lib/module/types.js.map +1 -1
- package/lib/module/useDescriptors.js +18 -9
- package/lib/module/useDescriptors.js.map +1 -1
- package/lib/module/useEventEmitter.js +43 -31
- package/lib/module/useEventEmitter.js.map +1 -1
- package/lib/module/useFocusEvents.js +6 -2
- package/lib/module/useFocusEvents.js.map +1 -1
- package/lib/module/useFocusedListenersChildrenAdapter.js +2 -2
- package/lib/module/useFocusedListenersChildrenAdapter.js.map +1 -1
- package/lib/module/useIsFocused.js +7 -12
- package/lib/module/useIsFocused.js.map +1 -1
- package/lib/module/useNavigation.js.map +1 -1
- package/lib/module/useNavigationBuilder.js +144 -86
- package/lib/module/useNavigationBuilder.js.map +1 -1
- package/lib/module/useNavigationCache.js +3 -3
- package/lib/module/useNavigationCache.js.map +1 -1
- package/lib/module/useNavigationHelpers.js +1 -1
- package/lib/module/useNavigationHelpers.js.map +1 -1
- package/lib/module/useNavigationIndependentTree.js +1 -1
- package/lib/module/useNavigationIndependentTree.js.map +1 -1
- package/lib/module/useNavigationState.js +6 -4
- package/lib/module/useNavigationState.js.map +1 -1
- package/lib/module/useOnAction.js +3 -3
- package/lib/module/useOnAction.js.map +1 -1
- package/lib/module/useOnGetState.js +6 -3
- package/lib/module/useOnGetState.js.map +1 -1
- package/lib/module/useOnPreventRemove.js +3 -3
- package/lib/module/useOnPreventRemove.js.map +1 -1
- package/lib/module/useOnRouteFocus.js +1 -1
- package/lib/module/useOnRouteFocus.js.map +1 -1
- package/lib/module/useOptionsGetters.js +7 -4
- package/lib/module/useOptionsGetters.js.map +1 -1
- package/lib/module/usePreventRemove.js +1 -1
- package/lib/module/usePreventRemove.js.map +1 -1
- package/lib/module/usePreventRemoveContext.js +1 -1
- package/lib/module/usePreventRemoveContext.js.map +1 -1
- package/lib/module/useRegisterNavigator.js +2 -2
- package/lib/module/useRegisterNavigator.js.map +1 -1
- package/lib/module/useRoute.js.map +1 -1
- package/lib/module/useRouteCache.js +2 -1
- package/lib/module/useRouteCache.js.map +1 -1
- package/lib/module/useScheduleUpdate.js +1 -1
- package/lib/module/useScheduleUpdate.js.map +1 -1
- package/lib/module/useStateForPath.js +1 -1
- package/lib/module/useStateForPath.js.map +1 -1
- package/lib/module/validatePathConfig.js +2 -1
- package/lib/module/validatePathConfig.js.map +1 -1
- package/lib/typescript/src/BaseNavigationContainer.d.ts +6 -3
- package/lib/typescript/src/BaseNavigationContainer.d.ts.map +1 -1
- package/lib/typescript/src/ConsumedParamsContext.d.ts +8 -0
- package/lib/typescript/src/ConsumedParamsContext.d.ts.map +1 -0
- package/lib/typescript/src/EnsureSingleNavigator.d.ts +1 -1
- package/lib/typescript/src/EnsureSingleNavigator.d.ts.map +1 -1
- package/lib/typescript/src/Group.d.ts +1 -1
- package/lib/typescript/src/Group.d.ts.map +1 -1
- package/lib/typescript/src/NavigationBuilderContext.d.ts +12 -6
- package/lib/typescript/src/NavigationBuilderContext.d.ts.map +1 -1
- package/lib/typescript/src/NavigationContainerRefContext.d.ts +1 -1
- package/lib/typescript/src/NavigationContainerRefContext.d.ts.map +1 -1
- package/lib/typescript/src/NavigationFocusedRouteStateContext.d.ts +4 -4
- package/lib/typescript/src/NavigationFocusedRouteStateContext.d.ts.map +1 -1
- package/lib/typescript/src/NavigationHelpersContext.d.ts +1 -1
- package/lib/typescript/src/NavigationHelpersContext.d.ts.map +1 -1
- package/lib/typescript/src/NavigationIndependentTree.d.ts +1 -1
- package/lib/typescript/src/NavigationIndependentTree.d.ts.map +1 -1
- package/lib/typescript/src/NavigationProvider.d.ts +10 -10
- package/lib/typescript/src/NavigationProvider.d.ts.map +1 -1
- package/lib/typescript/src/NavigationStateContext.d.ts +3 -3
- package/lib/typescript/src/NavigationStateContext.d.ts.map +1 -1
- package/lib/typescript/src/PreventRemoveProvider.d.ts +1 -1
- package/lib/typescript/src/PreventRemoveProvider.d.ts.map +1 -1
- package/lib/typescript/src/SceneView.d.ts +3 -2
- package/lib/typescript/src/SceneView.d.ts.map +1 -1
- package/lib/typescript/src/Screen.d.ts +1 -1
- package/lib/typescript/src/Screen.d.ts.map +1 -1
- package/lib/typescript/src/StaticContainer.d.ts +1 -1
- package/lib/typescript/src/StaticContainer.d.ts.map +1 -1
- package/lib/typescript/src/StaticNavigation.d.ts +123 -92
- package/lib/typescript/src/StaticNavigation.d.ts.map +1 -1
- package/lib/typescript/src/checkSerializable.d.ts +5 -3
- package/lib/typescript/src/checkSerializable.d.ts.map +1 -1
- package/lib/typescript/src/createNavigationContainerRef.d.ts +1 -1
- package/lib/typescript/src/createNavigationContainerRef.d.ts.map +1 -1
- package/lib/typescript/src/createNavigatorFactory.d.ts +17 -5
- package/lib/typescript/src/createNavigatorFactory.d.ts.map +1 -1
- package/lib/typescript/src/findFocusedRoute.d.ts +3 -3
- package/lib/typescript/src/findFocusedRoute.d.ts.map +1 -1
- package/lib/typescript/src/getActionFromState.d.ts +4 -4
- package/lib/typescript/src/getActionFromState.d.ts.map +1 -1
- package/lib/typescript/src/getPathFromState.d.ts +3 -3
- package/lib/typescript/src/getPathFromState.d.ts.map +1 -1
- package/lib/typescript/src/getPatternParts.d.ts +1 -0
- package/lib/typescript/src/getPatternParts.d.ts.map +1 -1
- package/lib/typescript/src/getStateFromPath.d.ts +5 -5
- package/lib/typescript/src/getStateFromPath.d.ts.map +1 -1
- package/lib/typescript/src/getStateFromRouteParams.d.ts +3 -0
- package/lib/typescript/src/getStateFromRouteParams.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +34 -33
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/theming/ThemeContext.d.ts +1 -1
- package/lib/typescript/src/theming/ThemeContext.d.ts.map +1 -1
- package/lib/typescript/src/theming/ThemeProvider.d.ts +2 -2
- package/lib/typescript/src/theming/ThemeProvider.d.ts.map +1 -1
- package/lib/typescript/src/theming/useTheme.d.ts +1 -1
- package/lib/typescript/src/theming/useTheme.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +215 -131
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/useChildListeners.d.ts +3 -3
- package/lib/typescript/src/useChildListeners.d.ts.map +1 -1
- package/lib/typescript/src/useComponent.d.ts +1 -1
- package/lib/typescript/src/useComponent.d.ts.map +1 -1
- package/lib/typescript/src/useDescriptors.d.ts +7 -7
- package/lib/typescript/src/useDescriptors.d.ts.map +1 -1
- package/lib/typescript/src/useEventEmitter.d.ts +1 -1
- package/lib/typescript/src/useEventEmitter.d.ts.map +1 -1
- package/lib/typescript/src/useFocusEvents.d.ts +2 -2
- package/lib/typescript/src/useFocusEvents.d.ts.map +1 -1
- package/lib/typescript/src/useFocusedListenersChildrenAdapter.d.ts +2 -2
- package/lib/typescript/src/useFocusedListenersChildrenAdapter.d.ts.map +1 -1
- package/lib/typescript/src/useIsFocused.d.ts +3 -0
- package/lib/typescript/src/useIsFocused.d.ts.map +1 -1
- package/lib/typescript/src/useKeyedChildListeners.d.ts +3 -3
- package/lib/typescript/src/useKeyedChildListeners.d.ts.map +1 -1
- package/lib/typescript/src/useNavigation.d.ts +5 -3
- package/lib/typescript/src/useNavigation.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationBuilder.d.ts +24 -24
- package/lib/typescript/src/useNavigationBuilder.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationCache.d.ts +3 -3
- package/lib/typescript/src/useNavigationCache.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationContainerRef.d.ts +1 -1
- package/lib/typescript/src/useNavigationContainerRef.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationHelpers.d.ts +19 -19
- package/lib/typescript/src/useNavigationHelpers.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationState.d.ts +2 -2
- package/lib/typescript/src/useNavigationState.d.ts.map +1 -1
- package/lib/typescript/src/useOnAction.d.ts +9 -9
- package/lib/typescript/src/useOnAction.d.ts.map +1 -1
- package/lib/typescript/src/useOnGetState.d.ts +1 -1
- package/lib/typescript/src/useOnGetState.d.ts.map +1 -1
- package/lib/typescript/src/useOnPreventRemove.d.ts +3 -3
- package/lib/typescript/src/useOnPreventRemove.d.ts.map +1 -1
- package/lib/typescript/src/useOnRouteFocus.d.ts +6 -6
- package/lib/typescript/src/useOnRouteFocus.d.ts.map +1 -1
- package/lib/typescript/src/useOptionsGetters.d.ts +1 -1
- package/lib/typescript/src/useOptionsGetters.d.ts.map +1 -1
- package/lib/typescript/src/usePreventRemoveContext.d.ts +1 -1
- package/lib/typescript/src/useRoute.d.ts +2 -2
- package/lib/typescript/src/useRoute.d.ts.map +1 -1
- package/lib/typescript/src/useRouteCache.d.ts +4 -4
- package/lib/typescript/src/useRouteCache.d.ts.map +1 -1
- package/lib/typescript/src/useScheduleUpdate.d.ts.map +1 -1
- package/lib/typescript/src/useStateForPath.d.ts +1 -1
- package/lib/typescript/src/useStateForPath.d.ts.map +1 -1
- package/lib/typescript/src/utilities.d.ts +45 -5
- package/lib/typescript/src/utilities.d.ts.map +1 -1
- package/lib/typescript/src/validatePathConfig.d.ts.map +1 -1
- package/package.json +23 -20
- package/src/BaseNavigationContainer.tsx +337 -326
- package/src/ConsumedParamsContext.tsx +10 -0
- package/src/NavigationBuilderContext.tsx +14 -8
- package/src/NavigationFocusedRouteStateContext.tsx +4 -4
- package/src/NavigationIndependentTree.tsx +8 -5
- package/src/NavigationProvider.tsx +17 -3
- package/src/NavigationStateContext.tsx +5 -6
- package/src/PreventRemoveProvider.tsx +3 -3
- package/src/SceneView.tsx +58 -56
- package/src/StaticNavigation.tsx +488 -250
- package/src/checkSerializable.tsx +22 -12
- package/src/createNavigatorFactory.tsx +83 -8
- package/src/findFocusedRoute.tsx +13 -8
- package/src/getActionFromState.tsx +68 -39
- package/src/getPathFromState.tsx +91 -27
- package/src/getPatternParts.tsx +8 -0
- package/src/getStateFromPath.tsx +555 -180
- package/src/getStateFromRouteParams.tsx +60 -0
- package/src/index.tsx +47 -5
- package/src/theming/useTheme.tsx +1 -1
- package/src/types.tsx +541 -338
- package/src/useDescriptors.tsx +27 -12
- package/src/useEventEmitter.tsx +45 -36
- package/src/useFocusEvents.tsx +8 -2
- package/src/useFocusedListenersChildrenAdapter.tsx +2 -2
- package/src/useIsFocused.tsx +14 -21
- package/src/useNavigation.tsx +8 -4
- package/src/useNavigationBuilder.tsx +220 -132
- package/src/useNavigationCache.tsx +6 -6
- package/src/useNavigationHelpers.tsx +1 -1
- package/src/useNavigationIndependentTree.tsx +1 -1
- package/src/useNavigationState.tsx +11 -7
- package/src/useOnAction.tsx +10 -10
- package/src/useOnGetState.tsx +5 -3
- package/src/useOnPreventRemove.tsx +3 -3
- package/src/useOnRouteFocus.tsx +10 -12
- package/src/useOptionsGetters.tsx +7 -4
- package/src/usePreventRemove.tsx +1 -1
- package/src/usePreventRemoveContext.tsx +1 -1
- package/src/useRegisterNavigator.tsx +2 -2
- package/src/useRoute.tsx +4 -2
- package/src/useRouteCache.tsx +2 -1
- package/src/useScheduleUpdate.tsx +1 -3
- package/src/useStateForPath.tsx +1 -1
- package/src/utilities.tsx +101 -5
- package/src/validatePathConfig.tsx +1 -0
- package/lib/module/CurrentRenderContext.js +0 -10
- package/lib/module/CurrentRenderContext.js.map +0 -1
- package/lib/module/useCurrentRender.js +0 -19
- package/lib/module/useCurrentRender.js.map +0 -1
- package/lib/typescript/src/CurrentRenderContext.d.ts +0 -9
- package/lib/typescript/src/CurrentRenderContext.d.ts.map +0 -1
- package/lib/typescript/src/useCurrentRender.d.ts +0 -14
- package/lib/typescript/src/useCurrentRender.d.ts.map +0 -1
- package/src/CurrentRenderContext.tsx +0 -9
- package/src/useCurrentRender.tsx +0 -31
|
@@ -1,6 +1,6 @@
|
|
|
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 { FlatType, KeyOf, NotUndefined, UnionToIntersection } from './utilities';
|
|
3
|
+
import type { FlatType, KeyOf, NotUndefined, StandardSchemaV1, UnionToIntersection } from './utilities.js';
|
|
4
4
|
/**
|
|
5
5
|
* Root navigator used in the app.
|
|
6
6
|
* It's used for the global types in the app.
|
|
@@ -35,7 +35,12 @@ export interface RootNavigator {
|
|
|
35
35
|
*/
|
|
36
36
|
export interface Theme {
|
|
37
37
|
}
|
|
38
|
-
export type RootParamList = RootNavigator extends
|
|
38
|
+
export type RootParamList = RootNavigator extends PrivateValueStore<[
|
|
39
|
+
infer ParamList extends {},
|
|
40
|
+
any,
|
|
41
|
+
any,
|
|
42
|
+
any
|
|
43
|
+
]> ? ParamList : {};
|
|
39
44
|
export type DefaultNavigatorOptions<ParamList extends ParamListBase, State extends NavigationState, ScreenOptions extends {}, EventMap extends EventMapBase, Navigation> = DefaultRouterOptions<KeyOf<ParamList>> & {
|
|
40
45
|
/**
|
|
41
46
|
* Children React Elements to extract the route configuration from.
|
|
@@ -46,31 +51,31 @@ export type DefaultNavigatorOptions<ParamList extends ParamListBase, State exten
|
|
|
46
51
|
* Layout for the navigator.
|
|
47
52
|
* Useful for wrapping with a component with access to navigator's state and options.
|
|
48
53
|
*/
|
|
49
|
-
layout?: (props: {
|
|
54
|
+
layout?: ((props: {
|
|
50
55
|
state: State;
|
|
51
56
|
navigation: NavigationHelpers<ParamList>;
|
|
52
57
|
descriptors: Record<string, Descriptor<ScreenOptions, NavigationProp<ParamList, keyof ParamList, State, ScreenOptions, EventMap>, RouteProp<ParamList>>>;
|
|
53
58
|
children: React.ReactNode;
|
|
54
|
-
}) => React.ReactElement;
|
|
59
|
+
}) => React.ReactElement) | undefined;
|
|
55
60
|
/**
|
|
56
61
|
* Event listeners for all the screens in the navigator.
|
|
57
62
|
*/
|
|
58
|
-
screenListeners?: ScreenListeners<State, EventMap> | ((props: {
|
|
63
|
+
screenListeners?: (ScreenListeners<State, EventMap> | ((props: {
|
|
59
64
|
route: RouteProp<ParamList>;
|
|
60
65
|
navigation: Navigation;
|
|
61
|
-
}) => ScreenListeners<State, EventMap>);
|
|
66
|
+
}) => ScreenListeners<State, EventMap>)) | undefined;
|
|
62
67
|
/**
|
|
63
68
|
* Default options for all screens under this navigator.
|
|
64
69
|
*/
|
|
65
|
-
screenOptions?: ScreenOptions | ((props: {
|
|
70
|
+
screenOptions?: (ScreenOptions | ((props: {
|
|
66
71
|
route: RouteProp<ParamList>;
|
|
67
72
|
navigation: Navigation;
|
|
68
73
|
theme: Theme;
|
|
69
|
-
}) => ScreenOptions);
|
|
74
|
+
}) => ScreenOptions)) | undefined;
|
|
70
75
|
/**
|
|
71
76
|
* Layout for all screens under this navigator.
|
|
72
77
|
*/
|
|
73
|
-
screenLayout?: (props: ScreenLayoutArgs<ParamList, keyof ParamList, ScreenOptions, Navigation>) => React.ReactElement;
|
|
78
|
+
screenLayout?: ((props: ScreenLayoutArgs<ParamList, keyof ParamList, ScreenOptions, Navigation>) => React.ReactElement) | undefined;
|
|
74
79
|
/**
|
|
75
80
|
* A function returning overrides for the underlying router used by the navigator.
|
|
76
81
|
* The overrides will be shallow merged onto the original router.
|
|
@@ -78,7 +83,7 @@ export type DefaultNavigatorOptions<ParamList extends ParamListBase, State exten
|
|
|
78
83
|
*
|
|
79
84
|
* This must be a pure function and cannot reference outside dynamic variables.
|
|
80
85
|
*/
|
|
81
|
-
router?: <Action extends NavigationAction>(original: Router<State, Action>) => Partial<Router<State, Action
|
|
86
|
+
router?: (<Action extends NavigationAction>(original: Router<State, Action>) => Partial<Router<State, Action>>) | undefined;
|
|
82
87
|
/**
|
|
83
88
|
* What should happen when the available route names change.
|
|
84
89
|
* e.g. when different screens are rendered based on a condition.
|
|
@@ -98,13 +103,13 @@ export type DefaultNavigatorOptions<ParamList extends ParamListBase, State exten
|
|
|
98
103
|
* - Direct navigation is only handled for `NAVIGATE` actions.
|
|
99
104
|
* - Unhandled state is restored only if the current state becomes invalid, i.e. it doesn't contain any currently defined screens.
|
|
100
105
|
*/
|
|
101
|
-
routeNamesChangeBehavior?: 'firstMatch' | 'lastUnhandled';
|
|
106
|
+
routeNamesChangeBehavior?: ('firstMatch' | 'lastUnhandled') | undefined;
|
|
102
107
|
};
|
|
103
108
|
export type EventMapBase = Record<string, {
|
|
104
109
|
data?: any;
|
|
105
|
-
canPreventDefault?: boolean;
|
|
110
|
+
canPreventDefault?: boolean | undefined;
|
|
106
111
|
}>;
|
|
107
|
-
export type EventMapCore<State extends NavigationState> = {
|
|
112
|
+
export type EventMapCore<in out State extends NavigationState> = {
|
|
108
113
|
focus: {
|
|
109
114
|
data: undefined;
|
|
110
115
|
};
|
|
@@ -128,7 +133,10 @@ export type EventArg<EventName, CanPreventDefault extends boolean | undefined =
|
|
|
128
133
|
* Type of the event (e.g. `focus`, `blur`)
|
|
129
134
|
*/
|
|
130
135
|
readonly type: EventName;
|
|
131
|
-
|
|
136
|
+
/**
|
|
137
|
+
* Key of the route which received the event.
|
|
138
|
+
*/
|
|
139
|
+
readonly target?: string | undefined;
|
|
132
140
|
} & (CanPreventDefault extends true ? {
|
|
133
141
|
/**
|
|
134
142
|
* Whether `event.preventDefault()` was called on this event object.
|
|
@@ -139,12 +147,12 @@ export type EventArg<EventName, CanPreventDefault extends boolean | undefined =
|
|
|
139
147
|
*/
|
|
140
148
|
preventDefault(): void;
|
|
141
149
|
} : {}) & (undefined extends Data ? {
|
|
142
|
-
readonly data?: Readonly<Data
|
|
150
|
+
readonly data?: Readonly<Data> | undefined;
|
|
143
151
|
} : {
|
|
144
152
|
readonly data: Readonly<Data>;
|
|
145
153
|
});
|
|
146
|
-
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;
|
|
147
|
-
export type EventConsumer<EventMap extends EventMapBase> = {
|
|
154
|
+
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;
|
|
155
|
+
export type EventConsumer<in out EventMap extends EventMapBase> = {
|
|
148
156
|
/**
|
|
149
157
|
* Subscribe to events from the parent navigator.
|
|
150
158
|
*
|
|
@@ -154,7 +162,7 @@ export type EventConsumer<EventMap extends EventMapBase> = {
|
|
|
154
162
|
addListener<EventName extends KeyOf<EventMap>>(type: EventName, callback: EventListenerCallback<EventMap, EventName>): () => void;
|
|
155
163
|
removeListener<EventName extends KeyOf<EventMap>>(type: EventName, callback: EventListenerCallback<EventMap, EventName>): void;
|
|
156
164
|
};
|
|
157
|
-
export type EventEmitter<EventMap extends EventMapBase> = {
|
|
165
|
+
export type EventEmitter<in out EventMap extends EventMapBase> = {
|
|
158
166
|
/**
|
|
159
167
|
* Emit an event to child screens.
|
|
160
168
|
*
|
|
@@ -174,7 +182,7 @@ export type EventEmitter<EventMap extends EventMapBase> = {
|
|
|
174
182
|
data: EventMap[EventName]['data'];
|
|
175
183
|
})): EventArg<EventName, EventMap[EventName]['canPreventDefault'], EventMap[EventName]['data']>;
|
|
176
184
|
};
|
|
177
|
-
export declare class PrivateValueStore<T extends [any, any, any]> {
|
|
185
|
+
export declare class PrivateValueStore<T extends [any, any, any, any]> {
|
|
178
186
|
/**
|
|
179
187
|
* UGLY HACK! DO NOT USE THE TYPE!!!
|
|
180
188
|
*
|
|
@@ -208,15 +216,15 @@ type NavigationHelpersCommon<ParamList extends ParamListBase, State extends Navi
|
|
|
208
216
|
screen: RouteName,
|
|
209
217
|
params?: ParamList[RouteName],
|
|
210
218
|
options?: {
|
|
211
|
-
merge?: boolean;
|
|
212
|
-
pop?: boolean;
|
|
219
|
+
merge?: boolean | undefined;
|
|
220
|
+
pop?: boolean | undefined;
|
|
213
221
|
}
|
|
214
222
|
] : [
|
|
215
223
|
screen: RouteName,
|
|
216
224
|
params: ParamList[RouteName],
|
|
217
225
|
options?: {
|
|
218
|
-
merge?: boolean;
|
|
219
|
-
pop?: boolean;
|
|
226
|
+
merge?: boolean | undefined;
|
|
227
|
+
pop?: boolean | undefined;
|
|
220
228
|
}
|
|
221
229
|
] : never): void;
|
|
222
230
|
/**
|
|
@@ -231,9 +239,9 @@ type NavigationHelpersCommon<ParamList extends ParamListBase, State extends Navi
|
|
|
231
239
|
navigate<RouteName extends keyof ParamList>(options: RouteName extends unknown ? {
|
|
232
240
|
name: RouteName;
|
|
233
241
|
params: ParamList[RouteName];
|
|
234
|
-
path?: string;
|
|
235
|
-
merge?: boolean;
|
|
236
|
-
pop?: boolean;
|
|
242
|
+
path?: string | undefined;
|
|
243
|
+
merge?: boolean | undefined;
|
|
244
|
+
pop?: boolean | undefined;
|
|
237
245
|
} : never): void;
|
|
238
246
|
/**
|
|
239
247
|
* Preloads the route in current navigation tree.
|
|
@@ -274,9 +282,9 @@ type NavigationHelpersCommon<ParamList extends ParamListBase, State extends Navi
|
|
|
274
282
|
* So don't use it in `render`.
|
|
275
283
|
*/
|
|
276
284
|
getState(): State;
|
|
277
|
-
}
|
|
285
|
+
};
|
|
278
286
|
type ParamType<ParamList extends {}, RouteName extends keyof ParamList | unknown, IsPartial extends boolean = false> = RouteName extends keyof ParamList ? ParamList[RouteName] extends undefined ? undefined : IsPartial extends true ? Partial<ParamList[RouteName]> : ParamList[RouteName] : unknown;
|
|
279
|
-
type NavigationHelpersRoute<ParamList extends {}, RouteName extends keyof ParamList = KeyOf<ParamList>> = {
|
|
287
|
+
type NavigationHelpersRoute<in out ParamList extends {}, in out RouteName extends keyof ParamList = KeyOf<ParamList>> = {
|
|
280
288
|
/**
|
|
281
289
|
* Update the param object for the route.
|
|
282
290
|
* The new params will be shallow merged with the old one.
|
|
@@ -299,34 +307,34 @@ type NavigationHelpersRoute<ParamList extends {}, RouteName extends keyof ParamL
|
|
|
299
307
|
*/
|
|
300
308
|
pushParams(params: ParamType<ParamList, RouteName>): void;
|
|
301
309
|
};
|
|
302
|
-
export type NavigationHelpers<ParamList extends ParamListBase, EventMap extends EventMapBase = {}> = NavigationHelpersCommon<ParamList> & EventEmitter<EventMap> & NavigationHelpersRoute<ParamList, keyof ParamList>;
|
|
310
|
+
export type NavigationHelpers<ParamList extends ParamListBase, EventMap extends EventMapBase = {}> = NavigationHelpersCommon<ParamList> & EventEmitter<EventMap> & NavigationHelpersRoute<ParamList, keyof ParamList> & PrivateValueStore<[ParamList, unknown, unknown, unknown]>;
|
|
303
311
|
export type NavigationContainerProps = {
|
|
304
312
|
/**
|
|
305
313
|
* Initial state object for the navigation tree.
|
|
306
314
|
*/
|
|
307
|
-
initialState?: InitialState;
|
|
315
|
+
initialState?: InitialState | undefined;
|
|
308
316
|
/**
|
|
309
317
|
* Callback which is called with the latest navigation state when it changes.
|
|
310
318
|
*/
|
|
311
|
-
onStateChange?: (state: Readonly<NavigationState> | undefined) => void;
|
|
319
|
+
onStateChange?: ((state: Readonly<NavigationState> | undefined) => void) | undefined;
|
|
312
320
|
/**
|
|
313
321
|
* Callback which is called after the navigation tree mounts.
|
|
314
322
|
*/
|
|
315
|
-
onReady?: () => void;
|
|
323
|
+
onReady?: (() => void) | undefined;
|
|
316
324
|
/**
|
|
317
325
|
* Callback which is called when an action is not handled.
|
|
318
326
|
*/
|
|
319
|
-
onUnhandledAction?: (action: Readonly<NavigationAction>) => void;
|
|
327
|
+
onUnhandledAction?: ((action: Readonly<NavigationAction>) => void) | undefined;
|
|
320
328
|
/**
|
|
321
329
|
* Theme object for the UI elements.
|
|
322
330
|
*/
|
|
323
|
-
theme?: Theme;
|
|
331
|
+
theme?: Theme | undefined;
|
|
324
332
|
/**
|
|
325
333
|
* Children elements to render.
|
|
326
334
|
*/
|
|
327
335
|
children: React.ReactNode;
|
|
328
336
|
};
|
|
329
|
-
|
|
337
|
+
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> & {
|
|
330
338
|
/**
|
|
331
339
|
* Update the options for the route.
|
|
332
340
|
* The options object will be shallow merged with default options object.
|
|
@@ -334,6 +342,8 @@ export type NavigationProp<ParamList extends {}, RouteName extends keyof ParamLi
|
|
|
334
342
|
* @param options Partial options object for the current screen.
|
|
335
343
|
*/
|
|
336
344
|
setOptions(options: Partial<ScreenOptions>): void;
|
|
345
|
+
} & NavigationHelpersRoute<ParamList, RouteName> & ActionHelpers & EventConsumer<EventMap & EventMapCore<State>>;
|
|
346
|
+
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> & {
|
|
337
347
|
/**
|
|
338
348
|
* Returns the navigation prop of the parent screen.
|
|
339
349
|
* If a route name is provided, the navigation prop from the parent screen with matching route name (including current) will be returned.
|
|
@@ -343,51 +353,59 @@ export type NavigationProp<ParamList extends {}, RouteName extends keyof ParamLi
|
|
|
343
353
|
*/
|
|
344
354
|
getParent(routeName: RouteName): NavigationProp<ParamList, RouteName, State, ScreenOptions, EventMap, ActionHelpers>;
|
|
345
355
|
getParent(): NavigationProp<ParamListBase> | undefined;
|
|
346
|
-
} &
|
|
347
|
-
export type RouteProp<ParamList extends ParamListBase, RouteName extends keyof ParamList = KeyOf<ParamList>> = Route<Extract<RouteName, string>, ParamList[RouteName]>;
|
|
348
|
-
export type CompositeNavigationProp<A extends NavigationProp<ParamListBase, any, any, any, any>, B extends NavigationProp<ParamListBase, any, any, any, any>> =
|
|
356
|
+
} & PrivateValueStore<[ParamList, RouteName, EventMap, ActionHelpers]>;
|
|
357
|
+
export type RouteProp<in out ParamList extends ParamListBase, in out RouteName extends keyof ParamList = KeyOf<ParamList>> = Route<Extract<RouteName, string>, ParamList[RouteName]>;
|
|
358
|
+
export type CompositeNavigationProp<A extends NavigationProp<ParamListBase, any, any, any, any>, B extends NavigationProp<ParamListBase, any, any, any, any>> = CompositeNavigationPropInternal<A, B,
|
|
349
359
|
/**
|
|
350
360
|
* Param list from both navigation objects needs to be combined
|
|
351
361
|
* For example, we should be able to navigate to screens in both A and B
|
|
352
362
|
*/
|
|
353
|
-
|
|
363
|
+
ParamListOfNavigationProp<A> & ParamListOfNavigationProp<B>,
|
|
354
364
|
/**
|
|
355
365
|
* The route name should refer to the route name specified in the first type
|
|
356
|
-
* Ideally it should work for any of them, but it's not possible to infer that way
|
|
357
|
-
*/
|
|
358
|
-
A extends NavigationProp<any, infer R> ? R : string,
|
|
359
|
-
/**
|
|
360
|
-
* The type of state should refer to the state specified in the first type
|
|
361
366
|
*/
|
|
362
|
-
A
|
|
367
|
+
RouteNameOfNavigationProp<A>,
|
|
363
368
|
/**
|
|
364
|
-
*
|
|
369
|
+
* Event map should refer to the config specified in the first type
|
|
365
370
|
*/
|
|
366
|
-
A
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
* This allows typechecking `addListener`/`removeListener`
|
|
370
|
-
*/
|
|
371
|
-
A extends NavigationProp<any, any, any, any, infer E> ? E : {}>, 'getParent'> & {
|
|
371
|
+
EventMapOfNavigationProp<A>>;
|
|
372
|
+
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
|
|
373
|
+
ActionHelpersOfNavigationProp<A> & ActionHelpersOfNavigationProp<B> & NavigationPropBase<ParamList, RouteName, StateOfNavigationProp<A>, ScreenOptionsOfNavigationProp<A>, EventMap> & {
|
|
372
374
|
getParent: A['getParent'] & B['getParent'];
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
+
} & PrivateValueStore<[
|
|
376
|
+
ParamList,
|
|
377
|
+
RouteName,
|
|
378
|
+
EventMap,
|
|
379
|
+
ActionHelpersOfNavigationProp<A> & ActionHelpersOfNavigationProp<B>
|
|
380
|
+
]>;
|
|
381
|
+
type PrivateValueOfNavigationProp<T> = T extends PrivateValueStore<infer Value> ? Value : [never, unknown, {}, {}];
|
|
382
|
+
type ParamListOfNavigationProp<T> = PrivateValueOfNavigationProp<T>[0];
|
|
383
|
+
type RouteNameOfNavigationProp<T> = PrivateValueOfNavigationProp<T>[1];
|
|
384
|
+
type ActionHelpersOfNavigationProp<T> = PrivateValueOfNavigationProp<T>[3];
|
|
385
|
+
type StateOfNavigationProp<T> = T extends {
|
|
386
|
+
getState: () => infer State extends NavigationState;
|
|
387
|
+
} ? State : NavigationState;
|
|
388
|
+
type ScreenOptionsOfNavigationProp<T> = T extends {
|
|
389
|
+
setOptions: (options: Partial<infer ScreenOptions>) => void;
|
|
390
|
+
} ? ScreenOptions : {};
|
|
391
|
+
type EventMapOfNavigationProp<T> = PrivateValueOfNavigationProp<T>[2];
|
|
392
|
+
export type CompositeScreenProps<in out A extends {
|
|
375
393
|
navigation: NavigationProp<ParamListBase, string, any, any, any>;
|
|
376
394
|
route: RouteProp<ParamListBase>;
|
|
377
|
-
}, B extends {
|
|
395
|
+
}, in out B extends {
|
|
378
396
|
navigation: NavigationProp<ParamListBase, string, any, any, any>;
|
|
379
397
|
}> = {
|
|
380
398
|
navigation: CompositeNavigationProp<A['navigation'], B['navigation']>;
|
|
381
399
|
route: A['route'];
|
|
382
400
|
};
|
|
383
|
-
export type ScreenLayoutArgs<ParamList extends ParamListBase, RouteName extends keyof ParamList, ScreenOptions extends {}, Navigation> = {
|
|
401
|
+
export type ScreenLayoutArgs<in out ParamList extends ParamListBase, in out RouteName extends keyof ParamList, in out ScreenOptions extends {}, in out Navigation> = {
|
|
384
402
|
route: RouteProp<ParamList, RouteName>;
|
|
385
403
|
options: ScreenOptions;
|
|
386
404
|
navigation: Navigation;
|
|
387
405
|
theme: Theme;
|
|
388
406
|
children: React.ReactElement;
|
|
389
407
|
};
|
|
390
|
-
export type Descriptor<ScreenOptions extends {}, Navigation extends NavigationProp<
|
|
408
|
+
export type Descriptor<out ScreenOptions extends {}, out Navigation extends NavigationProp<ParamListBase, any, any, any, any>, out Route extends RouteProp<any, any>> = {
|
|
391
409
|
/**
|
|
392
410
|
* Render the component associated with this route.
|
|
393
411
|
*/
|
|
@@ -405,7 +423,7 @@ export type Descriptor<ScreenOptions extends {}, Navigation extends NavigationPr
|
|
|
405
423
|
*/
|
|
406
424
|
navigation: Navigation;
|
|
407
425
|
};
|
|
408
|
-
export type ScreenListeners<State extends NavigationState, EventMap extends EventMapBase> = Partial<{
|
|
426
|
+
export type ScreenListeners<in out State extends NavigationState, in out EventMap extends EventMapBase> = Partial<{
|
|
409
427
|
[EventName in keyof (EventMap & EventMapCore<State>)]: EventListenerCallback<EventMap & EventMapCore<State>, EventName>;
|
|
410
428
|
}>;
|
|
411
429
|
type ScreenComponentType<ParamList extends ParamListBase, RouteName extends keyof ParamList> = React.ComponentType<{
|
|
@@ -417,15 +435,15 @@ export type RouteConfigComponent<ParamList extends ParamListBase, RouteName exte
|
|
|
417
435
|
* React component to render for this screen.
|
|
418
436
|
*/
|
|
419
437
|
component: ScreenComponentType<ParamList, RouteName>;
|
|
420
|
-
getComponent?: never;
|
|
421
|
-
children?: never;
|
|
438
|
+
getComponent?: never | undefined;
|
|
439
|
+
children?: never | undefined;
|
|
422
440
|
} | {
|
|
423
441
|
/**
|
|
424
442
|
* Lazily get a React component to render for this screen.
|
|
425
443
|
*/
|
|
426
444
|
getComponent: () => ScreenComponentType<ParamList, RouteName>;
|
|
427
|
-
component?: never;
|
|
428
|
-
children?: never;
|
|
445
|
+
component?: never | undefined;
|
|
446
|
+
children?: never | undefined;
|
|
429
447
|
} | {
|
|
430
448
|
/**
|
|
431
449
|
* Render callback to render content of this screen.
|
|
@@ -434,16 +452,16 @@ export type RouteConfigComponent<ParamList extends ParamListBase, RouteName exte
|
|
|
434
452
|
route: RouteProp<ParamList, RouteName>;
|
|
435
453
|
navigation: any;
|
|
436
454
|
}) => React.ReactNode;
|
|
437
|
-
component?: never;
|
|
438
|
-
getComponent?: never;
|
|
455
|
+
component?: never | undefined;
|
|
456
|
+
getComponent?: never | undefined;
|
|
439
457
|
};
|
|
440
|
-
export type RouteConfigProps<ParamList extends ParamListBase, RouteName extends keyof ParamList, State extends NavigationState, ScreenOptions extends {}, EventMap extends EventMapBase, Navigation> = {
|
|
458
|
+
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> = {
|
|
441
459
|
/**
|
|
442
460
|
* Optional key for this screen. This doesn't need to be unique.
|
|
443
461
|
* If the key changes, existing screens with this name will be removed or reset.
|
|
444
462
|
* Useful when we have some common screens and have conditional rendering.
|
|
445
463
|
*/
|
|
446
|
-
navigationKey?: string;
|
|
464
|
+
navigationKey?: string | undefined;
|
|
447
465
|
/**
|
|
448
466
|
* Route name of this screen.
|
|
449
467
|
*/
|
|
@@ -451,58 +469,58 @@ export type RouteConfigProps<ParamList extends ParamListBase, RouteName extends
|
|
|
451
469
|
/**
|
|
452
470
|
* Navigator options for this screen.
|
|
453
471
|
*/
|
|
454
|
-
options?: ScreenOptions | ((props: {
|
|
472
|
+
options?: (ScreenOptions | ((props: {
|
|
455
473
|
route: RouteProp<ParamList, RouteName>;
|
|
456
474
|
navigation: Navigation;
|
|
457
475
|
theme: Theme;
|
|
458
|
-
}) => ScreenOptions);
|
|
476
|
+
}) => ScreenOptions)) | undefined;
|
|
459
477
|
/**
|
|
460
478
|
* Event listeners for this screen.
|
|
461
479
|
*/
|
|
462
|
-
listeners?: ScreenListeners<State, EventMap> | ((props: {
|
|
480
|
+
listeners?: (ScreenListeners<State, EventMap> | ((props: {
|
|
463
481
|
route: RouteProp<ParamList, RouteName>;
|
|
464
482
|
navigation: Navigation;
|
|
465
|
-
}) => ScreenListeners<State, EventMap>);
|
|
483
|
+
}) => ScreenListeners<State, EventMap>)) | undefined;
|
|
466
484
|
/**
|
|
467
485
|
* Layout for this screen.
|
|
468
486
|
* Useful for wrapping the screen with custom containers.
|
|
469
487
|
* e.g. for styling, error boundaries, suspense, etc.
|
|
470
488
|
*/
|
|
471
|
-
layout?: (props: ScreenLayoutArgs<ParamList, RouteName, ScreenOptions, Navigation>) => React.ReactElement;
|
|
489
|
+
layout?: ((props: ScreenLayoutArgs<ParamList, RouteName, ScreenOptions, Navigation>) => React.ReactElement) | undefined;
|
|
472
490
|
/**
|
|
473
491
|
* Function to return an unique ID for this screen.
|
|
474
492
|
* Receives an object with the route params.
|
|
475
493
|
* For a given screen name, there will always be only one screen corresponding to an ID.
|
|
476
494
|
* If `undefined` is returned, it acts same as no `getId` being specified.
|
|
477
495
|
*/
|
|
478
|
-
getId?: ({ params, }: {
|
|
496
|
+
getId?: (({ params, }: {
|
|
479
497
|
params: Readonly<ParamList[RouteName]>;
|
|
480
|
-
}) => string | undefined;
|
|
498
|
+
}) => string | undefined) | undefined;
|
|
481
499
|
/**
|
|
482
500
|
* Initial params object for the route.
|
|
483
501
|
*/
|
|
484
|
-
initialParams?: Partial<ParamList[RouteName]
|
|
502
|
+
initialParams?: Partial<ParamList[RouteName]> | undefined;
|
|
485
503
|
};
|
|
486
504
|
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>;
|
|
487
|
-
export type RouteGroupConfig<ParamList extends ParamListBase, ScreenOptions extends {}, Navigation> = {
|
|
505
|
+
export type RouteGroupConfig<in out ParamList extends ParamListBase, in out ScreenOptions extends {}, in out Navigation> = {
|
|
488
506
|
/**
|
|
489
507
|
* Optional key for the screens in this group.
|
|
490
508
|
* If the key changes, all existing screens in this group will be removed or reset.
|
|
491
509
|
*/
|
|
492
|
-
navigationKey?: string;
|
|
510
|
+
navigationKey?: string | undefined;
|
|
493
511
|
/**
|
|
494
512
|
* Navigator options for this screen.
|
|
495
513
|
*/
|
|
496
|
-
screenOptions?: ScreenOptions | ((props: {
|
|
514
|
+
screenOptions?: (ScreenOptions | ((props: {
|
|
497
515
|
route: RouteProp<ParamList, keyof ParamList>;
|
|
498
516
|
navigation: Navigation;
|
|
499
517
|
theme: Theme;
|
|
500
|
-
}) => ScreenOptions);
|
|
518
|
+
}) => ScreenOptions)) | undefined;
|
|
501
519
|
/**
|
|
502
520
|
* Layout for the screens inside the group.
|
|
503
521
|
* This will override the `screenLayout` of parent group or navigator.
|
|
504
522
|
*/
|
|
505
|
-
screenLayout?: ((props: ScreenLayoutArgs<ParamList, keyof ParamList, ScreenOptions, Navigation>) => React.ReactElement) | {};
|
|
523
|
+
screenLayout?: (((props: ScreenLayoutArgs<ParamList, keyof ParamList, ScreenOptions, Navigation>) => React.ReactElement) | {}) | undefined;
|
|
506
524
|
/**
|
|
507
525
|
* Children React Elements to extract the route configuration from.
|
|
508
526
|
* Only `Screen`, `Group` and `React.Fragment` are supported as children.
|
|
@@ -556,6 +574,31 @@ export type NavigationContainerEventMap = {
|
|
|
556
574
|
stack: string | undefined;
|
|
557
575
|
};
|
|
558
576
|
};
|
|
577
|
+
/**
|
|
578
|
+
* Event that fires when an event is emitted.
|
|
579
|
+
* Only intended for debugging purposes, don't use it for app logic.
|
|
580
|
+
* This event will be emitted after all listeners have been called.
|
|
581
|
+
*/
|
|
582
|
+
__unsafe_event__: {
|
|
583
|
+
data: {
|
|
584
|
+
/**
|
|
585
|
+
* The type of the event that was emitted.
|
|
586
|
+
*/
|
|
587
|
+
type: string;
|
|
588
|
+
/**
|
|
589
|
+
* The data object passed when emitting the event.
|
|
590
|
+
*/
|
|
591
|
+
data: unknown;
|
|
592
|
+
/**
|
|
593
|
+
* The key of the target route which received the event.
|
|
594
|
+
*/
|
|
595
|
+
target: string | undefined;
|
|
596
|
+
/**
|
|
597
|
+
* Whether `event.preventDefault()` was called on this event.
|
|
598
|
+
*/
|
|
599
|
+
defaultPrevented: boolean | undefined;
|
|
600
|
+
};
|
|
601
|
+
};
|
|
559
602
|
};
|
|
560
603
|
/**
|
|
561
604
|
* A stripped down NavigationProp if the navigator is not known.
|
|
@@ -600,46 +643,46 @@ export type GenericNavigation<ParamList extends {}> = Omit<NavigationProp<ParamL
|
|
|
600
643
|
*/
|
|
601
644
|
setOptions(options: unknown): void;
|
|
602
645
|
};
|
|
603
|
-
export type RouteForName<ParamList extends {}, RouteName extends string> =
|
|
646
|
+
export type RouteForName<ParamList extends {}, RouteName extends string> = RouteForNameInternal<RouteName, ParamListRoute<ParamList>>;
|
|
647
|
+
type RouteForNameInternal<RouteName extends string, Routes> = string extends RouteName ? Routes : Extract<Routes, {
|
|
604
648
|
name: RouteName;
|
|
605
649
|
}>;
|
|
606
650
|
type ParamListRoute<ParamList extends {}> = {
|
|
607
651
|
[RouteName in keyof ParamList]: NavigatorScreenParams<{}> extends ParamList[RouteName] ? NotUndefined<ParamList[RouteName]> extends NavigatorScreenParams<infer T> ? ParamListRoute<T> | RouteProp<ParamList, RouteName> : RouteProp<ParamList, RouteName> : RouteProp<ParamList, RouteName>;
|
|
608
652
|
}[keyof ParamList];
|
|
609
653
|
type MaybeParamListRoute<ParamList extends {}> = ParamList extends ParamListBase ? ParamListRoute<ParamList> : Route<string>;
|
|
610
|
-
type BasicNavigationComposite<Navigation extends NavigationProp<any, any, any, any, any>, Parent
|
|
654
|
+
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>>;
|
|
611
655
|
type BasicNavigationList<ParamList extends {}, ExcludedRouteNames, Parent extends NavigationProp<any, any, any, any, any> | undefined> = UnionToIntersection<{
|
|
612
|
-
[RouteName in keyof ParamList]: (NavigatorScreenParams<{}> extends ParamList[RouteName] ? NotUndefined<ParamList[RouteName]> extends NavigatorScreenParams<infer T> ? BasicNavigationList<T, ExcludedRouteNames, NavigationProp<ParamList, RouteName>> : {} : {}) & (RouteName extends ExcludedRouteNames ? {} : {
|
|
656
|
+
[RouteName in keyof ParamList]: (NavigatorScreenParams<{}> extends ParamList[RouteName] ? NotUndefined<ParamList[RouteName]> extends NavigatorScreenParams<infer T> ? keyof T extends ExcludedRouteNames ? {} : BasicNavigationList<T, ExcludedRouteNames, NavigationProp<ParamList, RouteName>> : {} : {}) & (RouteName extends ExcludedRouteNames ? {} : {
|
|
613
657
|
[Key in RouteName]: BasicNavigationComposite<NavigationProp<ParamList, RouteName>, Parent>;
|
|
614
658
|
});
|
|
615
659
|
}[keyof ParamList]>;
|
|
616
|
-
export type NavigationListForNavigator<Navigator> = Navigator extends
|
|
617
|
-
export type NavigationListForNested<Navigator> =
|
|
618
|
-
type NavigationListForNestedInternal<Navigator
|
|
619
|
-
type NavigationListWithComposite<Parent extends NavigationProp<any, any, any, any, any>, NavigatorList extends Record<string, any>> = {
|
|
620
|
-
[K in keyof NavigatorList]: CompositeNavigationProp<NavigatorList[K], Parent>;
|
|
621
|
-
};
|
|
622
|
-
type NavigationListForStaticConfig<ParentList, Navigator> = Navigator extends {
|
|
660
|
+
export type NavigationListForNavigator<Navigator> = Navigator extends PrivateValueStore<infer Value> ? Value[1] : {};
|
|
661
|
+
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;
|
|
662
|
+
type NavigationListForNestedInternal<Navigator, Parent = undefined, NavigatorList extends Record<string, any> = NavigationListForNavigator<Navigator>, ComposedList = ComposeNavigationList<NavigatorList, Parent>> = Navigator extends {
|
|
623
663
|
readonly config: {
|
|
624
|
-
screens?:
|
|
625
|
-
groups?:
|
|
664
|
+
readonly screens?: infer Screens;
|
|
665
|
+
readonly groups?: infer Groups;
|
|
626
666
|
};
|
|
627
|
-
} ? NavigationListForScreens<
|
|
628
|
-
type
|
|
629
|
-
[K in keyof
|
|
667
|
+
} ? ComposedList & NavigationListForScreens<ComposedList, Screens> & NavigationListForGroups<ComposedList, Groups> : ComposedList;
|
|
668
|
+
type ComposeNavigationList<NavigatorList extends Record<string, any>, Parent> = Parent extends NavigationProp<any, any, any, any, any> ? {
|
|
669
|
+
[K in keyof NavigatorList]: CompositeNavigationProp<NavigatorList[K], Parent>;
|
|
670
|
+
} : NavigatorList;
|
|
671
|
+
type NavigationListForScreens<ParentList, Screens> = Screens extends {} ? UnionToIntersection<{
|
|
672
|
+
[K in keyof Screens]: Screens[K] extends {
|
|
630
673
|
config: any;
|
|
631
|
-
} ?
|
|
674
|
+
} ? K extends keyof ParentList ? NavigationListForNestedInternal<Screens[K], ParentList[K]> : never : Screens[K] extends {
|
|
632
675
|
screen: {
|
|
633
676
|
config: any;
|
|
634
677
|
};
|
|
635
|
-
} ?
|
|
636
|
-
}[keyof Screens]
|
|
637
|
-
type NavigationListForGroups<ParentList, Groups> = Groups extends
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
678
|
+
} ? K extends keyof ParentList ? NavigationListForNestedInternal<Screens[K]['screen'], ParentList[K]> : never : never;
|
|
679
|
+
}[keyof Screens]> : {};
|
|
680
|
+
type NavigationListForGroups<ParentList, Groups> = Groups extends {} ? UnionToIntersection<{
|
|
681
|
+
[K in keyof Groups]: Groups[K] extends {
|
|
682
|
+
screens: any;
|
|
683
|
+
} ? NavigationListForScreens<ParentList, Groups[K]['screens']> : never;
|
|
641
684
|
}[keyof Groups]> : {};
|
|
642
|
-
export type NavigationContainerRef<ParamList extends {}> = NavigationHelpers<ParamList> & EventConsumer<NavigationContainerEventMap> & {
|
|
685
|
+
export type NavigationContainerRef<ParamList extends {}> = Omit<NavigationHelpers<ParamList>, keyof NavigationHelpersRoute<{}>> & NavigationHelpersRoute<{}> & EventConsumer<NavigationContainerEventMap> & {
|
|
643
686
|
/**
|
|
644
687
|
* Reset the navigation state of the root navigator to the provided state.
|
|
645
688
|
*
|
|
@@ -666,29 +709,56 @@ export type NavigationContainerRef<ParamList extends {}> = NavigationHelpers<Par
|
|
|
666
709
|
* Stub function for setOptions on navigation object for use with useNavigation.
|
|
667
710
|
*/
|
|
668
711
|
setOptions(): never;
|
|
669
|
-
/**
|
|
670
|
-
* Stub function for getParent on navigation object for use with useNavigation.
|
|
671
|
-
*/
|
|
672
|
-
getParent(): undefined;
|
|
673
712
|
};
|
|
674
713
|
export type NavigationContainerRefWithCurrent<ParamList extends {}> = NavigationContainerRef<ParamList> & {
|
|
675
714
|
current: NavigationContainerRef<ParamList> | null;
|
|
676
715
|
};
|
|
677
|
-
export type NavigationListBase<ParamList extends ParamListBase> = {
|
|
716
|
+
export type NavigationListBase<in out ParamList extends ParamListBase> = {
|
|
678
717
|
[RouteName in keyof ParamList]: unknown;
|
|
679
718
|
};
|
|
680
|
-
|
|
719
|
+
type ActionHelpersOf<T> = T extends Record<string, (...args: any) => void> ? T : {};
|
|
720
|
+
export interface NavigatorTypeBagBase {
|
|
681
721
|
ParamList: {};
|
|
682
722
|
State: NavigationState;
|
|
683
723
|
ScreenOptions: {};
|
|
684
724
|
EventMap: {};
|
|
685
|
-
|
|
725
|
+
ActionHelpers: {};
|
|
726
|
+
NavigationList: {
|
|
727
|
+
[RouteName in keyof this['ParamList']]: NavigationProp<this['ParamList'], RouteName, this['State'], this['ScreenOptions'], this['EventMap'], ActionHelpersOf<this['ActionHelpers']>>;
|
|
728
|
+
};
|
|
686
729
|
Navigator: React.ComponentType<any>;
|
|
730
|
+
}
|
|
731
|
+
/**
|
|
732
|
+
* Adds a proper `ParamList` to a type bag interface
|
|
733
|
+
* So it can be used as `this['ParamList']`
|
|
734
|
+
*/
|
|
735
|
+
export type NavigatorTypeBagFor<TypeBag extends NavigatorTypeBagBase, ParamList extends {}> = TypeBag & {
|
|
736
|
+
ParamList: ParamList;
|
|
687
737
|
};
|
|
688
|
-
|
|
738
|
+
type TypedNavigatorComponent<Bag extends NavigatorTypeBagBase> = React.ComponentType<Omit<React.ComponentProps<TypedNavigatorInternal<Bag['ParamList'], Bag['State'], Bag['ScreenOptions'], Bag['EventMap'], Bag['NavigationList'], Bag['Navigator']>['Navigator']>, 'children'>>;
|
|
739
|
+
type TypedNavigatorStaticDecorated<Bag extends NavigatorTypeBagBase, Config> = {
|
|
740
|
+
getComponent: () => React.ComponentType<{}>;
|
|
689
741
|
config: Config;
|
|
690
|
-
}
|
|
691
|
-
|
|
742
|
+
} & PrivateValueStore<[
|
|
743
|
+
Bag['ParamList'],
|
|
744
|
+
Bag['NavigationList'],
|
|
745
|
+
unknown,
|
|
746
|
+
unknown
|
|
747
|
+
]>;
|
|
748
|
+
type TypedNavigatorStatic<in out Bag extends NavigatorTypeBagBase, in out Config> = {
|
|
749
|
+
config: Config;
|
|
750
|
+
with: (Component: React.ComponentType<{
|
|
751
|
+
Navigator: TypedNavigatorComponent<Bag>;
|
|
752
|
+
}>) => TypedNavigatorStaticDecorated<Bag, Config>;
|
|
753
|
+
getComponent: () => TypedNavigatorComponent<Bag>;
|
|
754
|
+
};
|
|
755
|
+
export type TypedNavigator<Bag extends NavigatorTypeBagBase, Config = unknown> = (undefined extends Config ? TypedNavigatorInternal<Bag['ParamList'], Bag['State'], Bag['ScreenOptions'], Bag['EventMap'], Bag['NavigationList'], Bag['Navigator']> : TypedNavigatorStatic<Bag, Config>) & PrivateValueStore<[
|
|
756
|
+
Bag['ParamList'],
|
|
757
|
+
Bag['NavigationList'],
|
|
758
|
+
unknown,
|
|
759
|
+
unknown
|
|
760
|
+
]>;
|
|
761
|
+
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>> = {
|
|
692
762
|
/**
|
|
693
763
|
* Navigator component which manages the child screens.
|
|
694
764
|
*/
|
|
@@ -708,29 +778,32 @@ export type NavigatorScreenParams<ParamList extends {}> = {
|
|
|
708
778
|
merge?: never;
|
|
709
779
|
initial?: never;
|
|
710
780
|
pop?: never;
|
|
711
|
-
|
|
781
|
+
preload?: never;
|
|
782
|
+
path?: string | undefined;
|
|
712
783
|
state: PartialState<NavigationState> | NavigationState | undefined;
|
|
713
784
|
} | {
|
|
714
785
|
[RouteName in keyof ParamList]: undefined extends ParamList[RouteName] ? {
|
|
715
786
|
screen: RouteName;
|
|
716
|
-
params?: ParamList[RouteName];
|
|
717
|
-
merge?: boolean;
|
|
718
|
-
initial?: boolean;
|
|
719
|
-
path?: string;
|
|
720
|
-
pop?: boolean;
|
|
787
|
+
params?: ParamList[RouteName] | undefined;
|
|
788
|
+
merge?: boolean | undefined;
|
|
789
|
+
initial?: boolean | undefined;
|
|
790
|
+
path?: string | undefined;
|
|
791
|
+
pop?: boolean | undefined;
|
|
792
|
+
preload?: boolean | undefined;
|
|
721
793
|
state?: never;
|
|
722
794
|
} : {
|
|
723
795
|
screen: RouteName;
|
|
724
796
|
params: ParamList[RouteName];
|
|
725
|
-
merge?: boolean;
|
|
726
|
-
initial?: boolean;
|
|
727
|
-
path?: string;
|
|
728
|
-
pop?: boolean;
|
|
797
|
+
merge?: boolean | undefined;
|
|
798
|
+
initial?: boolean | undefined;
|
|
799
|
+
path?: string | undefined;
|
|
800
|
+
pop?: boolean | undefined;
|
|
801
|
+
preload?: boolean | undefined;
|
|
729
802
|
state?: never;
|
|
730
803
|
};
|
|
731
804
|
}[keyof ParamList];
|
|
732
805
|
type ParseConfig<Params> = {
|
|
733
|
-
[K in keyof Params]?: (value: string) => Params[K]
|
|
806
|
+
[K in keyof Params]?: ((value: string) => Params[K]) | StandardSchemaV1<string | string[] | null | undefined, Params[K]>;
|
|
734
807
|
};
|
|
735
808
|
type StringifyConfig<Params> = {
|
|
736
809
|
[K in keyof Params]?: (value: Params[K]) => string;
|
|
@@ -746,9 +819,9 @@ type PathConfigAlias<Params> = {
|
|
|
746
819
|
* By default, paths are relating to the path config on the parent screen.
|
|
747
820
|
* If `exact` is set to `true`, the parent path configuration is not used.
|
|
748
821
|
*/
|
|
749
|
-
exact?: boolean;
|
|
822
|
+
exact?: boolean | undefined;
|
|
750
823
|
/**
|
|
751
|
-
* An object mapping the param name to a function
|
|
824
|
+
* An object mapping the param name to a parser function or a Standard Schema.
|
|
752
825
|
*
|
|
753
826
|
* @example
|
|
754
827
|
* ```js
|
|
@@ -758,7 +831,18 @@ type PathConfigAlias<Params> = {
|
|
|
758
831
|
* }
|
|
759
832
|
* ```
|
|
760
833
|
*/
|
|
761
|
-
parse?: ParseConfig<Params
|
|
834
|
+
parse?: ParseConfig<Params> | undefined;
|
|
835
|
+
/**
|
|
836
|
+
* Whether this path can resolve to multiple routes.
|
|
837
|
+
* Both routes should specify `shared: true` for this to work.
|
|
838
|
+
* By default, a path can only resolve to one route.
|
|
839
|
+
*
|
|
840
|
+
* This is useful when same screen used in multiple navigators,
|
|
841
|
+
* e.g. tabs with stacks containing profile screen in each stack.
|
|
842
|
+
*
|
|
843
|
+
* The path defined first will be the canonical path.
|
|
844
|
+
*/
|
|
845
|
+
shared?: boolean | undefined;
|
|
762
846
|
};
|
|
763
847
|
export type PathConfig<Params> = FlatType<Partial<PathConfigAlias<Params>> & {
|
|
764
848
|
/**
|
|
@@ -773,23 +857,23 @@ export type PathConfig<Params> = FlatType<Partial<PathConfigAlias<Params>> & {
|
|
|
773
857
|
* }
|
|
774
858
|
* ```
|
|
775
859
|
*/
|
|
776
|
-
stringify?: StringifyConfig<Params
|
|
860
|
+
stringify?: StringifyConfig<Params> | undefined;
|
|
777
861
|
/**
|
|
778
862
|
* Additional path alias that will be matched to the same screen.
|
|
779
863
|
*/
|
|
780
|
-
alias?: (string | PathConfigAlias<Params>)[];
|
|
864
|
+
alias?: (string | PathConfigAlias<Params>)[] | undefined;
|
|
781
865
|
} & (NonNullable<Params> extends NavigatorScreenParams<infer ParamList> ? {
|
|
782
866
|
/**
|
|
783
867
|
* Path configuration for child screens.
|
|
784
868
|
*/
|
|
785
|
-
screens?: PathConfigMap<ParamList
|
|
869
|
+
screens?: PathConfigMap<ParamList> | undefined;
|
|
786
870
|
/**
|
|
787
871
|
* Name of the initial route to use for the navigator when the path matches.
|
|
788
872
|
*/
|
|
789
|
-
initialRouteName?: keyof ParamList;
|
|
873
|
+
initialRouteName?: Extract<keyof ParamList, string> | undefined;
|
|
790
874
|
} : {})>;
|
|
791
875
|
export type PathConfigMap<ParamList extends {}> = {
|
|
792
|
-
[RouteName in keyof ParamList]?: string | PathConfig<ParamList[RouteName]
|
|
876
|
+
[RouteName in keyof ParamList]?: string | PathConfig<ParamList[RouteName]> | undefined;
|
|
793
877
|
};
|
|
794
878
|
export {};
|
|
795
879
|
//# sourceMappingURL=types.d.ts.map
|