@react-navigation/native 7.0.0-alpha.9 → 7.0.0-rc.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 (123) hide show
  1. package/lib/commonjs/Link.js +9 -10
  2. package/lib/commonjs/Link.js.map +1 -1
  3. package/lib/commonjs/LinkingContext.js +1 -1
  4. package/lib/commonjs/LinkingContext.js.map +1 -1
  5. package/lib/commonjs/LocaleDirContext.js +1 -1
  6. package/lib/commonjs/LocaleDirContext.js.map +1 -1
  7. package/lib/commonjs/NavigationContainer.js +14 -15
  8. package/lib/commonjs/NavigationContainer.js.map +1 -1
  9. package/lib/commonjs/ServerContainer.js +5 -6
  10. package/lib/commonjs/ServerContainer.js.map +1 -1
  11. package/lib/commonjs/ServerContext.js +1 -1
  12. package/lib/commonjs/ServerContext.js.map +1 -1
  13. package/lib/commonjs/UnhandledLinkingContext.js +1 -1
  14. package/lib/commonjs/UnhandledLinkingContext.js.map +1 -1
  15. package/lib/commonjs/__stubs__/createStackNavigator.js +7 -4
  16. package/lib/commonjs/__stubs__/createStackNavigator.js.map +1 -1
  17. package/lib/commonjs/__stubs__/window.js.map +1 -1
  18. package/lib/commonjs/createMemoryHistory.js +15 -16
  19. package/lib/commonjs/createMemoryHistory.js.map +1 -1
  20. package/lib/commonjs/createStaticNavigation.js +23 -11
  21. package/lib/commonjs/createStaticNavigation.js.map +1 -1
  22. package/lib/commonjs/extractPathFromURL.js +1 -1
  23. package/lib/commonjs/extractPathFromURL.js.map +1 -1
  24. package/lib/commonjs/index.js.map +1 -1
  25. package/lib/commonjs/theming/DarkTheme.js.map +1 -1
  26. package/lib/commonjs/theming/DefaultTheme.js.map +1 -1
  27. package/lib/commonjs/theming/fonts.js.map +1 -1
  28. package/lib/commonjs/types.js.map +1 -1
  29. package/lib/commonjs/useBackButton.js.map +1 -1
  30. package/lib/commonjs/useBackButton.native.js +1 -1
  31. package/lib/commonjs/useBackButton.native.js.map +1 -1
  32. package/lib/commonjs/useDocumentTitle.js +5 -6
  33. package/lib/commonjs/useDocumentTitle.js.map +1 -1
  34. package/lib/commonjs/useDocumentTitle.native.js.map +1 -1
  35. package/lib/commonjs/useLinkBuilder.js +1 -1
  36. package/lib/commonjs/useLinkBuilder.js.map +1 -1
  37. package/lib/commonjs/useLinkProps.js +7 -8
  38. package/lib/commonjs/useLinkProps.js.map +1 -1
  39. package/lib/commonjs/useLinkTo.js +1 -1
  40. package/lib/commonjs/useLinkTo.js.map +1 -1
  41. package/lib/commonjs/useLinking.js +22 -12
  42. package/lib/commonjs/useLinking.js.map +1 -1
  43. package/lib/commonjs/useLinking.native.js +31 -35
  44. package/lib/commonjs/useLinking.native.js.map +1 -1
  45. package/lib/commonjs/useLocale.js +1 -1
  46. package/lib/commonjs/useLocale.js.map +1 -1
  47. package/lib/commonjs/useScrollToTop.js +2 -2
  48. package/lib/commonjs/useScrollToTop.js.map +1 -1
  49. package/lib/commonjs/useThenable.js +1 -1
  50. package/lib/commonjs/useThenable.js.map +1 -1
  51. package/lib/commonjs/useUnhandledLinking.js +1 -1
  52. package/lib/commonjs/useUnhandledLinking.js.map +1 -1
  53. package/lib/module/Link.js +8 -9
  54. package/lib/module/Link.js.map +1 -1
  55. package/lib/module/LinkingContext.js.map +1 -1
  56. package/lib/module/LocaleDirContext.js.map +1 -1
  57. package/lib/module/NavigationContainer.js +12 -13
  58. package/lib/module/NavigationContainer.js.map +1 -1
  59. package/lib/module/ServerContainer.js +4 -5
  60. package/lib/module/ServerContainer.js.map +1 -1
  61. package/lib/module/ServerContext.js.map +1 -1
  62. package/lib/module/UnhandledLinkingContext.js.map +1 -1
  63. package/lib/module/__stubs__/createStackNavigator.js +5 -2
  64. package/lib/module/__stubs__/createStackNavigator.js.map +1 -1
  65. package/lib/module/__stubs__/window.js.map +1 -1
  66. package/lib/module/createMemoryHistory.js +15 -16
  67. package/lib/module/createMemoryHistory.js.map +1 -1
  68. package/lib/module/createStaticNavigation.js +22 -10
  69. package/lib/module/createStaticNavigation.js.map +1 -1
  70. package/lib/module/extractPathFromURL.js.map +1 -1
  71. package/lib/module/index.js.map +1 -1
  72. package/lib/module/theming/DarkTheme.js.map +1 -1
  73. package/lib/module/theming/DefaultTheme.js.map +1 -1
  74. package/lib/module/theming/fonts.js.map +1 -1
  75. package/lib/module/types.js.map +1 -1
  76. package/lib/module/useBackButton.js.map +1 -1
  77. package/lib/module/useBackButton.native.js.map +1 -1
  78. package/lib/module/useDocumentTitle.js +4 -5
  79. package/lib/module/useDocumentTitle.js.map +1 -1
  80. package/lib/module/useDocumentTitle.native.js.map +1 -1
  81. package/lib/module/useLinkBuilder.js.map +1 -1
  82. package/lib/module/useLinkProps.js +6 -7
  83. package/lib/module/useLinkProps.js.map +1 -1
  84. package/lib/module/useLinkTo.js.map +1 -1
  85. package/lib/module/useLinking.js +20 -10
  86. package/lib/module/useLinking.js.map +1 -1
  87. package/lib/module/useLinking.native.js +30 -34
  88. package/lib/module/useLinking.native.js.map +1 -1
  89. package/lib/module/useLocale.js.map +1 -1
  90. package/lib/module/useScrollToTop.js +1 -1
  91. package/lib/module/useScrollToTop.js.map +1 -1
  92. package/lib/module/useThenable.js.map +1 -1
  93. package/lib/module/useUnhandledLinking.js.map +1 -1
  94. package/lib/typescript/src/LinkingContext.d.ts +1 -1
  95. package/lib/typescript/src/LinkingContext.d.ts.map +1 -1
  96. package/lib/typescript/src/NavigationContainer.d.ts +2 -7
  97. package/lib/typescript/src/NavigationContainer.d.ts.map +1 -1
  98. package/lib/typescript/src/ServerContainer.d.ts.map +1 -1
  99. package/lib/typescript/src/UnhandledLinkingContext.d.ts.map +1 -1
  100. package/lib/typescript/src/__stubs__/createStackNavigator.d.ts +12 -30
  101. package/lib/typescript/src/__stubs__/createStackNavigator.d.ts.map +1 -1
  102. package/lib/typescript/src/__stubs__/window.d.ts +2 -2
  103. package/lib/typescript/src/createMemoryHistory.d.ts.map +1 -1
  104. package/lib/typescript/src/createStaticNavigation.d.ts +17 -3
  105. package/lib/typescript/src/createStaticNavigation.d.ts.map +1 -1
  106. package/lib/typescript/src/types.d.ts +20 -18
  107. package/lib/typescript/src/types.d.ts.map +1 -1
  108. package/lib/typescript/src/useBackButton.d.ts +0 -1
  109. package/lib/typescript/src/useBackButton.d.ts.map +1 -1
  110. package/lib/typescript/src/useLinkBuilder.d.ts +2 -2
  111. package/lib/typescript/src/useLinkProps.d.ts.map +1 -1
  112. package/lib/typescript/src/useLinking.d.ts +3 -26
  113. package/lib/typescript/src/useLinking.d.ts.map +1 -1
  114. package/lib/typescript/src/useLinking.native.d.ts +6 -6
  115. package/lib/typescript/src/useUnhandledLinking.d.ts.map +1 -1
  116. package/package.json +9 -9
  117. package/src/NavigationContainer.tsx +1 -1
  118. package/src/__stubs__/createStackNavigator.tsx +30 -2
  119. package/src/createMemoryHistory.tsx +4 -2
  120. package/src/createStaticNavigation.tsx +58 -8
  121. package/src/types.tsx +22 -20
  122. package/src/useLinking.tsx +23 -2
  123. package/src/useScrollToTop.tsx +1 -1
@@ -7,26 +7,26 @@ export declare function useLinking(ref: React.RefObject<NavigationContainerRef<P
7
7
  key: string;
8
8
  index: number;
9
9
  routeNames: string[];
10
- history?: unknown[] | undefined;
10
+ history?: unknown[];
11
11
  routes: import("@react-navigation/core").NavigationRoute<ParamListBase, string>[];
12
12
  type: string;
13
13
  stale: false;
14
14
  }>, "stale" | "routes">> & Readonly<{
15
- stale?: true | undefined;
15
+ stale?: true;
16
16
  routes: import("@react-navigation/core").PartialRoute<import("@react-navigation/core").Route<string, object | undefined>>[];
17
17
  }> & {
18
- state?: (Partial<Omit<Readonly<{
18
+ state?: Partial<Omit<Readonly<{
19
19
  key: string;
20
20
  index: number;
21
21
  routeNames: string[];
22
- history?: unknown[] | undefined;
22
+ history?: unknown[];
23
23
  routes: import("@react-navigation/core").NavigationRoute<ParamListBase, string>[];
24
24
  type: string;
25
25
  stale: false;
26
26
  }>, "stale" | "routes">> & Readonly<{
27
- stale?: true | undefined;
27
+ stale?: true;
28
28
  routes: import("@react-navigation/core").PartialRoute<import("@react-navigation/core").Route<string, object | undefined>>[];
29
- }> & any) | undefined;
29
+ }> & any;
30
30
  }) | undefined>;
31
31
  };
32
32
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"useUnhandledLinking.d.ts","sourceRoot":"","sources":["../../../src/useUnhandledLinking.tsx"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,eAAe,EACpB,KAAK,YAAY,EAClB,MAAM,wBAAwB,CAAC;AA2BhC,wBAAgB,4BAA4B;;gDAU1B,eAAe,KAC5B,aAAa,eAAe,CAAC,GAAG,SAAS;;EA+C7C"}
1
+ {"version":3,"file":"useUnhandledLinking.d.ts","sourceRoot":"","sources":["../../../src/useUnhandledLinking.tsx"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,eAAe,EACpB,KAAK,YAAY,EAClB,MAAM,wBAAwB,CAAC;AA2BhC,wBAAgB,4BAA4B;;gDAU1B,eAAe,KAC5B,YAAY,CAAC,eAAe,CAAC,GAAG,SAAS;;EA+C7C"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@react-navigation/native",
3
3
  "description": "React Native integration for React Navigation",
4
- "version": "7.0.0-alpha.9",
4
+ "version": "7.0.0-rc.1",
5
5
  "keywords": [
6
6
  "react-native",
7
7
  "react-navigation",
@@ -37,7 +37,7 @@
37
37
  "clean": "del lib"
38
38
  },
39
39
  "dependencies": {
40
- "@react-navigation/core": "^7.0.0-alpha.9",
40
+ "@react-navigation/core": "^7.0.0-rc.1",
41
41
  "escape-string-regexp": "^4.0.0",
42
42
  "fast-deep-equal": "^3.1.3",
43
43
  "nanoid": "3.3.7",
@@ -45,18 +45,18 @@
45
45
  },
46
46
  "devDependencies": {
47
47
  "@testing-library/react-native": "^12.4.3",
48
- "@types/react": "~18.2.45",
49
- "@types/react-dom": "~18.0.11",
48
+ "@types/react": "~18.2.79",
49
+ "@types/react-dom": "~18.2.25",
50
50
  "del-cli": "^5.1.0",
51
51
  "react": "18.2.0",
52
52
  "react-dom": "18.2.0",
53
- "react-native": "0.73.2",
53
+ "react-native": "0.74.2",
54
54
  "react-native-builder-bob": "^0.23.2",
55
- "typescript": "^5.3.3"
55
+ "typescript": "^5.5.2"
56
56
  },
57
57
  "peerDependencies": {
58
- "react": "*",
59
- "react-native": "0.73.2"
58
+ "react": ">= 18.2.0",
59
+ "react-native": ">= 0.72.0"
60
60
  },
61
61
  "react-native-builder-bob": {
62
62
  "source": "src",
@@ -72,5 +72,5 @@
72
72
  ]
73
73
  ]
74
74
  },
75
- "gitHead": "c7b047dec7c75bda359a618d39a2aac4c2aea9c1"
75
+ "gitHead": "18c09f1478a3efcb3a809305c5947b748f10c951"
76
76
  }
@@ -35,7 +35,7 @@ declare global {
35
35
  >;
36
36
  }
37
37
 
38
- global.REACT_NAVIGATION_DEVTOOLS = new WeakMap();
38
+ globalThis.REACT_NAVIGATION_DEVTOOLS = new WeakMap();
39
39
 
40
40
  type Props<ParamList extends {}> = NavigationContainerProps & {
41
41
  direction?: LocaleDirection;
@@ -1,11 +1,25 @@
1
1
  import {
2
2
  createNavigatorFactory,
3
+ type DefaultNavigatorOptions,
4
+ type NavigationListBase,
5
+ type ParamListBase,
6
+ type StackNavigationState,
3
7
  StackRouter,
8
+ type TypedNavigator,
4
9
  useNavigationBuilder,
5
10
  } from '@react-navigation/core';
6
11
  import * as React from 'react';
7
12
 
8
- export const createStackNavigator = createNavigatorFactory((props) => {
13
+ const StackNavigator = (
14
+ props: DefaultNavigatorOptions<
15
+ ParamListBase,
16
+ string | undefined,
17
+ StackNavigationState<ParamListBase>,
18
+ {},
19
+ {},
20
+ unknown
21
+ >
22
+ ) => {
9
23
  const { state, descriptors, NavigationContent } = useNavigationBuilder(
10
24
  StackRouter,
11
25
  props
@@ -16,4 +30,18 @@ export const createStackNavigator = createNavigatorFactory((props) => {
16
30
  {descriptors[state.routes[state.index].key].render()}
17
31
  </NavigationContent>
18
32
  );
19
- });
33
+ };
34
+
35
+ export function createStackNavigator<
36
+ ParamList extends ParamListBase,
37
+ >(): TypedNavigator<{
38
+ ParamList: ParamList;
39
+ NavigatorID: string | undefined;
40
+ State: StackNavigationState<ParamList>;
41
+ ScreenOptions: {};
42
+ EventMap: {};
43
+ NavigationList: NavigationListBase<ParamList>;
44
+ Navigator: typeof StackNavigator;
45
+ }> {
46
+ return createNavigatorFactory(StackNavigator)();
47
+ }
@@ -87,6 +87,7 @@ export function createMemoryHistory() {
87
87
  // Need to keep the hash part of the path if there was no previous history entry
88
88
  // or the previous history entry had the same path
89
89
  let pathWithHash = path;
90
+ const hash = pathWithHash.includes('#') ? '' : location.hash;
90
91
 
91
92
  if (!items.length || items.findIndex((item) => item.id === id) < 0) {
92
93
  // There are two scenarios for creating an array with only one history record:
@@ -95,12 +96,13 @@ export function createMemoryHistory() {
95
96
  // the page when navigating forward in history.
96
97
  // - This is the first time any state modifications are done
97
98
  // So we need to push the entry as there's nothing to replace
98
- pathWithHash = pathWithHash + location.hash;
99
+
100
+ pathWithHash = pathWithHash + hash;
99
101
  items = [{ path: pathWithHash, state, id }];
100
102
  index = 0;
101
103
  } else {
102
104
  if (items[index].path === path) {
103
- pathWithHash = pathWithHash + location.hash;
105
+ pathWithHash = pathWithHash + hash;
104
106
  }
105
107
  items[index] = { path, state, id };
106
108
  }
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  createComponentForStaticNavigation,
3
3
  createPathConfigForStaticNavigation,
4
+ type NavigationContainerRef,
4
5
  type ParamListBase,
5
6
  type StaticNavigation,
6
7
  } from '@react-navigation/core';
@@ -16,7 +17,24 @@ type Props = Omit<
16
17
  /**
17
18
  * Options for deep linking.
18
19
  */
19
- linking?: Omit<LinkingOptions<ParamListBase>, 'config'>;
20
+ linking?: Omit<LinkingOptions<ParamListBase>, 'config' | 'enabled'> & {
21
+ /**
22
+ * Whether deep link handling should be enabled.
23
+ * Defaults to `true` if any `linking` options are specified, `false` otherwise.
24
+ *
25
+ * When 'auto' is specified, all leaf screens will get a autogenerated path.
26
+ * The generated path will be a kebab-case version of the screen name.
27
+ * This can be overridden for specific screens by specifying `linking` for the screen.
28
+ */
29
+ enabled?: 'auto' | true | false;
30
+ /**
31
+ * Additional configuration
32
+ */
33
+ config?: Omit<
34
+ NonNullable<LinkingOptions<ParamListBase>['config']>,
35
+ 'screens'
36
+ >;
37
+ };
20
38
  };
21
39
 
22
40
  /**
@@ -28,17 +46,49 @@ type Props = Omit<
28
46
  */
29
47
  export function createStaticNavigation(tree: StaticNavigation<any, any, any>) {
30
48
  const Component = createComponentForStaticNavigation(tree, 'RootNavigator');
31
- const linkingConfig = {
32
- screens: tree.config.screens
33
- ? createPathConfigForStaticNavigation(tree)
34
- : {},
35
- };
36
49
 
37
- function Navigation({ linking, ...rest }: Props) {
50
+ function Navigation(
51
+ { linking, ...rest }: Props,
52
+ ref: React.Ref<NavigationContainerRef<ParamListBase>>
53
+ ) {
54
+ const screens = React.useMemo(() => {
55
+ if (tree.config.screens) {
56
+ return createPathConfigForStaticNavigation(
57
+ tree,
58
+ { initialRouteName: linking?.config?.initialRouteName },
59
+ linking?.enabled === 'auto'
60
+ );
61
+ }
62
+
63
+ return undefined;
64
+ }, [linking?.config, linking?.enabled]);
65
+
66
+ if (linking?.enabled === true && screens == null) {
67
+ throw new Error(
68
+ 'Linking is enabled but no linking configuration was found for the screens.\n\n' +
69
+ 'To solve this:\n' +
70
+ "- Specify a 'linking' property for the screens you want to link to.\n" +
71
+ "- Or set 'linking.enabled' to 'auto' to generate paths automatically.\n\n" +
72
+ 'See usage guide: https://reactnavigation.org/docs/7.x/static-configuration#linking'
73
+ );
74
+ }
75
+
38
76
  return (
39
77
  <NavigationContainer
40
78
  {...rest}
41
- linking={linking ? { ...linking, config: linkingConfig } : undefined}
79
+ ref={ref}
80
+ linking={
81
+ linking
82
+ ? {
83
+ ...linking,
84
+ enabled:
85
+ typeof linking.enabled === 'boolean'
86
+ ? linking.enabled
87
+ : screens != null,
88
+ config: screens ? { ...linking.config, screens } : undefined,
89
+ }
90
+ : undefined
91
+ }
42
92
  >
43
93
  <Component />
44
94
  </NavigationContainer>
package/src/types.tsx CHANGED
@@ -9,28 +9,10 @@ import type {
9
9
  declare global {
10
10
  // eslint-disable-next-line @typescript-eslint/no-namespace
11
11
  namespace ReactNavigation {
12
- interface Theme {
13
- dark: boolean;
14
- colors: {
15
- primary: string;
16
- background: string;
17
- card: string;
18
- text: string;
19
- border: string;
20
- notification: string;
21
- };
22
- fonts: {
23
- regular: FontStyle;
24
- medium: FontStyle;
25
- bold: FontStyle;
26
- heavy: FontStyle;
27
- };
28
- }
12
+ interface Theme extends NativeTheme {}
29
13
  }
30
14
  }
31
15
 
32
- export type LocaleDirection = 'ltr' | 'rtl';
33
-
34
16
  type FontStyle = {
35
17
  fontFamily: string;
36
18
  fontWeight:
@@ -47,7 +29,27 @@ type FontStyle = {
47
29
  | '900';
48
30
  };
49
31
 
50
- export type Theme = ReactNavigation.Theme;
32
+ interface NativeTheme {
33
+ dark: boolean;
34
+ colors: {
35
+ primary: string;
36
+ background: string;
37
+ card: string;
38
+ text: string;
39
+ border: string;
40
+ notification: string;
41
+ };
42
+ fonts: {
43
+ regular: FontStyle;
44
+ medium: FontStyle;
45
+ bold: FontStyle;
46
+ heavy: FontStyle;
47
+ };
48
+ }
49
+
50
+ export type Theme = NativeTheme;
51
+
52
+ export type LocaleDirection = 'ltr' | 'rtl';
51
53
 
52
54
  export type LinkingOptions<ParamList extends {}> = {
53
55
  /**
@@ -280,6 +280,8 @@ export function useLinking(
280
280
  route: ReturnType<typeof findFocusedRoute>,
281
281
  state: NavigationState
282
282
  ): string => {
283
+ let path;
284
+
283
285
  // If the `route` object contains a `path`, use that path as long as `route.name` and `params` still match
284
286
  // This makes sure that we preserve the original URL for wildcard routes
285
287
  if (route?.path) {
@@ -296,12 +298,31 @@ export function useLinking(
296
298
  focusedRoute.name === route.name &&
297
299
  isEqual(focusedRoute.params, route.params)
298
300
  ) {
299
- return route.path;
301
+ path = route.path;
300
302
  }
301
303
  }
302
304
  }
303
305
 
304
- return getPathFromStateRef.current(state, configRef.current);
306
+ if (path == null) {
307
+ path = getPathFromStateRef.current(state, configRef.current);
308
+ }
309
+
310
+ const previousRoute = previousStateRef.current
311
+ ? findFocusedRoute(previousStateRef.current)
312
+ : undefined;
313
+
314
+ // Preserve the hash if the route didn't change
315
+ if (
316
+ previousRoute &&
317
+ route &&
318
+ 'key' in previousRoute &&
319
+ 'key' in route &&
320
+ previousRoute.key === route.key
321
+ ) {
322
+ path = path + location.hash;
323
+ }
324
+
325
+ return path;
305
326
  };
306
327
 
307
328
  if (ref.current) {
@@ -39,7 +39,7 @@ function getScrollableNode(ref: React.RefObject<ScrollableWrapper>) {
39
39
  // We need to use `getScrollResponder` to get access to the scroll responder
40
40
  return ref.current.getScrollResponder();
41
41
  } else if ('getNode' in ref.current) {
42
- // When a `ScrollView` is wraped in `Animated.createAnimatedComponent`
42
+ // When a `ScrollView` is wrapped in `Animated.createAnimatedComponent`
43
43
  // we need to use `getNode` to get the ref to the actual scrollview.
44
44
  // Note that `getNode` is deprecated in newer versions of react-native
45
45
  // this is why we check if we already have a scrollable node above.