@react-navigation/core 8.0.0-alpha.1 → 8.0.0-alpha.11

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 (163) hide show
  1. package/lib/module/BaseNavigationContainer.js +14 -7
  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/NavigationBuilderContext.js +1 -0
  6. package/lib/module/NavigationBuilderContext.js.map +1 -1
  7. package/lib/module/NavigationIndependentTree.js +8 -4
  8. package/lib/module/NavigationIndependentTree.js.map +1 -1
  9. package/lib/module/NavigationProvider.js +14 -3
  10. package/lib/module/NavigationProvider.js.map +1 -1
  11. package/lib/module/NavigationStateContext.js.map +1 -1
  12. package/lib/module/PreventRemoveProvider.js +3 -3
  13. package/lib/module/PreventRemoveProvider.js.map +1 -1
  14. package/lib/module/SceneView.js +46 -56
  15. package/lib/module/SceneView.js.map +1 -1
  16. package/lib/module/StaticNavigation.js +34 -4
  17. package/lib/module/StaticNavigation.js.map +1 -1
  18. package/lib/module/createNavigatorFactory.js +22 -1
  19. package/lib/module/createNavigatorFactory.js.map +1 -1
  20. package/lib/module/getPathFromState.js +25 -3
  21. package/lib/module/getPathFromState.js.map +1 -1
  22. package/lib/module/getStateFromPath.js +158 -73
  23. package/lib/module/getStateFromPath.js.map +1 -1
  24. package/lib/module/getStateFromRouteParams.js +24 -0
  25. package/lib/module/getStateFromRouteParams.js.map +1 -0
  26. package/lib/module/index.js +1 -1
  27. package/lib/module/index.js.map +1 -1
  28. package/lib/module/theming/useTheme.js +1 -1
  29. package/lib/module/theming/useTheme.js.map +1 -1
  30. package/lib/module/types.js.map +1 -1
  31. package/lib/module/useCurrentRender.js +1 -1
  32. package/lib/module/useCurrentRender.js.map +1 -1
  33. package/lib/module/useDescriptors.js +12 -43
  34. package/lib/module/useDescriptors.js.map +1 -1
  35. package/lib/module/useFocusEvents.js +1 -1
  36. package/lib/module/useFocusEvents.js.map +1 -1
  37. package/lib/module/useFocusedListenersChildrenAdapter.js +1 -1
  38. package/lib/module/useFocusedListenersChildrenAdapter.js.map +1 -1
  39. package/lib/module/useIsFocused.js +7 -12
  40. package/lib/module/useIsFocused.js.map +1 -1
  41. package/lib/module/useNavigationBuilder.js +84 -38
  42. package/lib/module/useNavigationBuilder.js.map +1 -1
  43. package/lib/module/useNavigationCache.js +14 -56
  44. package/lib/module/useNavigationCache.js.map +1 -1
  45. package/lib/module/useNavigationHelpers.js +1 -1
  46. package/lib/module/useNavigationHelpers.js.map +1 -1
  47. package/lib/module/useNavigationIndependentTree.js +1 -1
  48. package/lib/module/useNavigationIndependentTree.js.map +1 -1
  49. package/lib/module/useNavigationState.js +4 -2
  50. package/lib/module/useNavigationState.js.map +1 -1
  51. package/lib/module/useOnAction.js +1 -1
  52. package/lib/module/useOnAction.js.map +1 -1
  53. package/lib/module/useOnGetState.js +2 -2
  54. package/lib/module/useOnGetState.js.map +1 -1
  55. package/lib/module/useOnPreventRemove.js +2 -2
  56. package/lib/module/useOnPreventRemove.js.map +1 -1
  57. package/lib/module/useOnRouteFocus.js +1 -1
  58. package/lib/module/useOnRouteFocus.js.map +1 -1
  59. package/lib/module/useOptionsGetters.js +2 -2
  60. package/lib/module/useOptionsGetters.js.map +1 -1
  61. package/lib/module/usePreventRemoveContext.js +1 -1
  62. package/lib/module/usePreventRemoveContext.js.map +1 -1
  63. package/lib/module/useRegisterNavigator.js +1 -1
  64. package/lib/module/useRegisterNavigator.js.map +1 -1
  65. package/lib/module/useScheduleUpdate.js +1 -1
  66. package/lib/module/useScheduleUpdate.js.map +1 -1
  67. package/lib/module/useStateForPath.js +1 -1
  68. package/lib/module/useStateForPath.js.map +1 -1
  69. package/lib/typescript/src/BaseNavigationContainer.d.ts +6 -3
  70. package/lib/typescript/src/BaseNavigationContainer.d.ts.map +1 -1
  71. package/lib/typescript/src/ConsumedParamsContext.d.ts +8 -0
  72. package/lib/typescript/src/ConsumedParamsContext.d.ts.map +1 -0
  73. package/lib/typescript/src/NavigationBuilderContext.d.ts +11 -5
  74. package/lib/typescript/src/NavigationBuilderContext.d.ts.map +1 -1
  75. package/lib/typescript/src/NavigationFocusedRouteStateContext.d.ts +4 -4
  76. package/lib/typescript/src/NavigationFocusedRouteStateContext.d.ts.map +1 -1
  77. package/lib/typescript/src/NavigationIndependentTree.d.ts.map +1 -1
  78. package/lib/typescript/src/NavigationProvider.d.ts +4 -4
  79. package/lib/typescript/src/NavigationProvider.d.ts.map +1 -1
  80. package/lib/typescript/src/NavigationStateContext.d.ts +3 -3
  81. package/lib/typescript/src/NavigationStateContext.d.ts.map +1 -1
  82. package/lib/typescript/src/SceneView.d.ts.map +1 -1
  83. package/lib/typescript/src/StaticContainer.d.ts +1 -1
  84. package/lib/typescript/src/StaticContainer.d.ts.map +1 -1
  85. package/lib/typescript/src/StaticNavigation.d.ts +39 -24
  86. package/lib/typescript/src/StaticNavigation.d.ts.map +1 -1
  87. package/lib/typescript/src/createNavigatorFactory.d.ts +1 -1
  88. package/lib/typescript/src/createNavigatorFactory.d.ts.map +1 -1
  89. package/lib/typescript/src/findFocusedRoute.d.ts +3 -3
  90. package/lib/typescript/src/findFocusedRoute.d.ts.map +1 -1
  91. package/lib/typescript/src/getActionFromState.d.ts +3 -3
  92. package/lib/typescript/src/getActionFromState.d.ts.map +1 -1
  93. package/lib/typescript/src/getPathFromState.d.ts +2 -2
  94. package/lib/typescript/src/getPathFromState.d.ts.map +1 -1
  95. package/lib/typescript/src/getStateFromPath.d.ts +3 -3
  96. package/lib/typescript/src/getStateFromPath.d.ts.map +1 -1
  97. package/lib/typescript/src/getStateFromRouteParams.d.ts +3 -0
  98. package/lib/typescript/src/getStateFromRouteParams.d.ts.map +1 -0
  99. package/lib/typescript/src/index.d.ts +2 -1
  100. package/lib/typescript/src/index.d.ts.map +1 -1
  101. package/lib/typescript/src/types.d.ts +144 -82
  102. package/lib/typescript/src/types.d.ts.map +1 -1
  103. package/lib/typescript/src/useDescriptors.d.ts +12 -25
  104. package/lib/typescript/src/useDescriptors.d.ts.map +1 -1
  105. package/lib/typescript/src/useIsFocused.d.ts +3 -0
  106. package/lib/typescript/src/useIsFocused.d.ts.map +1 -1
  107. package/lib/typescript/src/useNavigation.d.ts.map +1 -1
  108. package/lib/typescript/src/useNavigationBuilder.d.ts +20 -29
  109. package/lib/typescript/src/useNavigationBuilder.d.ts.map +1 -1
  110. package/lib/typescript/src/useNavigationCache.d.ts +2 -42
  111. package/lib/typescript/src/useNavigationCache.d.ts.map +1 -1
  112. package/lib/typescript/src/useNavigationHelpers.d.ts +18 -16
  113. package/lib/typescript/src/useNavigationHelpers.d.ts.map +1 -1
  114. package/lib/typescript/src/useNavigationState.d.ts.map +1 -1
  115. package/lib/typescript/src/useOnAction.d.ts +6 -6
  116. package/lib/typescript/src/useOnAction.d.ts.map +1 -1
  117. package/lib/typescript/src/useOnRouteFocus.d.ts +6 -6
  118. package/lib/typescript/src/useOnRouteFocus.d.ts.map +1 -1
  119. package/lib/typescript/src/useRouteCache.d.ts +2 -2
  120. package/lib/typescript/src/useScheduleUpdate.d.ts.map +1 -1
  121. package/lib/typescript/src/utilities.d.ts +42 -3
  122. package/lib/typescript/src/utilities.d.ts.map +1 -1
  123. package/package.json +20 -18
  124. package/src/BaseNavigationContainer.tsx +332 -326
  125. package/src/ConsumedParamsContext.tsx +10 -0
  126. package/src/NavigationBuilderContext.tsx +14 -8
  127. package/src/NavigationFocusedRouteStateContext.tsx +4 -4
  128. package/src/NavigationIndependentTree.tsx +8 -5
  129. package/src/NavigationProvider.tsx +17 -3
  130. package/src/NavigationStateContext.tsx +5 -6
  131. package/src/PreventRemoveProvider.tsx +3 -3
  132. package/src/SceneView.tsx +58 -56
  133. package/src/StaticNavigation.tsx +121 -51
  134. package/src/createNavigatorFactory.tsx +35 -4
  135. package/src/findFocusedRoute.tsx +3 -3
  136. package/src/getActionFromState.tsx +7 -7
  137. package/src/getPathFromState.tsx +53 -9
  138. package/src/getStateFromPath.tsx +255 -97
  139. package/src/getStateFromRouteParams.tsx +60 -0
  140. package/src/index.tsx +1 -1
  141. package/src/theming/useTheme.tsx +1 -1
  142. package/src/types.tsx +330 -187
  143. package/src/useCurrentRender.tsx +1 -1
  144. package/src/useDescriptors.tsx +13 -48
  145. package/src/useFocusEvents.tsx +1 -1
  146. package/src/useFocusedListenersChildrenAdapter.tsx +1 -1
  147. package/src/useIsFocused.tsx +14 -21
  148. package/src/useNavigation.tsx +2 -2
  149. package/src/useNavigationBuilder.tsx +131 -49
  150. package/src/useNavigationCache.tsx +12 -73
  151. package/src/useNavigationHelpers.tsx +1 -1
  152. package/src/useNavigationIndependentTree.tsx +1 -1
  153. package/src/useNavigationState.tsx +6 -4
  154. package/src/useOnAction.tsx +8 -8
  155. package/src/useOnGetState.tsx +2 -2
  156. package/src/useOnPreventRemove.tsx +2 -2
  157. package/src/useOnRouteFocus.tsx +10 -12
  158. package/src/useOptionsGetters.tsx +2 -2
  159. package/src/usePreventRemoveContext.tsx +1 -1
  160. package/src/useRegisterNavigator.tsx +1 -1
  161. package/src/useScheduleUpdate.tsx +1 -3
  162. package/src/useStateForPath.tsx +1 -1
  163. package/src/utilities.tsx +94 -4
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,15 +55,10 @@ 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
64
- >
65
- ? ParamList
58
+ RootNavigator extends PrivateValueStore<[infer ParamList, any, any]>
59
+ ? ParamList extends {}
60
+ ? ParamList
61
+ : {}
66
62
  : {};
67
63
 
68
64
  export type DefaultNavigatorOptions<
@@ -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
+ RouteProp<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: RouteProp<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: RouteProp<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,12 +173,12 @@ 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
184
  export type EventMapCore<State extends NavigationState> = {
@@ -189,7 +197,10 @@ export type EventArg<
189
197
  * Type of the event (e.g. `focus`, `blur`)
190
198
  */
191
199
  readonly type: EventName;
192
- readonly target?: string;
200
+ /**
201
+ * Key of the route which received the event.
202
+ */
203
+ readonly target?: string | undefined;
193
204
  } & (CanPreventDefault extends true
194
205
  ? {
195
206
  /**
@@ -203,15 +214,14 @@ export type EventArg<
203
214
  }
204
215
  : {}) &
205
216
  (undefined extends Data
206
- ? { readonly data?: Readonly<Data> }
217
+ ? { readonly data?: Readonly<Data> | undefined }
207
218
  : { readonly data: Readonly<Data> });
208
219
 
209
220
  export type EventListenerCallback<
210
221
  EventMap extends EventMapBase,
211
222
  EventName extends keyof EventMap,
212
- EventCanPreventDefault extends
213
- | boolean
214
- | undefined = EventMap[EventName]['canPreventDefault'],
223
+ EventCanPreventDefault extends boolean | undefined =
224
+ EventMap[EventName]['canPreventDefault'],
215
225
  > = (
216
226
  e: EventArg<
217
227
  EventName,
@@ -311,12 +321,18 @@ type NavigationHelpersCommon<
311
321
  ? [
312
322
  screen: RouteName,
313
323
  params?: ParamList[RouteName],
314
- options?: { merge?: boolean; pop?: boolean },
324
+ options?: {
325
+ merge?: boolean | undefined;
326
+ pop?: boolean | undefined;
327
+ },
315
328
  ]
316
329
  : [
317
330
  screen: RouteName,
318
331
  params: ParamList[RouteName],
319
- options?: { merge?: boolean; pop?: boolean },
332
+ options?: {
333
+ merge?: boolean | undefined;
334
+ pop?: boolean | undefined;
335
+ },
320
336
  ]
321
337
  : never
322
338
  ): void;
@@ -335,9 +351,9 @@ type NavigationHelpersCommon<
335
351
  ? {
336
352
  name: RouteName;
337
353
  params: ParamList[RouteName];
338
- path?: string;
339
- merge?: boolean;
340
- pop?: boolean;
354
+ path?: string | undefined;
355
+ merge?: boolean | undefined;
356
+ pop?: boolean | undefined;
341
357
  }
342
358
  : never
343
359
  ): void;
@@ -347,12 +363,25 @@ type NavigationHelpersCommon<
347
363
  *
348
364
  * @param screen Name of the route to preload.
349
365
  * @param [params] Params object for the route.
366
+ * @param [options.reuse] Whether to reuse a matching route or preloaded route.
350
367
  */
351
368
  preload<RouteName extends keyof ParamList>(
352
369
  ...args: RouteName extends unknown
353
370
  ? undefined extends ParamList[RouteName]
354
- ? [screen: RouteName, params?: ParamList[RouteName]]
355
- : [screen: RouteName, params: ParamList[RouteName]]
371
+ ? [
372
+ screen: RouteName,
373
+ params?: ParamList[RouteName],
374
+ options?: {
375
+ reuse?: boolean | undefined;
376
+ },
377
+ ]
378
+ : [
379
+ screen: RouteName,
380
+ params: ParamList[RouteName],
381
+ options?: {
382
+ reuse?: boolean | undefined;
383
+ },
384
+ ]
356
385
  : never
357
386
  ): void;
358
387
 
@@ -446,23 +475,27 @@ export type NavigationContainerProps = {
446
475
  /**
447
476
  * Initial state object for the navigation tree.
448
477
  */
449
- initialState?: InitialState;
478
+ initialState?: InitialState | undefined;
450
479
  /**
451
480
  * Callback which is called with the latest navigation state when it changes.
452
481
  */
453
- onStateChange?: (state: Readonly<NavigationState> | undefined) => void;
482
+ onStateChange?:
483
+ | ((state: Readonly<NavigationState> | undefined) => void)
484
+ | undefined;
454
485
  /**
455
486
  * Callback which is called after the navigation tree mounts.
456
487
  */
457
- onReady?: () => void;
488
+ onReady?: (() => void) | undefined;
458
489
  /**
459
490
  * Callback which is called when an action is not handled.
460
491
  */
461
- onUnhandledAction?: (action: Readonly<NavigationAction>) => void;
492
+ onUnhandledAction?:
493
+ | ((action: Readonly<NavigationAction>) => void)
494
+ | undefined;
462
495
  /**
463
496
  * Theme object for the UI elements.
464
497
  */
465
- theme?: Theme;
498
+ theme?: Theme | undefined;
466
499
  /**
467
500
  * Children elements to render.
468
501
  */
@@ -522,31 +555,60 @@ export type CompositeNavigationProp<
522
555
  * Param list from both navigation objects needs to be combined
523
556
  * For example, we should be able to navigate to screens in both A and B
524
557
  */
525
- (A extends NavigationHelpersCommon<infer T> ? T : never) &
526
- (B extends NavigationHelpersCommon<infer U> ? U : never),
558
+ ParamListOfNavigationProp<A> & ParamListOfNavigationProp<B>,
527
559
  /**
528
560
  * The route name should refer to the route name specified in the first type
529
- * Ideally it should work for any of them, but it's not possible to infer that way
530
561
  */
531
- A extends NavigationProp<any, infer R> ? R : string,
562
+ RouteNameOfNavigationProp<A>,
532
563
  /**
533
564
  * The type of state should refer to the state specified in the first type
534
565
  */
535
- A extends NavigationProp<any, any, infer S> ? S : NavigationState,
566
+ StateOfNavigationProp<A>,
536
567
  /**
537
568
  * Screen options should refer to the options specified in the first type
538
569
  */
539
- A extends NavigationProp<any, any, any, infer O> ? O : {},
570
+ ScreenOptionsOfNavigationProp<A>,
540
571
  /**
541
- * Event consumer config should refer to the config specified in the first type
542
- * This allows typechecking `addListener`/`removeListener`
572
+ * Event map should refer to the config specified in the first type
543
573
  */
544
- A extends NavigationProp<any, any, any, any, infer E> ? E : {}
574
+ EventMapOfNavigationProp<A>
545
575
  >,
546
576
  'getParent'
547
577
  > & {
548
578
  getParent: A['getParent'] & B['getParent'];
549
- };
579
+ } & // Mapped types don't preserve protected members
580
+ // So `Omit` drops `PrivateValueStore`'s `protected` brand
581
+ // We add it back so this can be used for type inference
582
+ PrivateValueStore<
583
+ [
584
+ ParamListOfNavigationProp<A> & ParamListOfNavigationProp<B>,
585
+ RouteNameOfNavigationProp<A>,
586
+ EventMapOfNavigationProp<A>,
587
+ ]
588
+ >;
589
+
590
+ type ParamListOfNavigationProp<T> =
591
+ T extends PrivateValueStore<[infer ParamList, any, any]> ? ParamList : never;
592
+
593
+ type RouteNameOfNavigationProp<T> =
594
+ T extends PrivateValueStore<[any, infer RouteName, any]>
595
+ ? RouteName
596
+ : unknown;
597
+
598
+ type StateOfNavigationProp<T> = T extends {
599
+ getState: () => infer State extends NavigationState;
600
+ }
601
+ ? State
602
+ : NavigationState;
603
+
604
+ type ScreenOptionsOfNavigationProp<T> = T extends {
605
+ setOptions: (options: Partial<infer ScreenOptions>) => void;
606
+ }
607
+ ? ScreenOptions
608
+ : {};
609
+
610
+ type EventMapOfNavigationProp<T> =
611
+ T extends PrivateValueStore<[any, any, infer EventMap]> ? EventMap : {};
550
612
 
551
613
  export type CompositeScreenProps<
552
614
  A extends {
@@ -576,7 +638,7 @@ export type ScreenLayoutArgs<
576
638
 
577
639
  export type Descriptor<
578
640
  ScreenOptions extends {},
579
- Navigation extends NavigationProp<any, any, any, any, any>,
641
+ Navigation extends NavigationProp<ParamListBase, any, any, any, any>,
580
642
  Route extends RouteProp<any, any>,
581
643
  > = {
582
644
  /**
@@ -629,16 +691,16 @@ export type RouteConfigComponent<
629
691
  * React component to render for this screen.
630
692
  */
631
693
  component: ScreenComponentType<ParamList, RouteName>;
632
- getComponent?: never;
633
- children?: never;
694
+ getComponent?: never | undefined;
695
+ children?: never | undefined;
634
696
  }
635
697
  | {
636
698
  /**
637
699
  * Lazily get a React component to render for this screen.
638
700
  */
639
701
  getComponent: () => ScreenComponentType<ParamList, RouteName>;
640
- component?: never;
641
- children?: never;
702
+ component?: never | undefined;
703
+ children?: never | undefined;
642
704
  }
643
705
  | {
644
706
  /**
@@ -648,8 +710,8 @@ export type RouteConfigComponent<
648
710
  route: RouteProp<ParamList, RouteName>;
649
711
  navigation: any;
650
712
  }) => React.ReactNode;
651
- component?: never;
652
- getComponent?: never;
713
+ component?: never | undefined;
714
+ getComponent?: never | undefined;
653
715
  };
654
716
 
655
717
  export type RouteConfigProps<
@@ -665,7 +727,7 @@ export type RouteConfigProps<
665
727
  * If the key changes, existing screens with this name will be removed or reset.
666
728
  * Useful when we have some common screens and have conditional rendering.
667
729
  */
668
- navigationKey?: string;
730
+ navigationKey?: string | undefined;
669
731
 
670
732
  /**
671
733
  * Route name of this screen.
@@ -676,31 +738,39 @@ export type RouteConfigProps<
676
738
  * Navigator options for this screen.
677
739
  */
678
740
  options?:
679
- | ScreenOptions
680
- | ((props: {
681
- route: RouteProp<ParamList, RouteName>;
682
- navigation: Navigation;
683
- theme: Theme;
684
- }) => ScreenOptions);
741
+ | (
742
+ | ScreenOptions
743
+ | ((props: {
744
+ route: RouteProp<ParamList, RouteName>;
745
+ navigation: Navigation;
746
+ theme: Theme;
747
+ }) => ScreenOptions)
748
+ )
749
+ | undefined;
685
750
 
686
751
  /**
687
752
  * Event listeners for this screen.
688
753
  */
689
754
  listeners?:
690
- | ScreenListeners<State, EventMap>
691
- | ((props: {
692
- route: RouteProp<ParamList, RouteName>;
693
- navigation: Navigation;
694
- }) => ScreenListeners<State, EventMap>);
755
+ | (
756
+ | ScreenListeners<State, EventMap>
757
+ | ((props: {
758
+ route: RouteProp<ParamList, RouteName>;
759
+ navigation: Navigation;
760
+ }) => ScreenListeners<State, EventMap>)
761
+ )
762
+ | undefined;
695
763
 
696
764
  /**
697
765
  * Layout for this screen.
698
766
  * Useful for wrapping the screen with custom containers.
699
767
  * e.g. for styling, error boundaries, suspense, etc.
700
768
  */
701
- layout?: (
702
- props: ScreenLayoutArgs<ParamList, RouteName, ScreenOptions, Navigation>
703
- ) => React.ReactElement;
769
+ layout?:
770
+ | ((
771
+ props: ScreenLayoutArgs<ParamList, RouteName, ScreenOptions, Navigation>
772
+ ) => React.ReactElement)
773
+ | undefined;
704
774
 
705
775
  /**
706
776
  * Function to return an unique ID for this screen.
@@ -708,16 +778,18 @@ export type RouteConfigProps<
708
778
  * For a given screen name, there will always be only one screen corresponding to an ID.
709
779
  * If `undefined` is returned, it acts same as no `getId` being specified.
710
780
  */
711
- getId?: ({
712
- params,
713
- }: {
714
- params: Readonly<ParamList[RouteName]>;
715
- }) => string | undefined;
781
+ getId?:
782
+ | (({
783
+ params,
784
+ }: {
785
+ params: Readonly<ParamList[RouteName]>;
786
+ }) => string | undefined)
787
+ | undefined;
716
788
 
717
789
  /**
718
790
  * Initial params object for the route.
719
791
  */
720
- initialParams?: Partial<ParamList[RouteName]>;
792
+ initialParams?: Partial<ParamList[RouteName]> | undefined;
721
793
  };
722
794
 
723
795
  export type RouteConfig<
@@ -746,35 +818,41 @@ export type RouteGroupConfig<
746
818
  * Optional key for the screens in this group.
747
819
  * If the key changes, all existing screens in this group will be removed or reset.
748
820
  */
749
- navigationKey?: string;
821
+ navigationKey?: string | undefined;
750
822
 
751
823
  /**
752
824
  * Navigator options for this screen.
753
825
  */
754
826
  screenOptions?:
755
- | ScreenOptions
756
- | ((props: {
757
- route: RouteProp<ParamList, keyof ParamList>;
758
- navigation: Navigation;
759
- theme: Theme;
760
- }) => ScreenOptions);
827
+ | (
828
+ | ScreenOptions
829
+ | ((props: {
830
+ route: RouteProp<ParamList, keyof ParamList>;
831
+ navigation: Navigation;
832
+ theme: Theme;
833
+ }) => ScreenOptions)
834
+ )
835
+ | undefined;
761
836
 
762
837
  /**
763
838
  * Layout for the screens inside the group.
764
839
  * This will override the `screenLayout` of parent group or navigator.
765
840
  */
766
841
  screenLayout?:
767
- | ((
768
- props: ScreenLayoutArgs<
769
- ParamList,
770
- keyof ParamList,
771
- ScreenOptions,
772
- Navigation
773
- >
774
- ) => React.ReactElement)
775
- | {
776
- // FIXME: TypeScript doesn't seem to infer `navigation` correctly without this
777
- };
842
+ | (
843
+ | ((
844
+ props: ScreenLayoutArgs<
845
+ ParamList,
846
+ keyof ParamList,
847
+ ScreenOptions,
848
+ Navigation
849
+ >
850
+ ) => React.ReactElement)
851
+ | {
852
+ // FIXME: TypeScript doesn't seem to infer `navigation` correctly without this
853
+ }
854
+ )
855
+ | undefined;
778
856
 
779
857
  /**
780
858
  * Children React Elements to extract the route configuration from.
@@ -826,6 +904,31 @@ export type NavigationContainerEventMap = {
826
904
  stack: string | undefined;
827
905
  };
828
906
  };
907
+ /**
908
+ * Event that fires when an event is emitted.
909
+ * Only intended for debugging purposes, don't use it for app logic.
910
+ * This event will be emitted after all listeners have been called.
911
+ */
912
+ __unsafe_event__: {
913
+ data: {
914
+ /**
915
+ * The type of the event that was emitted.
916
+ */
917
+ type: string;
918
+ /**
919
+ * The data object passed when emitting the event.
920
+ */
921
+ data: unknown;
922
+ /**
923
+ * The key of the target route which received the event.
924
+ */
925
+ target: string | undefined;
926
+ /**
927
+ * Whether `event.preventDefault()` was called on this event.
928
+ */
929
+ defaultPrevented: boolean | undefined;
930
+ };
931
+ };
829
932
  };
830
933
 
831
934
  /**
@@ -1026,40 +1129,39 @@ type NavigationListForGroups<ParentList, Groups> =
1026
1129
  >
1027
1130
  : {};
1028
1131
 
1029
- export type NavigationContainerRef<ParamList extends {}> =
1030
- NavigationHelpers<ParamList> &
1031
- EventConsumer<NavigationContainerEventMap> & {
1032
- /**
1033
- * Reset the navigation state of the root navigator to the provided state.
1034
- *
1035
- * @param state Navigation state object.
1036
- */
1037
- resetRoot(state?: PartialState<NavigationState> | NavigationState): void;
1038
- /**
1039
- * Get the rehydrated navigation state of the navigation tree.
1040
- */
1041
- getRootState(): NavigationState;
1042
- /**
1043
- * Get the currently focused navigation route.
1044
- */
1045
- getCurrentRoute(): MaybeParamListRoute<ParamList> | undefined;
1046
- /**
1047
- * Get the currently focused route's options.
1048
- */
1049
- getCurrentOptions(): object | undefined;
1050
- /**
1051
- * Whether the navigation container is ready to handle actions.
1052
- */
1053
- isReady(): boolean;
1054
- /**
1055
- * Stub function for setOptions on navigation object for use with useNavigation.
1056
- */
1057
- setOptions(): never;
1058
- /**
1059
- * Stub function for getParent on navigation object for use with useNavigation.
1060
- */
1061
- getParent(): undefined;
1062
- };
1132
+ export type NavigationContainerRef<ParamList extends {}> = Omit<
1133
+ NavigationHelpers<ParamList>,
1134
+ keyof NavigationHelpersRoute<{}>
1135
+ > &
1136
+ NavigationHelpersRoute<{}> &
1137
+ EventConsumer<NavigationContainerEventMap> & {
1138
+ /**
1139
+ * Reset the navigation state of the root navigator to the provided state.
1140
+ *
1141
+ * @param state Navigation state object.
1142
+ */
1143
+ resetRoot(state?: PartialState<NavigationState> | NavigationState): void;
1144
+ /**
1145
+ * Get the rehydrated navigation state of the navigation tree.
1146
+ */
1147
+ getRootState(): NavigationState;
1148
+ /**
1149
+ * Get the currently focused navigation route.
1150
+ */
1151
+ getCurrentRoute(): MaybeParamListRoute<ParamList> | undefined;
1152
+ /**
1153
+ * Get the currently focused route's options.
1154
+ */
1155
+ getCurrentOptions(): object | undefined;
1156
+ /**
1157
+ * Whether the navigation container is ready to handle actions.
1158
+ */
1159
+ isReady(): boolean;
1160
+ /**
1161
+ * Stub function for setOptions on navigation object for use with useNavigation.
1162
+ */
1163
+ setOptions(): never;
1164
+ };
1063
1165
 
1064
1166
  export type NavigationContainerRefWithCurrent<ParamList extends {}> =
1065
1167
  NavigationContainerRef<ParamList> & {
@@ -1079,18 +1181,51 @@ export type NavigatorTypeBagBase = {
1079
1181
  Navigator: React.ComponentType<any>;
1080
1182
  };
1081
1183
 
1184
+ type TypedNavigatorComponent<Bag extends NavigatorTypeBagBase> =
1185
+ React.ComponentType<
1186
+ Omit<
1187
+ React.ComponentProps<
1188
+ TypedNavigatorInternal<
1189
+ Bag['ParamList'],
1190
+ Bag['State'],
1191
+ Bag['ScreenOptions'],
1192
+ Bag['EventMap'],
1193
+ Bag['NavigationList'],
1194
+ Bag['Navigator']
1195
+ >['Navigator']
1196
+ >,
1197
+ 'children'
1198
+ >
1199
+ >;
1200
+
1201
+ type TypedNavigatorStaticDecorated<Bag extends NavigatorTypeBagBase, Config> = {
1202
+ getComponent: () => React.ComponentType<{}>;
1203
+ config: Config;
1204
+ } & PrivateValueStore<[Bag['ParamList'], Bag['NavigationList'], unknown]>;
1205
+
1206
+ type TypedNavigatorStatic<Bag extends NavigatorTypeBagBase, Config> = {
1207
+ config: Config;
1208
+ with: (
1209
+ Component: React.ComponentType<{
1210
+ Navigator: TypedNavigatorComponent<Bag>;
1211
+ }>
1212
+ ) => TypedNavigatorStaticDecorated<Bag, Config>;
1213
+ getComponent: () => TypedNavigatorComponent<Bag>;
1214
+ };
1215
+
1082
1216
  export type TypedNavigator<
1083
1217
  Bag extends NavigatorTypeBagBase,
1084
1218
  Config = unknown,
1085
- > = TypedNavigatorInternal<
1086
- Bag['ParamList'],
1087
- Bag['State'],
1088
- Bag['ScreenOptions'],
1089
- Bag['EventMap'],
1090
- Bag['NavigationList'],
1091
- Bag['Navigator']
1092
- > &
1093
- (undefined extends Config ? {} : { config: Config }) &
1219
+ > = (undefined extends Config
1220
+ ? TypedNavigatorInternal<
1221
+ Bag['ParamList'],
1222
+ Bag['State'],
1223
+ Bag['ScreenOptions'],
1224
+ Bag['EventMap'],
1225
+ Bag['NavigationList'],
1226
+ Bag['Navigator']
1227
+ >
1228
+ : TypedNavigatorStatic<Bag, Config>) &
1094
1229
  PrivateValueStore<[Bag['ParamList'], Bag['NavigationList'], unknown]>;
1095
1230
 
1096
1231
  type TypedNavigatorInternal<
@@ -1145,33 +1280,38 @@ export type NavigatorScreenParams<ParamList extends {}> =
1145
1280
  merge?: never;
1146
1281
  initial?: never;
1147
1282
  pop?: never;
1148
- path?: string;
1283
+ preload?: never;
1284
+ path?: string | undefined;
1149
1285
  state: PartialState<NavigationState> | NavigationState | undefined;
1150
1286
  }
1151
1287
  | {
1152
1288
  [RouteName in keyof ParamList]: undefined extends ParamList[RouteName]
1153
1289
  ? {
1154
1290
  screen: RouteName;
1155
- params?: ParamList[RouteName];
1156
- merge?: boolean;
1157
- initial?: boolean;
1158
- path?: string;
1159
- pop?: boolean;
1291
+ params?: ParamList[RouteName] | undefined;
1292
+ merge?: boolean | undefined;
1293
+ initial?: boolean | undefined;
1294
+ path?: string | undefined;
1295
+ pop?: boolean | undefined;
1296
+ preload?: boolean | undefined;
1160
1297
  state?: never;
1161
1298
  }
1162
1299
  : {
1163
1300
  screen: RouteName;
1164
1301
  params: ParamList[RouteName];
1165
- merge?: boolean;
1166
- initial?: boolean;
1167
- path?: string;
1168
- pop?: boolean;
1302
+ merge?: boolean | undefined;
1303
+ initial?: boolean | undefined;
1304
+ path?: string | undefined;
1305
+ pop?: boolean | undefined;
1306
+ preload?: boolean | undefined;
1169
1307
  state?: never;
1170
1308
  };
1171
1309
  }[keyof ParamList];
1172
1310
 
1173
1311
  type ParseConfig<Params> = {
1174
- [K in keyof Params]?: (value: string) => Params[K];
1312
+ [K in keyof Params]?:
1313
+ | ((value: string) => Params[K])
1314
+ | StandardSchemaV1<string | string[] | null | undefined, Params[K]>;
1175
1315
  };
1176
1316
 
1177
1317
  type StringifyConfig<Params> = {
@@ -1189,9 +1329,9 @@ type PathConfigAlias<Params> = {
1189
1329
  * By default, paths are relating to the path config on the parent screen.
1190
1330
  * If `exact` is set to `true`, the parent path configuration is not used.
1191
1331
  */
1192
- exact?: boolean;
1332
+ exact?: boolean | undefined;
1193
1333
  /**
1194
- * An object mapping the param name to a function which parses the param value.
1334
+ * An object mapping the param name to a parser function or a Standard Schema.
1195
1335
  *
1196
1336
  * @example
1197
1337
  * ```js
@@ -1201,7 +1341,7 @@ type PathConfigAlias<Params> = {
1201
1341
  * }
1202
1342
  * ```
1203
1343
  */
1204
- parse?: ParseConfig<Params>;
1344
+ parse?: ParseConfig<Params> | undefined;
1205
1345
  };
1206
1346
 
1207
1347
  export type PathConfig<Params> = FlatType<
@@ -1218,25 +1358,28 @@ export type PathConfig<Params> = FlatType<
1218
1358
  * }
1219
1359
  * ```
1220
1360
  */
1221
- stringify?: StringifyConfig<Params>;
1361
+ stringify?: StringifyConfig<Params> | undefined;
1222
1362
  /**
1223
1363
  * Additional path alias that will be matched to the same screen.
1224
1364
  */
1225
- alias?: (string | PathConfigAlias<Params>)[];
1365
+ alias?: (string | PathConfigAlias<Params>)[] | undefined;
1226
1366
  } & (NonNullable<Params> extends NavigatorScreenParams<infer ParamList>
1227
1367
  ? {
1228
1368
  /**
1229
1369
  * Path configuration for child screens.
1230
1370
  */
1231
- screens?: PathConfigMap<ParamList>;
1371
+ screens?: PathConfigMap<ParamList> | undefined;
1232
1372
  /**
1233
1373
  * Name of the initial route to use for the navigator when the path matches.
1234
1374
  */
1235
- initialRouteName?: keyof ParamList;
1375
+ initialRouteName?: Extract<keyof ParamList, string> | undefined;
1236
1376
  }
1237
1377
  : {})
1238
1378
  >;
1239
1379
 
1240
1380
  export type PathConfigMap<ParamList extends {}> = {
1241
- [RouteName in keyof ParamList]?: string | PathConfig<ParamList[RouteName]>;
1381
+ [RouteName in keyof ParamList]?:
1382
+ | string
1383
+ | PathConfig<ParamList[RouteName]>
1384
+ | undefined;
1242
1385
  };