@react-navigation/core 8.0.0-alpha.3 → 8.0.0-alpha.31

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.
Files changed (285) hide show
  1. package/lib/module/BaseNavigationContainer.js +38 -19
  2. package/lib/module/BaseNavigationContainer.js.map +1 -1
  3. package/lib/module/ConsumedParamsContext.js +5 -0
  4. package/lib/module/ConsumedParamsContext.js.map +1 -0
  5. package/lib/module/DataLoading.js +127 -0
  6. package/lib/module/DataLoading.js.map +1 -0
  7. package/lib/module/NavigationBuilderContext.js +1 -0
  8. package/lib/module/NavigationBuilderContext.js.map +1 -1
  9. package/lib/module/NavigationIndependentTree.js +20 -8
  10. package/lib/module/NavigationIndependentTree.js.map +1 -1
  11. package/lib/module/NavigationProvider.js +22 -11
  12. package/lib/module/NavigationProvider.js.map +1 -1
  13. package/lib/module/NavigationStateContext.js +3 -0
  14. package/lib/module/NavigationStateContext.js.map +1 -1
  15. package/lib/module/PreventRemoveContext.js.map +1 -1
  16. package/lib/module/PreventRemoveProvider.js +37 -27
  17. package/lib/module/PreventRemoveProvider.js.map +1 -1
  18. package/lib/module/SceneView.js +10 -41
  19. package/lib/module/SceneView.js.map +1 -1
  20. package/lib/module/StaticNavigation.js +179 -50
  21. package/lib/module/StaticNavigation.js.map +1 -1
  22. package/lib/module/StaticTreeContext.js +5 -0
  23. package/lib/module/StaticTreeContext.js.map +1 -0
  24. package/lib/module/checkSerializable.js +18 -13
  25. package/lib/module/checkSerializable.js.map +1 -1
  26. package/lib/module/createNavigationContainerRef.js +6 -8
  27. package/lib/module/createNavigationContainerRef.js.map +1 -1
  28. package/lib/module/createNavigatorFactory.js +27 -5
  29. package/lib/module/createNavigatorFactory.js.map +1 -1
  30. package/lib/module/findFocusedRoute.js +7 -4
  31. package/lib/module/findFocusedRoute.js.map +1 -1
  32. package/lib/module/getActionFromState.js +45 -20
  33. package/lib/module/getActionFromState.js.map +1 -1
  34. package/lib/module/getPathFromState.js +171 -90
  35. package/lib/module/getPathFromState.js.map +1 -1
  36. package/lib/module/getPatternParts.js +20 -4
  37. package/lib/module/getPatternParts.js.map +1 -1
  38. package/lib/module/getStateFromPath.js +487 -217
  39. package/lib/module/getStateFromPath.js.map +1 -1
  40. package/lib/module/getStateFromRouteParams.js +23 -0
  41. package/lib/module/getStateFromRouteParams.js.map +1 -0
  42. package/lib/module/index.js +5 -4
  43. package/lib/module/index.js.map +1 -1
  44. package/lib/module/theming/useTheme.js +1 -1
  45. package/lib/module/theming/useTheme.js.map +1 -1
  46. package/lib/module/types.js +35 -0
  47. package/lib/module/types.js.map +1 -1
  48. package/lib/module/useDescriptors.js +21 -11
  49. package/lib/module/useDescriptors.js.map +1 -1
  50. package/lib/module/useEventEmitter.js +48 -33
  51. package/lib/module/useEventEmitter.js.map +1 -1
  52. package/lib/module/useFocusEvents.js +12 -4
  53. package/lib/module/useFocusEvents.js.map +1 -1
  54. package/lib/module/useFocusedListenersChildrenAdapter.js +2 -2
  55. package/lib/module/useFocusedListenersChildrenAdapter.js.map +1 -1
  56. package/lib/module/useIsFocused.js +7 -12
  57. package/lib/module/useIsFocused.js.map +1 -1
  58. package/lib/module/useKeyedChildListeners.js +4 -2
  59. package/lib/module/useKeyedChildListeners.js.map +1 -1
  60. package/lib/module/useLazyValue.js.map +1 -1
  61. package/lib/module/useNavigation.js +2 -15
  62. package/lib/module/useNavigation.js.map +1 -1
  63. package/lib/module/useNavigationBuilder.js +204 -131
  64. package/lib/module/useNavigationBuilder.js.map +1 -1
  65. package/lib/module/useNavigationCache.js +22 -17
  66. package/lib/module/useNavigationCache.js.map +1 -1
  67. package/lib/module/useNavigationHelpers.js +28 -10
  68. package/lib/module/useNavigationHelpers.js.map +1 -1
  69. package/lib/module/useNavigationIndependentTree.js +1 -1
  70. package/lib/module/useNavigationIndependentTree.js.map +1 -1
  71. package/lib/module/useNavigationState.js +125 -45
  72. package/lib/module/useNavigationState.js.map +1 -1
  73. package/lib/module/useOnAction.js +37 -7
  74. package/lib/module/useOnAction.js.map +1 -1
  75. package/lib/module/useOnGetState.js +6 -3
  76. package/lib/module/useOnGetState.js.map +1 -1
  77. package/lib/module/useOnPreventRemove.js +39 -30
  78. package/lib/module/useOnPreventRemove.js.map +1 -1
  79. package/lib/module/useOnRouteFocus.js +1 -1
  80. package/lib/module/useOnRouteFocus.js.map +1 -1
  81. package/lib/module/useOptionsGetters.js +10 -5
  82. package/lib/module/useOptionsGetters.js.map +1 -1
  83. package/lib/module/usePreventRemove.js +10 -3
  84. package/lib/module/usePreventRemove.js.map +1 -1
  85. package/lib/module/usePreventRemoveContext.js +1 -1
  86. package/lib/module/usePreventRemoveContext.js.map +1 -1
  87. package/lib/module/useRegisterNavigator.js +2 -2
  88. package/lib/module/useRegisterNavigator.js.map +1 -1
  89. package/lib/module/useRoute.js +2 -0
  90. package/lib/module/useRoute.js.map +1 -1
  91. package/lib/module/useRouteCache.js +17 -11
  92. package/lib/module/useRouteCache.js.map +1 -1
  93. package/lib/module/useScheduleUpdate.js +9 -9
  94. package/lib/module/useScheduleUpdate.js.map +1 -1
  95. package/lib/module/useStateForPath.js +1 -1
  96. package/lib/module/useStateForPath.js.map +1 -1
  97. package/lib/module/useSyncState.js +32 -9
  98. package/lib/module/useSyncState.js.map +1 -1
  99. package/lib/module/validatePathConfig.js +50 -36
  100. package/lib/module/validatePathConfig.js.map +1 -1
  101. package/lib/typescript/src/BaseNavigationContainer.d.ts +6 -3
  102. package/lib/typescript/src/BaseNavigationContainer.d.ts.map +1 -1
  103. package/lib/typescript/src/ConsumedParamsContext.d.ts +3 -0
  104. package/lib/typescript/src/ConsumedParamsContext.d.ts.map +1 -0
  105. package/lib/typescript/src/DataLoading.d.ts +21 -0
  106. package/lib/typescript/src/DataLoading.d.ts.map +1 -0
  107. package/lib/typescript/src/EnsureSingleNavigator.d.ts +1 -1
  108. package/lib/typescript/src/EnsureSingleNavigator.d.ts.map +1 -1
  109. package/lib/typescript/src/Group.d.ts +1 -1
  110. package/lib/typescript/src/Group.d.ts.map +1 -1
  111. package/lib/typescript/src/NavigationBuilderContext.d.ts +9 -8
  112. package/lib/typescript/src/NavigationBuilderContext.d.ts.map +1 -1
  113. package/lib/typescript/src/NavigationContainerRefContext.d.ts +1 -1
  114. package/lib/typescript/src/NavigationContainerRefContext.d.ts.map +1 -1
  115. package/lib/typescript/src/NavigationFocusedRouteStateContext.d.ts +4 -4
  116. package/lib/typescript/src/NavigationFocusedRouteStateContext.d.ts.map +1 -1
  117. package/lib/typescript/src/NavigationHelpersContext.d.ts +1 -1
  118. package/lib/typescript/src/NavigationHelpersContext.d.ts.map +1 -1
  119. package/lib/typescript/src/NavigationIndependentTree.d.ts +1 -1
  120. package/lib/typescript/src/NavigationIndependentTree.d.ts.map +1 -1
  121. package/lib/typescript/src/NavigationProvider.d.ts +12 -13
  122. package/lib/typescript/src/NavigationProvider.d.ts.map +1 -1
  123. package/lib/typescript/src/NavigationStateContext.d.ts +4 -3
  124. package/lib/typescript/src/NavigationStateContext.d.ts.map +1 -1
  125. package/lib/typescript/src/PreventRemoveContext.d.ts +1 -0
  126. package/lib/typescript/src/PreventRemoveContext.d.ts.map +1 -1
  127. package/lib/typescript/src/PreventRemoveProvider.d.ts +1 -1
  128. package/lib/typescript/src/PreventRemoveProvider.d.ts.map +1 -1
  129. package/lib/typescript/src/SceneView.d.ts +4 -2
  130. package/lib/typescript/src/SceneView.d.ts.map +1 -1
  131. package/lib/typescript/src/Screen.d.ts +1 -1
  132. package/lib/typescript/src/Screen.d.ts.map +1 -1
  133. package/lib/typescript/src/StaticContainer.d.ts +1 -1
  134. package/lib/typescript/src/StaticContainer.d.ts.map +1 -1
  135. package/lib/typescript/src/StaticNavigation.d.ts +189 -109
  136. package/lib/typescript/src/StaticNavigation.d.ts.map +1 -1
  137. package/lib/typescript/src/StaticTreeContext.d.ts +4 -0
  138. package/lib/typescript/src/StaticTreeContext.d.ts.map +1 -0
  139. package/lib/typescript/src/checkSerializable.d.ts +8 -4
  140. package/lib/typescript/src/checkSerializable.d.ts.map +1 -1
  141. package/lib/typescript/src/createNavigationContainerRef.d.ts +1 -1
  142. package/lib/typescript/src/createNavigationContainerRef.d.ts.map +1 -1
  143. package/lib/typescript/src/createNavigatorFactory.d.ts +23 -5
  144. package/lib/typescript/src/createNavigatorFactory.d.ts.map +1 -1
  145. package/lib/typescript/src/findFocusedRoute.d.ts +3 -8
  146. package/lib/typescript/src/findFocusedRoute.d.ts.map +1 -1
  147. package/lib/typescript/src/getActionFromState.d.ts +4 -4
  148. package/lib/typescript/src/getActionFromState.d.ts.map +1 -1
  149. package/lib/typescript/src/getPathFromState.d.ts +3 -3
  150. package/lib/typescript/src/getPathFromState.d.ts.map +1 -1
  151. package/lib/typescript/src/getPatternParts.d.ts +1 -0
  152. package/lib/typescript/src/getPatternParts.d.ts.map +1 -1
  153. package/lib/typescript/src/getStateFromPath.d.ts +4 -7
  154. package/lib/typescript/src/getStateFromPath.d.ts.map +1 -1
  155. package/lib/typescript/src/getStateFromRouteParams.d.ts +3 -0
  156. package/lib/typescript/src/getStateFromRouteParams.d.ts.map +1 -0
  157. package/lib/typescript/src/index.d.ts +36 -33
  158. package/lib/typescript/src/index.d.ts.map +1 -1
  159. package/lib/typescript/src/theming/ThemeContext.d.ts +1 -1
  160. package/lib/typescript/src/theming/ThemeContext.d.ts.map +1 -1
  161. package/lib/typescript/src/theming/ThemeProvider.d.ts +2 -2
  162. package/lib/typescript/src/theming/ThemeProvider.d.ts.map +1 -1
  163. package/lib/typescript/src/theming/useTheme.d.ts +1 -1
  164. package/lib/typescript/src/theming/useTheme.d.ts.map +1 -1
  165. package/lib/typescript/src/types.d.ts +260 -159
  166. package/lib/typescript/src/types.d.ts.map +1 -1
  167. package/lib/typescript/src/useChildListeners.d.ts +3 -3
  168. package/lib/typescript/src/useChildListeners.d.ts.map +1 -1
  169. package/lib/typescript/src/useComponent.d.ts +1 -1
  170. package/lib/typescript/src/useComponent.d.ts.map +1 -1
  171. package/lib/typescript/src/useDescriptors.d.ts +10 -9
  172. package/lib/typescript/src/useDescriptors.d.ts.map +1 -1
  173. package/lib/typescript/src/useEventEmitter.d.ts +2 -2
  174. package/lib/typescript/src/useEventEmitter.d.ts.map +1 -1
  175. package/lib/typescript/src/useFocusEvents.d.ts +2 -2
  176. package/lib/typescript/src/useFocusEvents.d.ts.map +1 -1
  177. package/lib/typescript/src/useFocusedListenersChildrenAdapter.d.ts +2 -2
  178. package/lib/typescript/src/useFocusedListenersChildrenAdapter.d.ts.map +1 -1
  179. package/lib/typescript/src/useIsFocused.d.ts +3 -0
  180. package/lib/typescript/src/useIsFocused.d.ts.map +1 -1
  181. package/lib/typescript/src/useKeyedChildListeners.d.ts +3 -3
  182. package/lib/typescript/src/useKeyedChildListeners.d.ts.map +1 -1
  183. package/lib/typescript/src/useLazyValue.d.ts.map +1 -1
  184. package/lib/typescript/src/useNavigation.d.ts +4 -2
  185. package/lib/typescript/src/useNavigation.d.ts.map +1 -1
  186. package/lib/typescript/src/useNavigationBuilder.d.ts +23 -30
  187. package/lib/typescript/src/useNavigationBuilder.d.ts.map +1 -1
  188. package/lib/typescript/src/useNavigationCache.d.ts +3 -3
  189. package/lib/typescript/src/useNavigationCache.d.ts.map +1 -1
  190. package/lib/typescript/src/useNavigationContainerRef.d.ts +1 -1
  191. package/lib/typescript/src/useNavigationContainerRef.d.ts.map +1 -1
  192. package/lib/typescript/src/useNavigationHelpers.d.ts +19 -27
  193. package/lib/typescript/src/useNavigationHelpers.d.ts.map +1 -1
  194. package/lib/typescript/src/useNavigationState.d.ts +17 -3
  195. package/lib/typescript/src/useNavigationState.d.ts.map +1 -1
  196. package/lib/typescript/src/useOnAction.d.ts +9 -9
  197. package/lib/typescript/src/useOnAction.d.ts.map +1 -1
  198. package/lib/typescript/src/useOnGetState.d.ts +1 -1
  199. package/lib/typescript/src/useOnGetState.d.ts.map +1 -1
  200. package/lib/typescript/src/useOnPreventRemove.d.ts +5 -9
  201. package/lib/typescript/src/useOnPreventRemove.d.ts.map +1 -1
  202. package/lib/typescript/src/useOnRouteFocus.d.ts +6 -6
  203. package/lib/typescript/src/useOnRouteFocus.d.ts.map +1 -1
  204. package/lib/typescript/src/useOptionsGetters.d.ts +1 -1
  205. package/lib/typescript/src/useOptionsGetters.d.ts.map +1 -1
  206. package/lib/typescript/src/usePreventRemove.d.ts.map +1 -1
  207. package/lib/typescript/src/usePreventRemoveContext.d.ts +2 -1
  208. package/lib/typescript/src/usePreventRemoveContext.d.ts.map +1 -1
  209. package/lib/typescript/src/useRoute.d.ts +7 -3
  210. package/lib/typescript/src/useRoute.d.ts.map +1 -1
  211. package/lib/typescript/src/useRouteCache.d.ts +5 -5
  212. package/lib/typescript/src/useRouteCache.d.ts.map +1 -1
  213. package/lib/typescript/src/useScheduleUpdate.d.ts +5 -4
  214. package/lib/typescript/src/useScheduleUpdate.d.ts.map +1 -1
  215. package/lib/typescript/src/useStateForPath.d.ts +1 -1
  216. package/lib/typescript/src/useStateForPath.d.ts.map +1 -1
  217. package/lib/typescript/src/useSyncState.d.ts +1 -0
  218. package/lib/typescript/src/useSyncState.d.ts.map +1 -1
  219. package/lib/typescript/src/utilities.d.ts +74 -37
  220. package/lib/typescript/src/utilities.d.ts.map +1 -1
  221. package/lib/typescript/src/validatePathConfig.d.ts.map +1 -1
  222. package/package.json +23 -22
  223. package/src/BaseNavigationContainer.tsx +362 -334
  224. package/src/ConsumedParamsContext.tsx +5 -0
  225. package/src/DataLoading.tsx +203 -0
  226. package/src/NavigationBuilderContext.tsx +14 -9
  227. package/src/NavigationFocusedRouteStateContext.tsx +4 -4
  228. package/src/NavigationIndependentTree.tsx +23 -12
  229. package/src/NavigationProvider.tsx +26 -15
  230. package/src/NavigationStateContext.tsx +9 -6
  231. package/src/PreventRemoveContext.tsx +1 -0
  232. package/src/PreventRemoveProvider.tsx +51 -46
  233. package/src/SceneView.tsx +11 -39
  234. package/src/StaticNavigation.tsx +659 -307
  235. package/src/StaticTreeContext.tsx +7 -0
  236. package/src/checkSerializable.tsx +35 -19
  237. package/src/createNavigationContainerRef.tsx +12 -9
  238. package/src/createNavigatorFactory.tsx +92 -8
  239. package/src/findFocusedRoute.tsx +16 -16
  240. package/src/getActionFromState.tsx +87 -51
  241. package/src/getPathFromState.tsx +254 -128
  242. package/src/getPatternParts.tsx +25 -4
  243. package/src/getStateFromPath.tsx +821 -331
  244. package/src/getStateFromRouteParams.tsx +59 -0
  245. package/src/index.tsx +55 -5
  246. package/src/theming/useTheme.tsx +1 -1
  247. package/src/types.tsx +798 -373
  248. package/src/useDescriptors.tsx +31 -14
  249. package/src/useEventEmitter.tsx +52 -38
  250. package/src/useFocusEvents.tsx +15 -7
  251. package/src/useFocusedListenersChildrenAdapter.tsx +2 -2
  252. package/src/useIsFocused.tsx +14 -21
  253. package/src/useKeyedChildListeners.tsx +4 -2
  254. package/src/useLazyValue.tsx +2 -2
  255. package/src/useNavigation.tsx +7 -24
  256. package/src/useNavigationBuilder.tsx +314 -186
  257. package/src/useNavigationCache.tsx +32 -25
  258. package/src/useNavigationHelpers.tsx +27 -10
  259. package/src/useNavigationIndependentTree.tsx +1 -1
  260. package/src/useNavigationState.tsx +168 -69
  261. package/src/useOnAction.tsx +61 -13
  262. package/src/useOnGetState.tsx +5 -3
  263. package/src/useOnPreventRemove.tsx +75 -42
  264. package/src/useOnRouteFocus.tsx +10 -12
  265. package/src/useOptionsGetters.tsx +11 -5
  266. package/src/usePreventRemove.tsx +12 -3
  267. package/src/usePreventRemoveContext.tsx +1 -1
  268. package/src/useRegisterNavigator.tsx +2 -2
  269. package/src/useRoute.tsx +20 -6
  270. package/src/useRouteCache.tsx +22 -16
  271. package/src/useScheduleUpdate.tsx +9 -10
  272. package/src/useStateForPath.tsx +1 -1
  273. package/src/useSyncState.tsx +35 -9
  274. package/src/utilities.tsx +144 -31
  275. package/src/validatePathConfig.tsx +86 -57
  276. package/lib/module/CurrentRenderContext.js +0 -10
  277. package/lib/module/CurrentRenderContext.js.map +0 -1
  278. package/lib/module/useCurrentRender.js +0 -19
  279. package/lib/module/useCurrentRender.js.map +0 -1
  280. package/lib/typescript/src/CurrentRenderContext.d.ts +0 -9
  281. package/lib/typescript/src/CurrentRenderContext.d.ts.map +0 -1
  282. package/lib/typescript/src/useCurrentRender.d.ts +0 -14
  283. package/lib/typescript/src/useCurrentRender.d.ts.map +0 -1
  284. package/src/CurrentRenderContext.tsx +0 -9
  285. package/src/useCurrentRender.tsx +0 -31
package/src/types.tsx CHANGED
@@ -14,6 +14,7 @@ import type {
14
14
  FlatType,
15
15
  KeyOf,
16
16
  NotUndefined,
17
+ StandardSchemaV1,
17
18
  UnionToIntersection,
18
19
  } from './utilities';
19
20
 
@@ -54,13 +55,8 @@ export interface RootNavigator {}
54
55
  export interface Theme {}
55
56
 
56
57
  export type RootParamList =
57
- RootNavigator extends TypedNavigatorInternal<
58
- infer ParamList,
59
- any,
60
- any,
61
- any,
62
- any,
63
- any
58
+ RootNavigator extends PrivateValueStore<
59
+ [infer ParamList extends {}, any, any, any]
64
60
  >
65
61
  ? ParamList
66
62
  : {};
@@ -82,58 +78,68 @@ export type DefaultNavigatorOptions<
82
78
  * Layout for the navigator.
83
79
  * Useful for wrapping with a component with access to navigator's state and options.
84
80
  */
85
- layout?: (props: {
86
- state: State;
87
- navigation: NavigationHelpers<ParamList>;
88
- descriptors: Record<
89
- string,
90
- Descriptor<
91
- ScreenOptions,
92
- NavigationProp<
93
- ParamList,
94
- keyof ParamList,
95
- State,
96
- ScreenOptions,
97
- EventMap
98
- >,
99
- RouteProp<ParamList>
100
- >
101
- >;
102
- children: React.ReactNode;
103
- }) => React.ReactElement;
81
+ layout?:
82
+ | ((props: {
83
+ state: State;
84
+ navigation: NavigationHelpers<ParamList>;
85
+ descriptors: Record<
86
+ string,
87
+ Descriptor<
88
+ ScreenOptions,
89
+ NavigationProp<
90
+ ParamList,
91
+ keyof ParamList,
92
+ State,
93
+ ScreenOptions,
94
+ EventMap
95
+ >,
96
+ ScreenRouteProp<ParamList>
97
+ >
98
+ >;
99
+ children: React.ReactNode;
100
+ }) => React.ReactElement)
101
+ | undefined;
104
102
 
105
103
  /**
106
104
  * Event listeners for all the screens in the navigator.
107
105
  */
108
106
  screenListeners?:
109
- | ScreenListeners<State, EventMap>
110
- | ((props: {
111
- route: RouteProp<ParamList>;
112
- navigation: Navigation;
113
- }) => ScreenListeners<State, EventMap>);
107
+ | (
108
+ | ScreenListeners<State, EventMap>
109
+ | ((props: {
110
+ route: ScreenRouteProp<ParamList>;
111
+ navigation: Navigation;
112
+ }) => ScreenListeners<State, EventMap>)
113
+ )
114
+ | undefined;
114
115
 
115
116
  /**
116
117
  * Default options for all screens under this navigator.
117
118
  */
118
119
  screenOptions?:
119
- | ScreenOptions
120
- | ((props: {
121
- route: RouteProp<ParamList>;
122
- navigation: Navigation;
123
- theme: Theme;
124
- }) => ScreenOptions);
120
+ | (
121
+ | ScreenOptions
122
+ | ((props: {
123
+ route: ScreenRouteProp<ParamList>;
124
+ navigation: Navigation;
125
+ theme: Theme;
126
+ }) => ScreenOptions)
127
+ )
128
+ | undefined;
125
129
 
126
130
  /**
127
131
  * Layout for all screens under this navigator.
128
132
  */
129
- screenLayout?: (
130
- props: ScreenLayoutArgs<
131
- ParamList,
132
- keyof ParamList,
133
- ScreenOptions,
134
- Navigation
135
- >
136
- ) => React.ReactElement;
133
+ screenLayout?:
134
+ | ((
135
+ props: ScreenLayoutArgs<
136
+ ParamList,
137
+ keyof ParamList,
138
+ ScreenOptions,
139
+ Navigation
140
+ >
141
+ ) => React.ReactElement)
142
+ | undefined;
137
143
 
138
144
  /**
139
145
  * A function returning overrides for the underlying router used by the navigator.
@@ -142,9 +148,11 @@ export type DefaultNavigatorOptions<
142
148
  *
143
149
  * This must be a pure function and cannot reference outside dynamic variables.
144
150
  */
145
- router?: <Action extends NavigationAction>(
146
- original: Router<State, Action>
147
- ) => Partial<Router<State, Action>>;
151
+ router?:
152
+ | (<Action extends NavigationAction>(
153
+ original: Router<State, Action>
154
+ ) => Partial<Router<State, Action>>)
155
+ | undefined;
148
156
 
149
157
  /**
150
158
  * What should happen when the available route names change.
@@ -165,15 +173,15 @@ export type DefaultNavigatorOptions<
165
173
  * - Direct navigation is only handled for `NAVIGATE` actions.
166
174
  * - Unhandled state is restored only if the current state becomes invalid, i.e. it doesn't contain any currently defined screens.
167
175
  */
168
- routeNamesChangeBehavior?: 'firstMatch' | 'lastUnhandled';
176
+ routeNamesChangeBehavior?: ('firstMatch' | 'lastUnhandled') | undefined;
169
177
  };
170
178
 
171
179
  export type EventMapBase = Record<
172
180
  string,
173
- { data?: any; canPreventDefault?: boolean }
181
+ { data?: any; canPreventDefault?: boolean | undefined }
174
182
  >;
175
183
 
176
- export type EventMapCore<State extends NavigationState> = {
184
+ export type EventMapCore<in out State extends NavigationState> = {
177
185
  focus: { data: undefined };
178
186
  blur: { data: undefined };
179
187
  state: { data: { state: State } };
@@ -192,7 +200,7 @@ export type EventArg<
192
200
  /**
193
201
  * Key of the route which received the event.
194
202
  */
195
- readonly target?: string;
203
+ readonly target?: string | undefined;
196
204
  } & (CanPreventDefault extends true
197
205
  ? {
198
206
  /**
@@ -206,15 +214,14 @@ export type EventArg<
206
214
  }
207
215
  : {}) &
208
216
  (undefined extends Data
209
- ? { readonly data?: Readonly<Data> }
217
+ ? { readonly data?: Readonly<Data> | undefined }
210
218
  : { readonly data: Readonly<Data> });
211
219
 
212
220
  export type EventListenerCallback<
213
- EventMap extends EventMapBase,
214
- EventName extends keyof EventMap,
215
- EventCanPreventDefault extends
216
- | boolean
217
- | undefined = EventMap[EventName]['canPreventDefault'],
221
+ in out EventMap extends EventMapBase,
222
+ in out EventName extends keyof EventMap,
223
+ in out EventCanPreventDefault extends boolean | undefined =
224
+ EventMap[EventName]['canPreventDefault'],
218
225
  > = (
219
226
  e: EventArg<
220
227
  EventName,
@@ -223,7 +230,7 @@ export type EventListenerCallback<
223
230
  >
224
231
  ) => void;
225
232
 
226
- export type EventConsumer<EventMap extends EventMapBase> = {
233
+ export type EventConsumer<in out EventMap extends EventMapBase> = {
227
234
  /**
228
235
  * Subscribe to events from the parent navigator.
229
236
  *
@@ -240,7 +247,7 @@ export type EventConsumer<EventMap extends EventMapBase> = {
240
247
  ): void;
241
248
  };
242
249
 
243
- export type EventEmitter<EventMap extends EventMapBase> = {
250
+ export type EventEmitter<in out EventMap extends EventMapBase> = {
244
251
  /**
245
252
  * Emit an event to child screens.
246
253
  *
@@ -266,7 +273,7 @@ export type EventEmitter<EventMap extends EventMapBase> = {
266
273
  >;
267
274
  };
268
275
 
269
- export class PrivateValueStore<T extends [any, any, any]> {
276
+ export class PrivateValueStore<T extends [any, any, any, any]> {
270
277
  /**
271
278
  * UGLY HACK! DO NOT USE THE TYPE!!!
272
279
  *
@@ -280,6 +287,50 @@ export class PrivateValueStore<T extends [any, any, any]> {
280
287
  protected ''?: T;
281
288
  }
282
289
 
290
+ type NavigatorLike =
291
+ | {
292
+ Navigator: React.ComponentType<any>;
293
+ Screen: unknown;
294
+ Group: unknown;
295
+ }
296
+ | {
297
+ config: unknown;
298
+ getComponent: () => React.ComponentType<any>;
299
+ };
300
+
301
+ export type ParamListForNavigator<T extends {}> = T extends NavigatorLike
302
+ ? T extends PrivateValueStore<[infer ParamList extends {}, any, any, any]>
303
+ ? ParamList
304
+ : T
305
+ : T;
306
+
307
+ // Remove `undefined` before checking for nested navigator params.
308
+ // If nothing remains, avoid matching `never` against `NavigatorScreenParams`
309
+ type NestedNavigatorForScreenParams<T, Params = NotUndefined<T>> = [
310
+ Params,
311
+ ] extends [never]
312
+ ? never
313
+ : Params extends NavigatorScreenParams<infer Navigator>
314
+ ? Navigator extends PrivateValueStore<[any, any, any, any]>
315
+ ? Navigator extends NavigatorLike
316
+ ? Navigator
317
+ : never
318
+ : never
319
+ : never;
320
+
321
+ export type NestedNavigatorsForParamList<ParamList extends {}> = {
322
+ [RouteName in keyof ParamList as NestedNavigatorForScreenParams<
323
+ ParamList[RouteName]
324
+ > extends never
325
+ ? never
326
+ : RouteName]: NestedNavigatorForScreenParams<ParamList[RouteName]>;
327
+ };
328
+
329
+ type NavigateOptions = {
330
+ merge?: boolean | undefined;
331
+ pop?: boolean | undefined;
332
+ };
333
+
283
334
  type NavigationHelpersCommon<
284
335
  ParamList extends ParamListBase,
285
336
  State extends NavigationState = NavigationState,
@@ -314,37 +365,16 @@ type NavigationHelpersCommon<
314
365
  ? [
315
366
  screen: RouteName,
316
367
  params?: ParamList[RouteName],
317
- options?: { merge?: boolean; pop?: boolean },
368
+ options?: NavigateOptions,
318
369
  ]
319
370
  : [
320
371
  screen: RouteName,
321
372
  params: ParamList[RouteName],
322
- options?: { merge?: boolean; pop?: boolean },
373
+ options?: NavigateOptions,
323
374
  ]
324
375
  : never
325
376
  ): void;
326
377
 
327
- /**
328
- * Navigate to a route in current navigation tree.
329
- *
330
- * @param options.name Name of the route to navigate to.
331
- * @param [options.params] Params object for the route.
332
- * @param [options.path] Path to associate the route with (e.g. for deep links).
333
- * @param [options.merge] Whether to merge the params onto the route. Defaults to `false`.
334
- * @param [options.pop] Whether to pop routes in a stack to go back to the matching route. Defaults to `false`.
335
- */
336
- navigate<RouteName extends keyof ParamList>(
337
- options: RouteName extends unknown
338
- ? {
339
- name: RouteName;
340
- params: ParamList[RouteName];
341
- path?: string;
342
- merge?: boolean;
343
- pop?: boolean;
344
- }
345
- : never
346
- ): void;
347
-
348
378
  /**
349
379
  * Preloads the route in current navigation tree.
350
380
  *
@@ -395,11 +425,11 @@ type NavigationHelpersCommon<
395
425
  * So don't use it in `render`.
396
426
  */
397
427
  getState(): State;
398
- } & PrivateValueStore<[ParamList, unknown, unknown]>;
428
+ };
399
429
 
400
430
  type ParamType<
401
431
  ParamList extends {},
402
- RouteName extends keyof ParamList | unknown,
432
+ RouteName,
403
433
  IsPartial extends boolean = false,
404
434
  > = RouteName extends keyof ParamList
405
435
  ? ParamList[RouteName] extends undefined
@@ -410,8 +440,8 @@ type ParamType<
410
440
  : unknown;
411
441
 
412
442
  type NavigationHelpersRoute<
413
- ParamList extends {},
414
- RouteName extends keyof ParamList = KeyOf<ParamList>,
443
+ in out ParamList extends {},
444
+ in out RouteName extends keyof ParamList = KeyOf<ParamList>,
415
445
  > = {
416
446
  /**
417
447
  * Update the param object for the route.
@@ -443,43 +473,51 @@ export type NavigationHelpers<
443
473
  EventMap extends EventMapBase = {},
444
474
  > = NavigationHelpersCommon<ParamList> &
445
475
  EventEmitter<EventMap> &
446
- NavigationHelpersRoute<ParamList, keyof ParamList>;
476
+ NavigationHelpersRoute<ParamList, keyof ParamList> &
477
+ PrivateValueStore<[ParamList, unknown, unknown, unknown]>;
447
478
 
448
479
  export type NavigationContainerProps = {
449
480
  /**
450
481
  * Initial state object for the navigation tree.
451
482
  */
452
- initialState?: InitialState;
483
+ initialState?: InitialState | undefined;
453
484
  /**
454
485
  * Callback which is called with the latest navigation state when it changes.
455
486
  */
456
- onStateChange?: (state: Readonly<NavigationState> | undefined) => void;
487
+ onStateChange?:
488
+ | ((state: Readonly<NavigationState> | undefined) => void)
489
+ | undefined;
457
490
  /**
458
491
  * Callback which is called after the navigation tree mounts.
459
492
  */
460
- onReady?: () => void;
493
+ onReady?: (() => void) | undefined;
461
494
  /**
462
495
  * Callback which is called when an action is not handled.
463
496
  */
464
- onUnhandledAction?: (action: Readonly<NavigationAction>) => void;
497
+ onUnhandledAction?:
498
+ | ((action: Readonly<NavigationAction>) => void)
499
+ | undefined;
465
500
  /**
466
501
  * Theme object for the UI elements.
467
502
  */
468
- theme?: Theme;
503
+ theme?: Theme | undefined;
469
504
  /**
470
505
  * Children elements to render.
471
506
  */
472
507
  children: React.ReactNode;
473
508
  };
474
509
 
475
- export type NavigationProp<
510
+ // Everything in `NavigationProp` except `getParent` and the private brand.
511
+ // The composite navigation prop intersects this directly, so it doesn't have
512
+ // to walk `NavigationProp`'s members with `Omit` to drop `getParent`/the brand.
513
+ type NavigationPropBase<
476
514
  ParamList extends {},
477
515
  RouteName extends keyof ParamList = KeyOf<ParamList>,
478
516
  State extends NavigationState = NavigationState<ParamList>,
479
517
  ScreenOptions extends {} = {},
480
518
  EventMap extends EventMapBase = {},
481
519
  ActionHelpers extends Record<string, (...args: any) => void> = {},
482
- > = Omit<NavigationHelpersCommon<ParamList, State>, 'getParent'> & {
520
+ > = NavigationHelpersCommon<ParamList, State> & {
483
521
  /**
484
522
  * Update the options for the route.
485
523
  * The options object will be shallow merged with default options object.
@@ -487,6 +525,25 @@ export type NavigationProp<
487
525
  * @param options Partial options object for the current screen.
488
526
  */
489
527
  setOptions(options: Partial<ScreenOptions>): void;
528
+ } & NavigationHelpersRoute<ParamList, RouteName> &
529
+ ActionHelpers &
530
+ EventConsumer<EventMap & EventMapCore<State>>;
531
+
532
+ export type NavigationProp<
533
+ ParamList extends {},
534
+ RouteName extends keyof ParamList = KeyOf<ParamList>,
535
+ State extends NavigationState = NavigationState<ParamList>,
536
+ ScreenOptions extends {} = {},
537
+ EventMap extends EventMapBase = {},
538
+ ActionHelpers extends Record<string, (...args: any) => void> = {},
539
+ > = NavigationPropBase<
540
+ ParamList,
541
+ RouteName,
542
+ State,
543
+ ScreenOptions,
544
+ EventMap,
545
+ ActionHelpers
546
+ > & {
490
547
  /**
491
548
  * Returns the navigation prop of the parent screen.
492
549
  * If a route name is provided, the navigation prop from the parent screen with matching route name (including current) will be returned.
@@ -505,58 +562,100 @@ export type NavigationProp<
505
562
  ActionHelpers
506
563
  >;
507
564
  getParent(): NavigationProp<ParamListBase> | undefined;
508
- } & NavigationHelpersRoute<ParamList, RouteName> &
509
- ActionHelpers &
510
- EventConsumer<EventMap & EventMapCore<State>> &
511
- PrivateValueStore<[ParamList, RouteName, EventMap]>;
565
+ } & PrivateValueStore<[ParamList, RouteName, EventMap, ActionHelpers]>;
512
566
 
513
567
  export type RouteProp<
568
+ in out ParamList extends ParamListBase,
569
+ in out RouteName extends keyof ParamList = KeyOf<ParamList>,
570
+ > = Route<Extract<RouteName, string>, ParamList[RouteName]>;
571
+
572
+ type ScreenRouteProp<
514
573
  ParamList extends ParamListBase,
515
574
  RouteName extends keyof ParamList = KeyOf<ParamList>,
516
- > = Route<Extract<RouteName, string>, ParamList[RouteName]>;
575
+ > = {
576
+ [Name in Extract<RouteName, string>]: RouteProp<ParamList, Name>;
577
+ }[Extract<RouteName, string>];
517
578
 
518
579
  export type CompositeNavigationProp<
519
580
  A extends NavigationProp<ParamListBase, any, any, any, any>,
520
581
  B extends NavigationProp<ParamListBase, any, any, any, any>,
521
- > = Omit<A & B, keyof NavigationProp<any, any, any, any, any>> &
522
- Omit<
523
- NavigationProp<
524
- /**
525
- * Param list from both navigation objects needs to be combined
526
- * For example, we should be able to navigate to screens in both A and B
527
- */
528
- (A extends NavigationHelpersCommon<infer T> ? T : never) &
529
- (B extends NavigationHelpersCommon<infer U> ? U : never),
530
- /**
531
- * The route name should refer to the route name specified in the first type
532
- * Ideally it should work for any of them, but it's not possible to infer that way
533
- */
534
- A extends NavigationProp<any, infer R> ? R : string,
535
- /**
536
- * The type of state should refer to the state specified in the first type
537
- */
538
- A extends NavigationProp<any, any, infer S> ? S : NavigationState,
539
- /**
540
- * Screen options should refer to the options specified in the first type
541
- */
542
- A extends NavigationProp<any, any, any, infer O> ? O : {},
543
- /**
544
- * Event consumer config should refer to the config specified in the first type
545
- * This allows typechecking `addListener`/`removeListener`
546
- */
547
- A extends NavigationProp<any, any, any, any, infer E> ? E : {}
548
- >,
549
- 'getParent'
550
- > & {
551
- getParent: A['getParent'] & B['getParent'];
552
- };
582
+ > = CompositeNavigationPropInternal<
583
+ A,
584
+ B,
585
+ /**
586
+ * Param list from both navigation objects needs to be combined
587
+ * For example, we should be able to navigate to screens in both A and B
588
+ */
589
+ ParamListOfNavigationProp<A> & ParamListOfNavigationProp<B>,
590
+ /**
591
+ * The route name should refer to the route name specified in the first type
592
+ */
593
+ RouteNameOfNavigationProp<A>,
594
+ /**
595
+ * Event map should refer to the config specified in the first type
596
+ */
597
+ EventMapOfNavigationProp<A>
598
+ >;
599
+
600
+ type CompositeNavigationPropInternal<
601
+ A extends NavigationProp<ParamListBase, any, any, any, any>,
602
+ B extends NavigationProp<ParamListBase, any, any, any, any>,
603
+ ParamList extends {},
604
+ RouteName extends keyof ParamList,
605
+ EventMap extends EventMapBase,
606
+ > = // Action helpers are read from the private brand (4th slot) instead of
607
+ // `Omit<A & B, keyof NavigationProp>`, which had to walk the whole (possibly
608
+ // deeply composed) member set of `A & B` to drop the standard members.
609
+ ActionHelpersOfNavigationProp<A> &
610
+ ActionHelpersOfNavigationProp<B> &
611
+ // Intersect the brand-free base directly instead of `Omit`-ing `getParent`
612
+ // off a full `NavigationProp`, so we skip a mapped-type pass per composite.
613
+ NavigationPropBase<
614
+ ParamList,
615
+ RouteName,
616
+ StateOfNavigationProp<A>,
617
+ ScreenOptionsOfNavigationProp<A>,
618
+ EventMap
619
+ > & {
620
+ getParent: A['getParent'] & B['getParent'];
621
+ } & PrivateValueStore<
622
+ [
623
+ ParamList,
624
+ RouteName,
625
+ EventMap,
626
+ ActionHelpersOfNavigationProp<A> & ActionHelpersOfNavigationProp<B>,
627
+ ]
628
+ >;
629
+
630
+ type PrivateValueOfNavigationProp<T> =
631
+ T extends PrivateValueStore<infer Value> ? Value : [never, unknown, {}, {}];
632
+
633
+ type ParamListOfNavigationProp<T> = PrivateValueOfNavigationProp<T>[0];
634
+
635
+ type RouteNameOfNavigationProp<T> = PrivateValueOfNavigationProp<T>[1];
636
+
637
+ type ActionHelpersOfNavigationProp<T> = PrivateValueOfNavigationProp<T>[3];
638
+
639
+ type StateOfNavigationProp<T> = T extends {
640
+ getState: () => infer State extends NavigationState;
641
+ }
642
+ ? State
643
+ : NavigationState;
644
+
645
+ type ScreenOptionsOfNavigationProp<T> = T extends {
646
+ setOptions: (options: Partial<infer ScreenOptions>) => void;
647
+ }
648
+ ? ScreenOptions
649
+ : {};
650
+
651
+ type EventMapOfNavigationProp<T> = PrivateValueOfNavigationProp<T>[2];
553
652
 
554
653
  export type CompositeScreenProps<
555
- A extends {
654
+ in out A extends {
556
655
  navigation: NavigationProp<ParamListBase, string, any, any, any>;
557
656
  route: RouteProp<ParamListBase>;
558
657
  },
559
- B extends {
658
+ in out B extends {
560
659
  navigation: NavigationProp<ParamListBase, string, any, any, any>;
561
660
  },
562
661
  > = {
@@ -565,12 +664,12 @@ export type CompositeScreenProps<
565
664
  };
566
665
 
567
666
  export type ScreenLayoutArgs<
568
- ParamList extends ParamListBase,
569
- RouteName extends keyof ParamList,
570
- ScreenOptions extends {},
571
- Navigation,
667
+ in out ParamList extends ParamListBase,
668
+ in out RouteName extends keyof ParamList,
669
+ in out ScreenOptions extends {},
670
+ in out Navigation,
572
671
  > = {
573
- route: RouteProp<ParamList, RouteName>;
672
+ route: ScreenRouteProp<ParamList, RouteName>;
574
673
  options: ScreenOptions;
575
674
  navigation: Navigation;
576
675
  theme: Theme;
@@ -578,9 +677,9 @@ export type ScreenLayoutArgs<
578
677
  };
579
678
 
580
679
  export type Descriptor<
581
- ScreenOptions extends {},
582
- Navigation extends NavigationProp<any, any, any, any, any>,
583
- Route extends RouteProp<any, any>,
680
+ out ScreenOptions extends {},
681
+ out Navigation extends NavigationProp<ParamListBase, any, any, any, any>,
682
+ out Route extends RouteProp<any, any>,
584
683
  > = {
585
684
  /**
586
685
  * Render the component associated with this route.
@@ -604,8 +703,8 @@ export type Descriptor<
604
703
  };
605
704
 
606
705
  export type ScreenListeners<
607
- State extends NavigationState,
608
- EventMap extends EventMapBase,
706
+ in out State extends NavigationState,
707
+ in out EventMap extends EventMapBase,
609
708
  > = Partial<{
610
709
  [EventName in keyof (EventMap & EventMapCore<State>)]: EventListenerCallback<
611
710
  EventMap & EventMapCore<State>,
@@ -656,19 +755,19 @@ export type RouteConfigComponent<
656
755
  };
657
756
 
658
757
  export type RouteConfigProps<
659
- ParamList extends ParamListBase,
660
- RouteName extends keyof ParamList,
661
- State extends NavigationState,
662
- ScreenOptions extends {},
663
- EventMap extends EventMapBase,
664
- Navigation,
758
+ in out ParamList extends ParamListBase,
759
+ in out RouteName extends keyof ParamList,
760
+ in out State extends NavigationState,
761
+ in out ScreenOptions extends {},
762
+ in out EventMap extends EventMapBase,
763
+ in out Navigation,
665
764
  > = {
666
765
  /**
667
766
  * Optional key for this screen. This doesn't need to be unique.
668
767
  * If the key changes, existing screens with this name will be removed or reset.
669
768
  * Useful when we have some common screens and have conditional rendering.
670
769
  */
671
- navigationKey?: string;
770
+ navigationKey?: string | undefined;
672
771
 
673
772
  /**
674
773
  * Route name of this screen.
@@ -679,31 +778,39 @@ export type RouteConfigProps<
679
778
  * Navigator options for this screen.
680
779
  */
681
780
  options?:
682
- | ScreenOptions
683
- | ((props: {
684
- route: RouteProp<ParamList, RouteName>;
685
- navigation: Navigation;
686
- theme: Theme;
687
- }) => ScreenOptions);
781
+ | (
782
+ | ScreenOptions
783
+ | ((props: {
784
+ route: RouteProp<ParamList, RouteName>;
785
+ navigation: Navigation;
786
+ theme: Theme;
787
+ }) => ScreenOptions)
788
+ )
789
+ | undefined;
688
790
 
689
791
  /**
690
792
  * Event listeners for this screen.
691
793
  */
692
794
  listeners?:
693
- | ScreenListeners<State, EventMap>
694
- | ((props: {
695
- route: RouteProp<ParamList, RouteName>;
696
- navigation: Navigation;
697
- }) => ScreenListeners<State, EventMap>);
795
+ | (
796
+ | ScreenListeners<State, EventMap>
797
+ | ((props: {
798
+ route: RouteProp<ParamList, RouteName>;
799
+ navigation: Navigation;
800
+ }) => ScreenListeners<State, EventMap>)
801
+ )
802
+ | undefined;
698
803
 
699
804
  /**
700
805
  * Layout for this screen.
701
806
  * Useful for wrapping the screen with custom containers.
702
807
  * e.g. for styling, error boundaries, suspense, etc.
703
808
  */
704
- layout?: (
705
- props: ScreenLayoutArgs<ParamList, RouteName, ScreenOptions, Navigation>
706
- ) => React.ReactElement;
809
+ layout?:
810
+ | ((
811
+ props: ScreenLayoutArgs<ParamList, RouteName, ScreenOptions, Navigation>
812
+ ) => React.ReactElement)
813
+ | undefined;
707
814
 
708
815
  /**
709
816
  * Function to return an unique ID for this screen.
@@ -711,16 +818,18 @@ export type RouteConfigProps<
711
818
  * For a given screen name, there will always be only one screen corresponding to an ID.
712
819
  * If `undefined` is returned, it acts same as no `getId` being specified.
713
820
  */
714
- getId?: ({
715
- params,
716
- }: {
717
- params: Readonly<ParamList[RouteName]>;
718
- }) => string | undefined;
821
+ getId?:
822
+ | (({
823
+ params,
824
+ }: {
825
+ params: Readonly<ParamList[RouteName]>;
826
+ }) => string | undefined)
827
+ | undefined;
719
828
 
720
829
  /**
721
830
  * Initial params object for the route.
722
831
  */
723
- initialParams?: Partial<ParamList[RouteName]>;
832
+ initialParams?: Partial<ParamList[RouteName]> | undefined;
724
833
  };
725
834
 
726
835
  export type RouteConfig<
@@ -741,43 +850,49 @@ export type RouteConfig<
741
850
  RouteConfigComponent<ParamList, RouteName>;
742
851
 
743
852
  export type RouteGroupConfig<
744
- ParamList extends ParamListBase,
745
- ScreenOptions extends {},
746
- Navigation,
853
+ in out ParamList extends ParamListBase,
854
+ in out ScreenOptions extends {},
855
+ in out Navigation,
747
856
  > = {
748
857
  /**
749
858
  * Optional key for the screens in this group.
750
859
  * If the key changes, all existing screens in this group will be removed or reset.
751
860
  */
752
- navigationKey?: string;
861
+ navigationKey?: string | undefined;
753
862
 
754
863
  /**
755
864
  * Navigator options for this screen.
756
865
  */
757
866
  screenOptions?:
758
- | ScreenOptions
759
- | ((props: {
760
- route: RouteProp<ParamList, keyof ParamList>;
761
- navigation: Navigation;
762
- theme: Theme;
763
- }) => ScreenOptions);
867
+ | (
868
+ | ScreenOptions
869
+ | ((props: {
870
+ route: ScreenRouteProp<ParamList>;
871
+ navigation: Navigation;
872
+ theme: Theme;
873
+ }) => ScreenOptions)
874
+ )
875
+ | undefined;
764
876
 
765
877
  /**
766
878
  * Layout for the screens inside the group.
767
879
  * This will override the `screenLayout` of parent group or navigator.
768
880
  */
769
881
  screenLayout?:
770
- | ((
771
- props: ScreenLayoutArgs<
772
- ParamList,
773
- keyof ParamList,
774
- ScreenOptions,
775
- Navigation
776
- >
777
- ) => React.ReactElement)
778
- | {
779
- // FIXME: TypeScript doesn't seem to infer `navigation` correctly without this
780
- };
882
+ | (
883
+ | ((
884
+ props: ScreenLayoutArgs<
885
+ ParamList,
886
+ keyof ParamList,
887
+ ScreenOptions,
888
+ Navigation
889
+ >
890
+ ) => React.ReactElement)
891
+ | {
892
+ // FIXME: TypeScript doesn't seem to infer `navigation` correctly without this
893
+ }
894
+ )
895
+ | undefined;
781
896
 
782
897
  /**
783
898
  * Children React Elements to extract the route configuration from.
@@ -843,15 +958,19 @@ export type NavigationContainerEventMap = {
843
958
  /**
844
959
  * The data object passed when emitting the event.
845
960
  */
846
- data: unknown;
961
+ data?: unknown;
847
962
  /**
848
963
  * The key of the target route which received the event.
849
964
  */
850
- target: string | undefined;
965
+ target?: string | undefined;
851
966
  /**
852
967
  * Whether `event.preventDefault()` was called on this event.
853
968
  */
854
- defaultPrevented: boolean | undefined;
969
+ defaultPrevented?: boolean | undefined;
970
+ /**
971
+ * Prevent the default action which happens on this event.
972
+ */
973
+ preventDefault?: (() => void) | undefined;
855
974
  };
856
975
  };
857
976
  };
@@ -922,12 +1041,44 @@ export type GenericNavigation<ParamList extends {}> = Omit<
922
1041
  export type RouteForName<
923
1042
  ParamList extends {},
924
1043
  RouteName extends string,
925
- > = Extract<ParamListRoute<ParamList>, { name: RouteName }>;
1044
+ > = string extends RouteName
1045
+ ? // RouteName is a not a literal but `string`
1046
+ // Return union of all possible routes in the tree
1047
+ ParamListRoute<ParamList>
1048
+ : RouteForNameInternal<ParamList, RouteName>;
1049
+
1050
+ // Look up route object by checking each level and recursing into the nested param lists
1051
+ // This avoids building a union of all routes, which doesn't scale on large trees
1052
+ type RouteForNameInternal<ParamList extends {}, RouteName extends string> =
1053
+ | (RouteName extends KeyOf<ParamList>
1054
+ ? RouteProp<ParamList, RouteName>
1055
+ : never)
1056
+ | RouteForNameNested<NestedParamLists<ParamList>, RouteName>;
1057
+
1058
+ type RouteForNameNested<ParamLists, RouteName extends string> =
1059
+ // Distributes over the union of nested param lists
1060
+ // e.g. if ParamLists is A | B
1061
+ // TypeScript evaluates the branch once per member (A, then B)
1062
+ // and unions the outcomes
1063
+ ParamLists extends {} ? RouteForNameInternal<ParamLists, RouteName> : never;
1064
+
1065
+ /**
1066
+ * Union of param lists of the nested navigators in a param list.
1067
+ */
1068
+ export type NestedParamLists<ParamList extends {}> = {
1069
+ [RouteName in keyof ParamList]: NavigatorScreenParams<{}> extends ParamList[RouteName]
1070
+ ? NotUndefined<ParamList[RouteName]> extends NavigatorScreenParams<infer T>
1071
+ ? ParamListForNavigator<T>
1072
+ : never
1073
+ : never;
1074
+ }[keyof ParamList];
926
1075
 
927
1076
  type ParamListRoute<ParamList extends {}> = {
928
1077
  [RouteName in keyof ParamList]: NavigatorScreenParams<{}> extends ParamList[RouteName]
929
1078
  ? NotUndefined<ParamList[RouteName]> extends NavigatorScreenParams<infer T>
930
- ? ParamListRoute<T> | RouteProp<ParamList, RouteName>
1079
+ ?
1080
+ | ParamListRoute<ParamListForNavigator<T>>
1081
+ | RouteProp<ParamList, RouteName>
931
1082
  : RouteProp<ParamList, RouteName>
932
1083
  : RouteProp<ParamList, RouteName>;
933
1084
  }[keyof ParamList];
@@ -938,11 +1089,10 @@ type MaybeParamListRoute<ParamList extends {}> = ParamList extends ParamListBase
938
1089
 
939
1090
  type BasicNavigationComposite<
940
1091
  Navigation extends NavigationProp<any, any, any, any, any>,
941
- Parent,
942
- > =
943
- Parent extends NavigationProp<any, any, any, any, any>
944
- ? CompositeNavigationProp<Navigation, Parent>
945
- : Navigation;
1092
+ Parent extends NavigationProp<any, any, any, any, any> | undefined,
1093
+ > = Parent extends undefined
1094
+ ? Navigation
1095
+ : CompositeNavigationProp<Navigation, NonNullable<Parent>>;
946
1096
 
947
1097
  type BasicNavigationList<
948
1098
  ParamList extends {},
@@ -954,11 +1104,15 @@ type BasicNavigationList<
954
1104
  ? NotUndefined<ParamList[RouteName]> extends NavigatorScreenParams<
955
1105
  infer T
956
1106
  >
957
- ? BasicNavigationList<
958
- T,
959
- ExcludedRouteNames,
960
- NavigationProp<ParamList, RouteName>
961
- >
1107
+ ? ParamListForNavigator<T> extends infer NestedParamList extends {}
1108
+ ? keyof NestedParamList extends ExcludedRouteNames
1109
+ ? {}
1110
+ : BasicNavigationList<
1111
+ NestedParamList,
1112
+ ExcludedRouteNames,
1113
+ NavigationProp<ParamList, RouteName>
1114
+ >
1115
+ : {}
962
1116
  : {}
963
1117
  : {}) &
964
1118
  (RouteName extends ExcludedRouteNames
@@ -972,178 +1126,407 @@ type BasicNavigationList<
972
1126
  }[keyof ParamList]
973
1127
  >;
974
1128
 
975
- export type NavigationListForNavigator<Navigator> =
976
- Navigator extends TypedNavigator<infer Bag, any>
977
- ? Bag['NavigationList']
978
- : Navigator extends PrivateValueStore<[any, infer NavigationList, any]>
979
- ? NavigationList
980
- : {};
981
-
982
- export type NavigationListForNested<Navigator> = FlatType<
983
- NavigationListForNestedInternal<Navigator> &
984
- (Navigator extends TypedNavigator<infer Bag, any>
985
- ? BasicNavigationList<
986
- Bag['ParamList'],
987
- keyof NavigationListForNestedInternal<Navigator>,
988
- undefined
989
- >
990
- : Navigator extends PrivateValueStore<[infer ParamList, any, any]>
991
- ? ParamList extends {}
992
- ? BasicNavigationList<
993
- ParamList,
994
- keyof NavigationListForNestedInternal<Navigator>,
995
- undefined
996
- >
997
- : {}
998
- : {})
999
- >;
1129
+ type InheritedParentParams<ParentParamList, ParamList> = {
1130
+ [K in keyof ParentParamList as K extends keyof ParamList
1131
+ ? never
1132
+ : string extends K
1133
+ ? never
1134
+ : K]: ParentParamList[K];
1135
+ };
1000
1136
 
1001
- type NavigationListForNestedInternal<Navigator> =
1002
- NavigationListForNavigator<Navigator> &
1003
- NavigationListForStaticConfig<
1004
- NavigationListForNavigator<Navigator>,
1005
- Navigator
1137
+ type GenericNavigationComposite<
1138
+ ParamList extends ParamListBase,
1139
+ RouteName extends keyof ParamList,
1140
+ Parent,
1141
+ > =
1142
+ Parent extends NavigationProp<any, any, any, any, any>
1143
+ ? ParamListOfNavigationProp<Parent> extends infer ParentParamList
1144
+ ? NavigationProp<
1145
+ ParamList & InheritedParentParams<ParentParamList, ParamList>,
1146
+ RouteName
1147
+ > & { getParent: Parent['getParent'] }
1148
+ : never
1149
+ : NavigationProp<ParamList, RouteName>;
1150
+
1151
+ type NavigationListForScreenParams<
1152
+ T extends {},
1153
+ ParamList extends ParamListBase,
1154
+ RouteName extends keyof ParamList,
1155
+ ExcludedRouteNames,
1156
+ Parent extends NavigationProp<any, any, any, any, any> | undefined,
1157
+ > = T extends PrivateValueStore<[any, any, any, any]> & NavigatorLike
1158
+ ? NavigationListForNestedInternal<
1159
+ T,
1160
+ GenericNavigationComposite<ParamList, RouteName, Parent>
1161
+ >
1162
+ : NavigationListForParamListScreenParams<
1163
+ T,
1164
+ ParamList,
1165
+ RouteName,
1166
+ ExcludedRouteNames,
1167
+ Parent
1006
1168
  >;
1007
1169
 
1008
- type NavigationListWithComposite<
1009
- Parent extends NavigationProp<any, any, any, any, any>,
1010
- NavigatorList extends Record<string, any>,
1011
- > = {
1012
- [K in keyof NavigatorList]: CompositeNavigationProp<NavigatorList[K], Parent>;
1013
- };
1170
+ type NavigationListForParamListScreenParams<
1171
+ T extends {},
1172
+ ParamList extends ParamListBase,
1173
+ RouteName extends keyof ParamList,
1174
+ ExcludedRouteNames,
1175
+ Parent extends NavigationProp<any, any, any, any, any> | undefined,
1176
+ > =
1177
+ // `T` is only ever a plain param list here, since navigators are routed to
1178
+ // `NavigationListForNestedInternal` by `NavigationListForScreenParams`.
1179
+ // So there's no navigator to unwrap with `ParamListForNavigator`.
1180
+ T extends ParamListBase
1181
+ ? BasicNavigationListForParamList<
1182
+ T,
1183
+ ExcludedRouteNames,
1184
+ GenericNavigationComposite<ParamList, RouteName, Parent>
1185
+ >
1186
+ : {};
1187
+
1188
+ type BasicNavigationListForParamList<
1189
+ ParamList extends ParamListBase,
1190
+ ExcludedRouteNames,
1191
+ Parent extends NavigationProp<any, any, any, any, any> | undefined,
1192
+ > = UnionToIntersection<
1193
+ {
1194
+ [RouteName in keyof ParamList]: (NavigatorScreenParams<{}> extends ParamList[RouteName]
1195
+ ? NotUndefined<ParamList[RouteName]> extends NavigatorScreenParams<
1196
+ infer T
1197
+ >
1198
+ ? NavigationListForScreenParams<
1199
+ T,
1200
+ ParamList,
1201
+ RouteName,
1202
+ ExcludedRouteNames,
1203
+ Parent
1204
+ >
1205
+ : {}
1206
+ : {}) &
1207
+ (RouteName extends ExcludedRouteNames
1208
+ ? {}
1209
+ : {
1210
+ [Key in RouteName]: GenericNavigationComposite<
1211
+ ParamList,
1212
+ RouteName,
1213
+ Parent
1214
+ >;
1215
+ });
1216
+ }[keyof ParamList]
1217
+ >;
1014
1218
 
1015
- type NavigationListForStaticConfig<ParentList, Navigator> = Navigator extends {
1219
+ export type NavigationListForNavigator<Navigator> =
1220
+ Navigator extends PrivateValueStore<infer Value> ? Value[1] : {};
1221
+
1222
+ export type NavigationListForNested<Navigator> =
1223
+ NavigationListForNestedInternal<Navigator> extends infer NavigationList
1224
+ ? Navigator extends PrivateValueStore<[infer ParamList, any, any, any]>
1225
+ ? ParamList extends {}
1226
+ ? NavigationList &
1227
+ BasicNavigationList<ParamList, keyof NavigationList, undefined>
1228
+ : NavigationList
1229
+ : NavigationList
1230
+ : never;
1231
+
1232
+ type NavigationListForNestedInternal<
1233
+ Navigator,
1234
+ Parent = undefined,
1235
+ NavigatorList extends Record<string, any> =
1236
+ NavigationListForNavigator<Navigator>,
1237
+ Navigators = NestedNavigatorsOf<Navigator>,
1238
+ // This navigator's own routes, each composed with the accumulated parent.
1239
+ // It's threaded into the recursion as the parent for nested navigators so
1240
+ // each route is composed with its ancestors exactly once, instead of
1241
+ // re-wrapping the whole descendant list at every level (which is quadratic
1242
+ // in the nesting depth).
1243
+ ComposedList = ComposeNavigationList<NavigatorList, Parent>,
1244
+ > = (Navigator extends {
1016
1245
  readonly config: {
1017
- screens?: any;
1018
- groups?: any;
1246
+ readonly screens?: infer Screens;
1247
+ readonly groups?: infer Groups;
1019
1248
  };
1020
1249
  }
1021
- ? NavigationListForScreens<ParentList, Navigator['config']['screens']> &
1022
- NavigationListForGroups<ParentList, Navigator['config']['groups']>
1023
- : {};
1250
+ ? ComposedList &
1251
+ NavigationListForScreens<ComposedList, Screens> &
1252
+ NavigationListForGroups<ComposedList, Groups>
1253
+ : ComposedList) &
1254
+ NavigationListForNestedNavigators<ComposedList, Navigators> &
1255
+ NavigationListForDynamicNestedParamLists<Navigator, ComposedList, Navigators>;
1256
+
1257
+ type NavigationListForDynamicNestedParamLists<
1258
+ Navigator,
1259
+ ParentList,
1260
+ Navigators,
1261
+ > = Navigator extends { readonly config: unknown }
1262
+ ? {}
1263
+ : Navigator extends PrivateValueStore<[infer ParamList, any, any, any]>
1264
+ ? NavigationListForNestedParamLists<ParentList, ParamList, Navigators>
1265
+ : {};
1024
1266
 
1025
- type NavigationListForScreens<ParentList, Screens> = UnionToIntersection<
1026
- {
1027
- // Only check screens with static config to avoid overly-complex types
1028
- // Otherwise TypeScript fails to load the types due to complexity
1029
- [K in keyof Screens]: ParentList extends Record<K, any>
1030
- ? Screens[K] extends { config: any }
1031
- ? NavigationListWithComposite<
1032
- ParentList[K],
1033
- NavigationListForNested<Screens[K]>
1034
- >
1035
- : Screens[K] extends { screen: { config: any } }
1036
- ? NavigationListWithComposite<
1037
- ParentList[K],
1038
- NavigationListForNested<Screens[K]['screen']>
1039
- >
1040
- : {}
1041
- : {};
1042
- }[keyof Screens]
1043
- >;
1267
+ // Map of route name to nested navigator type
1268
+ // inferred from `NavigatorScreenParams<typeof Navigator>`
1269
+ type NestedNavigatorsOf<Navigator> =
1270
+ Navigator extends PrivateValueStore<[any, any, any, infer Nesting]>
1271
+ ? Nesting extends Record<string, any>
1272
+ ? Nesting
1273
+ : {}
1274
+ : {};
1044
1275
 
1045
- type NavigationListForGroups<ParentList, Groups> =
1046
- Groups extends Record<string, { screens: any }>
1047
- ? UnionToIntersection<
1048
- {
1049
- [K in keyof Groups]: NavigationListForScreens<
1050
- ParentList,
1051
- Groups[K]['screens']
1052
- >;
1053
- }[keyof Groups]
1054
- >
1276
+ // Like `NavigationListForScreens`, but reads nested navigators from the brand
1277
+ // map instead of a static config.
1278
+ type NavigationListForNestedNavigators<ParentList, Navigators> =
1279
+ UnionToIntersection<
1280
+ {
1281
+ [K in keyof Navigators]: K extends keyof ParentList
1282
+ ? NavigationListForNestedInternal<Navigators[K], ParentList[K]>
1283
+ : {};
1284
+ }[keyof Navigators]
1285
+ >;
1286
+
1287
+ // Fallback for dynamic nested routes declared through NavigatorScreenParams<ParamList>.
1288
+ // Param-list branches expose generic navigation props, while nested navigator
1289
+ // entries still recover their concrete navigator props.
1290
+ type NavigationListForNestedParamLists<ParentList, ParamList, Navigators> =
1291
+ ParentList extends Record<string, any>
1292
+ ? ParamList extends ParamListBase
1293
+ ? UnionToIntersection<
1294
+ {
1295
+ [K in keyof ParamList]: K extends keyof Navigators
1296
+ ? {}
1297
+ : K extends keyof ParentList
1298
+ ? NavigatorScreenParams<{}> extends ParamList[K]
1299
+ ? NotUndefined<ParamList[K]> extends NavigatorScreenParams<
1300
+ infer T
1301
+ >
1302
+ ? NavigationListForScreenParams<
1303
+ T,
1304
+ ParamList,
1305
+ K,
1306
+ keyof ParentList,
1307
+ ParentList[K]
1308
+ >
1309
+ : {}
1310
+ : {}
1311
+ : {};
1312
+ }[keyof ParamList]
1313
+ >
1314
+ : {}
1055
1315
  : {};
1056
1316
 
1057
- export type NavigationContainerRef<ParamList extends {}> =
1058
- NavigationHelpers<ParamList> &
1059
- EventConsumer<NavigationContainerEventMap> & {
1060
- /**
1061
- * Reset the navigation state of the root navigator to the provided state.
1062
- *
1063
- * @param state Navigation state object.
1064
- */
1065
- resetRoot(state?: PartialState<NavigationState> | NavigationState): void;
1066
- /**
1067
- * Get the rehydrated navigation state of the navigation tree.
1068
- */
1069
- getRootState(): NavigationState;
1070
- /**
1071
- * Get the currently focused navigation route.
1072
- */
1073
- getCurrentRoute(): MaybeParamListRoute<ParamList> | undefined;
1074
- /**
1075
- * Get the currently focused route's options.
1076
- */
1077
- getCurrentOptions(): object | undefined;
1078
- /**
1079
- * Whether the navigation container is ready to handle actions.
1080
- */
1081
- isReady(): boolean;
1082
- /**
1083
- * Stub function for setOptions on navigation object for use with useNavigation.
1084
- */
1085
- setOptions(): never;
1086
- /**
1087
- * Stub function for getParent on navigation object for use with useNavigation.
1088
- */
1089
- getParent(): undefined;
1090
- };
1317
+ // Compose every entry in a navigator's list with the accumulated parent.
1318
+ // When there's no parent (root navigator), the list is returned as-is so the
1319
+ // common shallow case doesn't pay for a redundant mapped type.
1320
+ type ComposeNavigationList<NavigatorList extends Record<string, any>, Parent> =
1321
+ Parent extends NavigationProp<any, any, any, any, any>
1322
+ ? {
1323
+ [K in keyof NavigatorList]: CompositeNavigationProp<
1324
+ NavigatorList[K],
1325
+ Parent
1326
+ >;
1327
+ }
1328
+ : NavigatorList;
1329
+
1330
+ type NavigationListForScreens<ParentList, Screens> = Screens extends {}
1331
+ ? UnionToIntersection<
1332
+ {
1333
+ // Only check screens with static config to avoid overly-complex types
1334
+ // Otherwise TypeScript fails to load the types due to complexity
1335
+ [K in keyof Screens]: Screens[K] extends { config: any }
1336
+ ? K extends keyof ParentList
1337
+ ? NavigationListForNestedInternal<Screens[K], ParentList[K]>
1338
+ : never
1339
+ : Screens[K] extends { screen: { config: any } }
1340
+ ? K extends keyof ParentList
1341
+ ? NavigationListForNestedInternal<
1342
+ Screens[K]['screen'],
1343
+ ParentList[K]
1344
+ >
1345
+ : never
1346
+ : never;
1347
+ }[keyof Screens]
1348
+ >
1349
+ : {};
1350
+
1351
+ type NavigationListForGroups<ParentList, Groups> = Groups extends {}
1352
+ ? UnionToIntersection<
1353
+ {
1354
+ [K in keyof Groups]: Groups[K] extends { screens: any }
1355
+ ? NavigationListForScreens<ParentList, Groups[K]['screens']>
1356
+ : never;
1357
+ }[keyof Groups]
1358
+ >
1359
+ : {};
1360
+
1361
+ export type NavigationContainerRef<ParamList extends {}> = Omit<
1362
+ NavigationHelpers<ParamList>,
1363
+ keyof NavigationHelpersRoute<{}>
1364
+ > &
1365
+ NavigationHelpersRoute<{}> &
1366
+ EventConsumer<NavigationContainerEventMap> & {
1367
+ /**
1368
+ * Reset the navigation state of the root navigator to the provided state.
1369
+ *
1370
+ * @param state Navigation state object.
1371
+ */
1372
+ resetRoot(state?: PartialState<NavigationState> | NavigationState): void;
1373
+ /**
1374
+ * Get the rehydrated navigation state of the navigation tree.
1375
+ */
1376
+ getRootState(): NavigationState;
1377
+ /**
1378
+ * Get the currently focused navigation route.
1379
+ */
1380
+ getCurrentRoute(): MaybeParamListRoute<ParamList> | undefined;
1381
+ /**
1382
+ * Get the currently focused route's options.
1383
+ */
1384
+ getCurrentOptions(): object | undefined;
1385
+ /**
1386
+ * Whether the navigation container is ready to handle actions.
1387
+ */
1388
+ isReady(): boolean;
1389
+ /**
1390
+ * Stub function for setOptions on navigation object for use with useNavigation.
1391
+ */
1392
+ setOptions(): never;
1393
+ };
1091
1394
 
1092
1395
  export type NavigationContainerRefWithCurrent<ParamList extends {}> =
1093
1396
  NavigationContainerRef<ParamList> & {
1094
1397
  current: NavigationContainerRef<ParamList> | null;
1095
1398
  };
1096
1399
 
1097
- export type NavigationListBase<ParamList extends ParamListBase> = {
1400
+ export type NavigationListBase<in out ParamList extends ParamListBase> = {
1098
1401
  [RouteName in keyof ParamList]: unknown;
1099
1402
  };
1100
1403
 
1101
- export type NavigatorTypeBagBase = {
1404
+ // Only use action helpers if all values are functions
1405
+ type ActionHelpersOf<T> =
1406
+ T extends Record<string, (...args: any) => void> ? T : {};
1407
+
1408
+ export interface NavigatorTypeBagBase {
1102
1409
  ParamList: {};
1103
1410
  State: NavigationState;
1104
1411
  ScreenOptions: {};
1105
1412
  EventMap: {};
1106
- NavigationList: NavigationListBase<ParamListBase>;
1413
+ ActionHelpers: {};
1414
+ NavigationList: {
1415
+ [RouteName in keyof this['ParamList']]: NavigationProp<
1416
+ this['ParamList'],
1417
+ RouteName,
1418
+ this['State'],
1419
+ this['ScreenOptions'],
1420
+ this['EventMap'],
1421
+ ActionHelpersOf<this['ActionHelpers']>
1422
+ >;
1423
+ };
1107
1424
  Navigator: React.ComponentType<any>;
1108
- };
1425
+ }
1109
1426
 
1110
- export type TypedNavigator<
1111
- Bag extends NavigatorTypeBagBase,
1112
- Config = unknown,
1113
- > = TypedNavigatorInternal<
1114
- Bag['ParamList'],
1115
- Bag['State'],
1116
- Bag['ScreenOptions'],
1117
- Bag['EventMap'],
1118
- Bag['NavigationList'],
1119
- Bag['Navigator']
1120
- > &
1121
- (undefined extends Config ? {} : { config: Config }) &
1122
- PrivateValueStore<[Bag['ParamList'], Bag['NavigationList'], unknown]>;
1427
+ /**
1428
+ * Adds a proper `ParamList` to a type bag interface
1429
+ * So it can be used as `this['ParamList']`
1430
+ */
1431
+ export type NavigatorTypeBagFor<
1432
+ TypeBag extends NavigatorTypeBagBase,
1433
+ ParamList extends {},
1434
+ > = TypeBag & { ParamList: ParamList };
1123
1435
 
1124
- type TypedNavigatorInternal<
1436
+ export type NavigatorProps<
1125
1437
  ParamList extends ParamListBase,
1126
1438
  State extends NavigationState,
1127
1439
  ScreenOptions extends {},
1128
1440
  EventMap extends EventMapBase,
1129
- NavigationList extends NavigationListBase<ParamList>,
1441
+ Navigation,
1130
1442
  Navigator extends React.ComponentType<any>,
1443
+ > = Omit<
1444
+ React.ComponentProps<Navigator>,
1445
+ keyof DefaultNavigatorOptions<any, any, any, any, any>
1446
+ > &
1447
+ DefaultNavigatorOptions<
1448
+ ParamList,
1449
+ State,
1450
+ ScreenOptions,
1451
+ EventMap,
1452
+ Navigation
1453
+ >;
1454
+
1455
+ type TypedNavigatorStaticComponent<Bag extends NavigatorTypeBagBase> =
1456
+ React.ComponentType<
1457
+ Partial<
1458
+ Omit<
1459
+ NavigatorProps<
1460
+ Bag['ParamList'],
1461
+ Bag['State'],
1462
+ Bag['ScreenOptions'],
1463
+ Bag['EventMap'],
1464
+ Bag['NavigationList'][keyof Bag['ParamList']],
1465
+ Bag['Navigator']
1466
+ >,
1467
+ 'children'
1468
+ >
1469
+ >
1470
+ >;
1471
+
1472
+ type TypedNavigatorStaticDecorated<Bag extends NavigatorTypeBagBase, Config> = {
1473
+ getComponent: () => React.ComponentType<{}>;
1474
+ config: Config;
1475
+ } & PrivateValueStore<
1476
+ [Bag['ParamList'], Bag['NavigationList'], unknown, unknown]
1477
+ >;
1478
+
1479
+ type TypedNavigatorStatic<
1480
+ in out Bag extends NavigatorTypeBagBase,
1481
+ in out Config,
1482
+ > = {
1483
+ config: Config;
1484
+ with: (
1485
+ Component: React.ComponentType<{
1486
+ Navigator: TypedNavigatorStaticComponent<Bag>;
1487
+ }>
1488
+ ) => TypedNavigatorStaticDecorated<Bag, Config>;
1489
+ getComponent: () => TypedNavigatorStaticComponent<Bag>;
1490
+ };
1491
+
1492
+ export type TypedNavigator<
1493
+ Bag extends NavigatorTypeBagBase,
1494
+ Config = unknown,
1495
+ Nesting = unknown,
1496
+ > = (undefined extends Config
1497
+ ? TypedNavigatorInternal<
1498
+ Bag['ParamList'],
1499
+ Bag['State'],
1500
+ Bag['ScreenOptions'],
1501
+ Bag['EventMap'],
1502
+ Bag['NavigationList'],
1503
+ Bag['Navigator']
1504
+ >
1505
+ : TypedNavigatorStatic<Bag, Config>) &
1506
+ PrivateValueStore<
1507
+ [Bag['ParamList'], Bag['NavigationList'], unknown, Nesting]
1508
+ >;
1509
+
1510
+ type TypedNavigatorInternal<
1511
+ in out ParamList extends ParamListBase,
1512
+ in out State extends NavigationState,
1513
+ in out ScreenOptions extends {},
1514
+ in out EventMap extends EventMapBase,
1515
+ in out NavigationList extends NavigationListBase<ParamList>,
1516
+ in out Navigator extends React.ComponentType<any>,
1131
1517
  > = {
1132
1518
  /**
1133
1519
  * Navigator component which manages the child screens.
1134
1520
  */
1135
1521
  Navigator: React.ComponentType<
1136
- Omit<
1137
- React.ComponentProps<Navigator>,
1138
- keyof DefaultNavigatorOptions<any, any, any, any, any>
1139
- > &
1140
- DefaultNavigatorOptions<
1141
- ParamList,
1142
- State,
1143
- ScreenOptions,
1144
- EventMap,
1145
- NavigationList[keyof ParamList]
1146
- >
1522
+ NavigatorProps<
1523
+ ParamList,
1524
+ State,
1525
+ ScreenOptions,
1526
+ EventMap,
1527
+ NavigationList[keyof ParamList],
1528
+ Navigator
1529
+ >
1147
1530
  >;
1148
1531
  /**
1149
1532
  * Component used for grouping multiple route configuration.
@@ -1166,40 +1549,59 @@ type TypedNavigatorInternal<
1166
1549
  ) => null;
1167
1550
  };
1168
1551
 
1169
- export type NavigatorScreenParams<ParamList extends {}> =
1552
+ declare const NavigatorScreenParamsSymbol: unique symbol;
1553
+
1554
+ type NavigatorScreenParamsBrand<T extends {}> = {
1555
+ // Preserve the original generic for inference without affecting assignability.
1556
+ // - The symbol key hides the property from normal object usage
1557
+ // - The actual type is intersected for inference
1558
+ // - The `any` makes the property effectively `any` for assignability
1559
+ readonly [NavigatorScreenParamsSymbol]?: any & { readonly type: T };
1560
+ };
1561
+
1562
+ type NavigatorScreenParamsForParamList<ParamList extends {}> =
1170
1563
  | {
1171
1564
  screen?: never;
1172
1565
  params?: never;
1173
1566
  merge?: never;
1174
1567
  initial?: never;
1175
1568
  pop?: never;
1176
- path?: string;
1569
+ preload?: never;
1570
+ path?: string | undefined;
1177
1571
  state: PartialState<NavigationState> | NavigationState | undefined;
1178
1572
  }
1179
1573
  | {
1180
1574
  [RouteName in keyof ParamList]: undefined extends ParamList[RouteName]
1181
1575
  ? {
1182
1576
  screen: RouteName;
1183
- params?: ParamList[RouteName];
1184
- merge?: boolean;
1185
- initial?: boolean;
1186
- path?: string;
1187
- pop?: boolean;
1577
+ params?: ParamList[RouteName] | undefined;
1578
+ merge?: boolean | undefined;
1579
+ initial?: boolean | undefined;
1580
+ path?: string | undefined;
1581
+ pop?: boolean | undefined;
1582
+ preload?: boolean | undefined;
1188
1583
  state?: never;
1189
1584
  }
1190
1585
  : {
1191
1586
  screen: RouteName;
1192
1587
  params: ParamList[RouteName];
1193
- merge?: boolean;
1194
- initial?: boolean;
1195
- path?: string;
1196
- pop?: boolean;
1588
+ merge?: boolean | undefined;
1589
+ initial?: boolean | undefined;
1590
+ path?: string | undefined;
1591
+ pop?: boolean | undefined;
1592
+ preload?: boolean | undefined;
1197
1593
  state?: never;
1198
1594
  };
1199
1595
  }[keyof ParamList];
1200
1596
 
1597
+ export type NavigatorScreenParams<ParamList extends {}> =
1598
+ NavigatorScreenParamsForParamList<ParamListForNavigator<ParamList>> &
1599
+ NavigatorScreenParamsBrand<ParamList>;
1600
+
1201
1601
  type ParseConfig<Params> = {
1202
- [K in keyof Params]?: (value: string) => Params[K];
1602
+ [K in keyof Params]?:
1603
+ | ((value: string) => Params[K])
1604
+ | StandardSchemaV1<string | string[] | null | undefined, Params[K]>;
1203
1605
  };
1204
1606
 
1205
1607
  type StringifyConfig<Params> = {
@@ -1217,9 +1619,9 @@ type PathConfigAlias<Params> = {
1217
1619
  * By default, paths are relating to the path config on the parent screen.
1218
1620
  * If `exact` is set to `true`, the parent path configuration is not used.
1219
1621
  */
1220
- exact?: boolean;
1622
+ exact?: boolean | undefined;
1221
1623
  /**
1222
- * An object mapping the param name to a function which parses the param value.
1624
+ * An object mapping the param name to a parser function or a Standard Schema.
1223
1625
  *
1224
1626
  * @example
1225
1627
  * ```js
@@ -1229,14 +1631,30 @@ type PathConfigAlias<Params> = {
1229
1631
  * }
1230
1632
  * ```
1231
1633
  */
1232
- parse?: ParseConfig<Params>;
1634
+ parse?: ParseConfig<Params> | undefined;
1635
+ /**
1636
+ * Whether this path can resolve to multiple routes.
1637
+ * Both routes should specify `shared: true` for this to work.
1638
+ * By default, a path can only resolve to one route.
1639
+ *
1640
+ * This is useful when same screen used in multiple navigators,
1641
+ * e.g. tabs with stacks containing profile screen in each stack.
1642
+ *
1643
+ * The path defined first will be the canonical path.
1644
+ */
1645
+ shared?: boolean | undefined;
1233
1646
  };
1234
1647
 
1235
1648
  export type PathConfig<Params> = FlatType<
1236
- Partial<PathConfigAlias<Params>> & {
1649
+ Partial<Omit<PathConfigAlias<Params>, 'path'>> & {
1650
+ /**
1651
+ * Path string to match against.
1652
+ * e.g. `/users/:id` will match `/users/1` and extract `id` param as `1`.
1653
+ */
1654
+ path?: string | undefined;
1237
1655
  /**
1238
1656
  * An object mapping the param name to a function which converts the param value to a string.
1239
- * By default, all params are converted to strings using `String(value)`.
1657
+ * By default, arrays and null are preserved for query params, and other values are converted using `String(value)`.
1240
1658
  * Keys are constrained to valid param names when Params type is provided.
1241
1659
  *
1242
1660
  * @example
@@ -1246,25 +1664,32 @@ export type PathConfig<Params> = FlatType<
1246
1664
  * }
1247
1665
  * ```
1248
1666
  */
1249
- stringify?: StringifyConfig<Params>;
1667
+ stringify?: StringifyConfig<Params> | undefined;
1250
1668
  /**
1251
1669
  * Additional path alias that will be matched to the same screen.
1252
1670
  */
1253
- alias?: (string | PathConfigAlias<Params>)[];
1671
+ alias?: (string | PathConfigAlias<Params>)[] | undefined;
1254
1672
  } & (NonNullable<Params> extends NavigatorScreenParams<infer ParamList>
1255
- ? {
1256
- /**
1257
- * Path configuration for child screens.
1258
- */
1259
- screens?: PathConfigMap<ParamList>;
1260
- /**
1261
- * Name of the initial route to use for the navigator when the path matches.
1262
- */
1263
- initialRouteName?: keyof ParamList;
1264
- }
1673
+ ? ParamListForNavigator<ParamList> extends infer ChildParamList extends {}
1674
+ ? {
1675
+ /**
1676
+ * Path configuration for child screens.
1677
+ */
1678
+ screens?: PathConfigMap<ChildParamList> | undefined;
1679
+ /**
1680
+ * Name of the initial route to use for the navigator when the path matches.
1681
+ */
1682
+ initialRouteName?:
1683
+ | Extract<keyof ChildParamList, string>
1684
+ | undefined;
1685
+ }
1686
+ : {}
1265
1687
  : {})
1266
1688
  >;
1267
1689
 
1268
1690
  export type PathConfigMap<ParamList extends {}> = {
1269
- [RouteName in keyof ParamList]?: string | PathConfig<ParamList[RouteName]>;
1691
+ [RouteName in keyof ParamList]?:
1692
+ | string
1693
+ | PathConfig<ParamList[RouteName]>
1694
+ | undefined;
1270
1695
  };