@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,229 +0,0 @@
1
- import type { NavigationState } from '@amazon-devices/react-navigation__core';
2
- import { nanoid } from 'nanoid/non-secure';
3
-
4
- type HistoryRecord = {
5
- // Unique identifier for this record to match it with window.history.state
6
- id: string;
7
- // Navigation state object for the history entry
8
- state: NavigationState;
9
- // Path of the history entry
10
- path: string;
11
- };
12
-
13
- export function createMemoryHistory() {
14
- let index = 0;
15
- let items: HistoryRecord[] = [];
16
-
17
- // Pending callbacks for `history.go(n)`
18
- // We might modify the callback stored if it was interrupted, so we have a ref to identify it
19
- const pending: { ref: unknown; cb: (interrupted?: boolean) => void }[] = [];
20
-
21
- const interrupt = () => {
22
- // If another history operation was performed we need to interrupt existing ones
23
- // This makes sure that calls such as `history.replace` after `history.go` don't happen
24
- // Since otherwise it won't be correct if something else has changed
25
- pending.forEach((it) => {
26
- const cb = it.cb;
27
- it.cb = () => cb(true);
28
- });
29
- };
30
-
31
- const history = {
32
- get index(): number {
33
- // We store an id in the state instead of an index
34
- // Index could get out of sync with in-memory values if page reloads
35
- const id = window.history.state?.id;
36
-
37
- if (id) {
38
- const index = items.findIndex((item) => item.id === id);
39
-
40
- return index > -1 ? index : 0;
41
- }
42
-
43
- return 0;
44
- },
45
-
46
- get(index: number) {
47
- return items[index];
48
- },
49
-
50
- backIndex({ path }: { path: string }) {
51
- // We need to find the index from the element before current to get closest path to go back to
52
- for (let i = index - 1; i >= 0; i--) {
53
- const item = items[i];
54
-
55
- if (item.path === path) {
56
- return i;
57
- }
58
- }
59
-
60
- return -1;
61
- },
62
-
63
- push({ path, state }: { path: string; state: NavigationState }) {
64
- interrupt();
65
-
66
- const id = nanoid();
67
-
68
- // When a new entry is pushed, all the existing entries after index will be inaccessible
69
- // So we remove any existing entries after the current index to clean them up
70
- items = items.slice(0, index + 1);
71
-
72
- items.push({ path, state, id });
73
- index = items.length - 1;
74
-
75
- // We pass empty string for title because it's ignored in all browsers except safari
76
- // We don't store state object in history.state because:
77
- // - browsers have limits on how big it can be, and we don't control the size
78
- // - while not recommended, there could be non-serializable data in state
79
- window.history.pushState({ id }, '', path);
80
- },
81
-
82
- replace({ path, state }: { path: string; state: NavigationState }) {
83
- interrupt();
84
-
85
- const id = window.history.state?.id ?? nanoid();
86
-
87
- // Need to keep the hash part of the path if there was no previous history entry
88
- // or the previous history entry had the same path
89
- let pathWithHash = path;
90
- const hash = pathWithHash.includes('#') ? '' : location.hash;
91
-
92
- if (!items.length || items.findIndex((item) => item.id === id) < 0) {
93
- // There are two scenarios for creating an array with only one history record:
94
- // - When loaded id not found in the items array, this function by default will replace
95
- // the first item. We need to keep only the new updated object, otherwise it will break
96
- // the page when navigating forward in history.
97
- // - This is the first time any state modifications are done
98
- // So we need to push the entry as there's nothing to replace
99
-
100
- pathWithHash = pathWithHash + hash;
101
- items = [{ path: pathWithHash, state, id }];
102
- index = 0;
103
- } else {
104
- if (items[index].path === path) {
105
- pathWithHash = pathWithHash + hash;
106
- }
107
- items[index] = { path, state, id };
108
- }
109
-
110
- window.history.replaceState({ id }, '', pathWithHash);
111
- },
112
-
113
- // `history.go(n)` is asynchronous, there are couple of things to keep in mind:
114
- // - it won't do anything if we can't go `n` steps, the `popstate` event won't fire.
115
- // - each `history.go(n)` call will trigger a separate `popstate` event with correct location.
116
- // - the `popstate` event fires before the next frame after calling `history.go(n)`.
117
- // This method differs from `history.go(n)` in the sense that it'll go back as many steps it can.
118
- go(n: number) {
119
- interrupt();
120
-
121
- // To guard against unexpected navigation out of the app we will assume that browser history is only as deep as the length of our memory
122
- // history. If we don't have an item to navigate to then update our index and navigate as far as we can without taking the user out of the app.
123
- const nextIndex = index + n;
124
- const lastItemIndex = items.length - 1;
125
- if (n < 0 && !items[nextIndex]) {
126
- // Attempted to navigate beyond the first index. Negating the current index will align the browser history with the first item.
127
- n = -index;
128
- index = 0;
129
- } else if (n > 0 && nextIndex > lastItemIndex) {
130
- // Attempted to navigate past the last index. Calculate how many indices away from the last index and go there.
131
- n = lastItemIndex - index;
132
- index = lastItemIndex;
133
- } else {
134
- index = nextIndex;
135
- }
136
-
137
- if (n === 0) {
138
- return;
139
- }
140
-
141
- // When we call `history.go`, `popstate` will fire when there's history to go back to
142
- // So we need to somehow handle following cases:
143
- // - There's history to go back, `history.go` is called, and `popstate` fires
144
- // - `history.go` is called multiple times, we need to resolve on respective `popstate`
145
- // - No history to go back, but `history.go` was called, browser has no API to detect it
146
- return new Promise<void>((resolve, reject) => {
147
- const done = (interrupted?: boolean) => {
148
- clearTimeout(timer);
149
-
150
- if (interrupted) {
151
- reject(new Error('History was changed during navigation.'));
152
- return;
153
- }
154
-
155
- // There seems to be a bug in Chrome regarding updating the title
156
- // If we set a title just before calling `history.go`, the title gets lost
157
- // However the value of `document.title` is still what we set it to
158
- // It's just not displayed in the tab bar
159
- // To update the tab bar, we need to reset the title to something else first (e.g. '')
160
- // And set the title to what it was before so it gets applied
161
- // It won't work without setting it to empty string coz otherwise title isn't changing
162
- // Which means that the browser won't do anything after setting the title
163
- const { title } = window.document;
164
-
165
- window.document.title = '';
166
- window.document.title = title;
167
-
168
- resolve();
169
- };
170
-
171
- pending.push({ ref: done, cb: done });
172
-
173
- // If navigation didn't happen within 100ms, assume that it won't happen
174
- // This may not be accurate, but hopefully it won't take so much time
175
- // In Chrome, navigation seems to happen instantly in next microtask
176
- // But on Firefox, it seems to take much longer, around 50ms from our testing
177
- // We're using a hacky timeout since there doesn't seem to be way to know for sure
178
- const timer = setTimeout(() => {
179
- const foundIndex = pending.findIndex((it) => it.ref === done);
180
-
181
- if (foundIndex > -1) {
182
- pending[foundIndex].cb();
183
- pending.splice(foundIndex, 1);
184
- }
185
-
186
- index = this.index;
187
- }, 100);
188
-
189
- const onPopState = () => {
190
- // Fix createMemoryHistory.index variable's value
191
- // as it may go out of sync when navigating in the browser.
192
- index = this.index;
193
-
194
- const last = pending.pop();
195
-
196
- window.removeEventListener('popstate', onPopState);
197
- last?.cb();
198
- };
199
-
200
- window.addEventListener('popstate', onPopState);
201
- window.history.go(n);
202
- });
203
- },
204
-
205
- // The `popstate` event is triggered when history changes, except `pushState` and `replaceState`
206
- // If we call `history.go(n)` ourselves, we don't want it to trigger the listener
207
- // Here we normalize it so that only external changes (e.g. user pressing back/forward) trigger the listener
208
- listen(listener: () => void) {
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
-
214
- if (pending.length) {
215
- // This was triggered by `history.go(n)`, we shouldn't call the listener
216
- return;
217
- }
218
-
219
- listener();
220
- };
221
-
222
- window.addEventListener('popstate', onPopState);
223
-
224
- return () => window.removeEventListener('popstate', onPopState);
225
- },
226
- };
227
-
228
- return history;
229
- }
@@ -1,109 +0,0 @@
1
- import {
2
- createComponentForStaticNavigation,
3
- createPathConfigForStaticNavigation,
4
- type NavigationContainerRef,
5
- type ParamListBase,
6
- type StaticNavigation,
7
- } from '@amazon-devices/react-navigation__core';
8
- import * as React from 'react';
9
-
10
- import { NavigationContainer } from './NavigationContainer';
11
- import type { LinkingOptions } from './types';
12
-
13
- type Props = Omit<
14
- React.ComponentProps<typeof NavigationContainer>,
15
- 'linking' | 'children'
16
- > & {
17
- /**
18
- * Options for deep linking.
19
- */
20
- linking?: Omit<LinkingOptions<ParamListBase>, 'config' | 'enabled'> & {
21
- /**
22
- * Whether deep link handling should be enabled.
23
- * Defaults to `true` if any `linking` options are specified, `false` otherwise.
24
- *
25
- * When 'auto' is specified, all leaf screens will get a autogenerated path.
26
- * The generated path will be a kebab-case version of the screen name.
27
- * This can be overridden for specific screens by specifying `linking` for the screen.
28
- */
29
- enabled?: 'auto' | true | false;
30
- /**
31
- * Additional configuration
32
- */
33
- config?: Omit<
34
- NonNullable<LinkingOptions<ParamListBase>['config']>,
35
- 'screens'
36
- >;
37
- };
38
- };
39
-
40
- /**
41
- * Create a navigation component from a static navigation config.
42
- * The returned component is a wrapper around `NavigationContainer`.
43
- *
44
- * @param tree Static navigation config.
45
- * @returns Navigation component to use in your app.
46
- */
47
- export function createStaticNavigation(tree: StaticNavigation<any, any, any>) {
48
- const Component = createComponentForStaticNavigation(tree, 'RootNavigator');
49
-
50
- function Navigation(
51
- { linking, ...rest }: Props,
52
- ref: React.Ref<NavigationContainerRef<ParamListBase>>
53
- ) {
54
- const linkingConfig = React.useMemo(() => {
55
- const screens = createPathConfigForStaticNavigation(
56
- tree,
57
- { initialRouteName: linking?.config?.initialRouteName },
58
- linking?.enabled === 'auto'
59
- );
60
-
61
- if (!screens) return;
62
-
63
- return {
64
- path: linking?.config?.path,
65
- initialRouteName: linking?.config?.initialRouteName,
66
- screens,
67
- };
68
- }, [
69
- linking?.enabled,
70
- linking?.config?.path,
71
- linking?.config?.initialRouteName,
72
- ]);
73
-
74
- const memoizedLinking = React.useMemo(() => {
75
- if (!linking) {
76
- return undefined;
77
- }
78
-
79
- const enabled =
80
- typeof linking.enabled === 'boolean'
81
- ? linking.enabled
82
- : linkingConfig?.screens != null;
83
-
84
- return {
85
- ...linking,
86
- enabled,
87
- config: linkingConfig,
88
- };
89
- }, [linking, linkingConfig]);
90
-
91
- if (linking?.enabled === true && linkingConfig?.screens == null) {
92
- throw new Error(
93
- 'Linking is enabled but no linking configuration was found for the screens.\n\n' +
94
- 'To solve this:\n' +
95
- "- Specify a 'linking' property for the screens you want to link to.\n" +
96
- "- Or set 'linking.enabled' to 'auto' to generate paths automatically.\n\n" +
97
- 'See usage guide: https://reactnavigation.org/docs/static-configuration#linking'
98
- );
99
- }
100
-
101
- return (
102
- <NavigationContainer {...rest} ref={ref} linking={memoizedLinking}>
103
- <Component />
104
- </NavigationContainer>
105
- );
106
- }
107
-
108
- return React.forwardRef(Navigation);
109
- }
@@ -1,29 +0,0 @@
1
- import escapeStringRegexp from 'escape-string-regexp';
2
-
3
- export function extractPathFromURL(prefixes: string[], url: string) {
4
- for (const prefix of prefixes) {
5
- const protocol = prefix.match(/^[^:]+:/)?.[0] ?? '';
6
- const host = prefix
7
- .replace(new RegExp(`^${escapeStringRegexp(protocol)}`), '')
8
- .replace(/\/+/g, '/') // Replace multiple slash (//) with single ones
9
- .replace(/^\//, ''); // Remove extra leading slash
10
-
11
- const prefixRegex = new RegExp(
12
- `^${escapeStringRegexp(protocol)}(/)*${host
13
- .split('.')
14
- .map((it) => (it === '*' ? '[^/]+' : escapeStringRegexp(it)))
15
- .join('\\.')}`
16
- );
17
-
18
- const [originAndPath, ...searchParams] = url.split('?');
19
- const normalizedURL = originAndPath
20
- .replace(/\/+/g, '/')
21
- .concat(searchParams.length ? `?${searchParams.join('?')}` : '');
22
-
23
- if (prefixRegex.test(normalizedURL)) {
24
- return normalizedURL.replace(prefixRegex, '');
25
- }
26
- }
27
-
28
- return undefined;
29
- }
@@ -1,15 +0,0 @@
1
- import type { Theme } from '../types';
2
- import { fonts } from './fonts';
3
-
4
- export const DarkTheme: Theme = {
5
- dark: true,
6
- colors: {
7
- primary: 'rgb(10, 132, 255)',
8
- background: 'rgb(1, 1, 1)',
9
- card: 'rgb(18, 18, 18)',
10
- text: 'rgb(229, 229, 231)',
11
- border: 'rgb(39, 39, 41)',
12
- notification: 'rgb(255, 69, 58)',
13
- },
14
- fonts,
15
- };
@@ -1,15 +0,0 @@
1
- import type { Theme } from '../types';
2
- import { fonts } from './fonts';
3
-
4
- export const DefaultTheme: Theme = {
5
- dark: false,
6
- colors: {
7
- primary: 'rgb(0, 122, 255)',
8
- background: 'rgb(242, 242, 242)',
9
- card: 'rgb(255, 255, 255)',
10
- text: 'rgb(28, 28, 30)',
11
- border: 'rgb(216, 216, 216)',
12
- notification: 'rgb(255, 59, 48)',
13
- },
14
- fonts,
15
- };
@@ -1,63 +0,0 @@
1
- import { Platform } from 'react-native';
2
-
3
- import type { Theme } from '../types';
4
-
5
- const WEB_FONT_STACK =
6
- 'system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"';
7
-
8
- export const fonts = Platform.select({
9
- web: {
10
- regular: {
11
- fontFamily: WEB_FONT_STACK,
12
- fontWeight: '400',
13
- },
14
- medium: {
15
- fontFamily: WEB_FONT_STACK,
16
- fontWeight: '500',
17
- },
18
- bold: {
19
- fontFamily: WEB_FONT_STACK,
20
- fontWeight: '600',
21
- },
22
- heavy: {
23
- fontFamily: WEB_FONT_STACK,
24
- fontWeight: '700',
25
- },
26
- },
27
- ios: {
28
- regular: {
29
- fontFamily: 'System',
30
- fontWeight: '400',
31
- },
32
- medium: {
33
- fontFamily: 'System',
34
- fontWeight: '500',
35
- },
36
- bold: {
37
- fontFamily: 'System',
38
- fontWeight: '600',
39
- },
40
- heavy: {
41
- fontFamily: 'System',
42
- fontWeight: '700',
43
- },
44
- },
45
- default: {
46
- regular: {
47
- fontFamily: 'sans-serif',
48
- fontWeight: 'normal',
49
- },
50
- medium: {
51
- fontFamily: 'sans-serif-medium',
52
- fontWeight: 'normal',
53
- },
54
- bold: {
55
- fontFamily: 'sans-serif',
56
- fontWeight: '600',
57
- },
58
- heavy: {
59
- fontFamily: 'sans-serif',
60
- fontWeight: '700',
61
- },
62
- },
63
- } as const satisfies Record<string, Theme['fonts']>);
package/src/types.tsx DELETED
@@ -1,191 +0,0 @@
1
- import type {
2
- getActionFromState as getActionFromStateDefault,
3
- getPathFromState as getPathFromStateDefault,
4
- getStateFromPath as getStateFromPathDefault,
5
- PathConfigMap,
6
- Route,
7
- } from '@amazon-devices/react-navigation__core';
8
-
9
- declare global {
10
- // eslint-disable-next-line @typescript-eslint/no-namespace
11
- namespace ReactNavigation {
12
- interface Theme extends NativeTheme {}
13
- }
14
- }
15
-
16
- type FontStyle = {
17
- fontFamily: string;
18
- fontWeight:
19
- | 'normal'
20
- | 'bold'
21
- | '100'
22
- | '200'
23
- | '300'
24
- | '400'
25
- | '500'
26
- | '600'
27
- | '700'
28
- | '800'
29
- | '900';
30
- };
31
-
32
- interface NativeTheme {
33
- dark: boolean;
34
- colors: {
35
- primary: string;
36
- background: string;
37
- card: string;
38
- text: string;
39
- border: string;
40
- notification: string;
41
- };
42
- fonts: {
43
- regular: FontStyle;
44
- medium: FontStyle;
45
- bold: FontStyle;
46
- heavy: FontStyle;
47
- };
48
- }
49
-
50
- export type Theme = NativeTheme;
51
-
52
- export type LocaleDirection = 'ltr' | 'rtl';
53
-
54
- export type LinkingOptions<ParamList extends {}> = {
55
- /**
56
- * Whether deep link handling should be enabled.
57
- * Defaults to true.
58
- */
59
- enabled?: boolean;
60
- /**
61
- * The prefixes are stripped from the URL before parsing them.
62
- * Usually they are the `scheme` + `host` (e.g. `myapp://chat?user=jane`)
63
- *
64
- * This is not supported on Web.
65
- *
66
- * @example
67
- * ```js
68
- * {
69
- * prefixes: [
70
- * "myapp://", // App-specific scheme
71
- * "https://example.com", // Prefix for universal links
72
- * "https://*.example.com" // Prefix which matches any subdomain
73
- * ]
74
- * }
75
- * ```
76
- */
77
- prefixes: string[];
78
- /**
79
- * Optional function which takes an incoming URL returns a boolean
80
- * indicating whether React Navigation should handle it.
81
- *
82
- * This can be used to disable deep linking for specific URLs.
83
- * e.g. URLs used for authentication, and not for deep linking to screens.
84
- *
85
- * This is not supported on Web.
86
- *
87
- * @example
88
- * ```js
89
- * {
90
- * // Filter out URLs used by expo-auth-session
91
- * filter: (url) => !url.includes('+expo-auth-session')
92
- * }
93
- * ```
94
- */
95
- filter?: (url: string) => boolean;
96
- /**
97
- * Config to fine-tune how to parse the path.
98
- *
99
- * @example
100
- * ```js
101
- * {
102
- * Chat: {
103
- * path: 'chat/:author/:id',
104
- * parse: { id: Number }
105
- * }
106
- * }
107
- * ```
108
- */
109
- config?: {
110
- /**
111
- * Path string to match against for the whole navigation tree.
112
- * It's not possible to specify params here since this doesn't belong to a screen.
113
- * This is useful when the whole app is under a specific path.
114
- * e.g. all of the screens are under `/admin` in `https://example.com/admin`
115
- */
116
- path?: string;
117
- /**
118
- * Path configuration for child screens.
119
- */
120
- screens: PathConfigMap<ParamList>;
121
- /**
122
- * Name of the initial route to use for the root navigator.
123
- */
124
- initialRouteName?: keyof ParamList;
125
- };
126
- /**
127
- * Custom function to get the initial URL used for linking.
128
- * Uses `Linking.getInitialURL()` by default.
129
- *
130
- * This is not supported on Web.
131
- *
132
- * @example
133
- * ```js
134
- * {
135
- * getInitialURL () => Linking.getInitialURL(),
136
- * }
137
- * ```
138
- */
139
- getInitialURL?: () =>
140
- | string
141
- | null
142
- | undefined
143
- | Promise<string | null | undefined>;
144
- /**
145
- * Custom function to get subscribe to URL updates.
146
- * Uses `Linking.addEventListener('url', callback)` by default.
147
- *
148
- * This is not supported on Web.
149
- *
150
- * @example
151
- * ```js
152
- * {
153
- * subscribe: (listener) => {
154
- * const onReceiveURL = ({ url }) => listener(url);
155
- *
156
- * Linking.addEventListener('url', onReceiveURL);
157
- *
158
- * return () => Linking.removeEventListener('url', onReceiveURL);
159
- * }
160
- * }
161
- * ```
162
- */
163
- subscribe?: (
164
- listener: (url: string) => void
165
- ) => undefined | void | (() => void);
166
- /**
167
- * Custom function to parse the URL to a valid navigation state (advanced).
168
- */
169
- getStateFromPath?: typeof getStateFromPathDefault;
170
- /**
171
- * Custom function to convert the state object to a valid URL (advanced).
172
- * Only applicable on Web.
173
- */
174
- getPathFromState?: typeof getPathFromStateDefault;
175
- /**
176
- * Custom function to convert the state object to a valid action (advanced).
177
- */
178
- getActionFromState?: typeof getActionFromStateDefault;
179
- };
180
-
181
- export type DocumentTitleOptions = {
182
- enabled?: boolean;
183
- formatter?: (
184
- options: Record<string, any> | undefined,
185
- route: Route<string> | undefined
186
- ) => string;
187
- };
188
-
189
- export type ServerContainerRef = {
190
- getCurrentOptions(): Record<string, any> | undefined;
191
- };
@@ -1,33 +0,0 @@
1
- import type {
2
- NavigationContainerRef,
3
- ParamListBase,
4
- } from '@amazon-devices/react-navigation__core';
5
- import * as React from 'react';
6
- import { BackHandler } from 'react-native';
7
-
8
- export function useBackButton(
9
- ref: React.RefObject<NavigationContainerRef<ParamListBase> | null>
10
- ) {
11
- React.useEffect(() => {
12
- const subscription = BackHandler.addEventListener(
13
- 'hardwareBackPress',
14
- () => {
15
- const navigation = ref.current;
16
-
17
- if (navigation == null) {
18
- return false;
19
- }
20
-
21
- if (navigation.canGoBack()) {
22
- navigation.goBack();
23
-
24
- return true;
25
- }
26
-
27
- return false;
28
- }
29
- );
30
-
31
- return () => subscription.remove();
32
- }, [ref]);
33
- }
@@ -1,11 +0,0 @@
1
- import type {
2
- NavigationContainerRef,
3
- ParamListBase,
4
- } from '@amazon-devices/react-navigation__core';
5
-
6
- export function useBackButton(
7
- _: React.RefObject<NavigationContainerRef<ParamListBase> | null>
8
- ) {
9
- // No-op
10
- // BackHandler is not available on web
11
- }