@react-navigation/core 7.14.0 → 8.0.0-alpha.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 (157) hide show
  1. package/lib/module/BaseNavigationContainer.js +4 -9
  2. package/lib/module/BaseNavigationContainer.js.map +1 -1
  3. package/lib/module/NavigationIndependentTree.js +12 -7
  4. package/lib/module/NavigationIndependentTree.js.map +1 -1
  5. package/lib/module/NavigationProvider.js +49 -0
  6. package/lib/module/NavigationProvider.js.map +1 -0
  7. package/lib/module/PreventRemoveProvider.js +1 -1
  8. package/lib/module/PreventRemoveProvider.js.map +1 -1
  9. package/lib/module/SceneView.js.map +1 -1
  10. package/lib/module/StaticNavigation.js +32 -21
  11. package/lib/module/StaticNavigation.js.map +1 -1
  12. package/lib/module/createNavigationContainerRef.js.map +1 -1
  13. package/lib/module/getActionFromState.js +3 -2
  14. package/lib/module/getActionFromState.js.map +1 -1
  15. package/lib/module/getPathFromState.js +1 -1
  16. package/lib/module/getPathFromState.js.map +1 -1
  17. package/lib/module/getStateFromPath.js +3 -3
  18. package/lib/module/getStateFromPath.js.map +1 -1
  19. package/lib/module/index.js +1 -2
  20. package/lib/module/index.js.map +1 -1
  21. package/lib/module/theming/ThemeContext.js.map +1 -1
  22. package/lib/module/theming/ThemeProvider.js.map +1 -1
  23. package/lib/module/theming/useTheme.js +1 -1
  24. package/lib/module/theming/useTheme.js.map +1 -1
  25. package/lib/module/types.js +41 -0
  26. package/lib/module/types.js.map +1 -1
  27. package/lib/module/useChildListeners.js +2 -4
  28. package/lib/module/useChildListeners.js.map +1 -1
  29. package/lib/module/useDescriptors.js +5 -9
  30. package/lib/module/useDescriptors.js.map +1 -1
  31. package/lib/module/useEventEmitter.js +9 -20
  32. package/lib/module/useEventEmitter.js.map +1 -1
  33. package/lib/module/useFocusEvents.js +1 -1
  34. package/lib/module/useFocusEvents.js.map +1 -1
  35. package/lib/module/useNavigation.js +31 -8
  36. package/lib/module/useNavigation.js.map +1 -1
  37. package/lib/module/useNavigationBuilder.js +10 -12
  38. package/lib/module/useNavigationBuilder.js.map +1 -1
  39. package/lib/module/useNavigationCache.js +18 -11
  40. package/lib/module/useNavigationCache.js.map +1 -1
  41. package/lib/module/useNavigationHelpers.js +2 -14
  42. package/lib/module/useNavigationHelpers.js.map +1 -1
  43. package/lib/module/useNavigationState.js +42 -9
  44. package/lib/module/useNavigationState.js.map +1 -1
  45. package/lib/module/useOnAction.js +2 -7
  46. package/lib/module/useOnAction.js.map +1 -1
  47. package/lib/module/useOnGetState.js +1 -1
  48. package/lib/module/useOnGetState.js.map +1 -1
  49. package/lib/module/useOnPreventRemove.js +1 -1
  50. package/lib/module/useOnPreventRemove.js.map +1 -1
  51. package/lib/module/useRoute.js +23 -5
  52. package/lib/module/useRoute.js.map +1 -1
  53. package/lib/module/useScheduleUpdate.js +1 -2
  54. package/lib/module/useScheduleUpdate.js.map +1 -1
  55. package/lib/module/useSyncState.js +25 -9
  56. package/lib/module/useSyncState.js.map +1 -1
  57. package/lib/module/utilities.js +2 -0
  58. package/lib/module/utilities.js.map +1 -0
  59. package/lib/typescript/src/BaseNavigationContainer.d.ts.map +1 -1
  60. package/lib/typescript/src/NavigationIndependentTree.d.ts.map +1 -1
  61. package/lib/typescript/src/NavigationProvider.d.ts +44 -0
  62. package/lib/typescript/src/NavigationProvider.d.ts.map +1 -0
  63. package/lib/typescript/src/SceneView.d.ts +1 -1
  64. package/lib/typescript/src/SceneView.d.ts.map +1 -1
  65. package/lib/typescript/src/StaticNavigation.d.ts +231 -80
  66. package/lib/typescript/src/StaticNavigation.d.ts.map +1 -1
  67. package/lib/typescript/src/createNavigationContainerRef.d.ts +2 -2
  68. package/lib/typescript/src/createNavigationContainerRef.d.ts.map +1 -1
  69. package/lib/typescript/src/getStateFromPath.d.ts.map +1 -1
  70. package/lib/typescript/src/index.d.ts +2 -3
  71. package/lib/typescript/src/index.d.ts.map +1 -1
  72. package/lib/typescript/src/theming/ThemeContext.d.ts +2 -1
  73. package/lib/typescript/src/theming/ThemeContext.d.ts.map +1 -1
  74. package/lib/typescript/src/theming/ThemeProvider.d.ts +2 -1
  75. package/lib/typescript/src/theming/ThemeProvider.d.ts.map +1 -1
  76. package/lib/typescript/src/theming/useTheme.d.ts +1 -1
  77. package/lib/typescript/src/theming/useTheme.d.ts.map +1 -1
  78. package/lib/typescript/src/types.d.ts +188 -133
  79. package/lib/typescript/src/types.d.ts.map +1 -1
  80. package/lib/typescript/src/useChildListeners.d.ts.map +1 -1
  81. package/lib/typescript/src/useDescriptors.d.ts +27 -109
  82. package/lib/typescript/src/useDescriptors.d.ts.map +1 -1
  83. package/lib/typescript/src/useEventEmitter.d.ts.map +1 -1
  84. package/lib/typescript/src/useNavigation.d.ts +7 -5
  85. package/lib/typescript/src/useNavigation.d.ts.map +1 -1
  86. package/lib/typescript/src/useNavigationBuilder.d.ts +25 -114
  87. package/lib/typescript/src/useNavigationBuilder.d.ts.map +1 -1
  88. package/lib/typescript/src/useNavigationCache.d.ts +8 -22
  89. package/lib/typescript/src/useNavigationCache.d.ts.map +1 -1
  90. package/lib/typescript/src/useNavigationContainerRef.d.ts +2 -2
  91. package/lib/typescript/src/useNavigationContainerRef.d.ts.map +1 -1
  92. package/lib/typescript/src/useNavigationHelpers.d.ts +3 -11
  93. package/lib/typescript/src/useNavigationHelpers.d.ts.map +1 -1
  94. package/lib/typescript/src/useNavigationState.d.ts +10 -3
  95. package/lib/typescript/src/useNavigationState.d.ts.map +1 -1
  96. package/lib/typescript/src/useOnAction.d.ts.map +1 -1
  97. package/lib/typescript/src/useRoute.d.ts +8 -2
  98. package/lib/typescript/src/useRoute.d.ts.map +1 -1
  99. package/lib/typescript/src/useRouteCache.d.ts +12 -3
  100. package/lib/typescript/src/useRouteCache.d.ts.map +1 -1
  101. package/lib/typescript/src/useScheduleUpdate.d.ts.map +1 -1
  102. package/lib/typescript/src/useSyncState.d.ts.map +1 -1
  103. package/lib/typescript/src/utilities.d.ts +99 -0
  104. package/lib/typescript/src/utilities.d.ts.map +1 -0
  105. package/package.json +7 -7
  106. package/src/BaseNavigationContainer.tsx +3 -9
  107. package/src/NavigationIndependentTree.tsx +17 -9
  108. package/src/NavigationProvider.tsx +64 -0
  109. package/src/PreventRemoveProvider.tsx +1 -1
  110. package/src/SceneView.tsx +1 -7
  111. package/src/StaticNavigation.tsx +372 -134
  112. package/src/createNavigationContainerRef.tsx +2 -1
  113. package/src/getActionFromState.tsx +4 -2
  114. package/src/getPathFromState.tsx +6 -5
  115. package/src/getStateFromPath.tsx +11 -11
  116. package/src/index.tsx +8 -4
  117. package/src/theming/ThemeContext.tsx +3 -3
  118. package/src/theming/ThemeProvider.tsx +2 -1
  119. package/src/theming/useTheme.tsx +1 -1
  120. package/src/types.tsx +392 -243
  121. package/src/useChildListeners.tsx +3 -2
  122. package/src/useDescriptors.tsx +11 -17
  123. package/src/useEventEmitter.tsx +14 -31
  124. package/src/useFocusEvents.tsx +1 -1
  125. package/src/useNavigation.tsx +57 -14
  126. package/src/useNavigationBuilder.tsx +10 -13
  127. package/src/useNavigationCache.tsx +40 -18
  128. package/src/useNavigationContainerRef.tsx +2 -2
  129. package/src/useNavigationHelpers.tsx +2 -19
  130. package/src/useNavigationState.tsx +90 -19
  131. package/src/useOnAction.tsx +1 -12
  132. package/src/useOnGetState.tsx +1 -1
  133. package/src/useOnPreventRemove.tsx +1 -1
  134. package/src/useRoute.tsx +52 -7
  135. package/src/useScheduleUpdate.tsx +1 -2
  136. package/src/useSyncState.tsx +28 -13
  137. package/src/utilities.tsx +122 -0
  138. package/lib/module/DeprecatedNavigationInChildContext.js +0 -9
  139. package/lib/module/DeprecatedNavigationInChildContext.js.map +0 -1
  140. package/lib/module/NavigationContext.js +0 -8
  141. package/lib/module/NavigationContext.js.map +0 -1
  142. package/lib/module/NavigationRouteContext.js +0 -9
  143. package/lib/module/NavigationRouteContext.js.map +0 -1
  144. package/lib/module/useClientLayoutEffect.js +0 -9
  145. package/lib/module/useClientLayoutEffect.js.map +0 -1
  146. package/lib/typescript/src/DeprecatedNavigationInChildContext.d.ts +0 -6
  147. package/lib/typescript/src/DeprecatedNavigationInChildContext.d.ts.map +0 -1
  148. package/lib/typescript/src/NavigationContext.d.ts +0 -8
  149. package/lib/typescript/src/NavigationContext.d.ts.map +0 -1
  150. package/lib/typescript/src/NavigationRouteContext.d.ts +0 -7
  151. package/lib/typescript/src/NavigationRouteContext.d.ts.map +0 -1
  152. package/lib/typescript/src/useClientLayoutEffect.d.ts +0 -6
  153. package/lib/typescript/src/useClientLayoutEffect.d.ts.map +0 -1
  154. package/src/DeprecatedNavigationInChildContext.tsx +0 -6
  155. package/src/NavigationContext.tsx +0 -11
  156. package/src/NavigationRouteContext.tsx +0 -9
  157. package/src/useClientLayoutEffect.tsx +0 -10
@@ -167,9 +167,10 @@ export function getActionFromState(
167
167
  const createNormalizedConfigItem = (config: PathConfig<object> | string) =>
168
168
  typeof config === 'object' && config != null
169
169
  ? {
170
- initialRouteName: config.initialRouteName,
170
+ initialRouteName:
171
+ 'initialRouteName' in config ? config.initialRouteName : undefined,
171
172
  screens:
172
- config.screens != null
173
+ 'screens' in config && config.screens != null
173
174
  ? createNormalizedConfigs(config.screens)
174
175
  : undefined,
175
176
  }
@@ -177,6 +178,7 @@ const createNormalizedConfigItem = (config: PathConfig<object> | string) =>
177
178
 
178
179
  const createNormalizedConfigs = (options: PathConfigMap<object>) =>
179
180
  Object.entries(options).reduce<Record<string, ConfigItem>>((acc, [k, v]) => {
181
+ // @ts-expect-error -we can't properly type this
180
182
  acc[k] = createNormalizedConfigItem(v);
181
183
  return acc;
182
184
  }, {});
@@ -17,7 +17,7 @@ type Options<ParamList extends {}> = {
17
17
 
18
18
  type State = NavigationState | Omit<PartialState<NavigationState>, 'stale'>;
19
19
 
20
- type StringifyConfig = Record<string, (value: unknown) => string>;
20
+ type StringifyConfig = Record<string, ((value: unknown) => string) | undefined>;
21
21
 
22
22
  type ConfigItem = {
23
23
  parts?: PatternPart[];
@@ -288,7 +288,7 @@ export function getPathFromState<ParamList extends {}>(
288
288
  }
289
289
 
290
290
  const createConfigItem = (
291
- config: PathConfig<object> | string,
291
+ config: PathConfig<{}> | string,
292
292
  parentParts?: PatternPart[]
293
293
  ): ConfigItem => {
294
294
  if (typeof config === 'string') {
@@ -320,9 +320,10 @@ const createConfigItem = (
320
320
  ? getPatternParts(config.path)
321
321
  : undefined;
322
322
 
323
- const screens = config.screens
324
- ? createNormalizedConfigs(config.screens, parts)
325
- : undefined;
323
+ const screens =
324
+ 'screens' in config && config.screens
325
+ ? createNormalizedConfigs(config.screens, parts)
326
+ : undefined;
326
327
 
327
328
  return {
328
329
  parts,
@@ -1,7 +1,6 @@
1
1
  import type {
2
2
  InitialState,
3
3
  NavigationState,
4
- ParamListBase,
5
4
  PartialState,
6
5
  } from '@react-navigation/routers';
7
6
  import escape from 'escape-string-regexp';
@@ -20,7 +19,7 @@ type Options<ParamList extends {}> = {
20
19
  screens: PathConfigMap<ParamList>;
21
20
  };
22
21
 
23
- type ParseConfig = Record<string, (value: string) => unknown>;
22
+ type ParseConfig = Record<string, ((value: string) => unknown) | undefined>;
24
23
 
25
24
  type RouteConfig = {
26
25
  screen: string;
@@ -213,7 +212,7 @@ function getInitialRoutes(options?: Options<{}>) {
213
212
 
214
213
  function getSortedNormalizedConfigs(
215
214
  initialRoutes: InitialRouteConfig[],
216
- screens: Record<string, string | PathConfig<ParamListBase>> = {}
215
+ screens: Record<string, string | PathConfig<{}>> = {}
217
216
  ) {
218
217
  // Create a normalized configs array which will be easier to use
219
218
  return ([] as RouteConfig[])
@@ -418,7 +417,7 @@ const matchAgainstConfigs = (remaining: string, configs: RouteConfig[]) => {
418
417
 
419
418
  const createNormalizedConfigs = (
420
419
  screen: string,
421
- routeConfig: Record<string, string | PathConfig<ParamListBase>>,
420
+ routeConfig: Record<string, string | PathConfig<{}>>,
422
421
  initials: InitialRouteConfig[],
423
422
  paths: { screen: string; path: string }[],
424
423
  parentScreens: string[],
@@ -500,9 +499,12 @@ const createNormalizedConfigs = (
500
499
  );
501
500
  }
502
501
 
503
- if (config.screens) {
502
+ if ('screens' in config && config.screens) {
504
503
  // property `initialRouteName` without `screens` has no purpose
505
- if (config.initialRouteName) {
504
+ if (
505
+ 'initialRouteName' in config &&
506
+ typeof config.initialRouteName === 'string'
507
+ ) {
506
508
  initials.push({
507
509
  initialRouteName: config.initialRouteName,
508
510
  parentScreens,
@@ -512,7 +514,7 @@ const createNormalizedConfigs = (
512
514
  Object.keys(config.screens).forEach((nestedConfig) => {
513
515
  const result = createNormalizedConfigs(
514
516
  nestedConfig,
515
- config.screens as Record<string, string | PathConfig<ParamListBase>>,
517
+ config.screens as Record<string, string | PathConfig<{}>>,
516
518
  initials,
517
519
  [...paths],
518
520
  [...parentScreens],
@@ -709,10 +711,7 @@ const createNestedStateObject = (
709
711
  return state;
710
712
  };
711
713
 
712
- const parseQueryParams = (
713
- path: string,
714
- parseConfig?: Record<string, (value: string) => unknown>
715
- ) => {
714
+ const parseQueryParams = (path: string, parseConfig?: ParseConfig) => {
716
715
  const query = path.split('?')[1];
717
716
  const params: Record<string, unknown> = queryString.parse(query);
718
717
 
@@ -720,6 +719,7 @@ const parseQueryParams = (
720
719
  Object.keys(params).forEach((name) => {
721
720
  if (
722
721
  Object.hasOwnProperty.call(parseConfig, name) &&
722
+ parseConfig[name] &&
723
723
  typeof params[name] === 'string'
724
724
  ) {
725
725
  params[name] = parseConfig[name](params[name]);
package/src/index.tsx CHANGED
@@ -8,21 +8,25 @@ export { getFocusedRouteNameFromRoute } from './getFocusedRouteNameFromRoute';
8
8
  export { getPathFromState } from './getPathFromState';
9
9
  export { getStateFromPath } from './getStateFromPath';
10
10
  export { NavigationContainerRefContext } from './NavigationContainerRefContext';
11
- export { NavigationContext } from './NavigationContext';
12
11
  export { NavigationHelpersContext } from './NavigationHelpersContext';
13
12
  export { NavigationIndependentTree } from './NavigationIndependentTree';
14
13
  export { NavigationMetaContext } from './NavigationMetaContext';
15
- export { NavigationRouteContext } from './NavigationRouteContext';
14
+ export {
15
+ NavigationContext,
16
+ NavigationProvider,
17
+ NavigationRouteContext,
18
+ } from './NavigationProvider';
16
19
  export { PreventRemoveContext } from './PreventRemoveContext';
17
20
  export { PreventRemoveProvider } from './PreventRemoveProvider';
18
21
  export {
19
22
  createComponentForStaticNavigation,
20
23
  createPathConfigForStaticNavigation,
21
24
  type StaticConfig,
22
- type StaticConfigGroup,
23
- type StaticConfigScreens,
24
25
  type StaticNavigation,
25
26
  type StaticParamList,
27
+ type StaticScreenConfig,
28
+ type StaticScreenConfigLinking,
29
+ type StaticScreenConfigScreen,
26
30
  type StaticScreenProps,
27
31
  } from './StaticNavigation';
28
32
  export { ThemeContext } from './theming/ThemeContext';
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
2
 
3
- export const ThemeContext = React.createContext<
4
- ReactNavigation.Theme | undefined
5
- >(undefined);
3
+ import type { Theme } from '../types';
4
+
5
+ export const ThemeContext = React.createContext<Theme | undefined>(undefined);
6
6
 
7
7
  ThemeContext.displayName = 'ThemeContext';
@@ -1,9 +1,10 @@
1
1
  import * as React from 'react';
2
2
 
3
+ import type { Theme } from '../types';
3
4
  import { ThemeContext } from './ThemeContext';
4
5
 
5
6
  type Props = {
6
- value: ReactNavigation.Theme | undefined;
7
+ value: Theme | undefined;
7
8
  children: React.ReactNode;
8
9
  };
9
10
 
@@ -7,7 +7,7 @@ export function useTheme() {
7
7
 
8
8
  if (theme == null) {
9
9
  throw new Error(
10
- "Couldn't find a theme. Is your component inside NavigationContainer or does it have a theme?"
10
+ "Couldn't find a theme. Is your component inside NavigationContainer or a ThemeProvider?"
11
11
  );
12
12
  }
13
13