@amazon-devices/react-navigation__native 2.0.1758683737

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 (189) hide show
  1. package/LICENSE +7 -0
  2. package/README.md +5 -0
  3. package/SystemBundles/6132afb62bda3afb78ba1a1aca51924df73e9dbcc77106aa0f97a0ef68b04ebb.bundle +15196 -0
  4. package/SystemBundles/6132afb62bda3afb78ba1a1aca51924df73e9dbcc77106aa0f97a0ef68b04ebb.map +1 -0
  5. package/SystemModules/amzn__react-navigation__native-2.modules.txt +76 -0
  6. package/SystemModules/amzn__react-navigation__native-2.private.modules.txt +101 -0
  7. package/SystemModules/keplerscript-system-bundle-config.json +7 -0
  8. package/THIRD_PARTY_NOTICES.txt +24 -0
  9. package/kepler-compatibility.json +8 -0
  10. package/kepler-transformed-package-info.json +3 -0
  11. package/lib/commonjs/Link.js +50 -0
  12. package/lib/commonjs/Link.js.map +1 -0
  13. package/lib/commonjs/LinkingContext.js +15 -0
  14. package/lib/commonjs/LinkingContext.js.map +1 -0
  15. package/lib/commonjs/NavigationContainer.js +109 -0
  16. package/lib/commonjs/NavigationContainer.js.map +1 -0
  17. package/lib/commonjs/ServerContainer.js +54 -0
  18. package/lib/commonjs/ServerContainer.js.map +1 -0
  19. package/lib/commonjs/ServerContext.js +12 -0
  20. package/lib/commonjs/ServerContext.js.map +1 -0
  21. package/lib/commonjs/createMemoryHistory.js +220 -0
  22. package/lib/commonjs/createMemoryHistory.js.map +1 -0
  23. package/lib/commonjs/extractPathFromURL.js +25 -0
  24. package/lib/commonjs/extractPathFromURL.js.map +1 -0
  25. package/lib/commonjs/index.js +129 -0
  26. package/lib/commonjs/index.js.map +1 -0
  27. package/lib/commonjs/theming/DarkTheme.js +19 -0
  28. package/lib/commonjs/theming/DarkTheme.js.map +1 -0
  29. package/lib/commonjs/theming/DefaultTheme.js +19 -0
  30. package/lib/commonjs/theming/DefaultTheme.js.map +1 -0
  31. package/lib/commonjs/theming/ThemeContext.js +15 -0
  32. package/lib/commonjs/theming/ThemeContext.js.map +1 -0
  33. package/lib/commonjs/theming/ThemeProvider.js +20 -0
  34. package/lib/commonjs/theming/ThemeProvider.js.map +1 -0
  35. package/lib/commonjs/theming/useTheme.js +16 -0
  36. package/lib/commonjs/theming/useTheme.js.map +1 -0
  37. package/lib/commonjs/types.js +6 -0
  38. package/lib/commonjs/types.js.map +1 -0
  39. package/lib/commonjs/useBackButton.js +11 -0
  40. package/lib/commonjs/useBackButton.js.map +1 -0
  41. package/lib/commonjs/useBackButton.native.js +27 -0
  42. package/lib/commonjs/useBackButton.native.js.map +1 -0
  43. package/lib/commonjs/useDocumentTitle.js +32 -0
  44. package/lib/commonjs/useDocumentTitle.js.map +1 -0
  45. package/lib/commonjs/useDocumentTitle.native.js +10 -0
  46. package/lib/commonjs/useDocumentTitle.native.js.map +1 -0
  47. package/lib/commonjs/useLinkBuilder.js +63 -0
  48. package/lib/commonjs/useLinkBuilder.js.map +1 -0
  49. package/lib/commonjs/useLinkProps.js +97 -0
  50. package/lib/commonjs/useLinkProps.js.map +1 -0
  51. package/lib/commonjs/useLinkTo.js +45 -0
  52. package/lib/commonjs/useLinkTo.js.map +1 -0
  53. package/lib/commonjs/useLinking.js +303 -0
  54. package/lib/commonjs/useLinking.js.map +1 -0
  55. package/lib/commonjs/useLinking.native.js +152 -0
  56. package/lib/commonjs/useLinking.native.js.map +1 -0
  57. package/lib/commonjs/useScrollToTop.js +95 -0
  58. package/lib/commonjs/useScrollToTop.js.map +1 -0
  59. package/lib/commonjs/useThenable.js +41 -0
  60. package/lib/commonjs/useThenable.js.map +1 -0
  61. package/lib/module/Link.js +41 -0
  62. package/lib/module/Link.js.map +1 -0
  63. package/lib/module/LinkingContext.js +7 -0
  64. package/lib/module/LinkingContext.js.map +1 -0
  65. package/lib/module/NavigationContainer.js +100 -0
  66. package/lib/module/NavigationContainer.js.map +1 -0
  67. package/lib/module/ServerContainer.js +45 -0
  68. package/lib/module/ServerContainer.js.map +1 -0
  69. package/lib/module/ServerContext.js +4 -0
  70. package/lib/module/ServerContext.js.map +1 -0
  71. package/lib/module/createMemoryHistory.js +214 -0
  72. package/lib/module/createMemoryHistory.js.map +1 -0
  73. package/lib/module/extractPathFromURL.js +18 -0
  74. package/lib/module/extractPathFromURL.js.map +1 -0
  75. package/lib/module/index.js +15 -0
  76. package/lib/module/index.js.map +1 -0
  77. package/lib/module/theming/DarkTheme.js +13 -0
  78. package/lib/module/theming/DarkTheme.js.map +1 -0
  79. package/lib/module/theming/DefaultTheme.js +13 -0
  80. package/lib/module/theming/DefaultTheme.js.map +1 -0
  81. package/lib/module/theming/ThemeContext.js +6 -0
  82. package/lib/module/theming/ThemeContext.js.map +1 -0
  83. package/lib/module/theming/ThemeProvider.js +11 -0
  84. package/lib/module/theming/ThemeProvider.js.map +1 -0
  85. package/lib/module/theming/useTheme.js +7 -0
  86. package/lib/module/theming/useTheme.js.map +1 -0
  87. package/lib/module/types.js +2 -0
  88. package/lib/module/types.js.map +1 -0
  89. package/lib/module/useBackButton.js +5 -0
  90. package/lib/module/useBackButton.js.map +1 -0
  91. package/lib/module/useBackButton.native.js +19 -0
  92. package/lib/module/useBackButton.native.js.map +1 -0
  93. package/lib/module/useDocumentTitle.js +24 -0
  94. package/lib/module/useDocumentTitle.js.map +1 -0
  95. package/lib/module/useDocumentTitle.native.js +4 -0
  96. package/lib/module/useDocumentTitle.native.js.map +1 -0
  97. package/lib/module/useLinkBuilder.js +54 -0
  98. package/lib/module/useLinkBuilder.js.map +1 -0
  99. package/lib/module/useLinkProps.js +88 -0
  100. package/lib/module/useLinkProps.js.map +1 -0
  101. package/lib/module/useLinkTo.js +36 -0
  102. package/lib/module/useLinkTo.js.map +1 -0
  103. package/lib/module/useLinking.js +292 -0
  104. package/lib/module/useLinking.js.map +1 -0
  105. package/lib/module/useLinking.native.js +143 -0
  106. package/lib/module/useLinking.native.js.map +1 -0
  107. package/lib/module/useScrollToTop.js +87 -0
  108. package/lib/module/useScrollToTop.js.map +1 -0
  109. package/lib/module/useThenable.js +33 -0
  110. package/lib/module/useThenable.js.map +1 -0
  111. package/lib/typescript/src/Link.d.ts +24 -0
  112. package/lib/typescript/src/Link.d.ts.map +1 -0
  113. package/lib/typescript/src/LinkingContext.d.ts +8 -0
  114. package/lib/typescript/src/LinkingContext.d.ts.map +1 -0
  115. package/lib/typescript/src/NavigationContainer.d.ts +26 -0
  116. package/lib/typescript/src/NavigationContainer.d.ts.map +1 -0
  117. package/lib/typescript/src/ServerContainer.d.ts +15 -0
  118. package/lib/typescript/src/ServerContainer.d.ts.map +1 -0
  119. package/lib/typescript/src/ServerContext.d.ts +10 -0
  120. package/lib/typescript/src/ServerContext.d.ts.map +1 -0
  121. package/lib/typescript/src/__mocks__/window.d.ts +19 -0
  122. package/lib/typescript/src/__mocks__/window.d.ts.map +1 -0
  123. package/lib/typescript/src/createMemoryHistory.d.ts +25 -0
  124. package/lib/typescript/src/createMemoryHistory.d.ts.map +1 -0
  125. package/lib/typescript/src/extractPathFromURL.d.ts +2 -0
  126. package/lib/typescript/src/extractPathFromURL.d.ts.map +1 -0
  127. package/lib/typescript/src/index.d.ts +15 -0
  128. package/lib/typescript/src/index.d.ts.map +1 -0
  129. package/lib/typescript/src/theming/DarkTheme.d.ts +4 -0
  130. package/lib/typescript/src/theming/DarkTheme.d.ts.map +1 -0
  131. package/lib/typescript/src/theming/DefaultTheme.d.ts +4 -0
  132. package/lib/typescript/src/theming/DefaultTheme.d.ts.map +1 -0
  133. package/lib/typescript/src/theming/ThemeContext.d.ts +5 -0
  134. package/lib/typescript/src/theming/ThemeContext.d.ts.map +1 -0
  135. package/lib/typescript/src/theming/ThemeProvider.d.ts +9 -0
  136. package/lib/typescript/src/theming/ThemeProvider.d.ts.map +1 -0
  137. package/lib/typescript/src/theming/useTheme.d.ts +2 -0
  138. package/lib/typescript/src/theming/useTheme.d.ts.map +1 -0
  139. package/lib/typescript/src/types.d.ts +127 -0
  140. package/lib/typescript/src/types.d.ts.map +1 -0
  141. package/lib/typescript/src/useBackButton.d.ts +4 -0
  142. package/lib/typescript/src/useBackButton.d.ts.map +1 -0
  143. package/lib/typescript/src/useBackButton.native.d.ts +4 -0
  144. package/lib/typescript/src/useBackButton.native.d.ts.map +1 -0
  145. package/lib/typescript/src/useDocumentTitle.d.ts +8 -0
  146. package/lib/typescript/src/useDocumentTitle.d.ts.map +1 -0
  147. package/lib/typescript/src/useDocumentTitle.native.d.ts +2 -0
  148. package/lib/typescript/src/useDocumentTitle.native.d.ts.map +1 -0
  149. package/lib/typescript/src/useLinkBuilder.d.ts +6 -0
  150. package/lib/typescript/src/useLinkBuilder.d.ts.map +1 -0
  151. package/lib/typescript/src/useLinkProps.d.ts +21 -0
  152. package/lib/typescript/src/useLinkProps.d.ts.map +1 -0
  153. package/lib/typescript/src/useLinkTo.d.ts +9 -0
  154. package/lib/typescript/src/useLinkTo.d.ts.map +1 -0
  155. package/lib/typescript/src/useLinking.d.ts +55 -0
  156. package/lib/typescript/src/useLinking.d.ts.map +1 -0
  157. package/lib/typescript/src/useLinking.native.d.ts +51 -0
  158. package/lib/typescript/src/useLinking.native.d.ts.map +1 -0
  159. package/lib/typescript/src/useScrollToTop.d.ts +27 -0
  160. package/lib/typescript/src/useScrollToTop.d.ts.map +1 -0
  161. package/lib/typescript/src/useThenable.d.ts +2 -0
  162. package/lib/typescript/src/useThenable.d.ts.map +1 -0
  163. package/package.json +1 -0
  164. package/src/Link.tsx +53 -0
  165. package/src/LinkingContext.tsx +12 -0
  166. package/src/NavigationContainer.tsx +152 -0
  167. package/src/ServerContainer.tsx +56 -0
  168. package/src/ServerContext.tsx +14 -0
  169. package/src/__mocks__/window.tsx +77 -0
  170. package/src/createMemoryHistory.tsx +224 -0
  171. package/src/extractPathFromURL.tsx +29 -0
  172. package/src/index.tsx +14 -0
  173. package/src/theming/DarkTheme.tsx +15 -0
  174. package/src/theming/DefaultTheme.tsx +15 -0
  175. package/src/theming/ThemeContext.tsx +10 -0
  176. package/src/theming/ThemeProvider.tsx +15 -0
  177. package/src/theming/useTheme.tsx +9 -0
  178. package/src/types.tsx +145 -0
  179. package/src/useBackButton.native.tsx +33 -0
  180. package/src/useBackButton.tsx +11 -0
  181. package/src/useDocumentTitle.native.tsx +3 -0
  182. package/src/useDocumentTitle.tsx +41 -0
  183. package/src/useLinkBuilder.tsx +82 -0
  184. package/src/useLinkProps.tsx +126 -0
  185. package/src/useLinkTo.tsx +71 -0
  186. package/src/useLinking.native.tsx +215 -0
  187. package/src/useLinking.tsx +395 -0
  188. package/src/useScrollToTop.tsx +116 -0
  189. package/src/useThenable.tsx +41 -0
@@ -0,0 +1,116 @@
1
+ import {
2
+ EventArg,
3
+ NavigationProp,
4
+ useNavigation,
5
+ useRoute,
6
+ } from '@amazon-devices/react-navigation__core';
7
+ import * as React from 'react';
8
+ import type { ScrollView } from 'react-native';
9
+
10
+ type ScrollOptions = { x?: number; y?: number; animated?: boolean };
11
+
12
+ type ScrollableView =
13
+ | { scrollToTop(): void }
14
+ | { scrollTo(options: ScrollOptions): void }
15
+ | { scrollToOffset(options: { offset?: number; animated?: boolean }): void }
16
+ | { scrollResponderScrollTo(options: ScrollOptions): void };
17
+
18
+ type ScrollableWrapper =
19
+ | { getScrollResponder(): React.ReactNode | ScrollView }
20
+ | { getNode(): ScrollableView }
21
+ | ScrollableView;
22
+
23
+ function getScrollableNode(ref: React.RefObject<ScrollableWrapper>) {
24
+ if (ref.current == null) {
25
+ return null;
26
+ }
27
+
28
+ if (
29
+ 'scrollToTop' in ref.current ||
30
+ 'scrollTo' in ref.current ||
31
+ 'scrollToOffset' in ref.current ||
32
+ 'scrollResponderScrollTo' in ref.current
33
+ ) {
34
+ // This is already a scrollable node.
35
+ return ref.current;
36
+ } else if ('getScrollResponder' in ref.current) {
37
+ // If the view is a wrapper like FlatList, SectionList etc.
38
+ // We need to use `getScrollResponder` to get access to the scroll responder
39
+ return ref.current.getScrollResponder();
40
+ } else if ('getNode' in ref.current) {
41
+ // When a `ScrollView` is wraped in `Animated.createAnimatedComponent`
42
+ // we need to use `getNode` to get the ref to the actual scrollview.
43
+ // Note that `getNode` is deprecated in newer versions of react-native
44
+ // this is why we check if we already have a scrollable node above.
45
+ return ref.current.getNode();
46
+ } else {
47
+ return ref.current;
48
+ }
49
+ }
50
+
51
+ export default function useScrollToTop(
52
+ ref: React.RefObject<ScrollableWrapper>
53
+ ) {
54
+ const navigation = useNavigation();
55
+ const route = useRoute();
56
+
57
+ React.useEffect(() => {
58
+ let tabNavigations: NavigationProp<ReactNavigation.RootParamList>[] = [];
59
+ let currentNavigation = navigation;
60
+
61
+ // If the screen is nested inside multiple tab navigators, we should scroll to top for any of them
62
+ // So we need to find all the parent tab navigators and add the listeners there
63
+ while (currentNavigation) {
64
+ if (currentNavigation.getState().type === 'tab') {
65
+ tabNavigations.push(currentNavigation);
66
+ }
67
+
68
+ currentNavigation = currentNavigation.getParent();
69
+ }
70
+
71
+ if (tabNavigations.length === 0) {
72
+ return;
73
+ }
74
+
75
+ const unsubscribers = tabNavigations.map((tab) => {
76
+ return tab.addListener(
77
+ // We don't wanna import tab types here to avoid extra deps
78
+ // in addition, there are multiple tab implementations
79
+ // @ts-expect-error
80
+ 'tabPress',
81
+ (e: EventArg<'tabPress', true>) => {
82
+ // We should scroll to top only when the screen is focused
83
+ const isFocused = navigation.isFocused();
84
+
85
+ // In a nested stack navigator, tab press resets the stack to first screen
86
+ // So we should scroll to top only when we are on first screen
87
+ const isFirst =
88
+ tabNavigations.includes(navigation) ||
89
+ navigation.getState().routes[0].key === route.key;
90
+
91
+ // Run the operation in the next frame so we're sure all listeners have been run
92
+ // This is necessary to know if preventDefault() has been called
93
+ requestAnimationFrame(() => {
94
+ const scrollable = getScrollableNode(ref) as ScrollableWrapper;
95
+
96
+ if (isFocused && isFirst && scrollable && !e.defaultPrevented) {
97
+ if ('scrollToTop' in scrollable) {
98
+ scrollable.scrollToTop();
99
+ } else if ('scrollTo' in scrollable) {
100
+ scrollable.scrollTo({ y: 0, animated: true });
101
+ } else if ('scrollToOffset' in scrollable) {
102
+ scrollable.scrollToOffset({ offset: 0, animated: true });
103
+ } else if ('scrollResponderScrollTo' in scrollable) {
104
+ scrollable.scrollResponderScrollTo({ y: 0, animated: true });
105
+ }
106
+ }
107
+ });
108
+ }
109
+ );
110
+ });
111
+
112
+ return () => {
113
+ unsubscribers.forEach((unsubscribe) => unsubscribe());
114
+ };
115
+ }, [navigation, ref, route.key]);
116
+ }
@@ -0,0 +1,41 @@
1
+ import * as React from 'react';
2
+
3
+ export default function useThenable<T>(create: () => PromiseLike<T>) {
4
+ const [promise] = React.useState(create);
5
+
6
+ let initialState: [boolean, T | undefined] = [false, undefined];
7
+
8
+ // Check if our thenable is synchronous
9
+ promise.then((result) => {
10
+ initialState = [true, result];
11
+ });
12
+
13
+ const [state, setState] = React.useState(initialState);
14
+ const [resolved] = state;
15
+
16
+ React.useEffect(() => {
17
+ let cancelled = false;
18
+
19
+ const resolve = async () => {
20
+ let result;
21
+
22
+ try {
23
+ result = await promise;
24
+ } finally {
25
+ if (!cancelled) {
26
+ setState([true, result]);
27
+ }
28
+ }
29
+ };
30
+
31
+ if (!resolved) {
32
+ resolve();
33
+ }
34
+
35
+ return () => {
36
+ cancelled = true;
37
+ };
38
+ }, [promise, resolved]);
39
+
40
+ return state;
41
+ }