@react-navigation/core 6.4.5 → 7.0.0-alpha.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 (135) hide show
  1. package/README.md +1 -1
  2. package/lib/commonjs/BaseNavigationContainer.js +44 -33
  3. package/lib/commonjs/BaseNavigationContainer.js.map +1 -1
  4. package/lib/commonjs/DeprecatedNavigationInChildContext.js +16 -0
  5. package/lib/commonjs/DeprecatedNavigationInChildContext.js.map +1 -0
  6. package/lib/commonjs/NavigationIndependentTree.js +33 -0
  7. package/lib/commonjs/NavigationIndependentTree.js.map +1 -0
  8. package/lib/commonjs/NavigationIndependentTreeContext.js +16 -0
  9. package/lib/commonjs/NavigationIndependentTreeContext.js.map +1 -0
  10. package/lib/commonjs/StaticNavigation.js +160 -0
  11. package/lib/commonjs/StaticNavigation.js.map +1 -0
  12. package/lib/commonjs/createNavigatorFactory.js +16 -7
  13. package/lib/commonjs/createNavigatorFactory.js.map +1 -1
  14. package/lib/commonjs/getActionFromState.js.map +1 -1
  15. package/lib/commonjs/index.js +52 -0
  16. package/lib/commonjs/index.js.map +1 -1
  17. package/lib/commonjs/types.js.map +1 -1
  18. package/lib/commonjs/useDescriptors.js +21 -18
  19. package/lib/commonjs/useDescriptors.js.map +1 -1
  20. package/lib/commonjs/useNavigationBuilder.js +1 -1
  21. package/lib/commonjs/useNavigationBuilder.js.map +1 -1
  22. package/lib/commonjs/useNavigationCache.js +9 -7
  23. package/lib/commonjs/useNavigationCache.js.map +1 -1
  24. package/lib/commonjs/useNavigationIndependentTree.js +15 -0
  25. package/lib/commonjs/useNavigationIndependentTree.js.map +1 -0
  26. package/lib/commonjs/useOnAction.js +11 -7
  27. package/lib/commonjs/useOnAction.js.map +1 -1
  28. package/lib/module/BaseNavigationContainer.js +44 -33
  29. package/lib/module/BaseNavigationContainer.js.map +1 -1
  30. package/lib/module/DeprecatedNavigationInChildContext.js +8 -0
  31. package/lib/module/DeprecatedNavigationInChildContext.js.map +1 -0
  32. package/lib/module/NavigationIndependentTree.js +25 -0
  33. package/lib/module/NavigationIndependentTree.js.map +1 -0
  34. package/lib/module/NavigationIndependentTreeContext.js +8 -0
  35. package/lib/module/NavigationIndependentTreeContext.js.map +1 -0
  36. package/lib/module/StaticNavigation.js +156 -0
  37. package/lib/module/StaticNavigation.js.map +1 -0
  38. package/lib/module/createNavigatorFactory.js +16 -7
  39. package/lib/module/createNavigatorFactory.js.map +1 -1
  40. package/lib/module/getActionFromState.js.map +1 -1
  41. package/lib/module/index.js +3 -0
  42. package/lib/module/index.js.map +1 -1
  43. package/lib/module/types.js.map +1 -1
  44. package/lib/module/useDescriptors.js +21 -18
  45. package/lib/module/useDescriptors.js.map +1 -1
  46. package/lib/module/useNavigationBuilder.js +1 -1
  47. package/lib/module/useNavigationBuilder.js.map +1 -1
  48. package/lib/module/useNavigationCache.js +9 -7
  49. package/lib/module/useNavigationCache.js.map +1 -1
  50. package/lib/module/useNavigationIndependentTree.js +6 -0
  51. package/lib/module/useNavigationIndependentTree.js.map +1 -0
  52. package/lib/module/useOnAction.js +11 -7
  53. package/lib/module/useOnAction.js.map +1 -1
  54. package/lib/typescript/src/BaseNavigationContainer.d.ts +2 -0
  55. package/lib/typescript/src/BaseNavigationContainer.d.ts.map +1 -1
  56. package/lib/typescript/src/DeprecatedNavigationInChildContext.d.ts +7 -0
  57. package/lib/typescript/src/DeprecatedNavigationInChildContext.d.ts.map +1 -0
  58. package/lib/typescript/src/EnsureSingleNavigator.d.ts +1 -1
  59. package/lib/typescript/src/EnsureSingleNavigator.d.ts.map +1 -1
  60. package/lib/typescript/src/NavigationBuilderContext.d.ts +9 -9
  61. package/lib/typescript/src/NavigationBuilderContext.d.ts.map +1 -1
  62. package/lib/typescript/src/NavigationIndependentTree.d.ts +8 -0
  63. package/lib/typescript/src/NavigationIndependentTree.d.ts.map +1 -0
  64. package/lib/typescript/src/NavigationIndependentTreeContext.d.ts +7 -0
  65. package/lib/typescript/src/NavigationIndependentTreeContext.d.ts.map +1 -0
  66. package/lib/typescript/src/PreventRemoveContext.d.ts +1 -1
  67. package/lib/typescript/src/PreventRemoveContext.d.ts.map +1 -1
  68. package/lib/typescript/src/PreventRemoveProvider.d.ts +1 -1
  69. package/lib/typescript/src/PreventRemoveProvider.d.ts.map +1 -1
  70. package/lib/typescript/src/SceneView.d.ts +1 -1
  71. package/lib/typescript/src/SceneView.d.ts.map +1 -1
  72. package/lib/typescript/src/StaticNavigation.d.ts +159 -0
  73. package/lib/typescript/src/StaticNavigation.d.ts.map +1 -0
  74. package/lib/typescript/src/createNavigatorFactory.d.ts +8 -2
  75. package/lib/typescript/src/createNavigatorFactory.d.ts.map +1 -1
  76. package/lib/typescript/src/getActionFromState.d.ts +2 -2
  77. package/lib/typescript/src/getActionFromState.d.ts.map +1 -1
  78. package/lib/typescript/src/getPathFromState.d.ts +2 -2
  79. package/lib/typescript/src/getPathFromState.d.ts.map +1 -1
  80. package/lib/typescript/src/getStateFromPath.d.ts +2 -2
  81. package/lib/typescript/src/getStateFromPath.d.ts.map +1 -1
  82. package/lib/typescript/src/index.d.ts +3 -0
  83. package/lib/typescript/src/index.d.ts.map +1 -1
  84. package/lib/typescript/src/types.d.ts +109 -57
  85. package/lib/typescript/src/types.d.ts.map +1 -1
  86. package/lib/typescript/src/useComponent.d.ts +1 -1
  87. package/lib/typescript/src/useComponent.d.ts.map +1 -1
  88. package/lib/typescript/src/useCurrentRender.d.ts +1 -1
  89. package/lib/typescript/src/useCurrentRender.d.ts.map +1 -1
  90. package/lib/typescript/src/useDescriptors.d.ts +11 -9
  91. package/lib/typescript/src/useDescriptors.d.ts.map +1 -1
  92. package/lib/typescript/src/useEventEmitter.d.ts +1 -1
  93. package/lib/typescript/src/useEventEmitter.d.ts.map +1 -1
  94. package/lib/typescript/src/useFocusEffect.d.ts +1 -1
  95. package/lib/typescript/src/useFocusEffect.d.ts.map +1 -1
  96. package/lib/typescript/src/useFocusEvents.d.ts +1 -1
  97. package/lib/typescript/src/useFocusEvents.d.ts.map +1 -1
  98. package/lib/typescript/src/useFocusedListenersChildrenAdapter.d.ts +1 -1
  99. package/lib/typescript/src/useFocusedListenersChildrenAdapter.d.ts.map +1 -1
  100. package/lib/typescript/src/useNavigationBuilder.d.ts +33 -17
  101. package/lib/typescript/src/useNavigationBuilder.d.ts.map +1 -1
  102. package/lib/typescript/src/useNavigationCache.d.ts +4 -4
  103. package/lib/typescript/src/useNavigationCache.d.ts.map +1 -1
  104. package/lib/typescript/src/useNavigationHelpers.d.ts +11 -9
  105. package/lib/typescript/src/useNavigationHelpers.d.ts.map +1 -1
  106. package/lib/typescript/src/useNavigationIndependentTree.d.ts +2 -0
  107. package/lib/typescript/src/useNavigationIndependentTree.d.ts.map +1 -0
  108. package/lib/typescript/src/useNavigationState.d.ts +1 -1
  109. package/lib/typescript/src/useNavigationState.d.ts.map +1 -1
  110. package/lib/typescript/src/useOnAction.d.ts +1 -1
  111. package/lib/typescript/src/useOnAction.d.ts.map +1 -1
  112. package/lib/typescript/src/useOnGetState.d.ts +1 -1
  113. package/lib/typescript/src/useOnGetState.d.ts.map +1 -1
  114. package/lib/typescript/src/useOnPreventRemove.d.ts +1 -1
  115. package/lib/typescript/src/useOnPreventRemove.d.ts.map +1 -1
  116. package/lib/typescript/src/useOnRouteFocus.d.ts +1 -1
  117. package/lib/typescript/src/useOnRouteFocus.d.ts.map +1 -1
  118. package/lib/typescript/src/useOptionsGetters.d.ts +1 -1
  119. package/lib/typescript/src/useOptionsGetters.d.ts.map +1 -1
  120. package/package.json +11 -11
  121. package/src/BaseNavigationContainer.tsx +68 -64
  122. package/src/DeprecatedNavigationInChildContext.tsx +8 -0
  123. package/src/NavigationIndependentTree.tsx +25 -0
  124. package/src/NavigationIndependentTreeContext.tsx +8 -0
  125. package/src/StaticNavigation.tsx +401 -0
  126. package/src/createNavigatorFactory.tsx +38 -9
  127. package/src/getActionFromState.tsx +2 -8
  128. package/src/getPathFromState.tsx +1 -1
  129. package/src/index.tsx +9 -0
  130. package/src/types.tsx +111 -40
  131. package/src/useDescriptors.tsx +24 -19
  132. package/src/useNavigationBuilder.tsx +26 -5
  133. package/src/useNavigationCache.tsx +8 -4
  134. package/src/useNavigationIndependentTree.tsx +7 -0
  135. package/src/useOnAction.tsx +13 -5
@@ -0,0 +1,401 @@
1
+ import type { NavigationState, ParamListBase } from '@react-navigation/routers';
2
+ import * as React from 'react';
3
+
4
+ import fromEntries from './fromEntries';
5
+ import type {
6
+ DefaultNavigatorOptions,
7
+ EventMapBase,
8
+ NavigatorScreenParams,
9
+ PathConfig,
10
+ RouteConfig,
11
+ RouteGroupConfig,
12
+ } from './types';
13
+ import useRoute from './useRoute';
14
+
15
+ /**
16
+ * Flatten a type to remove all type alias names, unions etc.
17
+ * This will show a plain object when hovering over the type.
18
+ */
19
+ type FlatType<T> = { [K in keyof T]: T[K] } & {};
20
+
21
+ /**
22
+ * keyof T doesn't work for union types. We can use distributive conditional types instead.
23
+ * https://www.typescriptlang.org/docs/handbook/2/conditional-types.html#distributive-conditional-types
24
+ */
25
+ type KeysOf<T> = T extends any ? keyof T : never;
26
+
27
+ type UnknownToUndefined<T> = unknown extends T ? undefined : T;
28
+
29
+ type ParamsForScreenComponent<T> = T extends {
30
+ screen: React.ComponentType<{ route: { params: infer P } }>;
31
+ }
32
+ ? P
33
+ : T extends React.ComponentType<{ route: { params: infer P } }>
34
+ ? P
35
+ : undefined;
36
+
37
+ type ParamsForScreen<T> = T extends { screen: StaticNavigation<any, any, any> }
38
+ ? NavigatorScreenParams<StaticParamList<T['screen']>> | undefined
39
+ : T extends StaticNavigation<any, any, any>
40
+ ? NavigatorScreenParams<StaticParamList<T>> | undefined
41
+ : UnknownToUndefined<ParamsForScreenComponent<T>>;
42
+
43
+ type ParamListForScreens<
44
+ Screens extends StaticConfigScreens<
45
+ ParamListBase,
46
+ NavigationState,
47
+ {},
48
+ EventMapBase
49
+ >
50
+ > = {
51
+ [Key in KeysOf<Screens>]: ParamsForScreen<Screens[Key]>;
52
+ };
53
+
54
+ type ParamListForGroups<
55
+ Groups extends
56
+ | Readonly<{
57
+ [key: string]: {
58
+ screens: StaticConfigScreens<
59
+ ParamListBase,
60
+ NavigationState,
61
+ {},
62
+ EventMapBase
63
+ >;
64
+ };
65
+ }>
66
+ | undefined
67
+ > = Groups extends {
68
+ [key: string]: {
69
+ screens: StaticConfigScreens<
70
+ ParamListBase,
71
+ NavigationState,
72
+ {},
73
+ EventMapBase
74
+ >;
75
+ };
76
+ }
77
+ ? ParamListForScreens<Groups[keyof Groups]['screens']>
78
+ : {};
79
+
80
+ type StaticConfigScreens<
81
+ ParamList extends ParamListBase,
82
+ State extends NavigationState,
83
+ ScreenOptions extends {},
84
+ EventMap extends EventMapBase
85
+ > = {
86
+ [key in keyof ParamList]:
87
+ | React.ComponentType<any>
88
+ | StaticNavigation<any, any, any>
89
+ | (Omit<
90
+ RouteConfig<ParamList, keyof ParamList, State, ScreenOptions, EventMap>,
91
+ 'name' | 'component' | 'getComponent' | 'children'
92
+ > & {
93
+ /**
94
+ * Callback to determine whether the screen should be rendered or not.
95
+ * This can be useful for conditional rendering of screens,
96
+ * e.g. - if you want to render a different screen for logged in users.
97
+ *
98
+ * You can use a custom hook to use custom logic to determine the return value.
99
+ *
100
+ * @example
101
+ * ```js
102
+ * if: useIsLoggedIn
103
+ * ```
104
+ */
105
+ if?: () => boolean;
106
+ /**
107
+ * Linking config for the screen.
108
+ * This can be a string to specify the path, or an object with more options.
109
+ *
110
+ * @example
111
+ * ```js
112
+ * linking: {
113
+ * path: 'profile/:id',
114
+ * exact: true,
115
+ * },
116
+ * ```
117
+ */
118
+ linking?:
119
+ | FlatType<
120
+ Pick<
121
+ PathConfig<ParamList>,
122
+ 'path' | 'exact' | 'parse' | 'stringify'
123
+ >
124
+ >
125
+ | string;
126
+ /**
127
+ * Static navigation config or Component to render for the screen.
128
+ */
129
+ screen: StaticNavigation<any, any, any> | React.ComponentType<any>;
130
+ });
131
+ };
132
+
133
+ type GroupConfig<
134
+ ParamList extends ParamListBase,
135
+ State extends NavigationState,
136
+ ScreenOptions extends {},
137
+ EventMap extends EventMapBase
138
+ > = Omit<RouteGroupConfig<ParamList, ScreenOptions>, 'screens' | 'children'> & {
139
+ /**
140
+ * Callback to determine whether the screens in the group should be rendered or not.
141
+ * This can be useful for conditional rendering of group of screens.
142
+ */
143
+ if?: () => boolean;
144
+ /**
145
+ * Static navigation config or Component to render for the screen.
146
+ */
147
+ screens: StaticConfigScreens<ParamList, State, ScreenOptions, EventMap>;
148
+ };
149
+
150
+ export type StaticConfig<
151
+ ParamList extends ParamListBase,
152
+ State extends NavigationState,
153
+ ScreenOptions extends {},
154
+ EventMap extends EventMapBase,
155
+ Navigator extends React.ComponentType<{}>
156
+ > = Omit<
157
+ Omit<
158
+ React.ComponentProps<Navigator>,
159
+ keyof DefaultNavigatorOptions<
160
+ ParamListBase,
161
+ NavigationState,
162
+ {},
163
+ EventMapBase
164
+ >
165
+ > &
166
+ DefaultNavigatorOptions<ParamList, State, ScreenOptions, EventMap>,
167
+ 'screens' | 'children'
168
+ > & {
169
+ /**
170
+ * Screens to render in the navigator and their configuration.
171
+ */
172
+ screens: StaticConfigScreens<ParamList, State, ScreenOptions, EventMap>;
173
+ /**
174
+ * Groups of screens to render in the navigator and their configuration.
175
+ */
176
+ groups?: {
177
+ [key: string]: GroupConfig<ParamList, State, ScreenOptions, EventMap>;
178
+ };
179
+ };
180
+
181
+ /**
182
+ * Props for a screen component which is rendered by a static navigator.
183
+ * Takes the route params as a generic argument.
184
+ */
185
+ export type StaticScreenProps<T extends Record<string, unknown> | undefined> = {
186
+ route: {
187
+ params: T;
188
+ };
189
+ };
190
+
191
+ /**
192
+ * Infer the param list from the static navigation config.
193
+ */
194
+ export type StaticParamList<
195
+ T extends {
196
+ readonly config: {
197
+ readonly screens: Record<string, any>;
198
+ readonly groups?: {
199
+ [key: string]: {
200
+ screens: Record<string, any>;
201
+ };
202
+ };
203
+ };
204
+ }
205
+ > = FlatType<
206
+ ParamListForScreens<T['config']['screens']> &
207
+ ParamListForGroups<T['config']['groups']>
208
+ >;
209
+
210
+ export type StaticNavigation<NavigatorProps, GroupProps, ScreenProps> = {
211
+ Navigator: React.ComponentType<NavigatorProps>;
212
+ Group: React.ComponentType<GroupProps>;
213
+ Screen: React.ComponentType<ScreenProps>;
214
+ config: StaticConfig<
215
+ ParamListBase,
216
+ NavigationState,
217
+ {},
218
+ EventMapBase,
219
+ React.ComponentType<any>
220
+ >;
221
+ };
222
+
223
+ const MemoizedScreen = React.memo(
224
+ <T extends React.ComponentType<any>>({ component }: { component: T }) => {
225
+ const route = useRoute();
226
+ const children = React.createElement(component, { route });
227
+
228
+ return children;
229
+ }
230
+ );
231
+
232
+ const getItemsFromScreens = (
233
+ Screen: React.ComponentType<any>,
234
+ screens: StaticConfigScreens<any, any, any, any>
235
+ ) => {
236
+ return Object.entries(screens).map(([name, item]) => {
237
+ let component: React.ComponentType<any> | undefined;
238
+ let props: {} = {};
239
+ let useIf: (() => boolean) | undefined;
240
+
241
+ let isNavigator = false;
242
+
243
+ if ('screen' in item) {
244
+ const { screen, if: _if, ...rest } = item;
245
+
246
+ useIf = _if;
247
+ props = rest;
248
+
249
+ if (typeof screen === 'function') {
250
+ component = screen;
251
+ } else if ('config' in screen) {
252
+ isNavigator = true;
253
+ component = createComponentForStaticNavigation(
254
+ screen,
255
+ `${name}Navigator`
256
+ );
257
+ }
258
+ } else if (typeof item === 'function') {
259
+ component = item;
260
+ } else if ('config' in item) {
261
+ isNavigator = true;
262
+ component = createComponentForStaticNavigation(item, `${name}Navigator`);
263
+ }
264
+
265
+ if (component == null) {
266
+ throw new Error(
267
+ `Couldn't find a 'screen' property for the screen '${name}'. This can happen if you passed 'undefined'. You likely forgot to export your component from the file it's defined in, or mixed up default import and named import when importing.`
268
+ );
269
+ }
270
+
271
+ let element = isNavigator ? (
272
+ React.createElement(component, {})
273
+ ) : (
274
+ <MemoizedScreen component={component} />
275
+ );
276
+
277
+ return () => {
278
+ const shouldRender = useIf == null || useIf();
279
+
280
+ if (!shouldRender) {
281
+ return null;
282
+ }
283
+
284
+ return (
285
+ <Screen key={name} name={name} {...props}>
286
+ {() => element}
287
+ </Screen>
288
+ );
289
+ };
290
+ });
291
+ };
292
+
293
+ /**
294
+ * Create a component that renders a navigator based on the static configuration.
295
+ *
296
+ * @param tree Static navigation config.
297
+ * @param displayName Name of the component to be displayed in React DevTools.
298
+ * @returns A component which renders the navigator.
299
+ */
300
+ export function createComponentForStaticNavigation(
301
+ tree: StaticNavigation<any, any, any>,
302
+ displayName: string
303
+ ): React.ComponentType<{}> {
304
+ const { Navigator, Group, Screen, config } = tree;
305
+ const { screens, groups, ...rest } = config;
306
+
307
+ const items = getItemsFromScreens(Screen, screens);
308
+
309
+ if (groups) {
310
+ items.push(
311
+ ...Object.entries(groups).map(([key, { if: useIf, ...group }]) => {
312
+ const groupItems = getItemsFromScreens(Screen, group.screens);
313
+
314
+ return () => {
315
+ // Call unconditionally since screen configs may contain `useIf` hooks
316
+ const children = groupItems.map((item) => item());
317
+
318
+ const shouldRender = useIf == null || useIf();
319
+
320
+ if (!shouldRender) {
321
+ return null;
322
+ }
323
+
324
+ return (
325
+ <Group navigationKey={key} {...group} key={key}>
326
+ {children}
327
+ </Group>
328
+ );
329
+ };
330
+ })
331
+ );
332
+ }
333
+
334
+ const NavigatorComponent = () => {
335
+ const children = items.map((item) => item());
336
+
337
+ return <Navigator {...rest}>{children}</Navigator>;
338
+ };
339
+
340
+ NavigatorComponent.displayName = displayName;
341
+
342
+ return NavigatorComponent;
343
+ }
344
+
345
+ /**
346
+ * Create a path config object from a static navigation config for deep linking.
347
+ *
348
+ * @param tree Static navigation config.
349
+ * @returns Path config object to use in linking config.
350
+ *
351
+ * @example
352
+ * ```js
353
+ * const config = {
354
+ * screens: {
355
+ * Home: {
356
+ * screens: createPathConfigForStaticNavigation(HomeTabs),
357
+ * },
358
+ * },
359
+ * };
360
+ * ```
361
+ */
362
+ export function createPathConfigForStaticNavigation(tree: {
363
+ config: {
364
+ screens: StaticConfigScreens<
365
+ ParamListBase,
366
+ NavigationState,
367
+ {},
368
+ EventMapBase
369
+ >;
370
+ };
371
+ }) {
372
+ return fromEntries(
373
+ Object.entries(tree.config.screens)
374
+ .map(([key, item]) => {
375
+ const screenConfig: PathConfig<ParamListBase> = {};
376
+
377
+ if ('linking' in item) {
378
+ if (typeof item.linking === 'string') {
379
+ screenConfig.path = item.linking;
380
+ } else {
381
+ Object.assign(screenConfig, item.linking);
382
+ }
383
+ }
384
+
385
+ if ('config' in item) {
386
+ screenConfig.screens = createPathConfigForStaticNavigation(item);
387
+ } else if (
388
+ 'screen' in item &&
389
+ 'config' in item.screen &&
390
+ item.screen.config.screens
391
+ ) {
392
+ screenConfig.screens = createPathConfigForStaticNavigation(
393
+ item.screen
394
+ );
395
+ }
396
+
397
+ return [key, screenConfig] as const;
398
+ })
399
+ .filter(([, screen]) => Object.keys(screen).length > 0)
400
+ );
401
+ }
@@ -3,13 +3,14 @@ import type * as React from 'react';
3
3
 
4
4
  import Group from './Group';
5
5
  import Screen from './Screen';
6
+ import type { StaticConfig } from './StaticNavigation';
6
7
  import type { EventMapBase, TypedNavigator } from './types';
7
8
 
8
9
  /**
9
10
  * Higher order component to create a `Navigator` and `Screen` pair.
10
11
  * Custom navigators should wrap the navigator component in `createNavigator` before exporting.
11
12
  *
12
- * @param Navigator The navigtor component to wrap.
13
+ * @param Navigator The navigator component to wrap.
13
14
  * @returns Factory method to create a `Navigator` and `Screen` pair.
14
15
  */
15
16
  export default function createNavigatorFactory<
@@ -18,23 +19,51 @@ export default function createNavigatorFactory<
18
19
  EventMap extends EventMapBase,
19
20
  NavigatorComponent extends React.ComponentType<any>
20
21
  >(Navigator: NavigatorComponent) {
21
- return function <ParamList extends ParamListBase>(): TypedNavigator<
22
+ function createNavigator<ParamList extends ParamListBase>(): TypedNavigator<
22
23
  ParamList,
23
24
  State,
24
25
  ScreenOptions,
25
26
  EventMap,
26
27
  typeof Navigator
27
- > {
28
- if (arguments[0] !== undefined) {
29
- throw new Error(
30
- "Creating a navigator doesn't take an argument. Maybe you are trying to use React Navigation 4 API? See https://reactnavigation.org/docs/hello-react-navigation for the latest API and guides."
31
- );
28
+ >;
29
+
30
+ // eslint-disable-next-line no-redeclare
31
+ function createNavigator<
32
+ ParamList extends ParamListBase,
33
+ Config extends StaticConfig<
34
+ ParamList,
35
+ State,
36
+ ScreenOptions,
37
+ EventMap,
38
+ typeof Navigator
39
+ >
40
+ >(
41
+ config: Config
42
+ ): TypedNavigator<
43
+ ParamList,
44
+ State,
45
+ ScreenOptions,
46
+ EventMap,
47
+ typeof Navigator
48
+ > & { config: Config };
49
+
50
+ // eslint-disable-next-line no-redeclare
51
+ function createNavigator(config?: any): any {
52
+ if (config != null) {
53
+ return {
54
+ Navigator,
55
+ Screen,
56
+ Group,
57
+ config,
58
+ };
32
59
  }
33
60
 
34
61
  return {
35
62
  Navigator,
36
- Group,
37
63
  Screen,
64
+ Group,
38
65
  };
39
- };
66
+ }
67
+
68
+ return createNavigator;
40
69
  }
@@ -63,10 +63,7 @@ export default function getActionFromState(
63
63
 
64
64
  let current: PartialState<NavigationState> | undefined = route?.state;
65
65
  let config: ConfigItem | undefined = normalizedConfig?.screens?.[route?.name];
66
- let params = { ...route.params } as NavigatorScreenParams<
67
- ParamListBase,
68
- NavigationState
69
- >;
66
+ let params = { ...route.params } as NavigatorScreenParams<ParamListBase>;
70
67
 
71
68
  let payload = route
72
69
  ? { name: route.name, path: route.path, params }
@@ -111,10 +108,7 @@ export default function getActionFromState(
111
108
 
112
109
  if (route.state) {
113
110
  params.params = { ...route.params };
114
- params = params.params as NavigatorScreenParams<
115
- ParamListBase,
116
- NavigationState
117
- >;
111
+ params = params.params as NavigatorScreenParams<ParamListBase>;
118
112
  } else {
119
113
  params.path = route.path;
120
114
  params.params = route.params;
@@ -9,7 +9,7 @@ import fromEntries from './fromEntries';
9
9
  import type { PathConfig, PathConfigMap } from './types';
10
10
  import validatePathConfig from './validatePathConfig';
11
11
 
12
- type Options<ParamList> = {
12
+ type Options<ParamList extends {}> = {
13
13
  initialRouteName?: string;
14
14
  screens: PathConfigMap<ParamList>;
15
15
  };
package/src/index.tsx CHANGED
@@ -10,15 +10,24 @@ export { default as getStateFromPath } from './getStateFromPath';
10
10
  export { default as NavigationContainerRefContext } from './NavigationContainerRefContext';
11
11
  export { default as NavigationContext } from './NavigationContext';
12
12
  export { default as NavigationHelpersContext } from './NavigationHelpersContext';
13
+ export { default as NavigationIndependentTree } from './NavigationIndependentTree';
13
14
  export { default as NavigationRouteContext } from './NavigationRouteContext';
14
15
  export { default as PreventRemoveContext } from './PreventRemoveContext';
15
16
  export { default as PreventRemoveProvider } from './PreventRemoveProvider';
17
+ export {
18
+ createComponentForStaticNavigation,
19
+ createPathConfigForStaticNavigation,
20
+ StaticNavigation,
21
+ StaticParamList,
22
+ StaticScreenProps,
23
+ } from './StaticNavigation';
16
24
  export * from './types';
17
25
  export { default as useFocusEffect } from './useFocusEffect';
18
26
  export { default as useIsFocused } from './useIsFocused';
19
27
  export { default as useNavigation } from './useNavigation';
20
28
  export { default as useNavigationBuilder } from './useNavigationBuilder';
21
29
  export { default as useNavigationContainerRef } from './useNavigationContainerRef';
30
+ export { default as useNavigationIndependentTree } from './useNavigationIndependentTree';
22
31
  export { default as useNavigationState } from './useNavigationState';
23
32
  export { default as UNSTABLE_usePreventRemove } from './usePreventRemove';
24
33
  export { default as usePreventRemoveContext } from './usePreventRemoveContext';