@amazon-devices/react-navigation__native 8.0.9000000000 → 8.0.9000000002

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 (67) hide show
  1. package/SystemModules/amzn__react-navigation__native-8.private.modules.txt +38 -33
  2. package/kepler-compatibility.json +4 -2
  3. package/lib/module/index.js +0 -19
  4. package/oss-attribution/attribution.txt +50 -0
  5. package/oss-attribution/licenseInfos.json +18 -0
  6. package/package.json +1 -1
  7. package/src/index.tsx +1 -17
  8. package/SystemBundles/0fc5c971c5cf41a0dab235bcc6d58e5c06d9aaff650fa9815b525f8b9bb70a03.bundle +0 -9116
  9. package/SystemBundles/0fc5c971c5cf41a0dab235bcc6d58e5c06d9aaff650fa9815b525f8b9bb70a03.map +0 -3543
  10. package/lib/module/Link.js +0 -62
  11. package/lib/module/LinkingContext.js +0 -11
  12. package/lib/module/LocaleDirContext.js +0 -6
  13. package/lib/module/NavigationContainer.js +0 -128
  14. package/lib/module/ServerContainer.js +0 -55
  15. package/lib/module/ServerContext.js +0 -5
  16. package/lib/module/UnhandledLinkingContext.js +0 -14
  17. package/lib/module/__stubs__/createStackNavigator.js +0 -18
  18. package/lib/module/__stubs__/window.js +0 -75
  19. package/lib/module/createMemoryHistory.js +0 -216
  20. package/lib/module/createStaticNavigation.js +0 -54
  21. package/lib/module/extractPathFromURL.js +0 -19
  22. package/lib/module/theming/DarkTheme.js +0 -16
  23. package/lib/module/theming/DefaultTheme.js +0 -16
  24. package/lib/module/theming/fonts.js +0 -61
  25. package/lib/module/types.js +0 -4
  26. package/lib/module/useBackButton.js +0 -7
  27. package/lib/module/useBackButton.native.js +0 -21
  28. package/lib/module/useDocumentTitle.js +0 -26
  29. package/lib/module/useDocumentTitle.native.js +0 -6
  30. package/lib/module/useLinkBuilder.js +0 -85
  31. package/lib/module/useLinkProps.js +0 -93
  32. package/lib/module/useLinkTo.js +0 -26
  33. package/lib/module/useLinking.js +0 -320
  34. package/lib/module/useLinking.native.js +0 -148
  35. package/lib/module/useLocale.js +0 -18
  36. package/lib/module/useRoutePath.js +0 -30
  37. package/lib/module/useScrollToTop.js +0 -91
  38. package/lib/module/useThenable.js +0 -36
  39. package/src/Link.tsx +0 -69
  40. package/src/LinkingContext.tsx +0 -16
  41. package/src/LocaleDirContext.tsx +0 -7
  42. package/src/NavigationContainer.tsx +0 -211
  43. package/src/ServerContainer.tsx +0 -57
  44. package/src/ServerContext.tsx +0 -12
  45. package/src/UnhandledLinkingContext.tsx +0 -18
  46. package/src/__stubs__/createStackNavigator.tsx +0 -46
  47. package/src/__stubs__/window.tsx +0 -77
  48. package/src/createMemoryHistory.tsx +0 -229
  49. package/src/createStaticNavigation.tsx +0 -109
  50. package/src/extractPathFromURL.tsx +0 -29
  51. package/src/theming/DarkTheme.tsx +0 -15
  52. package/src/theming/DefaultTheme.tsx +0 -15
  53. package/src/theming/fonts.tsx +0 -63
  54. package/src/types.tsx +0 -191
  55. package/src/useBackButton.native.tsx +0 -33
  56. package/src/useBackButton.tsx +0 -11
  57. package/src/useDocumentTitle.native.tsx +0 -3
  58. package/src/useDocumentTitle.tsx +0 -41
  59. package/src/useLinkBuilder.tsx +0 -127
  60. package/src/useLinkProps.tsx +0 -156
  61. package/src/useLinkTo.tsx +0 -31
  62. package/src/useLinking.native.tsx +0 -217
  63. package/src/useLinking.tsx +0 -442
  64. package/src/useLocale.tsx +0 -18
  65. package/src/useRoutePath.tsx +0 -34
  66. package/src/useScrollToTop.tsx +0 -120
  67. package/src/useThenable.tsx +0 -42
@@ -1,320 +0,0 @@
1
- "use strict";
2
-
3
- import { findFocusedRoute, getActionFromState as getActionFromStateDefault, getPathFromState as getPathFromStateDefault, getStateFromPath as getStateFromPathDefault, useNavigationIndependentTree } from '@amazon-devices/react-navigation__core';
4
- import isEqual from 'fast-deep-equal';
5
- import * as React from 'react';
6
- import { createMemoryHistory } from "./createMemoryHistory.js";
7
- import { ServerContext } from "./ServerContext.js";
8
- /**
9
- * Find the matching navigation state that changed between 2 navigation states
10
- * e.g.: a -> b -> c -> d and a -> b -> c -> e -> f, if history in b changed, b is the matching state
11
- */
12
- const findMatchingState = (a, b) => {
13
- if (a === undefined || b === undefined || a.key !== b.key) {
14
- return [undefined, undefined];
15
- }
16
-
17
- // Tab and drawer will have `history` property, but stack will have history in `routes`
18
- const aHistoryLength = a.history ? a.history.length : a.routes.length;
19
- const bHistoryLength = b.history ? b.history.length : b.routes.length;
20
- const aRoute = a.routes[a.index];
21
- const bRoute = b.routes[b.index];
22
- const aChildState = aRoute.state;
23
- const bChildState = bRoute.state;
24
-
25
- // Stop here if this is the state object that changed:
26
- // - history length is different
27
- // - focused routes are different
28
- // - one of them doesn't have child state
29
- // - child state keys are different
30
- if (aHistoryLength !== bHistoryLength || aRoute.key !== bRoute.key || aChildState === undefined || bChildState === undefined || aChildState.key !== bChildState.key) {
31
- return [a, b];
32
- }
33
- return findMatchingState(aChildState, bChildState);
34
- };
35
-
36
- /**
37
- * Run async function in series as it's called.
38
- */
39
- export const series = cb => {
40
- let queue = Promise.resolve();
41
- const callback = () => {
42
- // eslint-disable-next-line promise/no-callback-in-promise
43
- queue = queue.then(cb);
44
- };
45
- return callback;
46
- };
47
- const linkingHandlers = [];
48
- export function useLinking(ref, {
49
- enabled = true,
50
- config,
51
- getStateFromPath = getStateFromPathDefault,
52
- getPathFromState = getPathFromStateDefault,
53
- getActionFromState = getActionFromStateDefault
54
- }, onUnhandledLinking) {
55
- const independent = useNavigationIndependentTree();
56
- React.useEffect(() => {
57
- if (process.env.NODE_ENV === 'production') {
58
- return undefined;
59
- }
60
- if (independent) {
61
- return undefined;
62
- }
63
- if (enabled !== false && linkingHandlers.length) {
64
- 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());
65
- }
66
- const handler = Symbol();
67
- if (enabled !== false) {
68
- linkingHandlers.push(handler);
69
- }
70
- return () => {
71
- const index = linkingHandlers.indexOf(handler);
72
- if (index > -1) {
73
- linkingHandlers.splice(index, 1);
74
- }
75
- };
76
- }, [enabled, independent]);
77
- const [history] = React.useState(createMemoryHistory);
78
-
79
- // We store these options in ref to avoid re-creating getInitialState and re-subscribing listeners
80
- // This lets user avoid wrapping the items in `React.useCallback` or `React.useMemo`
81
- // Not re-creating `getInitialState` is important coz it makes it easier for the user to use in an effect
82
- const enabledRef = React.useRef(enabled);
83
- const configRef = React.useRef(config);
84
- const getStateFromPathRef = React.useRef(getStateFromPath);
85
- const getPathFromStateRef = React.useRef(getPathFromState);
86
- const getActionFromStateRef = React.useRef(getActionFromState);
87
- React.useEffect(() => {
88
- enabledRef.current = enabled;
89
- configRef.current = config;
90
- getStateFromPathRef.current = getStateFromPath;
91
- getPathFromStateRef.current = getPathFromState;
92
- getActionFromStateRef.current = getActionFromState;
93
- });
94
- const validateRoutesNotExistInRootState = React.useCallback(state => {
95
- const navigation = ref.current;
96
- const rootState = navigation?.getRootState();
97
- // Make sure that the routes in the state exist in the root navigator
98
- // Otherwise there's an error in the linking configuration
99
- return state?.routes.some(r => !rootState?.routeNames.includes(r.name));
100
- }, [ref]);
101
- const server = React.useContext(ServerContext);
102
- const getInitialState = React.useCallback(() => {
103
- let value;
104
- if (enabledRef.current) {
105
- const location = server?.location ?? (typeof window !== 'undefined' ? window.location : undefined);
106
- const path = location ? location.pathname + location.search : undefined;
107
- if (path) {
108
- value = getStateFromPathRef.current(path, configRef.current);
109
- }
110
-
111
- // If the link were handled, it gets cleared in NavigationContainer
112
- onUnhandledLinking(path);
113
- }
114
- const thenable = {
115
- then(onfulfilled) {
116
- return Promise.resolve(onfulfilled ? onfulfilled(value) : value);
117
- },
118
- catch() {
119
- return thenable;
120
- }
121
- };
122
- return thenable;
123
- // eslint-disable-next-line react-hooks/exhaustive-deps
124
- }, []);
125
- const previousIndexRef = React.useRef(undefined);
126
- const previousStateRef = React.useRef(undefined);
127
- const pendingPopStatePathRef = React.useRef(undefined);
128
- React.useEffect(() => {
129
- previousIndexRef.current = history.index;
130
- return history.listen(() => {
131
- const navigation = ref.current;
132
- if (!navigation || !enabled) {
133
- return;
134
- }
135
- const {
136
- location
137
- } = window;
138
- const path = location.pathname + location.search;
139
- const index = history.index;
140
- const previousIndex = previousIndexRef.current ?? 0;
141
- previousIndexRef.current = index;
142
- pendingPopStatePathRef.current = path;
143
-
144
- // When browser back/forward is clicked, we first need to check if state object for this index exists
145
- // If it does we'll reset to that state object
146
- // Otherwise, we'll handle it like a regular deep link
147
- const record = history.get(index);
148
- if (record?.path === path && record?.state) {
149
- navigation.resetRoot(record.state);
150
- return;
151
- }
152
- const state = getStateFromPathRef.current(path, configRef.current);
153
-
154
- // We should only dispatch an action when going forward
155
- // Otherwise the action will likely add items to history, which would mess things up
156
- if (state) {
157
- // If the link were handled, it gets cleared in NavigationContainer
158
- onUnhandledLinking(path);
159
- // Make sure that the routes in the state exist in the root navigator
160
- // Otherwise there's an error in the linking configuration
161
- if (validateRoutesNotExistInRootState(state)) {
162
- return;
163
- }
164
- if (index > previousIndex) {
165
- const action = getActionFromStateRef.current(state, configRef.current);
166
- if (action !== undefined) {
167
- try {
168
- navigation.dispatch(action);
169
- } catch (e) {
170
- // Ignore any errors from deep linking.
171
- // This could happen in case of malformed links, navigation object not being initialized etc.
172
- console.warn(`An error occurred when trying to handle the link '${path}': ${typeof e === 'object' && e != null && 'message' in e ? e.message : e}`);
173
- }
174
- } else {
175
- navigation.resetRoot(state);
176
- }
177
- } else {
178
- navigation.resetRoot(state);
179
- }
180
- } else {
181
- // if current path didn't return any state, we should revert to initial state
182
- navigation.resetRoot(state);
183
- }
184
- });
185
- }, [enabled, history, onUnhandledLinking, ref, validateRoutesNotExistInRootState]);
186
- React.useEffect(() => {
187
- if (!enabled) {
188
- return;
189
- }
190
- const getPathForRoute = (route, state) => {
191
- let path;
192
-
193
- // If the `route` object contains a `path`, use that path as long as `route.name` and `params` still match
194
- // This makes sure that we preserve the original URL for wildcard routes
195
- if (route?.path) {
196
- const stateForPath = getStateFromPathRef.current(route.path, configRef.current);
197
- if (stateForPath) {
198
- const focusedRoute = findFocusedRoute(stateForPath);
199
- if (focusedRoute && focusedRoute.name === route.name && isEqual(focusedRoute.params, route.params)) {
200
- path = route.path;
201
- }
202
- }
203
- }
204
- if (path == null) {
205
- path = getPathFromStateRef.current(state, configRef.current);
206
- }
207
- const previousRoute = previousStateRef.current ? findFocusedRoute(previousStateRef.current) : undefined;
208
-
209
- // Preserve the hash if the route didn't change
210
- if (previousRoute && route && 'key' in previousRoute && 'key' in route && previousRoute.key === route.key) {
211
- path = path + location.hash;
212
- }
213
- return path;
214
- };
215
- if (ref.current) {
216
- // We need to record the current metadata on the first render if they aren't set
217
- // This will allow the initial state to be in the history entry
218
- const state = ref.current.getRootState();
219
- if (state) {
220
- const route = findFocusedRoute(state);
221
- const path = getPathForRoute(route, state);
222
- if (previousStateRef.current === undefined) {
223
- previousStateRef.current = state;
224
- }
225
- history.replace({
226
- path,
227
- state
228
- });
229
- }
230
- }
231
- const onStateChange = async () => {
232
- const navigation = ref.current;
233
- if (!navigation || !enabled) {
234
- return;
235
- }
236
- const previousState = previousStateRef.current;
237
- const state = navigation.getRootState();
238
-
239
- // root state may not available, for example when root navigators switch inside the container
240
- if (!state) {
241
- return;
242
- }
243
- const pendingPath = pendingPopStatePathRef.current;
244
- const route = findFocusedRoute(state);
245
- const path = getPathForRoute(route, state);
246
- previousStateRef.current = state;
247
- pendingPopStatePathRef.current = undefined;
248
-
249
- // To detect the kind of state change, we need to:
250
- // - Find the common focused navigation state in previous and current state
251
- // - If only the route keys changed, compare history/routes.length to check if we go back/forward/replace
252
- // - If no common focused navigation state found, it's a replace
253
- const [previousFocusedState, focusedState] = findMatchingState(previousState, state);
254
- if (previousFocusedState && focusedState &&
255
- // We should only handle push/pop if path changed from what was in last `popstate`
256
- // Otherwise it's likely a change triggered by `popstate`
257
- path !== pendingPath) {
258
- const historyDelta = (focusedState.history ? focusedState.history.length : focusedState.routes.length) - (previousFocusedState.history ? previousFocusedState.history.length : previousFocusedState.routes.length);
259
- if (historyDelta > 0) {
260
- // If history length is increased, we should pushState
261
- // Note that path might not actually change here, for example, drawer open should pushState
262
- history.push({
263
- path,
264
- state
265
- });
266
- } else if (historyDelta < 0) {
267
- // If history length is decreased, i.e. entries were removed, we want to go back
268
-
269
- const nextIndex = history.backIndex({
270
- path
271
- });
272
- const currentIndex = history.index;
273
- try {
274
- if (nextIndex !== -1 && nextIndex < currentIndex &&
275
- // We should only go back if the entry exists and it's less than current index
276
- history.get(nextIndex)) {
277
- // An existing entry for this path exists and it's less than current index, go back to that
278
- await history.go(nextIndex - currentIndex);
279
- } else {
280
- // We couldn't find an existing entry to go back to, so we'll go back by the delta
281
- // This won't be correct if multiple routes were pushed in one go before
282
- // Usually this shouldn't happen and this is a fallback for that
283
- await history.go(historyDelta);
284
- }
285
-
286
- // Store the updated state as well as fix the path if incorrect
287
- history.replace({
288
- path,
289
- state
290
- });
291
- } catch (e) {
292
- // The navigation was interrupted
293
- }
294
- } else {
295
- // If history length is unchanged, we want to replaceState
296
- history.replace({
297
- path,
298
- state
299
- });
300
- }
301
- } else {
302
- // If no common navigation state was found, assume it's a replace
303
- // This would happen if the user did a reset/conditionally changed navigators
304
- history.replace({
305
- path,
306
- state
307
- });
308
- }
309
- };
310
-
311
- // We debounce onStateChange coz we don't want multiple state changes to be handled at one time
312
- // This could happen since `history.go(n)` is asynchronous
313
- // If `pushState` or `replaceState` were called before `history.go(n)` completes, it'll mess stuff up
314
- return ref.current?.addListener('state', series(onStateChange));
315
- }, [enabled, history, ref]);
316
- return {
317
- getInitialState
318
- };
319
- }
320
- //# sourceMappingURL=useLinking.js.map
@@ -1,148 +0,0 @@
1
- "use strict";
2
-
3
- import { getActionFromState as getActionFromStateDefault, getStateFromPath as getStateFromPathDefault, useNavigationIndependentTree } from '@amazon-devices/react-navigation__core';
4
- import * as React from 'react';
5
- import { Linking, Platform } from 'react-native';
6
- import { extractPathFromURL } from "./extractPathFromURL.js";
7
- const linkingHandlers = [];
8
- export function useLinking(ref, {
9
- enabled = true,
10
- prefixes,
11
- filter,
12
- config,
13
- getInitialURL = () => Promise.race([Linking.getInitialURL(), new Promise(resolve => {
14
- // Timeout in 150ms if `getInitialState` doesn't resolve
15
- // Workaround for https://github.com/facebook/react-native/issues/25675
16
- setTimeout(resolve, 150);
17
- })]),
18
- subscribe = listener => {
19
- const callback = ({
20
- url
21
- }) => listener(url);
22
- const subscription = Linking.addEventListener('url', callback);
23
-
24
- // Storing this in a local variable stops Jest from complaining about import after teardown
25
- // @ts-expect-error: removeEventListener is not present in newer RN versions
26
- const removeEventListener = Linking.removeEventListener?.bind(Linking);
27
- return () => {
28
- // https://github.com/facebook/react-native/commit/6d1aca806cee86ad76de771ed3a1cc62982ebcd7
29
- if (subscription?.remove) {
30
- subscription.remove();
31
- } else {
32
- removeEventListener?.('url', callback);
33
- }
34
- };
35
- },
36
- getStateFromPath = getStateFromPathDefault,
37
- getActionFromState = getActionFromStateDefault
38
- }, onUnhandledLinking) {
39
- const independent = useNavigationIndependentTree();
40
- React.useEffect(() => {
41
- if (process.env.NODE_ENV === 'production') {
42
- return undefined;
43
- }
44
- if (independent) {
45
- return undefined;
46
- }
47
- if (enabled !== false && linkingHandlers.length) {
48
- 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());
49
- }
50
- const handler = Symbol();
51
- if (enabled !== false) {
52
- linkingHandlers.push(handler);
53
- }
54
- return () => {
55
- const index = linkingHandlers.indexOf(handler);
56
- if (index > -1) {
57
- linkingHandlers.splice(index, 1);
58
- }
59
- };
60
- }, [enabled, independent]);
61
-
62
- // We store these options in ref to avoid re-creating getInitialState and re-subscribing listeners
63
- // This lets user avoid wrapping the items in `React.useCallback` or `React.useMemo`
64
- // Not re-creating `getInitialState` is important coz it makes it easier for the user to use in an effect
65
- const enabledRef = React.useRef(enabled);
66
- const prefixesRef = React.useRef(prefixes);
67
- const filterRef = React.useRef(filter);
68
- const configRef = React.useRef(config);
69
- const getInitialURLRef = React.useRef(getInitialURL);
70
- const getStateFromPathRef = React.useRef(getStateFromPath);
71
- const getActionFromStateRef = React.useRef(getActionFromState);
72
- React.useEffect(() => {
73
- enabledRef.current = enabled;
74
- prefixesRef.current = prefixes;
75
- filterRef.current = filter;
76
- configRef.current = config;
77
- getInitialURLRef.current = getInitialURL;
78
- getStateFromPathRef.current = getStateFromPath;
79
- getActionFromStateRef.current = getActionFromState;
80
- });
81
- const getStateFromURL = React.useCallback(url => {
82
- if (!url || filterRef.current && !filterRef.current(url)) {
83
- return undefined;
84
- }
85
- const path = extractPathFromURL(prefixesRef.current, url);
86
- return path !== undefined ? getStateFromPathRef.current(path, configRef.current) : undefined;
87
- }, []);
88
- const getInitialState = React.useCallback(() => {
89
- let state;
90
- if (enabledRef.current) {
91
- const url = getInitialURLRef.current();
92
- if (url != null) {
93
- if (typeof url !== 'string') {
94
- return url.then(url => {
95
- const state = getStateFromURL(url);
96
- if (typeof url === 'string') {
97
- // If the link were handled, it gets cleared in NavigationContainer
98
- onUnhandledLinking(extractPathFromURL(prefixes, url));
99
- }
100
- return state;
101
- });
102
- } else {
103
- onUnhandledLinking(extractPathFromURL(prefixes, url));
104
- }
105
- }
106
- state = getStateFromURL(url);
107
- }
108
- const thenable = {
109
- then(onfulfilled) {
110
- return Promise.resolve(onfulfilled ? onfulfilled(state) : state);
111
- },
112
- catch() {
113
- return thenable;
114
- }
115
- };
116
- return thenable;
117
- }, [getStateFromURL, onUnhandledLinking, prefixes]);
118
- React.useEffect(() => {
119
- const listener = url => {
120
- if (!enabled) {
121
- return;
122
- }
123
- const navigation = ref.current;
124
- const state = navigation ? getStateFromURL(url) : undefined;
125
- if (navigation && state) {
126
- // If the link were handled, it gets cleared in NavigationContainer
127
- onUnhandledLinking(extractPathFromURL(prefixes, url));
128
- const action = getActionFromStateRef.current(state, configRef.current);
129
- if (action !== undefined) {
130
- try {
131
- navigation.dispatch(action);
132
- } catch (e) {
133
- // Ignore any errors from deep linking.
134
- // This could happen in case of malformed links, navigation object not being initialized etc.
135
- console.warn(`An error occurred when trying to handle the link '${url}': ${typeof e === 'object' && e != null && 'message' in e ? e.message : e}`);
136
- }
137
- } else {
138
- navigation.resetRoot(state);
139
- }
140
- }
141
- };
142
- return subscribe(listener);
143
- }, [enabled, getStateFromURL, onUnhandledLinking, prefixes, ref, subscribe]);
144
- return {
145
- getInitialState
146
- };
147
- }
148
- //# sourceMappingURL=useLinking.native.js.map
@@ -1,18 +0,0 @@
1
- "use strict";
2
-
3
- import * as React from 'react';
4
- import { LocaleDirContext } from "./LocaleDirContext.js";
5
-
6
- /**
7
- * Hook to access the text direction specified in the `NavigationContainer`.
8
- */
9
- export function useLocale() {
10
- const direction = React.useContext(LocaleDirContext);
11
- if (direction === undefined) {
12
- throw new Error("Couldn't determine the text direction. Is your component inside NavigationContainer?");
13
- }
14
- return {
15
- direction
16
- };
17
- }
18
- //# sourceMappingURL=useLocale.js.map
@@ -1,30 +0,0 @@
1
- "use strict";
2
-
3
- import { getPathFromState, useStateForPath } from '@amazon-devices/react-navigation__core';
4
- import * as React from 'react';
5
- import { LinkingContext } from "./LinkingContext.js";
6
-
7
- /**
8
- * Hook to get the path for the current route based on linking options.
9
- *
10
- * @returns Path for the current route.
11
- */
12
- export function useRoutePath() {
13
- const {
14
- options
15
- } = React.useContext(LinkingContext);
16
- const state = useStateForPath();
17
- if (state === undefined) {
18
- throw new Error("Couldn't find a state for the route object. Is your component inside a screen in a navigator?");
19
- }
20
- const getPathFromStateHelper = options?.getPathFromState ?? getPathFromState;
21
- const path = React.useMemo(() => {
22
- if (options?.enabled === false) {
23
- return undefined;
24
- }
25
- const path = getPathFromStateHelper(state, options?.config);
26
- return path;
27
- }, [options?.enabled, options?.config, state, getPathFromStateHelper]);
28
- return path;
29
- }
30
- //# sourceMappingURL=useRoutePath.js.map
@@ -1,91 +0,0 @@
1
- "use strict";
2
-
3
- import { NavigationContext, useRoute } from '@amazon-devices/react-navigation__core';
4
- import * as React from 'react';
5
- function getScrollableNode(ref) {
6
- if (ref.current == null) {
7
- return null;
8
- }
9
- if ('scrollToTop' in ref.current || 'scrollTo' in ref.current || 'scrollToOffset' in ref.current || 'scrollResponderScrollTo' in ref.current) {
10
- // This is already a scrollable node.
11
- return ref.current;
12
- } else if ('getScrollResponder' in ref.current) {
13
- // If the view is a wrapper like FlatList, SectionList etc.
14
- // We need to use `getScrollResponder` to get access to the scroll responder
15
- return ref.current.getScrollResponder();
16
- } else if ('getNode' in ref.current) {
17
- // When a `ScrollView` is wrapped in `Animated.createAnimatedComponent`
18
- // we need to use `getNode` to get the ref to the actual scrollview.
19
- // Note that `getNode` is deprecated in newer versions of react-native
20
- // this is why we check if we already have a scrollable node above.
21
- return ref.current.getNode();
22
- } else {
23
- return ref.current;
24
- }
25
- }
26
- export function useScrollToTop(ref) {
27
- const navigation = React.useContext(NavigationContext);
28
- const route = useRoute();
29
- if (navigation === undefined) {
30
- throw new Error("Couldn't find a navigation object. Is your component inside NavigationContainer?");
31
- }
32
- React.useEffect(() => {
33
- const tabNavigations = [];
34
- let currentNavigation = navigation;
35
- // If the screen is nested inside multiple tab navigators, we should scroll to top for any of them
36
- // So we need to find all the parent tab navigators and add the listeners there
37
- while (currentNavigation) {
38
- if (currentNavigation.getState().type === 'tab') {
39
- tabNavigations.push(currentNavigation);
40
- }
41
- currentNavigation = currentNavigation.getParent();
42
- }
43
- if (tabNavigations.length === 0) {
44
- return;
45
- }
46
- const unsubscribers = tabNavigations.map(tab => {
47
- return tab.addListener(
48
- // We don't wanna import tab types here to avoid extra deps
49
- // in addition, there are multiple tab implementations
50
- // @ts-expect-error the `tabPress` event is only available when navigation type is tab
51
- 'tabPress', e => {
52
- // We should scroll to top only when the screen is focused
53
- const isFocused = navigation.isFocused();
54
-
55
- // In a nested stack navigator, tab press resets the stack to first screen
56
- // So we should scroll to top only when we are on first screen
57
- const isFirst = tabNavigations.includes(navigation) || navigation.getState().routes[0].key === route.key;
58
-
59
- // Run the operation in the next frame so we're sure all listeners have been run
60
- // This is necessary to know if preventDefault() has been called
61
- requestAnimationFrame(() => {
62
- const scrollable = getScrollableNode(ref);
63
- if (isFocused && isFirst && scrollable && !e.defaultPrevented) {
64
- if ('scrollToTop' in scrollable) {
65
- scrollable.scrollToTop();
66
- } else if ('scrollTo' in scrollable) {
67
- scrollable.scrollTo({
68
- y: 0,
69
- animated: true
70
- });
71
- } else if ('scrollToOffset' in scrollable) {
72
- scrollable.scrollToOffset({
73
- offset: 0,
74
- animated: true
75
- });
76
- } else if ('scrollResponderScrollTo' in scrollable) {
77
- scrollable.scrollResponderScrollTo({
78
- y: 0,
79
- animated: true
80
- });
81
- }
82
- }
83
- });
84
- });
85
- });
86
- return () => {
87
- unsubscribers.forEach(unsubscribe => unsubscribe());
88
- };
89
- }, [navigation, ref, route.key]);
90
- }
91
- //# sourceMappingURL=useScrollToTop.js.map
@@ -1,36 +0,0 @@
1
- "use strict";
2
-
3
- import * as React from 'react';
4
- export function useThenable(create) {
5
- const [promise] = React.useState(create);
6
- let initialState = [false, undefined];
7
-
8
- // Check if our thenable is synchronous
9
- // eslint-disable-next-line promise/catch-or-return, promise/always-return
10
- promise.then(result => {
11
- initialState = [true, result];
12
- });
13
- const [state, setState] = React.useState(initialState);
14
- const [resolved] = state;
15
- React.useEffect(() => {
16
- let cancelled = false;
17
- const resolve = async () => {
18
- let result;
19
- try {
20
- result = await promise;
21
- } finally {
22
- if (!cancelled) {
23
- setState([true, result]);
24
- }
25
- }
26
- };
27
- if (!resolved) {
28
- resolve();
29
- }
30
- return () => {
31
- cancelled = true;
32
- };
33
- }, [promise, resolved]);
34
- return state;
35
- }
36
- //# sourceMappingURL=useThenable.js.map