@react-navigation/core 7.17.5 → 7.19.0

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 (79) hide show
  1. package/lib/module/StaticNavigation.js +6 -0
  2. package/lib/module/StaticNavigation.js.map +1 -1
  3. package/lib/module/index.js +1 -1
  4. package/lib/module/index.js.map +1 -1
  5. package/lib/module/useNavigationBuilder.js +6 -1
  6. package/lib/module/useNavigationBuilder.js.map +1 -1
  7. package/lib/typescript/src/BaseNavigationContainer.d.ts +1 -1
  8. package/lib/typescript/src/BaseNavigationContainer.d.ts.map +1 -1
  9. package/lib/typescript/src/Group.d.ts +1 -1
  10. package/lib/typescript/src/Group.d.ts.map +1 -1
  11. package/lib/typescript/src/NavigationBuilderContext.d.ts +1 -1
  12. package/lib/typescript/src/NavigationBuilderContext.d.ts.map +1 -1
  13. package/lib/typescript/src/NavigationContainerRefContext.d.ts +1 -1
  14. package/lib/typescript/src/NavigationContainerRefContext.d.ts.map +1 -1
  15. package/lib/typescript/src/NavigationContext.d.ts +1 -1
  16. package/lib/typescript/src/NavigationContext.d.ts.map +1 -1
  17. package/lib/typescript/src/NavigationHelpersContext.d.ts +1 -1
  18. package/lib/typescript/src/NavigationHelpersContext.d.ts.map +1 -1
  19. package/lib/typescript/src/NavigationProvider.d.ts +1 -1
  20. package/lib/typescript/src/NavigationProvider.d.ts.map +1 -1
  21. package/lib/typescript/src/SceneView.d.ts +1 -1
  22. package/lib/typescript/src/SceneView.d.ts.map +1 -1
  23. package/lib/typescript/src/Screen.d.ts +1 -1
  24. package/lib/typescript/src/Screen.d.ts.map +1 -1
  25. package/lib/typescript/src/StaticNavigation.d.ts +59 -3
  26. package/lib/typescript/src/StaticNavigation.d.ts.map +1 -1
  27. package/lib/typescript/src/createNavigationContainerRef.d.ts +1 -1
  28. package/lib/typescript/src/createNavigationContainerRef.d.ts.map +1 -1
  29. package/lib/typescript/src/getActionFromState.d.ts +1 -1
  30. package/lib/typescript/src/getActionFromState.d.ts.map +1 -1
  31. package/lib/typescript/src/getPathFromState.d.ts +1 -1
  32. package/lib/typescript/src/getPathFromState.d.ts.map +1 -1
  33. package/lib/typescript/src/getStateFromPath.d.ts +1 -1
  34. package/lib/typescript/src/getStateFromPath.d.ts.map +1 -1
  35. package/lib/typescript/src/index.d.ts +34 -34
  36. package/lib/typescript/src/index.d.ts.map +1 -1
  37. package/lib/typescript/src/useChildListeners.d.ts +3 -3
  38. package/lib/typescript/src/useChildListeners.d.ts.map +1 -1
  39. package/lib/typescript/src/useCurrentRender.d.ts +1 -1
  40. package/lib/typescript/src/useCurrentRender.d.ts.map +1 -1
  41. package/lib/typescript/src/useDescriptors.d.ts +7 -7
  42. package/lib/typescript/src/useDescriptors.d.ts.map +1 -1
  43. package/lib/typescript/src/useEventEmitter.d.ts +1 -1
  44. package/lib/typescript/src/useEventEmitter.d.ts.map +1 -1
  45. package/lib/typescript/src/useFocusEvents.d.ts +2 -2
  46. package/lib/typescript/src/useFocusEvents.d.ts.map +1 -1
  47. package/lib/typescript/src/useFocusedListenersChildrenAdapter.d.ts +2 -2
  48. package/lib/typescript/src/useFocusedListenersChildrenAdapter.d.ts.map +1 -1
  49. package/lib/typescript/src/useKeyedChildListeners.d.ts +3 -3
  50. package/lib/typescript/src/useKeyedChildListeners.d.ts.map +1 -1
  51. package/lib/typescript/src/useNavigation.d.ts +1 -1
  52. package/lib/typescript/src/useNavigation.d.ts.map +1 -1
  53. package/lib/typescript/src/useNavigationBuilder.d.ts +11 -11
  54. package/lib/typescript/src/useNavigationBuilder.d.ts.map +1 -1
  55. package/lib/typescript/src/useNavigationCache.d.ts +4 -4
  56. package/lib/typescript/src/useNavigationCache.d.ts.map +1 -1
  57. package/lib/typescript/src/useNavigationContainerRef.d.ts +1 -1
  58. package/lib/typescript/src/useNavigationContainerRef.d.ts.map +1 -1
  59. package/lib/typescript/src/useNavigationHelpers.d.ts +3 -3
  60. package/lib/typescript/src/useNavigationHelpers.d.ts.map +1 -1
  61. package/lib/typescript/src/useOnAction.d.ts +3 -3
  62. package/lib/typescript/src/useOnAction.d.ts.map +1 -1
  63. package/lib/typescript/src/useOnGetState.d.ts +1 -1
  64. package/lib/typescript/src/useOnGetState.d.ts.map +1 -1
  65. package/lib/typescript/src/useOnPreventRemove.d.ts +3 -3
  66. package/lib/typescript/src/useOnPreventRemove.d.ts.map +1 -1
  67. package/lib/typescript/src/useOptionsGetters.d.ts +1 -1
  68. package/lib/typescript/src/useOptionsGetters.d.ts.map +1 -1
  69. package/lib/typescript/src/usePreventRemoveContext.d.ts +1 -1
  70. package/lib/typescript/src/useRoute.d.ts +1 -1
  71. package/lib/typescript/src/useRoute.d.ts.map +1 -1
  72. package/lib/typescript/src/useRouteCache.d.ts +1 -1
  73. package/lib/typescript/src/useRouteCache.d.ts.map +1 -1
  74. package/lib/typescript/src/useStateForPath.d.ts +1 -1
  75. package/lib/typescript/src/useStateForPath.d.ts.map +1 -1
  76. package/package.json +4 -4
  77. package/src/StaticNavigation.tsx +117 -1
  78. package/src/index.tsx +2 -0
  79. package/src/useNavigationBuilder.tsx +5 -0
@@ -6,12 +6,14 @@ import type {
6
6
  DefaultNavigatorOptions,
7
7
  EventMapBase,
8
8
  NavigationListBase,
9
+ NavigatorScreenParams,
9
10
  NavigatorTypeBagBase,
10
11
  PathConfig,
11
12
  PathConfigMap,
12
13
  RouteConfigComponent,
13
14
  RouteConfigProps,
14
15
  RouteGroupConfig,
16
+ StaticParamList,
15
17
  } from './types';
16
18
  import { useRoute } from './useRoute';
17
19
 
@@ -34,6 +36,86 @@ type StaticRouteConfig<
34
36
  > &
35
37
  RouteConfigComponent<ParamList, RouteName>;
36
38
 
39
+ type StaticScreenConfigBrand = {
40
+ readonly __reactNavigationStaticScreenConfig: true;
41
+ };
42
+
43
+ type UnknownToUndefined<T> = unknown extends T ? undefined : T;
44
+
45
+ type ParamsForStaticScreenComponent<T> =
46
+ T extends React.ComponentType<{ route: { params: infer P } }>
47
+ ? UnknownToUndefined<P>
48
+ : undefined;
49
+
50
+ type ParamsForStaticScreen<T> =
51
+ T extends StaticNavigation<any, any, any>
52
+ ? NavigatorScreenParams<StaticParamList<T>> | undefined
53
+ : ParamsForStaticScreenComponent<T>;
54
+
55
+ type ParamListForStaticScreenConfig<Params> = {
56
+ Screen: Params extends object | undefined ? Params : never;
57
+ };
58
+
59
+ type StaticScreenConfigLinking =
60
+ | PathConfig<ParamListBase>
61
+ | string
62
+ | null
63
+ | undefined;
64
+
65
+ type StaticScreenConfigScreen =
66
+ | React.ComponentType<any>
67
+ | StaticNavigation<any, any, any>;
68
+
69
+ type StaticScreenConfig<
70
+ Screen extends StaticScreenConfigScreen,
71
+ State extends NavigationState,
72
+ ScreenOptions extends {},
73
+ EventMap extends EventMapBase,
74
+ Navigation,
75
+ Params = ParamsForStaticScreen<Screen>,
76
+ > = Omit<
77
+ StaticRouteConfig<
78
+ ParamListForStaticScreenConfig<Params>,
79
+ 'Screen',
80
+ State,
81
+ ScreenOptions,
82
+ EventMap,
83
+ Navigation
84
+ >,
85
+ 'name' | 'component' | 'getComponent' | 'children'
86
+ > & {
87
+ /**
88
+ * Callback to determine whether the screen should be rendered or not.
89
+ * This can be useful for conditional rendering of screens,
90
+ * e.g. - if you want to render a different screen for logged in users.
91
+ *
92
+ * You can use a custom hook to use custom logic to determine the return value.
93
+ *
94
+ * @example
95
+ * ```js
96
+ * if: useIsLoggedIn
97
+ * ```
98
+ */
99
+ if?: () => boolean;
100
+ /**
101
+ * Linking config for the screen.
102
+ * This can be a string to specify the path, or an object with more options.
103
+ *
104
+ * @example
105
+ * ```js
106
+ * linking: {
107
+ * path: 'profile/:id',
108
+ * exact: true,
109
+ * },
110
+ * ```
111
+ */
112
+ linking?: StaticScreenConfigLinking;
113
+ /**
114
+ * Static navigation config or Component to render for the screen.
115
+ */
116
+ screen: Screen;
117
+ };
118
+
37
119
  export type StaticConfigScreens<
38
120
  ParamList extends ParamListBase,
39
121
  State extends NavigationState,
@@ -85,7 +167,13 @@ export type StaticConfigScreens<
85
167
  * Static navigation config or Component to render for the screen.
86
168
  */
87
169
  screen: StaticNavigation<any, any, any> | React.ComponentType<any>;
88
- });
170
+ })
171
+ | StaticScreenConfigBranded;
172
+ };
173
+
174
+ type StaticScreenConfigBranded = StaticScreenConfigBrand & {
175
+ screen: StaticScreenConfigScreen;
176
+ if?: () => boolean;
89
177
  };
90
178
 
91
179
  export type StaticConfigGroup<
@@ -229,6 +317,34 @@ export type StaticNavigation<NavigatorProps, GroupProps, ScreenProps> =
229
317
  Screen: React.ComponentType<ScreenProps>;
230
318
  };
231
319
 
320
+ export type StaticScreenFactory<Bag extends NavigatorTypeBagBase> = <
321
+ const Screen extends StaticScreenConfigScreen,
322
+ >(
323
+ config: StaticScreenConfig<
324
+ Screen,
325
+ Bag['State'],
326
+ Bag['ScreenOptions'],
327
+ Bag['EventMap'],
328
+ Bag['NavigationList'][keyof Bag['ParamList']]
329
+ >
330
+ ) => StaticScreenConfig<
331
+ Screen,
332
+ Bag['State'],
333
+ Bag['ScreenOptions'],
334
+ Bag['EventMap'],
335
+ Bag['NavigationList'][keyof Bag['ParamList']]
336
+ > &
337
+ StaticScreenConfigBrand;
338
+
339
+ /**
340
+ * Helper to create a typed `createXScreen` for static configuration.
341
+ */
342
+ export function createScreenFactory<
343
+ TypeBag extends NavigatorTypeBagBase,
344
+ >(): StaticScreenFactory<TypeBag> {
345
+ return ((config: unknown) => config) as never;
346
+ }
347
+
232
348
  const MemoizedScreen = React.memo(
233
349
  <T extends React.ComponentType<any>>({ component }: { component: T }) => {
234
350
  const route = useRoute();
package/src/index.tsx CHANGED
@@ -21,10 +21,12 @@ export { PreventRemoveProvider } from './PreventRemoveProvider';
21
21
  export {
22
22
  createComponentForStaticNavigationDeprecated as createComponentForStaticNavigation,
23
23
  createPathConfigForStaticNavigation,
24
+ createScreenFactory,
24
25
  type StaticConfig,
25
26
  type StaticConfigGroup,
26
27
  type StaticConfigScreens,
27
28
  type StaticNavigation,
29
+ type StaticScreenFactory,
28
30
  type StaticScreenProps,
29
31
  } from './StaticNavigation';
30
32
  export { ThemeContext } from './theming/ThemeContext';
@@ -781,6 +781,11 @@ export function useNavigationBuilder<
781
781
  setCurrentState(undefined);
782
782
  stateCleanupRef.current = true;
783
783
  }
784
+
785
+ // Reset so that StrictMode's second mount re-propagates state correctly.
786
+ // Without this, the guard above sees the same reference and skips setState,
787
+ // causing the initial state to be lost after cleanup wipes the container state.
788
+ lastNotifiedStateRef.current = null;
784
789
  };
785
790
  // eslint-disable-next-line react-hooks/exhaustive-deps
786
791
  }, []);