@amazon-devices/react-navigation__native 7.0.1758683737 → 8.0.9000000000

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 (230) hide show
  1. package/SystemBundles/0fc5c971c5cf41a0dab235bcc6d58e5c06d9aaff650fa9815b525f8b9bb70a03.bundle +9116 -0
  2. package/SystemBundles/0fc5c971c5cf41a0dab235bcc6d58e5c06d9aaff650fa9815b525f8b9bb70a03.map +3543 -0
  3. package/SystemModules/amzn__react-navigation__native-8.modules.txt +24 -0
  4. package/SystemModules/amzn__react-navigation__native-8.private.modules.txt +77 -0
  5. package/SystemModules/keplerscript-system-bundle-config.json +4 -4
  6. package/kepler-compatibility.json +2 -4
  7. package/lib/module/Link.js +31 -10
  8. package/lib/module/Link.js.map +1 -1
  9. package/lib/module/LinkingContext.js +7 -3
  10. package/lib/module/LinkingContext.js.map +1 -1
  11. package/lib/module/LocaleDirContext.js +6 -0
  12. package/lib/module/LocaleDirContext.js.map +1 -0
  13. package/lib/module/NavigationContainer.js +87 -59
  14. package/lib/module/NavigationContainer.js.map +1 -1
  15. package/lib/module/ServerContainer.js +20 -10
  16. package/lib/module/ServerContainer.js.map +1 -1
  17. package/lib/module/ServerContext.js +3 -2
  18. package/lib/module/ServerContext.js.map +1 -1
  19. package/lib/module/UnhandledLinkingContext.js +14 -0
  20. package/lib/module/UnhandledLinkingContext.js.map +1 -0
  21. package/lib/module/__stubs__/createStackNavigator.js +18 -0
  22. package/lib/module/__stubs__/createStackNavigator.js.map +1 -0
  23. package/lib/module/__stubs__/window.js +75 -0
  24. package/lib/module/__stubs__/window.js.map +1 -0
  25. package/lib/module/createMemoryHistory.js +19 -17
  26. package/lib/module/createMemoryHistory.js.map +1 -1
  27. package/lib/module/createStaticNavigation.js +54 -0
  28. package/lib/module/createStaticNavigation.js.map +1 -0
  29. package/lib/module/extractPathFromURL.js +6 -5
  30. package/lib/module/extractPathFromURL.js.map +1 -1
  31. package/lib/module/index.js +18 -13
  32. package/lib/module/index.js.map +1 -1
  33. package/lib/module/package.json +1 -0
  34. package/lib/module/theming/DarkTheme.js +6 -3
  35. package/lib/module/theming/DarkTheme.js.map +1 -1
  36. package/lib/module/theming/DefaultTheme.js +6 -3
  37. package/lib/module/theming/DefaultTheme.js.map +1 -1
  38. package/lib/module/theming/fonts.js +61 -0
  39. package/lib/module/theming/fonts.js.map +1 -0
  40. package/lib/module/types.js +2 -0
  41. package/lib/module/types.js.map +1 -1
  42. package/lib/module/useBackButton.js +3 -1
  43. package/lib/module/useBackButton.js.map +1 -1
  44. package/lib/module/useBackButton.native.js +3 -1
  45. package/lib/module/useBackButton.native.js.map +1 -1
  46. package/lib/module/useDocumentTitle.js +6 -4
  47. package/lib/module/useDocumentTitle.js.map +1 -1
  48. package/lib/module/useDocumentTitle.native.js +4 -2
  49. package/lib/module/useDocumentTitle.native.js.map +1 -1
  50. package/lib/module/useLinkBuilder.js +71 -40
  51. package/lib/module/useLinkBuilder.js.map +1 -1
  52. package/lib/module/useLinkProps.js +41 -36
  53. package/lib/module/useLinkProps.js.map +1 -1
  54. package/lib/module/useLinkTo.js +18 -28
  55. package/lib/module/useLinkTo.js.map +1 -1
  56. package/lib/module/useLinking.js +47 -19
  57. package/lib/module/useLinking.js.map +1 -1
  58. package/lib/module/useLinking.native.js +33 -28
  59. package/lib/module/useLinking.native.js.map +1 -1
  60. package/lib/module/useLocale.js +18 -0
  61. package/lib/module/useLocale.js.map +1 -0
  62. package/lib/module/useRoutePath.js +30 -0
  63. package/lib/module/useRoutePath.js.map +1 -0
  64. package/lib/module/useScrollToTop.js +11 -7
  65. package/lib/module/useScrollToTop.js.map +1 -1
  66. package/lib/module/useThenable.js +4 -1
  67. package/lib/module/useThenable.js.map +1 -1
  68. package/lib/typescript/package.json +1 -0
  69. package/lib/typescript/src/Link.d.ts +8 -10
  70. package/lib/typescript/src/Link.d.ts.map +1 -1
  71. package/lib/typescript/src/LinkingContext.d.ts +2 -3
  72. package/lib/typescript/src/LinkingContext.d.ts.map +1 -1
  73. package/lib/typescript/src/LocaleDirContext.d.ts +4 -0
  74. package/lib/typescript/src/LocaleDirContext.d.ts.map +1 -0
  75. package/lib/typescript/src/NavigationContainer.d.ts +36 -13
  76. package/lib/typescript/src/NavigationContainer.d.ts.map +1 -1
  77. package/lib/typescript/src/ServerContainer.d.ts +2 -3
  78. package/lib/typescript/src/ServerContainer.d.ts.map +1 -1
  79. package/lib/typescript/src/ServerContext.d.ts +1 -2
  80. package/lib/typescript/src/ServerContext.d.ts.map +1 -1
  81. package/lib/typescript/src/UnhandledLinkingContext.d.ts +6 -0
  82. package/lib/typescript/src/UnhandledLinkingContext.d.ts.map +1 -0
  83. package/lib/typescript/src/__stubs__/createStackNavigator.d.ts +13 -0
  84. package/lib/typescript/src/__stubs__/createStackNavigator.d.ts.map +1 -0
  85. package/lib/typescript/src/{__mocks__ → __stubs__}/window.d.ts +5 -6
  86. package/lib/typescript/src/__stubs__/window.d.ts.map +1 -0
  87. package/lib/typescript/src/createMemoryHistory.d.ts +1 -1
  88. package/lib/typescript/src/createMemoryHistory.d.ts.map +1 -1
  89. package/lib/typescript/src/createStaticNavigation.d.ts +34 -0
  90. package/lib/typescript/src/createStaticNavigation.d.ts.map +1 -0
  91. package/lib/typescript/src/extractPathFromURL.d.ts +1 -1
  92. package/lib/typescript/src/extractPathFromURL.d.ts.map +1 -1
  93. package/lib/typescript/src/index.d.ts +15 -12
  94. package/lib/typescript/src/index.d.ts.map +1 -1
  95. package/lib/typescript/src/theming/DarkTheme.d.ts +1 -2
  96. package/lib/typescript/src/theming/DarkTheme.d.ts.map +1 -1
  97. package/lib/typescript/src/theming/DefaultTheme.d.ts +1 -2
  98. package/lib/typescript/src/theming/DefaultTheme.d.ts.map +1 -1
  99. package/lib/typescript/src/theming/fonts.d.ts +53 -0
  100. package/lib/typescript/src/theming/fonts.d.ts.map +1 -0
  101. package/lib/typescript/src/types.d.ts +35 -3
  102. package/lib/typescript/src/types.d.ts.map +1 -1
  103. package/lib/typescript/src/useBackButton.d.ts +1 -2
  104. package/lib/typescript/src/useBackButton.d.ts.map +1 -1
  105. package/lib/typescript/src/useBackButton.native.d.ts +1 -1
  106. package/lib/typescript/src/useBackButton.native.d.ts.map +1 -1
  107. package/lib/typescript/src/useDocumentTitle.d.ts +1 -1
  108. package/lib/typescript/src/useDocumentTitle.d.ts.map +1 -1
  109. package/lib/typescript/src/useDocumentTitle.native.d.ts +1 -1
  110. package/lib/typescript/src/useDocumentTitle.native.d.ts.map +1 -1
  111. package/lib/typescript/src/useLinkBuilder.d.ts +97 -3
  112. package/lib/typescript/src/useLinkBuilder.d.ts.map +1 -1
  113. package/lib/typescript/src/useLinkProps.d.ts +23 -10
  114. package/lib/typescript/src/useLinkProps.d.ts.map +1 -1
  115. package/lib/typescript/src/useLinkTo.d.ts +6 -8
  116. package/lib/typescript/src/useLinkTo.d.ts.map +1 -1
  117. package/lib/typescript/src/useLinking.d.ts +5 -46
  118. package/lib/typescript/src/useLinking.d.ts.map +1 -1
  119. package/lib/typescript/src/useLinking.native.d.ts +11 -29
  120. package/lib/typescript/src/useLinking.native.d.ts.map +1 -1
  121. package/lib/typescript/src/useLocale.d.ts +7 -0
  122. package/lib/typescript/src/useLocale.d.ts.map +1 -0
  123. package/lib/typescript/src/useRoutePath.d.ts +7 -0
  124. package/lib/typescript/src/useRoutePath.d.ts.map +1 -0
  125. package/lib/typescript/src/useScrollToTop.d.ts +2 -2
  126. package/lib/typescript/src/useScrollToTop.d.ts.map +1 -1
  127. package/lib/typescript/src/useThenable.d.ts +1 -1
  128. package/lib/typescript/src/useThenable.d.ts.map +1 -1
  129. package/package.json +1 -1
  130. package/src/Link.tsx +36 -20
  131. package/src/LinkingContext.tsx +9 -5
  132. package/src/LocaleDirContext.tsx +7 -0
  133. package/src/NavigationContainer.tsx +128 -69
  134. package/src/ServerContainer.tsx +4 -3
  135. package/src/ServerContext.tsx +1 -3
  136. package/src/UnhandledLinkingContext.tsx +18 -0
  137. package/src/__stubs__/createStackNavigator.tsx +46 -0
  138. package/src/{__mocks__ → __stubs__}/window.tsx +8 -8
  139. package/src/createMemoryHistory.tsx +16 -11
  140. package/src/createStaticNavigation.tsx +109 -0
  141. package/src/extractPathFromURL.tsx +3 -3
  142. package/src/index.tsx +15 -12
  143. package/src/theming/DarkTheme.tsx +3 -3
  144. package/src/theming/DefaultTheme.tsx +3 -3
  145. package/src/theming/fonts.tsx +63 -0
  146. package/src/types.tsx +49 -3
  147. package/src/useBackButton.native.tsx +2 -2
  148. package/src/useBackButton.tsx +2 -2
  149. package/src/useDocumentTitle.native.tsx +2 -2
  150. package/src/useDocumentTitle.tsx +2 -2
  151. package/src/useLinkBuilder.tsx +100 -55
  152. package/src/useLinkProps.tsx +80 -50
  153. package/src/useLinkTo.tsx +13 -53
  154. package/src/useLinking.native.tsx +33 -31
  155. package/src/useLinking.tsx +70 -23
  156. package/src/useLocale.tsx +18 -0
  157. package/src/useRoutePath.tsx +34 -0
  158. package/src/useScrollToTop.tsx +16 -12
  159. package/src/useThenable.tsx +2 -1
  160. package/SystemBundles/8f36606502d3b658fa1ffc07fee4da0e39a8ce388742799c9ccdb66b39ef0362.bundle +0 -15196
  161. package/SystemBundles/8f36606502d3b658fa1ffc07fee4da0e39a8ce388742799c9ccdb66b39ef0362.map +0 -1
  162. package/SystemModules/amzn__react-navigation__native-7.modules.txt +0 -76
  163. package/SystemModules/amzn__react-navigation__native-7.private.modules.txt +0 -101
  164. package/THIRD_PARTY_NOTICES.txt +0 -24
  165. package/lib/commonjs/Link.js +0 -50
  166. package/lib/commonjs/Link.js.map +0 -1
  167. package/lib/commonjs/LinkingContext.js +0 -15
  168. package/lib/commonjs/LinkingContext.js.map +0 -1
  169. package/lib/commonjs/NavigationContainer.js +0 -109
  170. package/lib/commonjs/NavigationContainer.js.map +0 -1
  171. package/lib/commonjs/ServerContainer.js +0 -54
  172. package/lib/commonjs/ServerContainer.js.map +0 -1
  173. package/lib/commonjs/ServerContext.js +0 -12
  174. package/lib/commonjs/ServerContext.js.map +0 -1
  175. package/lib/commonjs/createMemoryHistory.js +0 -220
  176. package/lib/commonjs/createMemoryHistory.js.map +0 -1
  177. package/lib/commonjs/extractPathFromURL.js +0 -25
  178. package/lib/commonjs/extractPathFromURL.js.map +0 -1
  179. package/lib/commonjs/index.js +0 -129
  180. package/lib/commonjs/index.js.map +0 -1
  181. package/lib/commonjs/theming/DarkTheme.js +0 -19
  182. package/lib/commonjs/theming/DarkTheme.js.map +0 -1
  183. package/lib/commonjs/theming/DefaultTheme.js +0 -19
  184. package/lib/commonjs/theming/DefaultTheme.js.map +0 -1
  185. package/lib/commonjs/theming/ThemeContext.js +0 -15
  186. package/lib/commonjs/theming/ThemeContext.js.map +0 -1
  187. package/lib/commonjs/theming/ThemeProvider.js +0 -20
  188. package/lib/commonjs/theming/ThemeProvider.js.map +0 -1
  189. package/lib/commonjs/theming/useTheme.js +0 -16
  190. package/lib/commonjs/theming/useTheme.js.map +0 -1
  191. package/lib/commonjs/types.js +0 -6
  192. package/lib/commonjs/types.js.map +0 -1
  193. package/lib/commonjs/useBackButton.js +0 -11
  194. package/lib/commonjs/useBackButton.js.map +0 -1
  195. package/lib/commonjs/useBackButton.native.js +0 -27
  196. package/lib/commonjs/useBackButton.native.js.map +0 -1
  197. package/lib/commonjs/useDocumentTitle.js +0 -32
  198. package/lib/commonjs/useDocumentTitle.js.map +0 -1
  199. package/lib/commonjs/useDocumentTitle.native.js +0 -10
  200. package/lib/commonjs/useDocumentTitle.native.js.map +0 -1
  201. package/lib/commonjs/useLinkBuilder.js +0 -63
  202. package/lib/commonjs/useLinkBuilder.js.map +0 -1
  203. package/lib/commonjs/useLinkProps.js +0 -97
  204. package/lib/commonjs/useLinkProps.js.map +0 -1
  205. package/lib/commonjs/useLinkTo.js +0 -45
  206. package/lib/commonjs/useLinkTo.js.map +0 -1
  207. package/lib/commonjs/useLinking.js +0 -303
  208. package/lib/commonjs/useLinking.js.map +0 -1
  209. package/lib/commonjs/useLinking.native.js +0 -152
  210. package/lib/commonjs/useLinking.native.js.map +0 -1
  211. package/lib/commonjs/useScrollToTop.js +0 -95
  212. package/lib/commonjs/useScrollToTop.js.map +0 -1
  213. package/lib/commonjs/useThenable.js +0 -41
  214. package/lib/commonjs/useThenable.js.map +0 -1
  215. package/lib/module/theming/ThemeContext.js +0 -6
  216. package/lib/module/theming/ThemeContext.js.map +0 -1
  217. package/lib/module/theming/ThemeProvider.js +0 -11
  218. package/lib/module/theming/ThemeProvider.js.map +0 -1
  219. package/lib/module/theming/useTheme.js +0 -7
  220. package/lib/module/theming/useTheme.js.map +0 -1
  221. package/lib/typescript/src/__mocks__/window.d.ts.map +0 -1
  222. package/lib/typescript/src/theming/ThemeContext.d.ts +0 -5
  223. package/lib/typescript/src/theming/ThemeContext.d.ts.map +0 -1
  224. package/lib/typescript/src/theming/ThemeProvider.d.ts +0 -9
  225. package/lib/typescript/src/theming/ThemeProvider.d.ts.map +0 -1
  226. package/lib/typescript/src/theming/useTheme.d.ts +0 -2
  227. package/lib/typescript/src/theming/useTheme.d.ts.map +0 -1
  228. package/src/theming/ThemeContext.tsx +0 -10
  229. package/src/theming/ThemeProvider.tsx +0 -15
  230. package/src/theming/useTheme.tsx +0 -9
@@ -1,2 +1,2 @@
1
- export default function useThenable<T>(create: () => PromiseLike<T>): [boolean, T | undefined];
1
+ export declare function useThenable<T>(create: () => PromiseLike<T>): [boolean, T | undefined];
2
2
  //# sourceMappingURL=useThenable.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useThenable.d.ts","sourceRoot":"","sources":["../../../src/useThenable.tsx"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC,CAAC,CAAC,4BAsClE"}
1
+ {"version":3,"file":"useThenable.d.ts","sourceRoot":"","sources":["../../../src/useThenable.tsx"],"names":[],"mappings":"AAEA,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC,CAAC,CAAC,4BAuC1D"}
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name": "@amazon-devices/react-navigation__native", "description": "React Native integration for React Navigation", "version": "7.0.1758683737+6.1.9", "keywords": ["react-native", "react-navigation", "ios", "android"], "license": "See license in LICENSE", "repository": {"type": "git", "url": "https://github.com/react-navigation/react-navigation.git", "directory": "packages/native"}, "bugs": {"url": "https://github.com/react-navigation/react-navigation/issues"}, "homepage": "https://reactnavigation.org", "main": "lib/commonjs/index.js", "react-native": "src/index.tsx", "source": "src/index.tsx", "module": "lib/module/index.js", "types": "lib/typescript/src/index.d.ts", "files": ["src", "lib", "!**/__tests__", "kepler-compatibility.json", "SystemModules", "SystemBundles", "THIRD_PARTY_NOTICES.txt", "kepler-transformed-package-info.json"], "sideEffects": false, "kepler": {"temporary-alias-for-package": {"name": "@react-navigation/native", "version": "6.1.9"}}, "publishConfig": {"access": "public"}, "scripts": {"clean": "del lib"}, "dependencies": {"@amazon-devices/react-navigation__core": "^7.0.0", "@amazon-devices/react-navigation__routers": "^7.0.0", "escape-string-regexp": "4.0.0", "fast-deep-equal": "3.1.3", "nanoid": "3.1.23"}, "devDependencies": {"@testing-library/react-native": "11.5.4", "@types/react": "17.0.2", "@types/react-dom": "18.0.10", "@types/jest": "26.0.15", "del-cli": "5.0.0", "react": "17.0.2", "react-dom": "18.2.0", "react-native": "0.72.0", "react-native-builder-bob": "0.20.4", "typescript": "4.9.4"}, "peerDependencies": {"react": "*", "react-native": "*"}, "react-native-builder-bob": {"source": "src", "output": "lib", "targets": ["commonjs", "module", ["typescript", {"project": "tsconfig.build.json"}]]}}
1
+ {"name": "@amazon-devices/react-navigation__native", "description": "React Native integration for React Navigation", "version": "8.0.9000000000+7.1.22", "keywords": ["react-native", "react-navigation", "ios", "android"], "license": "See license in LICENSE", "repository": {"type": "git", "url": "https://github.com/react-navigation/react-navigation.git", "directory": "packages/native"}, "bugs": {"url": "https://github.com/react-navigation/react-navigation/issues"}, "homepage": "https://reactnavigation.org", "main": "./lib/module/index.js", "types": "./lib/typescript/src/index.d.ts", "exports": {".": {"source": "./src/index.tsx", "types": "./lib/typescript/src/index.d.ts", "default": "./lib/module/index.js"}, "./package.json": "./package.json"}, "files": ["src", "lib", "!**/__tests__", "kepler-compatibility.json", "SystemModules", "SystemBundles", "kepler-transformed-package-info.json"], "sideEffects": false, "kepler": {"temporary-alias-for-package": {"name": "@react-navigation/native", "version": "7.0.14"}}, "publishConfig": {"access": "public"}, "scripts": {"clean": "del lib"}, "dependencies": {"@amazon-devices/react-navigation__routers": "^8.0.1", "@amazon-devices/react-navigation__core": "^8.0.1", "escape-string-regexp": "^4.0.0", "fast-deep-equal": "^3.1.3", "nanoid": "^3.3.11", "use-latest-callback": "^0.2.4"}, "devDependencies": {"@jest/globals": "^30.0.0", "@testing-library/react-native": "^13.2.0", "@types/react": "~19.0.10", "@types/react-dom": "~19.1.3", "del-cli": "^6.0.0", "react": "19.0.0", "react-dom": "19.0.0", "react-native": "0.79.3", "react-native-builder-bob": "^0.40.12", "react-test-renderer": "19.0.0", "typescript": "^5.8.3"}, "peerDependencies": {"react": ">= 18.2.0", "react-native": "*"}, "react-native-builder-bob": {"source": "src", "output": "lib", "targets": [["module", {"esm": true}], ["typescript", {"project": "tsconfig.build.json"}]]}}
package/src/Link.tsx CHANGED
@@ -1,36 +1,48 @@
1
- import type { NavigationAction } from '@amazon-devices/react-navigation__core';
1
+ import { useTheme } from '@amazon-devices/react-navigation__core';
2
2
  import * as React from 'react';
3
- import { GestureResponderEvent, Platform, Text, TextProps } from 'react-native';
3
+ import {
4
+ type GestureResponderEvent,
5
+ Platform,
6
+ Text,
7
+ type TextProps,
8
+ } from 'react-native';
4
9
 
5
- import useLinkProps from './useLinkProps';
6
- import type { To } from './useLinkTo';
10
+ import { type LinkProps, useLinkProps } from './useLinkProps';
7
11
 
8
- type Props<ParamList extends ReactNavigation.RootParamList> = {
9
- to: To<ParamList>;
10
- action?: NavigationAction;
11
- target?: string;
12
- onPress?: (
13
- e: React.MouseEvent<HTMLAnchorElement, MouseEvent> | GestureResponderEvent
14
- ) => void;
15
- } & (Omit<TextProps, 'disabled'> & {
16
- disabled?: boolean | null;
17
- children: React.ReactNode;
18
- });
12
+ type Props<ParamList extends ReactNavigation.RootParamList> =
13
+ LinkProps<ParamList> &
14
+ Omit<TextProps, 'disabled'> & {
15
+ target?: string;
16
+ onPress?: (
17
+ e:
18
+ | React.MouseEvent<HTMLAnchorElement, MouseEvent>
19
+ | GestureResponderEvent
20
+ ) => void;
21
+ disabled?: boolean | null;
22
+ children: React.ReactNode;
23
+ };
19
24
 
20
25
  /**
21
26
  * Component to render link to another screen using a path.
22
27
  * Uses an anchor tag on the web.
23
28
  *
24
- * @param props.to Absolute path to screen (e.g. `/feeds/hot`).
29
+ * @param props.screen Name of the screen to navigate to (e.g. `'Feeds'`).
30
+ * @param props.params Params to pass to the screen to navigate to (e.g. `{ sort: 'hot' }`).
31
+ * @param props.href Optional absolute path to use for the href (e.g. `/feeds/hot`).
25
32
  * @param props.action Optional action to use for in-page navigation. By default, the path is parsed to an action based on linking config.
26
33
  * @param props.children Child elements to render the content.
27
34
  */
28
- export default function Link<ParamList extends ReactNavigation.RootParamList>({
29
- to,
35
+ export function Link<ParamList extends ReactNavigation.RootParamList>({
36
+ screen,
37
+ params,
30
38
  action,
39
+ href,
40
+ style,
31
41
  ...rest
32
42
  }: Props<ParamList>) {
33
- const props = useLinkProps<ParamList>({ to, action });
43
+ const { colors, fonts } = useTheme();
44
+ // @ts-expect-error: This is already type-checked by the prop types
45
+ const props = useLinkProps<ParamList>({ screen, params, action, href });
34
46
 
35
47
  const onPress = (
36
48
  e: React.MouseEvent<HTMLAnchorElement, MouseEvent> | GestureResponderEvent
@@ -39,7 +51,10 @@ export default function Link<ParamList extends ReactNavigation.RootParamList>({
39
51
  rest.onPress?.(e);
40
52
  }
41
53
 
42
- props.onPress(e);
54
+ // Let user prevent default behavior
55
+ if (!e.defaultPrevented) {
56
+ props.onPress(e);
57
+ }
43
58
  };
44
59
 
45
60
  return React.createElement(Text, {
@@ -49,5 +64,6 @@ export default function Link<ParamList extends ReactNavigation.RootParamList>({
49
64
  web: { onClick: onPress } as any,
50
65
  default: { onPress },
51
66
  }),
67
+ style: [{ color: colors.primary }, fonts.regular, style],
52
68
  });
53
69
  }
@@ -3,10 +3,14 @@ import * as React from 'react';
3
3
 
4
4
  import type { LinkingOptions } from './types';
5
5
 
6
- const LinkingContext = React.createContext<{
7
- options: LinkingOptions<ParamListBase> | undefined;
8
- }>({ options: undefined });
6
+ const MISSING_CONTEXT_ERROR = "Couldn't find a LinkingContext context.";
9
7
 
10
- LinkingContext.displayName = 'LinkingContext';
8
+ export const LinkingContext = React.createContext<{
9
+ options?: LinkingOptions<ParamListBase>;
10
+ }>({
11
+ get options(): any {
12
+ throw new Error(MISSING_CONTEXT_ERROR);
13
+ },
14
+ });
11
15
 
12
- export default LinkingContext;
16
+ LinkingContext.displayName = 'LinkingContext';
@@ -0,0 +1,7 @@
1
+ import * as React from 'react';
2
+
3
+ import type { LocaleDirection } from './types';
4
+
5
+ export const LocaleDirContext = React.createContext<LocaleDirection>('ltr');
6
+
7
+ LocaleDirContext.displayName = 'LocaleDirContext';
@@ -3,21 +3,30 @@ import {
3
3
  getActionFromState,
4
4
  getPathFromState,
5
5
  getStateFromPath,
6
- NavigationContainerProps,
7
- NavigationContainerRef,
8
- ParamListBase,
6
+ type NavigationContainerProps,
7
+ type NavigationContainerRef,
8
+ type NavigationState,
9
+ type ParamListBase,
10
+ ThemeProvider,
9
11
  validatePathConfig,
10
12
  } from '@amazon-devices/react-navigation__core';
11
13
  import * as React from 'react';
12
-
13
- import LinkingContext from './LinkingContext';
14
- import DefaultTheme from './theming/DefaultTheme';
15
- import ThemeProvider from './theming/ThemeProvider';
16
- import type { DocumentTitleOptions, LinkingOptions, Theme } from './types';
17
- import useBackButton from './useBackButton';
18
- import useDocumentTitle from './useDocumentTitle';
19
- import useLinking from './useLinking';
20
- import useThenable from './useThenable';
14
+ import { I18nManager } from 'react-native';
15
+ import useLatestCallback from 'use-latest-callback';
16
+
17
+ import { LinkingContext } from './LinkingContext';
18
+ import { LocaleDirContext } from './LocaleDirContext';
19
+ import { DefaultTheme } from './theming/DefaultTheme';
20
+ import type {
21
+ DocumentTitleOptions,
22
+ LinkingOptions,
23
+ LocaleDirection,
24
+ } from './types';
25
+ import { UnhandledLinkingContext } from './UnhandledLinkingContext';
26
+ import { useBackButton } from './useBackButton';
27
+ import { useDocumentTitle } from './useDocumentTitle';
28
+ import { useLinking } from './useLinking';
29
+ import { useThenable } from './useThenable';
21
30
 
22
31
  declare global {
23
32
  var REACT_NAVIGATION_DEVTOOLS: WeakMap<
@@ -26,37 +35,50 @@ declare global {
26
35
  >;
27
36
  }
28
37
 
29
- global.REACT_NAVIGATION_DEVTOOLS = new WeakMap();
38
+ globalThis.REACT_NAVIGATION_DEVTOOLS = new WeakMap();
30
39
 
31
40
  type Props<ParamList extends {}> = NavigationContainerProps & {
32
- theme?: Theme;
41
+ /**
42
+ * Initial state object for the navigation tree.
43
+ *
44
+ * If this is provided, deep link or URLs won't be handled on the initial render.
45
+ */
46
+ initialState?: NavigationContainerProps['initialState'];
47
+ /**
48
+ * Text direction of the components. Defaults to `'ltr'`.
49
+ */
50
+ direction?: LocaleDirection;
51
+ /**
52
+ * Options for deep linking.
53
+ *
54
+ * Deep link handling is enabled when this prop is provided,
55
+ * unless `linking.enabled` is `false`.
56
+ */
33
57
  linking?: LinkingOptions<ParamList>;
58
+ /**
59
+ * Fallback element to render until initial state is resolved from deep linking.
60
+ *
61
+ * Defaults to `null`.
62
+ */
34
63
  fallback?: React.ReactNode;
64
+ /**
65
+ * Options to configure the document title on Web.
66
+ *
67
+ * Updating document title is handled by default,
68
+ * unless `documentTitle.enabled` is `false`.
69
+ */
35
70
  documentTitle?: DocumentTitleOptions;
36
- onReady?: () => void;
37
71
  };
38
72
 
39
- /**
40
- * Container component which holds the navigation state designed for React Native apps.
41
- * This should be rendered at the root wrapping the whole app.
42
- *
43
- * @param props.initialState Initial state object for the navigation tree. When deep link handling is enabled, this will override deep links when specified. Make sure that you don't specify an `initialState` when there's a deep link (`Linking.getInitialURL()`).
44
- * @param props.onReady Callback which is called after the navigation tree mounts.
45
- * @param props.onStateChange Callback which is called with the latest navigation state when it changes.
46
- * @param props.theme Theme object for the navigators.
47
- * @param props.linking Options for deep linking. Deep link handling is enabled when this prop is provided, unless `linking.enabled` is `false`.
48
- * @param props.fallback Fallback component to render until we have finished getting initial state when linking is enabled. Defaults to `null`.
49
- * @param props.documentTitle Options to configure the document title on Web. Updating document title is handled by default unless `documentTitle.enabled` is `false`.
50
- * @param props.children Child elements to render the content.
51
- * @param props.ref Ref object which refers to the navigation object containing helper methods.
52
- */
53
73
  function NavigationContainerInner(
54
74
  {
75
+ direction = I18nManager.getConstants().isRTL ? 'rtl' : 'ltr',
55
76
  theme = DefaultTheme,
56
77
  linking,
57
78
  fallback = null,
58
79
  documentTitle,
59
80
  onReady,
81
+ onStateChange,
60
82
  ...rest
61
83
  }: Props<ParamListBase>,
62
84
  ref?: React.Ref<NavigationContainerRef<ParamListBase> | null>
@@ -73,13 +95,52 @@ function NavigationContainerInner(
73
95
  useBackButton(refContainer);
74
96
  useDocumentTitle(refContainer, documentTitle);
75
97
 
76
- const { getInitialState } = useLinking(refContainer, {
77
- independent: rest.independent,
78
- enabled: isLinkingEnabled,
79
- prefixes: [],
80
- ...linking,
98
+ const [lastUnhandledLink, setLastUnhandledLink] = React.useState<
99
+ string | undefined
100
+ >();
101
+
102
+ const { getInitialState } = useLinking(
103
+ refContainer,
104
+ {
105
+ enabled: isLinkingEnabled,
106
+ prefixes: [],
107
+ ...linking,
108
+ },
109
+ setLastUnhandledLink
110
+ );
111
+
112
+ const linkingContext = React.useMemo(() => ({ options: linking }), [linking]);
113
+
114
+ const unhandledLinkingContext = React.useMemo(
115
+ () => ({ lastUnhandledLink, setLastUnhandledLink }),
116
+ [lastUnhandledLink, setLastUnhandledLink]
117
+ );
118
+
119
+ const onReadyForLinkingHandling = useLatestCallback(() => {
120
+ // If the screen path matches lastUnhandledLink, we do not track it
121
+ const path = refContainer.current?.getCurrentRoute()?.path;
122
+ setLastUnhandledLink((previousLastUnhandledLink) => {
123
+ if (previousLastUnhandledLink === path) {
124
+ return undefined;
125
+ }
126
+ return previousLastUnhandledLink;
127
+ });
128
+ onReady?.();
81
129
  });
82
130
 
131
+ const onStateChangeForLinkingHandling = useLatestCallback(
132
+ (state: Readonly<NavigationState> | undefined) => {
133
+ // If the screen path matches lastUnhandledLink, we do not track it
134
+ const path = refContainer.current?.getCurrentRoute()?.path;
135
+ setLastUnhandledLink((previousLastUnhandledLink) => {
136
+ if (previousLastUnhandledLink === path) {
137
+ return undefined;
138
+ }
139
+ return previousLastUnhandledLink;
140
+ });
141
+ onStateChange?.(state);
142
+ }
143
+ );
83
144
  // Add additional linking related info to the ref
84
145
  // This will be used by the devtools
85
146
  React.useEffect(() => {
@@ -102,51 +163,49 @@ function NavigationContainerInner(
102
163
 
103
164
  const [isResolved, initialState] = useThenable(getInitialState);
104
165
 
166
+ // FIXME
167
+ // @ts-expect-error not sure why this is not working
105
168
  React.useImperativeHandle(ref, () => refContainer.current);
106
169
 
107
- const linkingContext = React.useMemo(() => ({ options: linking }), [linking]);
108
-
109
- const isReady = rest.initialState != null || !isLinkingEnabled || isResolved;
170
+ const isLinkingReady =
171
+ rest.initialState != null || !isLinkingEnabled || isResolved;
110
172
 
111
- const onReadyRef = React.useRef(onReady);
112
-
113
- React.useEffect(() => {
114
- onReadyRef.current = onReady;
115
- });
116
-
117
- React.useEffect(() => {
118
- if (isReady) {
119
- onReadyRef.current?.();
120
- }
121
- }, [isReady]);
122
-
123
- if (!isReady) {
124
- // This is temporary until we have Suspense for data-fetching
125
- // Then the fallback will be handled by a parent `Suspense` component
126
- return fallback as React.ReactElement;
173
+ if (!isLinkingReady) {
174
+ return (
175
+ <LocaleDirContext.Provider value={direction}>
176
+ <ThemeProvider value={theme}>{fallback}</ThemeProvider>
177
+ </LocaleDirContext.Provider>
178
+ );
127
179
  }
128
180
 
129
181
  return (
130
- <LinkingContext.Provider value={linkingContext}>
131
- <ThemeProvider value={theme}>
132
- <BaseNavigationContainer
133
- {...rest}
134
- initialState={
135
- rest.initialState == null ? initialState : rest.initialState
136
- }
137
- ref={refContainer}
138
- />
139
- </ThemeProvider>
140
- </LinkingContext.Provider>
182
+ <LocaleDirContext.Provider value={direction}>
183
+ <UnhandledLinkingContext.Provider value={unhandledLinkingContext}>
184
+ <LinkingContext.Provider value={linkingContext}>
185
+ <BaseNavigationContainer
186
+ {...rest}
187
+ theme={theme}
188
+ onReady={onReadyForLinkingHandling}
189
+ onStateChange={onStateChangeForLinkingHandling}
190
+ initialState={
191
+ rest.initialState == null ? initialState : rest.initialState
192
+ }
193
+ ref={refContainer}
194
+ />
195
+ </LinkingContext.Provider>
196
+ </UnhandledLinkingContext.Provider>
197
+ </LocaleDirContext.Provider>
141
198
  );
142
199
  }
143
200
 
144
- const NavigationContainer = React.forwardRef(NavigationContainerInner) as <
145
- RootParamList extends {} = ReactNavigation.RootParamList
146
- >(
201
+ /**
202
+ * Container component that manages the navigation state.
203
+ * This should be rendered at the root wrapping the whole app.
204
+ */
205
+ export const NavigationContainer = React.forwardRef(
206
+ NavigationContainerInner
207
+ ) as <RootParamList extends {} = ReactNavigation.RootParamList>(
147
208
  props: Props<RootParamList> & {
148
209
  ref?: React.Ref<NavigationContainerRef<RootParamList>>;
149
210
  }
150
211
  ) => React.ReactElement;
151
-
152
- export default NavigationContainer;
@@ -1,7 +1,7 @@
1
1
  import { CurrentRenderContext } from '@amazon-devices/react-navigation__core';
2
2
  import * as React from 'react';
3
3
 
4
- import ServerContext, { ServerContextType } from './ServerContext';
4
+ import { ServerContext, type ServerContextType } from './ServerContext';
5
5
  import type { ServerContainerRef } from './types';
6
6
 
7
7
  type Props = ServerContextType & {
@@ -15,7 +15,7 @@ type Props = ServerContextType & {
15
15
  * @param props.children Child elements to render the content.
16
16
  * @param props.ref Ref object which contains helper methods.
17
17
  */
18
- export default React.forwardRef(function ServerContainer(
18
+ export const ServerContainer = React.forwardRef(function ServerContainer(
19
19
  { children, location }: Props,
20
20
  ref: React.Ref<ServerContainerRef>
21
21
  ) {
@@ -25,6 +25,7 @@ export default React.forwardRef(function ServerContainer(
25
25
  );
26
26
  }, []);
27
27
 
28
+ // eslint-disable-next-line @eslint-react/no-unstable-context-value
28
29
  const current: { options?: object } = {};
29
30
 
30
31
  if (ref) {
@@ -41,12 +42,12 @@ export default React.forwardRef(function ServerContainer(
41
42
  if (typeof ref === 'function') {
42
43
  ref(value);
43
44
  } else {
44
- // @ts-expect-error: the TS types are incorrect and say that ref.current is readonly
45
45
  ref.current = value;
46
46
  }
47
47
  }
48
48
 
49
49
  return (
50
+ // eslint-disable-next-line @eslint-react/no-unstable-context-value
50
51
  <ServerContext.Provider value={{ location }}>
51
52
  <CurrentRenderContext.Provider value={current}>
52
53
  {children}
@@ -7,8 +7,6 @@ export type ServerContextType = {
7
7
  };
8
8
  };
9
9
 
10
- const ServerContext = React.createContext<ServerContextType | undefined>(
10
+ export const ServerContext = React.createContext<ServerContextType | undefined>(
11
11
  undefined
12
12
  );
13
-
14
- export default ServerContext;
@@ -0,0 +1,18 @@
1
+ import * as React from 'react';
2
+
3
+ const MISSING_CONTEXT_ERROR =
4
+ "Couldn't find an UnhandledLinkingContext context.";
5
+
6
+ export const UnhandledLinkingContext = React.createContext<{
7
+ lastUnhandledLink: string | undefined;
8
+ setLastUnhandledLink: (lastUnhandledUrl: string | undefined) => void;
9
+ }>({
10
+ get lastUnhandledLink(): any {
11
+ throw new Error(MISSING_CONTEXT_ERROR);
12
+ },
13
+ get setLastUnhandledLink(): any {
14
+ throw new Error(MISSING_CONTEXT_ERROR);
15
+ },
16
+ });
17
+
18
+ UnhandledLinkingContext.displayName = 'UnhandledLinkingContext';
@@ -0,0 +1,46 @@
1
+ import {
2
+ createNavigatorFactory,
3
+ type DefaultNavigatorOptions,
4
+ type NavigationListBase,
5
+ type ParamListBase,
6
+ type StackNavigationState,
7
+ StackRouter,
8
+ type TypedNavigator,
9
+ useNavigationBuilder,
10
+ } from '@amazon-devices/react-navigation__core';
11
+
12
+ const StackNavigator = (
13
+ props: DefaultNavigatorOptions<
14
+ ParamListBase,
15
+ string | undefined,
16
+ StackNavigationState<ParamListBase>,
17
+ {},
18
+ {},
19
+ unknown
20
+ >
21
+ ) => {
22
+ const { state, descriptors, NavigationContent } = useNavigationBuilder(
23
+ StackRouter,
24
+ props
25
+ );
26
+
27
+ return (
28
+ <NavigationContent>
29
+ {descriptors[state.routes[state.index].key].render()}
30
+ </NavigationContent>
31
+ );
32
+ };
33
+
34
+ export function createStackNavigator<
35
+ ParamList extends ParamListBase,
36
+ >(): TypedNavigator<{
37
+ ParamList: ParamList;
38
+ NavigatorID: string | undefined;
39
+ State: StackNavigationState<ParamList>;
40
+ ScreenOptions: {};
41
+ EventMap: {};
42
+ NavigationList: NavigationListBase<ParamList>;
43
+ Navigator: typeof StackNavigator;
44
+ }> {
45
+ return createNavigatorFactory(StackNavigator)();
46
+ }
@@ -1,4 +1,4 @@
1
- const location = new URL('', 'http://example.com');
1
+ let location = new URL('', 'http://example.com');
2
2
 
3
3
  let listeners: (() => void)[] = [];
4
4
  let entries = [{ state: null, href: location.href }];
@@ -12,7 +12,7 @@ const history = {
12
12
  },
13
13
 
14
14
  pushState(state: any, _: string, path: string) {
15
- Object.assign(location, new URL(path, location.origin));
15
+ location = new URL(path, location.origin);
16
16
 
17
17
  currentState = state;
18
18
  entries = entries.slice(0, index + 1);
@@ -21,7 +21,7 @@ const history = {
21
21
  },
22
22
 
23
23
  replaceState(state: any, _: string, path: string) {
24
- Object.assign(location, new URL(path, location.origin));
24
+ location = new URL(path, location.origin);
25
25
 
26
26
  currentState = state;
27
27
  entries[index] = { state, href: location.href };
@@ -35,7 +35,7 @@ const history = {
35
35
  ) {
36
36
  index += n;
37
37
  const entry = entries[index];
38
- Object.assign(location, new URL(entry.href));
38
+ location = new URL(entry.href);
39
39
  currentState = entry.state;
40
40
  listeners.forEach((cb) => cb());
41
41
  }
@@ -63,9 +63,11 @@ const removeEventListener = (type: 'popstate', listener: () => void) => {
63
63
  }
64
64
  };
65
65
 
66
- const window = {
66
+ export const window = {
67
67
  document: { title: '' },
68
- location,
68
+ get location() {
69
+ return location;
70
+ },
69
71
  history,
70
72
  addEventListener,
71
73
  removeEventListener,
@@ -73,5 +75,3 @@ const window = {
73
75
  return window;
74
76
  },
75
77
  };
76
-
77
- export default window;
@@ -10,7 +10,7 @@ type HistoryRecord = {
10
10
  path: string;
11
11
  };
12
12
 
13
- export default function createMemoryHistory() {
13
+ export function createMemoryHistory() {
14
14
  let index = 0;
15
15
  let items: HistoryRecord[] = [];
16
16
 
@@ -87,6 +87,7 @@ export default 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 default 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
  }
@@ -174,21 +176,20 @@ export default function createMemoryHistory() {
174
176
  // But on Firefox, it seems to take much longer, around 50ms from our testing
175
177
  // We're using a hacky timeout since there doesn't seem to be way to know for sure
176
178
  const timer = setTimeout(() => {
177
- const index = pending.findIndex((it) => it.ref === done);
179
+ const foundIndex = pending.findIndex((it) => it.ref === done);
178
180
 
179
- if (index > -1) {
180
- pending[index].cb();
181
- pending.splice(index, 1);
181
+ if (foundIndex > -1) {
182
+ pending[foundIndex].cb();
183
+ pending.splice(foundIndex, 1);
182
184
  }
185
+
186
+ index = this.index;
183
187
  }, 100);
184
188
 
185
189
  const onPopState = () => {
186
- const id = window.history.state?.id;
187
- const currentIndex = items.findIndex((item) => item.id === id);
188
-
189
190
  // Fix createMemoryHistory.index variable's value
190
191
  // as it may go out of sync when navigating in the browser.
191
- index = Math.max(currentIndex, 0);
192
+ index = this.index;
192
193
 
193
194
  const last = pending.pop();
194
195
 
@@ -206,6 +207,10 @@ export default function createMemoryHistory() {
206
207
  // Here we normalize it so that only external changes (e.g. user pressing back/forward) trigger the listener
207
208
  listen(listener: () => void) {
208
209
  const onPopState = () => {
210
+ // Fix createMemoryHistory.index variable's value
211
+ // as it may go out of sync when navigating in the browser.
212
+ index = this.index;
213
+
209
214
  if (pending.length) {
210
215
  // This was triggered by `history.go(n)`, we shouldn't call the listener
211
216
  return;