@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,292 @@
1
+ import { findFocusedRoute, getActionFromState as getActionFromStateDefault, getPathFromState as getPathFromStateDefault, getStateFromPath as getStateFromPathDefault } from '@amazon-devices/react-navigation__core';
2
+ import isEqual from 'fast-deep-equal';
3
+ import * as React from 'react';
4
+ import createMemoryHistory from './createMemoryHistory';
5
+ import ServerContext from './ServerContext';
6
+ /**
7
+ * Find the matching navigation state that changed between 2 navigation states
8
+ * e.g.: a -> b -> c -> d and a -> b -> c -> e -> f, if history in b changed, b is the matching state
9
+ */
10
+ const findMatchingState = (a, b) => {
11
+ if (a === undefined || b === undefined || a.key !== b.key) {
12
+ return [undefined, undefined];
13
+ }
14
+
15
+ // Tab and drawer will have `history` property, but stack will have history in `routes`
16
+ const aHistoryLength = a.history ? a.history.length : a.routes.length;
17
+ const bHistoryLength = b.history ? b.history.length : b.routes.length;
18
+ const aRoute = a.routes[a.index];
19
+ const bRoute = b.routes[b.index];
20
+ const aChildState = aRoute.state;
21
+ const bChildState = bRoute.state;
22
+
23
+ // Stop here if this is the state object that changed:
24
+ // - history length is different
25
+ // - focused routes are different
26
+ // - one of them doesn't have child state
27
+ // - child state keys are different
28
+ if (aHistoryLength !== bHistoryLength || aRoute.key !== bRoute.key || aChildState === undefined || bChildState === undefined || aChildState.key !== bChildState.key) {
29
+ return [a, b];
30
+ }
31
+ return findMatchingState(aChildState, bChildState);
32
+ };
33
+
34
+ /**
35
+ * Run async function in series as it's called.
36
+ */
37
+ export const series = cb => {
38
+ let queue = Promise.resolve();
39
+ const callback = () => {
40
+ queue = queue.then(cb);
41
+ };
42
+ return callback;
43
+ };
44
+ let linkingHandlers = [];
45
+ export default function useLinking(ref, {
46
+ independent,
47
+ enabled = true,
48
+ config,
49
+ getStateFromPath = getStateFromPathDefault,
50
+ getPathFromState = getPathFromStateDefault,
51
+ getActionFromState = getActionFromStateDefault
52
+ }) {
53
+ React.useEffect(() => {
54
+ if (process.env.NODE_ENV === 'production') {
55
+ return undefined;
56
+ }
57
+ if (independent) {
58
+ return undefined;
59
+ }
60
+ if (enabled !== false && linkingHandlers.length) {
61
+ console.error(['Looks like you have configured linking in multiple places. This is likely an error since deep links should only be handled in one place to avoid conflicts. Make sure that:', "- You don't have multiple NavigationContainers in the app each with 'linking' enabled", '- Only a single instance of the root component is rendered'].join('\n').trim());
62
+ }
63
+ const handler = Symbol();
64
+ if (enabled !== false) {
65
+ linkingHandlers.push(handler);
66
+ }
67
+ return () => {
68
+ const index = linkingHandlers.indexOf(handler);
69
+ if (index > -1) {
70
+ linkingHandlers.splice(index, 1);
71
+ }
72
+ };
73
+ }, [enabled, independent]);
74
+ const [history] = React.useState(createMemoryHistory);
75
+
76
+ // We store these options in ref to avoid re-creating getInitialState and re-subscribing listeners
77
+ // This lets user avoid wrapping the items in `React.useCallback` or `React.useMemo`
78
+ // Not re-creating `getInitialState` is important coz it makes it easier for the user to use in an effect
79
+ const enabledRef = React.useRef(enabled);
80
+ const configRef = React.useRef(config);
81
+ const getStateFromPathRef = React.useRef(getStateFromPath);
82
+ const getPathFromStateRef = React.useRef(getPathFromState);
83
+ const getActionFromStateRef = React.useRef(getActionFromState);
84
+ React.useEffect(() => {
85
+ enabledRef.current = enabled;
86
+ configRef.current = config;
87
+ getStateFromPathRef.current = getStateFromPath;
88
+ getPathFromStateRef.current = getPathFromState;
89
+ getActionFromStateRef.current = getActionFromState;
90
+ });
91
+ const server = React.useContext(ServerContext);
92
+ const getInitialState = React.useCallback(() => {
93
+ let value;
94
+ if (enabledRef.current) {
95
+ const location = (server === null || server === void 0 ? void 0 : server.location) ?? (typeof window !== 'undefined' ? window.location : undefined);
96
+ const path = location ? location.pathname + location.search : undefined;
97
+ if (path) {
98
+ value = getStateFromPathRef.current(path, configRef.current);
99
+ }
100
+ }
101
+ const thenable = {
102
+ then(onfulfilled) {
103
+ return Promise.resolve(onfulfilled ? onfulfilled(value) : value);
104
+ },
105
+ catch() {
106
+ return thenable;
107
+ }
108
+ };
109
+ return thenable;
110
+ // eslint-disable-next-line react-hooks/exhaustive-deps
111
+ }, []);
112
+ const previousIndexRef = React.useRef(undefined);
113
+ const previousStateRef = React.useRef(undefined);
114
+ const pendingPopStatePathRef = React.useRef(undefined);
115
+ React.useEffect(() => {
116
+ previousIndexRef.current = history.index;
117
+ return history.listen(() => {
118
+ const navigation = ref.current;
119
+ if (!navigation || !enabled) {
120
+ return;
121
+ }
122
+ const path = location.pathname + location.search;
123
+ const index = history.index;
124
+ const previousIndex = previousIndexRef.current ?? 0;
125
+ previousIndexRef.current = index;
126
+ pendingPopStatePathRef.current = path;
127
+
128
+ // When browser back/forward is clicked, we first need to check if state object for this index exists
129
+ // If it does we'll reset to that state object
130
+ // Otherwise, we'll handle it like a regular deep link
131
+ const record = history.get(index);
132
+ if ((record === null || record === void 0 ? void 0 : record.path) === path && record !== null && record !== void 0 && record.state) {
133
+ navigation.resetRoot(record.state);
134
+ return;
135
+ }
136
+ const state = getStateFromPathRef.current(path, configRef.current);
137
+
138
+ // We should only dispatch an action when going forward
139
+ // Otherwise the action will likely add items to history, which would mess things up
140
+ if (state) {
141
+ // Make sure that the routes in the state exist in the root navigator
142
+ // Otherwise there's an error in the linking configuration
143
+ const rootState = navigation.getRootState();
144
+ if (state.routes.some(r => !(rootState !== null && rootState !== void 0 && rootState.routeNames.includes(r.name)))) {
145
+ console.warn("The navigation state parsed from the URL contains routes not present in the root navigator. This usually means that the linking configuration doesn't match the navigation structure. See https://reactnavigation.org/docs/configuring-links for more details on how to specify a linking configuration.");
146
+ return;
147
+ }
148
+ if (index > previousIndex) {
149
+ const action = getActionFromStateRef.current(state, configRef.current);
150
+ if (action !== undefined) {
151
+ try {
152
+ navigation.dispatch(action);
153
+ } catch (e) {
154
+ // Ignore any errors from deep linking.
155
+ // This could happen in case of malformed links, navigation object not being initialized etc.
156
+ console.warn(`An error occurred when trying to handle the link '${path}': ${typeof e === 'object' && e != null && 'message' in e ? e.message : e}`);
157
+ }
158
+ } else {
159
+ navigation.resetRoot(state);
160
+ }
161
+ } else {
162
+ navigation.resetRoot(state);
163
+ }
164
+ } else {
165
+ // if current path didn't return any state, we should revert to initial state
166
+ navigation.resetRoot(state);
167
+ }
168
+ });
169
+ }, [enabled, history, ref]);
170
+ React.useEffect(() => {
171
+ var _ref$current;
172
+ if (!enabled) {
173
+ return;
174
+ }
175
+ const getPathForRoute = (route, state) => {
176
+ // If the `route` object contains a `path`, use that path as long as `route.name` and `params` still match
177
+ // This makes sure that we preserve the original URL for wildcard routes
178
+ if (route !== null && route !== void 0 && route.path) {
179
+ const stateForPath = getStateFromPathRef.current(route.path, configRef.current);
180
+ if (stateForPath) {
181
+ const focusedRoute = findFocusedRoute(stateForPath);
182
+ if (focusedRoute && focusedRoute.name === route.name && isEqual(focusedRoute.params, route.params)) {
183
+ return route.path;
184
+ }
185
+ }
186
+ }
187
+ return getPathFromStateRef.current(state, configRef.current);
188
+ };
189
+ if (ref.current) {
190
+ // We need to record the current metadata on the first render if they aren't set
191
+ // This will allow the initial state to be in the history entry
192
+ const state = ref.current.getRootState();
193
+ if (state) {
194
+ const route = findFocusedRoute(state);
195
+ const path = getPathForRoute(route, state);
196
+ if (previousStateRef.current === undefined) {
197
+ previousStateRef.current = state;
198
+ }
199
+ history.replace({
200
+ path,
201
+ state
202
+ });
203
+ }
204
+ }
205
+ const onStateChange = async () => {
206
+ const navigation = ref.current;
207
+ if (!navigation || !enabled) {
208
+ return;
209
+ }
210
+ const previousState = previousStateRef.current;
211
+ const state = navigation.getRootState();
212
+
213
+ // root state may not available, for example when root navigators switch inside the container
214
+ if (!state) {
215
+ return;
216
+ }
217
+ const pendingPath = pendingPopStatePathRef.current;
218
+ const route = findFocusedRoute(state);
219
+ const path = getPathForRoute(route, state);
220
+ previousStateRef.current = state;
221
+ pendingPopStatePathRef.current = undefined;
222
+
223
+ // To detect the kind of state change, we need to:
224
+ // - Find the common focused navigation state in previous and current state
225
+ // - If only the route keys changed, compare history/routes.length to check if we go back/forward/replace
226
+ // - If no common focused navigation state found, it's a replace
227
+ const [previousFocusedState, focusedState] = findMatchingState(previousState, state);
228
+ if (previousFocusedState && focusedState &&
229
+ // We should only handle push/pop if path changed from what was in last `popstate`
230
+ // Otherwise it's likely a change triggered by `popstate`
231
+ path !== pendingPath) {
232
+ const historyDelta = (focusedState.history ? focusedState.history.length : focusedState.routes.length) - (previousFocusedState.history ? previousFocusedState.history.length : previousFocusedState.routes.length);
233
+ if (historyDelta > 0) {
234
+ // If history length is increased, we should pushState
235
+ // Note that path might not actually change here, for example, drawer open should pushState
236
+ history.push({
237
+ path,
238
+ state
239
+ });
240
+ } else if (historyDelta < 0) {
241
+ // If history length is decreased, i.e. entries were removed, we want to go back
242
+
243
+ const nextIndex = history.backIndex({
244
+ path
245
+ });
246
+ const currentIndex = history.index;
247
+ try {
248
+ if (nextIndex !== -1 && nextIndex < currentIndex) {
249
+ // An existing entry for this path exists and it's less than current index, go back to that
250
+ await history.go(nextIndex - currentIndex);
251
+ } else {
252
+ // We couldn't find an existing entry to go back to, so we'll go back by the delta
253
+ // This won't be correct if multiple routes were pushed in one go before
254
+ // Usually this shouldn't happen and this is a fallback for that
255
+ await history.go(historyDelta);
256
+ }
257
+
258
+ // Store the updated state as well as fix the path if incorrect
259
+ history.replace({
260
+ path,
261
+ state
262
+ });
263
+ } catch (e) {
264
+ // The navigation was interrupted
265
+ }
266
+ } else {
267
+ // If history length is unchanged, we want to replaceState
268
+ history.replace({
269
+ path,
270
+ state
271
+ });
272
+ }
273
+ } else {
274
+ // If no common navigation state was found, assume it's a replace
275
+ // This would happen if the user did a reset/conditionally changed navigators
276
+ history.replace({
277
+ path,
278
+ state
279
+ });
280
+ }
281
+ };
282
+
283
+ // We debounce onStateChange coz we don't want multiple state changes to be handled at one time
284
+ // This could happen since `history.go(n)` is asynchronous
285
+ // If `pushState` or `replaceState` were called before `history.go(n)` completes, it'll mess stuff up
286
+ return (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.addListener('state', series(onStateChange));
287
+ }, [enabled, history, ref]);
288
+ return {
289
+ getInitialState
290
+ };
291
+ }
292
+ //# sourceMappingURL=useLinking.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["findFocusedRoute","getActionFromState","getActionFromStateDefault","getPathFromState","getPathFromStateDefault","getStateFromPath","getStateFromPathDefault","isEqual","React","createMemoryHistory","ServerContext","findMatchingState","a","b","undefined","key","aHistoryLength","history","length","routes","bHistoryLength","aRoute","index","bRoute","aChildState","state","bChildState","series","cb","queue","Promise","resolve","callback","then","linkingHandlers","useLinking","ref","independent","enabled","config","useEffect","process","env","NODE_ENV","console","error","join","trim","handler","Symbol","push","indexOf","splice","useState","enabledRef","useRef","configRef","getStateFromPathRef","getPathFromStateRef","getActionFromStateRef","current","server","useContext","getInitialState","useCallback","value","location","window","path","pathname","search","thenable","onfulfilled","catch","previousIndexRef","previousStateRef","pendingPopStatePathRef","listen","navigation","previousIndex","record","get","resetRoot","rootState","getRootState","some","r","routeNames","includes","name","warn","action","dispatch","e","message","_ref$current","getPathForRoute","route","stateForPath","focusedRoute","params","replace","onStateChange","previousState","pendingPath","previousFocusedState","focusedState","historyDelta","nextIndex","backIndex","currentIndex","go","addListener"],"sourceRoot":"../../src","sources":["useLinking.tsx"],"mappings":"AAAA,SACEA,gBAAgB,EAChBC,kBAAkB,IAAIC,yBAAyB,EAC/CC,gBAAgB,IAAIC,uB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AAI,CAAC;YAAEkB,IAAI;YAAE3C;UAAM,CAAC,CAAC;QAC/B,CAAC,MAAM,IAAIkF,YAAY,GAAG,CAAC,EAAE;UAC3B;;UAEA,MAAMC,SAAS,GAAG3F,OAAO,CAAC4F,SAAS,CAAC;YAAEzC;UAAK,CAAC,CAAC;UAC7C,MAAM0C,YAAY,GAAG7F,OAAO,CAACK,KAAK;UAElC,IAAI;YACF,IAAIsF,SAAS,KAAK,CAAC,CAAC,IAAIA,SAAS,GAAGE,YAAY,EAAE;cAChD;cACA,MAAM7F,OAAO,CAAC8F,EAAE,CAACH,SAAS,GAAGE,YAAY,CAAC;YAC5C,CAAC,MAAM;cACL;cACA;cACA;cACA,MAAM7F,OAAO,CAAC8F,EAAE,CAACJ,YAAY,CAAC;YAChC;;YAEA;YACA1F,OAAO,CAACoF,OAAO,CAAC;cAAEjC,IAAI;cAAE3C;YAAM,CAAC,CAAC;UAClC,CAAC,CAAC,OAAOoE,CAAC,EAAE;YACV;UAAA;QAEJ,CAAC,MAAM;UACL;UACA5E,OAAO,CAACoF,OAAO,CAAC;YAAEjC,IAAI;YAAE3C;UAAM,CAAC,CAAC;QAClC;MACF,CAAC,MAAM;QACL;QACA;QACAR,OAAO,CAACoF,OAAO,CAAC;UAAEjC,IAAI;UAAE3C;QAAM,CAAC,CAAC;MAClC;IACF,CAAC;;IAED;IACA;IACA;IACA,QAAAsE,YAAA,GAAO3D,GAAG,CAACwB,OAAO,cAAAmC,YAAA,uBAAXA,YAAA,CAAaiB,WAAW,CAAC,OAAO,EAAErF,MAAM,CAAC2E,aAAa,CAAC,CAAC;EACjE,CAAC,EAAE,CAAChE,OAAO,EAAErB,OAAO,EAAEmB,GAAG,CAAC,CAAC;EAE3B,OAAO;IACL2B;EACF,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1,143 @@
1
+ import { getActionFromState as getActionFromStateDefault, getStateFromPath as getStateFromPathDefault } from '@amazon-devices/react-navigation__core';
2
+ import * as React from 'react';
3
+ import { Linking, Platform } from 'react-native';
4
+ import extractPathFromURL from './extractPathFromURL';
5
+ let linkingHandlers = [];
6
+ export default function useLinking(ref, {
7
+ independent,
8
+ enabled = true,
9
+ prefixes,
10
+ filter,
11
+ config,
12
+ getInitialURL = () => Promise.race([Linking.getInitialURL(), new Promise(resolve =>
13
+ // Timeout in 150ms if `getInitialState` doesn't resolve
14
+ // Workaround for https://github.com/facebook/react-native/issues/25675
15
+ setTimeout(resolve, 150))]),
16
+ subscribe = listener => {
17
+ var _Linking$removeEventL;
18
+ const callback = ({
19
+ url
20
+ }) => listener(url);
21
+ const subscription = Linking.addEventListener('url', callback);
22
+
23
+ // Storing this in a local variable stops Jest from complaining about import after teardown
24
+ // @ts-expect-error: removeEventListener is not present in newer RN versions
25
+ const removeEventListener = (_Linking$removeEventL = Linking.removeEventListener) === null || _Linking$removeEventL === void 0 ? void 0 : _Linking$removeEventL.bind(Linking);
26
+ return () => {
27
+ // https://github.com/facebook/react-native/commit/6d1aca806cee86ad76de771ed3a1cc62982ebcd7
28
+ if (subscription !== null && subscription !== void 0 && subscription.remove) {
29
+ subscription.remove();
30
+ } else {
31
+ removeEventListener === null || removeEventListener === void 0 || removeEventListener('url', callback);
32
+ }
33
+ };
34
+ },
35
+ getStateFromPath = getStateFromPathDefault,
36
+ getActionFromState = getActionFromStateDefault
37
+ }) {
38
+ React.useEffect(() => {
39
+ if (process.env.NODE_ENV === 'production') {
40
+ return undefined;
41
+ }
42
+ if (independent) {
43
+ return undefined;
44
+ }
45
+ if (enabled !== false && linkingHandlers.length) {
46
+ console.error(['Looks like you have configured linking in multiple places. This is likely an error since deep links should only be handled in one place to avoid conflicts. Make sure that:', "- You don't have multiple NavigationContainers in the app each with 'linking' enabled", '- Only a single instance of the root component is rendered', Platform.OS === 'android' ? "- You have set 'android:launchMode=singleTask' in the '<activity />' section of the 'AndroidManifest.xml' file to avoid launching multiple instances" : ''].join('\n').trim());
47
+ }
48
+ const handler = Symbol();
49
+ if (enabled !== false) {
50
+ linkingHandlers.push(handler);
51
+ }
52
+ return () => {
53
+ const index = linkingHandlers.indexOf(handler);
54
+ if (index > -1) {
55
+ linkingHandlers.splice(index, 1);
56
+ }
57
+ };
58
+ }, [enabled, independent]);
59
+
60
+ // We store these options in ref to avoid re-creating getInitialState and re-subscribing listeners
61
+ // This lets user avoid wrapping the items in `React.useCallback` or `React.useMemo`
62
+ // Not re-creating `getInitialState` is important coz it makes it easier for the user to use in an effect
63
+ const enabledRef = React.useRef(enabled);
64
+ const prefixesRef = React.useRef(prefixes);
65
+ const filterRef = React.useRef(filter);
66
+ const configRef = React.useRef(config);
67
+ const getInitialURLRef = React.useRef(getInitialURL);
68
+ const getStateFromPathRef = React.useRef(getStateFromPath);
69
+ const getActionFromStateRef = React.useRef(getActionFromState);
70
+ React.useEffect(() => {
71
+ enabledRef.current = enabled;
72
+ prefixesRef.current = prefixes;
73
+ filterRef.current = filter;
74
+ configRef.current = config;
75
+ getInitialURLRef.current = getInitialURL;
76
+ getStateFromPathRef.current = getStateFromPath;
77
+ getActionFromStateRef.current = getActionFromState;
78
+ });
79
+ const getStateFromURL = React.useCallback(url => {
80
+ if (!url || filterRef.current && !filterRef.current(url)) {
81
+ return undefined;
82
+ }
83
+ const path = extractPathFromURL(prefixesRef.current, url);
84
+ return path !== undefined ? getStateFromPathRef.current(path, configRef.current) : undefined;
85
+ }, []);
86
+ const getInitialState = React.useCallback(() => {
87
+ let state;
88
+ if (enabledRef.current) {
89
+ const url = getInitialURLRef.current();
90
+ if (url != null && typeof url !== 'string') {
91
+ return url.then(url => {
92
+ const state = getStateFromURL(url);
93
+ return state;
94
+ });
95
+ }
96
+ state = getStateFromURL(url);
97
+ }
98
+ const thenable = {
99
+ then(onfulfilled) {
100
+ return Promise.resolve(onfulfilled ? onfulfilled(state) : state);
101
+ },
102
+ catch() {
103
+ return thenable;
104
+ }
105
+ };
106
+ return thenable;
107
+ }, [getStateFromURL]);
108
+ React.useEffect(() => {
109
+ const listener = url => {
110
+ if (!enabled) {
111
+ return;
112
+ }
113
+ const navigation = ref.current;
114
+ const state = navigation ? getStateFromURL(url) : undefined;
115
+ if (navigation && state) {
116
+ // Make sure that the routes in the state exist in the root navigator
117
+ // Otherwise there's an error in the linking configuration
118
+ const rootState = navigation.getRootState();
119
+ if (state.routes.some(r => !(rootState !== null && rootState !== void 0 && rootState.routeNames.includes(r.name)))) {
120
+ console.warn("The navigation state parsed from the URL contains routes not present in the root navigator. This usually means that the linking configuration doesn't match the navigation structure. See https://reactnavigation.org/docs/configuring-links for more details on how to specify a linking configuration.");
121
+ return;
122
+ }
123
+ const action = getActionFromStateRef.current(state, configRef.current);
124
+ if (action !== undefined) {
125
+ try {
126
+ navigation.dispatch(action);
127
+ } catch (e) {
128
+ // Ignore any errors from deep linking.
129
+ // This could happen in case of malformed links, navigation object not being initialized etc.
130
+ console.warn(`An error occurred when trying to handle the link '${url}': ${typeof e === 'object' && e != null && 'message' in e ? e.message : e}`);
131
+ }
132
+ } else {
133
+ navigation.resetRoot(state);
134
+ }
135
+ }
136
+ };
137
+ return subscribe(listener);
138
+ }, [enabled, getStateFromURL, ref, subscribe]);
139
+ return {
140
+ getInitialState
141
+ };
142
+ }
143
+ //# sourceMappingURL=useLinking.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["getActionFromState","getActionFromStateDefault","getStateFromPath","getStateFromPathDefault","React","Linking","Platform","extractPathFromURL","linkingHandlers","useLinking","ref","independent","enabled","prefixes","filter","config","getInitialURL","Promise","race","resolve","setTimeout","subscribe","listener","_Linking$removeEventL","callback","url","subscription","addEventListener","removeEventListener","bind","remove","useEffect","process","env","NODE_ENV","undefined","length","console","error","OS","join","trim","handler","Symbol","push","index","indexOf","splice","enabledRef","useRef","prefixesRef","filterRef","configRef","getInitialURLRef","getStateFromPathRef","getActionFromStateRef","current","getStateFromURL","useCallback","path","getInitialState","state","then","thenable","onfulfilled","catch","navigation","rootState","getRootState","routes","some","r","routeNames","includes","name","warn","action","dispatch","e","message","resetRoot"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AI;YACF+B,UAAU,CAACW,QAAQ,CAACD,MAAM,CAAC;UAC7B,CAAC,CAAC,OAAOE,CAAC,EAAE;YACV;YACA;YACAzC,OAAO,CAACsC,IAAI,CACV,qDAAqDlD,GAAG,MACtD,OAAOqD,CAAC,KAAK,QAAQ,IAAIA,CAAC,IAAI,IAAI,IAAI,SAAS,IAAIA,CAAC,GAChDA,CAAC,CAACC,OAAO,GACTD,CAAC,EAET,CAAC;UACH;QACF,CAAC,MAAM;UACLZ,UAAU,CAACc,SAAS,CAACnB,KAAK,CAAC;QAC7B;MACF;IACF,CAAC;IAED,OAAOxC,SAAS,CAACC,QAAQ,CAAC;EAC5B,CAAC,EAAE,CAACV,OAAO,EAAE6C,eAAe,EAAE/C,GAAG,EAAEW,SAAS,CAAC,CAAC;EAE9C,OAAO;IACLuC;EACF,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1,87 @@
1
+ import { useNavigation, useRoute } from '@amazon-devices/react-navigation__core';
2
+ import * as React from 'react';
3
+ function getScrollableNode(ref) {
4
+ if (ref.current == null) {
5
+ return null;
6
+ }
7
+ if ('scrollToTop' in ref.current || 'scrollTo' in ref.current || 'scrollToOffset' in ref.current || 'scrollResponderScrollTo' in ref.current) {
8
+ // This is already a scrollable node.
9
+ return ref.current;
10
+ } else if ('getScrollResponder' in ref.current) {
11
+ // If the view is a wrapper like FlatList, SectionList etc.
12
+ // We need to use `getScrollResponder` to get access to the scroll responder
13
+ return ref.current.getScrollResponder();
14
+ } else if ('getNode' in ref.current) {
15
+ // When a `ScrollView` is wraped in `Animated.createAnimatedComponent`
16
+ // we need to use `getNode` to get the ref to the actual scrollview.
17
+ // Note that `getNode` is deprecated in newer versions of react-native
18
+ // this is why we check if we already have a scrollable node above.
19
+ return ref.current.getNode();
20
+ } else {
21
+ return ref.current;
22
+ }
23
+ }
24
+ export default function useScrollToTop(ref) {
25
+ const navigation = useNavigation();
26
+ const route = useRoute();
27
+ React.useEffect(() => {
28
+ let tabNavigations = [];
29
+ let currentNavigation = navigation;
30
+
31
+ // If the screen is nested inside multiple tab navigators, we should scroll to top for any of them
32
+ // So we need to find all the parent tab navigators and add the listeners there
33
+ while (currentNavigation) {
34
+ if (currentNavigation.getState().type === 'tab') {
35
+ tabNavigations.push(currentNavigation);
36
+ }
37
+ currentNavigation = currentNavigation.getParent();
38
+ }
39
+ if (tabNavigations.length === 0) {
40
+ return;
41
+ }
42
+ const unsubscribers = tabNavigations.map(tab => {
43
+ return tab.addListener(
44
+ // We don't wanna import tab types here to avoid extra deps
45
+ // in addition, there are multiple tab implementations
46
+ // @ts-expect-error
47
+ 'tabPress', e => {
48
+ // We should scroll to top only when the screen is focused
49
+ const isFocused = navigation.isFocused();
50
+
51
+ // In a nested stack navigator, tab press resets the stack to first screen
52
+ // So we should scroll to top only when we are on first screen
53
+ const isFirst = tabNavigations.includes(navigation) || navigation.getState().routes[0].key === route.key;
54
+
55
+ // Run the operation in the next frame so we're sure all listeners have been run
56
+ // This is necessary to know if preventDefault() has been called
57
+ requestAnimationFrame(() => {
58
+ const scrollable = getScrollableNode(ref);
59
+ if (isFocused && isFirst && scrollable && !e.defaultPrevented) {
60
+ if ('scrollToTop' in scrollable) {
61
+ scrollable.scrollToTop();
62
+ } else if ('scrollTo' in scrollable) {
63
+ scrollable.scrollTo({
64
+ y: 0,
65
+ animated: true
66
+ });
67
+ } else if ('scrollToOffset' in scrollable) {
68
+ scrollable.scrollToOffset({
69
+ offset: 0,
70
+ animated: true
71
+ });
72
+ } else if ('scrollResponderScrollTo' in scrollable) {
73
+ scrollable.scrollResponderScrollTo({
74
+ y: 0,
75
+ animated: true
76
+ });
77
+ }
78
+ }
79
+ });
80
+ });
81
+ });
82
+ return () => {
83
+ unsubscribers.forEach(unsubscribe => unsubscribe());
84
+ };
85
+ }, [navigation, ref, route.key]);
86
+ }
87
+ //# sourceMappingURL=useScrollToTop.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useNavigation","useRoute","React","getScrollableNode","ref","current","getScrollResponder","getNode","useScrollToTop","navigation","route","useEffect","tabNavigations","currentNavigation","getState","type","push","getParent","length","unsubscribers","map","tab","addListener","e","isFocused","isFirst","includes","routes","key","requestAnimationFrame","scrollable","defaultPrevented","scrollToTop","scrollTo","y","animated","scrollToOffset","offset","scrollResponderScrollTo","forEach","unsubscribe"],"sourceRoot":"../../src","sources":["useScrollToTop.tsx"],"mappings":"AAAA,SAGEA,aAAa,EACbC,QAAQ,QACH,8BAA8B;AACrC,OAAO,KAAKC,KAAK,MAAM,OAAO;AAgB9B,SAASC,iBAAiBA,CAACC,GAAuC,EAAE;EAClE,IAAIA,GAAG,CAACC,OAAO,IAAI,IAAI,EAAE;IACvB,OAAO,IAAI;EACb;EAEA,IACE,aAAa,IAAID,GAAG,CAACC,OAAO,IAC5B,UAAU,IAAID,GAAG,CAACC,OAAO,IACzB,gBAAgB,IAAID,GAAG,CAACC,OAAO,IAC/B,yBAAyB,IAAID,GAAG,CAACC,OAAO,EACxC;IACA;IACA,OAAOD,GAAG,CAACC,OAAO;EACpB,CAAC,MAAM,IAAI,oBAAoB,IAAID,GAAG,CAACC,OAAO,EAAE;IAC9C;IACA;IACA,OAAOD,GAAG,CAACC,OAAO,CAACC,kBAAkB,CAAC,CAAC;EACzC,CAAC,MAAM,IAAI,SAAS,IAAIF,GAAG,CAACC,OAAO,EAAE;IACnC;IACA;IACA;IACA;IACA,OAAOD,GAAG,CAACC,OAAO,CAACE,OAAO,CAAC,CAAC;EAC9B,CAAC,MAAM;IACL,OAAOH,GAAG,CAACC,OAAO;EACpB;AACF;AAEA,eAAe,SAASG,cAAcA,CACpCJ,GAAuC,EACvC;EACA,MAAMK,UAAU,GAAGT,aAAa,CAAC,CAAC;EAClC,MAAMU,KAAK,GAAGT,QAAQ,CAAC,CAAC;EAExBC,KAAK,CAACS,SAAS,CAAC,MAAM;IACpB,IAAIC,cAA+D,GAAG,EAAE;IACxE,IAAIC,iBAAiB,GAAGJ,UAAU;;IAElC;IACA;IACA,OAAOI,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IAAI,yBAAyB,IAAIL,UAAU,EAAE;cAClDA,UAAU,CAACQ,uBAAuB,CAAC;gBAAEJ,CAAC,EAAE,CAAC;gBAAEC,QAAQ,EAAE;cAAK,CAAC,CAAC;YAC9D;UACF;QACF,CAAC,CAAC;MACJ,CACF,CAAC;IACH,CAAC,CAAC;IAEF,OAAO,MAAM;MACXhB,aAAa,CAACoB,OAAO,CAAEC,WAAW,IAAKA,WAAW,CAAC,CAAC,CAAC;IACvD,CAAC;EACH,CAAC,EAAE,CAAC/B,UAAU,EAAEL,GAAG,EAAEM,KAAK,CAACkB,GAAG,CAAC,CAAC;AAClC","ignoreList":[]}
@@ -0,0 +1,33 @@
1
+ import * as React from 'react';
2
+ export default function useThenable(create) {
3
+ const [promise] = React.useState(create);
4
+ let initialState = [false, undefined];
5
+
6
+ // Check if our thenable is synchronous
7
+ promise.then(result => {
8
+ initialState = [true, result];
9
+ });
10
+ const [state, setState] = React.useState(initialState);
11
+ const [resolved] = state;
12
+ React.useEffect(() => {
13
+ let cancelled = false;
14
+ const resolve = async () => {
15
+ let result;
16
+ try {
17
+ result = await promise;
18
+ } finally {
19
+ if (!cancelled) {
20
+ setState([true, result]);
21
+ }
22
+ }
23
+ };
24
+ if (!resolved) {
25
+ resolve();
26
+ }
27
+ return () => {
28
+ cancelled = true;
29
+ };
30
+ }, [promise, resolved]);
31
+ return state;
32
+ }
33
+ //# sourceMappingURL=useThenable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","useThenable","create","promise","useState","initialState","undefined","then","result","state","setState","resolved","useEffect","cancelled","resolve"],"sourceRoot":"../../src","sources":["useThenable.tsx"],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAE9B,eAAe,SAASC,WAAWA,CAAIC,MAA4B,EAAE;EACnE,MAAM,CAACC,OAAO,CAAC,GAAGH,KAAK,CAACI,QAAQ,CAACF,MAAM,CAAC;EAExC,IAAIG,YAAsC,GAAG,CAAC,KAAK,EAAEC,SAAS,CAAC;;EAE/D;EACAH,OAAO,CAACI,IAAI,CAAEC,MAAM,IAAK;IACvBH,YAAY,GAAG,CAAC,IAAI,EAAEG,MAAM,CAAC;EAC/B,CAAC,CAAC;EAEF,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAGV,KAAK,CAACI,QAAQ,CAACC,YAAY,CAAC;EACtD,MAAM,CAACM,QAAQ,CAAC,GAAGF,KAAK;EAExBT,KAAK,CAACY,SAAS,CAAC,MAAM;IACpB,IAAIC,SAAS,GAAG,KAAK;IAErB,MAAMC,OAAO,GAAG,MAAAA,CAAA,KAAY;MAC1B,IAAIN,MAAM;MAEV,IAAI;QACFA,MAAM,GAAG,MAAML,OAAO;MACxB,CAAC,SAAS;QACR,IAAI,CAACU,SAAS,EAAE;UACdH,QAAQ,CAAC,CAAC,IAAI,EAAEF,MAAM,CAAC,CAAC;QAC1B;MACF;IACF,CAAC;IAED,IAAI,CAACG,QAAQ,EAAE;MACbG,OAAO,CAAC,CAAC;IACX;IAEA,OAAO,MAAM;MACXD,SAAS,GAAG,IAAI;IAClB,CAAC;EACH,CAAC,EAAE,CAACV,OAAO,EAAEQ,QAAQ,CAAC,CAAC;EAEvB,OAAOF,KAAK;AACd","ignoreList":[]}
@@ -0,0 +1,24 @@
1
+ import type { NavigationAction } from '@amazon-devices/react-navigation__core';
2
+ import * as React from 'react';
3
+ import { GestureResponderEvent, Text, TextProps } from 'react-native';
4
+ import type { To } from './useLinkTo';
5
+ type Props<ParamList extends ReactNavigation.RootParamList> = {
6
+ to: To<ParamList>;
7
+ action?: NavigationAction;
8
+ target?: string;
9
+ onPress?: (e: React.MouseEvent<HTMLAnchorElement, MouseEvent> | GestureResponderEvent) => void;
10
+ } & (Omit<TextProps, 'disabled'> & {
11
+ disabled?: boolean | null;
12
+ children: React.ReactNode;
13
+ });
14
+ /**
15
+ * Component to render link to another screen using a path.
16
+ * Uses an anchor tag on the web.
17
+ *
18
+ * @param props.to Absolute path to screen (e.g. `/feeds/hot`).
19
+ * @param props.action Optional action to use for in-page navigation. By default, the path is parsed to an action based on linking config.
20
+ * @param props.children Child elements to render the content.
21
+ */
22
+ export default function Link<ParamList extends ReactNavigation.RootParamList>({ to, action, ...rest }: Props<ParamList>): React.CElement<TextProps, Text>;
23
+ export {};
24
+ //# sourceMappingURL=Link.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Link.d.ts","sourceRoot":"","sources":["../../../src/Link.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,qBAAqB,EAAY,IAAI,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGhF,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAEtC,KAAK,KAAK,CAAC,SAAS,SAAS,eAAe,CAAC,aAAa,IAAI;IAC5D,EAAE,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC;IAClB,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,CACR,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,iBAAiB,EAAE,UAAU,CAAC,GAAG,qBAAqB,KACvE,IAAI,CAAC;CACX,GAAG,CAAC,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC,GAAG;IACjC,QAAQ,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAC1B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,CAAC,CAAC;AAEH;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,IAAI,CAAC,SAAS,SAAS,eAAe,CAAC,aAAa,EAAE,EAC5E,EAAE,EACF,MAAM,EACN,GAAG,IAAI,EACR,EAAE,KAAK,CAAC,SAAS,CAAC,mCAqBlB"}
@@ -0,0 +1,8 @@
1
+ import type { ParamListBase } from '@amazon-devices/react-navigation__core';
2
+ import * as React from 'react';
3
+ import type { LinkingOptions } from './types';
4
+ declare const LinkingContext: React.Context<{
5
+ options: LinkingOptions<ParamListBase> | undefined;
6
+ }>;
7
+ export default LinkingContext;
8
+ //# sourceMappingURL=LinkingContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LinkingContext.d.ts","sourceRoot":"","sources":["../../../src/LinkingContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,QAAA,MAAM,cAAc;aACT,eAAe,aAAa,CAAC,GAAG,SAAS;EAC1B,CAAC;AAI3B,eAAe,cAAc,CAAC"}