@react-navigation/core 7.5.0 → 7.6.1

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 (34) hide show
  1. package/lib/commonjs/StaticNavigation.js.map +1 -1
  2. package/lib/commonjs/package.json +1 -0
  3. package/lib/commonjs/types.js.map +1 -1
  4. package/lib/module/StaticNavigation.js.map +1 -1
  5. package/lib/module/package.json +1 -0
  6. package/lib/module/types.js.map +1 -1
  7. package/lib/typescript/commonjs/src/types.d.ts +39 -33
  8. package/lib/typescript/commonjs/src/types.d.ts.map +1 -1
  9. package/lib/typescript/commonjs/src/useComponent.d.ts +1 -1
  10. package/lib/typescript/commonjs/src/useComponent.d.ts.map +1 -1
  11. package/lib/typescript/commonjs/src/useDescriptors.d.ts +24 -18
  12. package/lib/typescript/commonjs/src/useDescriptors.d.ts.map +1 -1
  13. package/lib/typescript/commonjs/src/useNavigationBuilder.d.ts +36 -27
  14. package/lib/typescript/commonjs/src/useNavigationBuilder.d.ts.map +1 -1
  15. package/lib/typescript/commonjs/src/useNavigationCache.d.ts +12 -9
  16. package/lib/typescript/commonjs/src/useNavigationCache.d.ts.map +1 -1
  17. package/lib/typescript/commonjs/src/useNavigationHelpers.d.ts +12 -9
  18. package/lib/typescript/commonjs/src/useNavigationHelpers.d.ts.map +1 -1
  19. package/lib/typescript/module/src/types.d.ts +39 -33
  20. package/lib/typescript/module/src/types.d.ts.map +1 -1
  21. package/lib/typescript/module/src/useComponent.d.ts +1 -1
  22. package/lib/typescript/module/src/useComponent.d.ts.map +1 -1
  23. package/lib/typescript/module/src/useDescriptors.d.ts +24 -18
  24. package/lib/typescript/module/src/useDescriptors.d.ts.map +1 -1
  25. package/lib/typescript/module/src/useNavigationBuilder.d.ts +36 -27
  26. package/lib/typescript/module/src/useNavigationBuilder.d.ts.map +1 -1
  27. package/lib/typescript/module/src/useNavigationCache.d.ts +12 -9
  28. package/lib/typescript/module/src/useNavigationCache.d.ts.map +1 -1
  29. package/lib/typescript/module/src/useNavigationHelpers.d.ts +12 -9
  30. package/lib/typescript/module/src/useNavigationHelpers.d.ts.map +1 -1
  31. package/package.json +4 -4
  32. package/src/StaticNavigation.tsx +1 -1
  33. package/src/types.tsx +53 -51
  34. package/src/useComponent.tsx +1 -1
package/src/types.tsx CHANGED
@@ -23,21 +23,6 @@ declare global {
23
23
 
24
24
  type Keyof<T extends {}> = Extract<keyof T, string>;
25
25
 
26
- type ScreenParamsPair<
27
- ParamList extends ParamListBase,
28
- RouteName extends keyof ParamList,
29
- > = {
30
- // First we use a mapped type to get an union of screen & params pairs
31
- // Then we pick the pair which matches the RouteName
32
- // Mapped type is used instead of just ParamList[RouteName]
33
- // Otherwise it'll result in union of all params leading to incorrect types
34
- [Screen in keyof ParamList]: undefined extends ParamList[Screen] // Params are either undefined or a union with undefined
35
- ?
36
- | [screen: Screen] // if the params are optional, we don't have to provide it
37
- | [screen: Screen, params: ParamList[Screen]]
38
- : [screen: Screen, params: ParamList[Screen]];
39
- }[RouteName];
40
-
41
26
  export type DefaultNavigatorOptions<
42
27
  ParamList extends ParamListBase,
43
28
  NavigatorID extends string | undefined,
@@ -110,7 +95,7 @@ export type DefaultNavigatorOptions<
110
95
 
111
96
  /**
112
97
  * A function returning overrides for the underlying router used by the navigator.
113
- * The overrides will be shallow merged into the original router.
98
+ * The overrides will be shallow merged onto the original router.
114
99
  * It receives the original router as an argument to the function.
115
100
  *
116
101
  * This must be a pure function and cannot reference outside dynamic variables.
@@ -256,21 +241,30 @@ type NavigationHelpersCommon<
256
241
  * Navigate to a screen in the current or parent navigator.
257
242
  * If we're already on the screen, update the params instead.
258
243
  *
259
- * @param name Name of the route to navigate to.
244
+ * @param screen Name of the route to navigate to.
260
245
  * @param [params] Params object for the route.
261
- * @param [merge] Whether to merge the params onto the route.
246
+ * @param [options.merge] Whether to merge the params onto the route. Defaults to `false`.
247
+ * @param [options.pop] Whether to pop routes in a stack to go back to the matching route. Defaults to `false`.
262
248
  */
263
249
  navigate<RouteName extends keyof ParamList>(
264
- ...args: {
265
- [Screen in keyof ParamList]: undefined extends ParamList[Screen]
266
- ?
267
- | [screen: Screen]
268
- | [screen: Screen, params: ParamList[Screen]]
269
- | [screen: Screen, params: ParamList[Screen], merge: boolean]
270
- :
271
- | [screen: Screen, params: ParamList[Screen]]
272
- | [screen: Screen, params: ParamList[Screen], merge: boolean];
273
- }[RouteName]
250
+ ...args: // This condition allows us to iterate over a union type
251
+ // This is to avoid getting a union of all the params from `ParamList[RouteName]`,
252
+ // which will get our types all mixed up if a union RouteName is passed in.
253
+ RouteName extends unknown
254
+ ? // This condition checks if the params are optional,
255
+ // which means it's either undefined or a union with undefined
256
+ undefined extends ParamList[RouteName]
257
+ ? [
258
+ screen: RouteName,
259
+ params?: ParamList[RouteName],
260
+ options?: { merge?: boolean; pop?: boolean },
261
+ ]
262
+ : [
263
+ screen: RouteName,
264
+ params: ParamList[RouteName],
265
+ options?: { merge?: boolean; pop?: boolean },
266
+ ]
267
+ : never
274
268
  ): void;
275
269
 
276
270
  /**
@@ -279,19 +273,19 @@ type NavigationHelpersCommon<
279
273
  * @param options.name Name of the route to navigate to.
280
274
  * @param [options.params] Params object for the route.
281
275
  * @param [options.path] Path to associate the route with (e.g. for deep links).
282
- * @param [options.merge] Whether to merge the params onto the route.
283
- * @param [options.pop] Whether to pop routes in a stack to go back to the matching route.
276
+ * @param [options.merge] Whether to merge the params onto the route. Defaults to `false`.
277
+ * @param [options.pop] Whether to pop routes in a stack to go back to the matching route. Defaults to `false`.
284
278
  */
285
279
  navigate<RouteName extends keyof ParamList>(
286
- options: {
287
- [Screen in keyof ParamList]: {
288
- name: Screen;
289
- params: ParamList[Screen];
290
- path?: string;
291
- merge?: boolean;
292
- pop?: boolean;
293
- };
294
- }[RouteName]
280
+ options: RouteName extends unknown
281
+ ? {
282
+ name: RouteName;
283
+ params: ParamList[RouteName];
284
+ path?: string;
285
+ merge?: boolean;
286
+ pop?: boolean;
287
+ }
288
+ : never
295
289
  ): void;
296
290
 
297
291
  /**
@@ -299,11 +293,15 @@ type NavigationHelpersCommon<
299
293
  *
300
294
  * @deprecated Use `navigate` instead.
301
295
  *
302
- * @param name Name of the route to navigate to.
296
+ * @param screen Name of the route to navigate to.
303
297
  * @param [params] Params object for the route.
304
298
  */
305
299
  navigateDeprecated<RouteName extends keyof ParamList>(
306
- ...args: ScreenParamsPair<ParamList, RouteName>
300
+ ...args: RouteName extends unknown
301
+ ? undefined extends ParamList[RouteName]
302
+ ? [screen: RouteName, params?: ParamList[RouteName]]
303
+ : [screen: RouteName, params: ParamList[RouteName]]
304
+ : never
307
305
  ): void;
308
306
 
309
307
  /**
@@ -314,23 +312,27 @@ type NavigationHelpersCommon<
314
312
  * @param options Object with `name` for the route to navigate to, and a `params` object.
315
313
  */
316
314
  navigateDeprecated<RouteName extends keyof ParamList>(
317
- options: {
318
- [Screen in keyof ParamList]: {
319
- name: Screen;
320
- params: ParamList[Screen];
321
- merge?: boolean;
322
- };
323
- }[RouteName]
315
+ options: RouteName extends unknown
316
+ ? {
317
+ name: RouteName;
318
+ params: ParamList[RouteName];
319
+ merge?: boolean;
320
+ }
321
+ : never
324
322
  ): void;
325
323
 
326
324
  /**
327
325
  * Preloads the route in current navigation tree.
328
326
  *
329
- * @param name Name of the route to navigate to.
327
+ * @param screen Name of the route to preload.
330
328
  * @param [params] Params object for the route.
331
329
  */
332
330
  preload<RouteName extends keyof ParamList>(
333
- ...args: ScreenParamsPair<ParamList, RouteName>
331
+ ...args: RouteName extends unknown
332
+ ? undefined extends ParamList[RouteName]
333
+ ? [screen: RouteName, params?: ParamList[RouteName]]
334
+ : [screen: RouteName, params: ParamList[RouteName]]
335
+ : never
334
336
  ): void;
335
337
 
336
338
  /**
@@ -549,7 +551,7 @@ export type Descriptor<
549
551
  /**
550
552
  * Render the component associated with this route.
551
553
  */
552
- render(): JSX.Element;
554
+ render(): React.JSX.Element;
553
555
 
554
556
  /**
555
557
  * Options for the route.
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
 
3
- type Render = (children: React.ReactNode) => JSX.Element;
3
+ type Render = (children: React.ReactNode) => React.JSX.Element;
4
4
 
5
5
  type Props = {
6
6
  render: Render;