@amazon-devices/react-navigation__native 8.0.9000000001 → 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 (62) hide show
  1. package/kepler-compatibility.json +2 -1
  2. package/lib/module/index.js +0 -19
  3. package/package.json +1 -1
  4. package/src/index.tsx +1 -17
  5. package/lib/module/Link.js +0 -62
  6. package/lib/module/LinkingContext.js +0 -11
  7. package/lib/module/LocaleDirContext.js +0 -6
  8. package/lib/module/NavigationContainer.js +0 -128
  9. package/lib/module/ServerContainer.js +0 -55
  10. package/lib/module/ServerContext.js +0 -5
  11. package/lib/module/UnhandledLinkingContext.js +0 -14
  12. package/lib/module/__stubs__/createStackNavigator.js +0 -18
  13. package/lib/module/__stubs__/window.js +0 -75
  14. package/lib/module/createMemoryHistory.js +0 -216
  15. package/lib/module/createStaticNavigation.js +0 -54
  16. package/lib/module/extractPathFromURL.js +0 -19
  17. package/lib/module/theming/DarkTheme.js +0 -16
  18. package/lib/module/theming/DefaultTheme.js +0 -16
  19. package/lib/module/theming/fonts.js +0 -61
  20. package/lib/module/types.js +0 -4
  21. package/lib/module/useBackButton.js +0 -7
  22. package/lib/module/useBackButton.native.js +0 -21
  23. package/lib/module/useDocumentTitle.js +0 -26
  24. package/lib/module/useDocumentTitle.native.js +0 -6
  25. package/lib/module/useLinkBuilder.js +0 -85
  26. package/lib/module/useLinkProps.js +0 -93
  27. package/lib/module/useLinkTo.js +0 -26
  28. package/lib/module/useLinking.js +0 -320
  29. package/lib/module/useLinking.native.js +0 -148
  30. package/lib/module/useLocale.js +0 -18
  31. package/lib/module/useRoutePath.js +0 -30
  32. package/lib/module/useScrollToTop.js +0 -91
  33. package/lib/module/useThenable.js +0 -36
  34. package/src/Link.tsx +0 -69
  35. package/src/LinkingContext.tsx +0 -16
  36. package/src/LocaleDirContext.tsx +0 -7
  37. package/src/NavigationContainer.tsx +0 -211
  38. package/src/ServerContainer.tsx +0 -57
  39. package/src/ServerContext.tsx +0 -12
  40. package/src/UnhandledLinkingContext.tsx +0 -18
  41. package/src/__stubs__/createStackNavigator.tsx +0 -46
  42. package/src/__stubs__/window.tsx +0 -77
  43. package/src/createMemoryHistory.tsx +0 -229
  44. package/src/createStaticNavigation.tsx +0 -109
  45. package/src/extractPathFromURL.tsx +0 -29
  46. package/src/theming/DarkTheme.tsx +0 -15
  47. package/src/theming/DefaultTheme.tsx +0 -15
  48. package/src/theming/fonts.tsx +0 -63
  49. package/src/types.tsx +0 -191
  50. package/src/useBackButton.native.tsx +0 -33
  51. package/src/useBackButton.tsx +0 -11
  52. package/src/useDocumentTitle.native.tsx +0 -3
  53. package/src/useDocumentTitle.tsx +0 -41
  54. package/src/useLinkBuilder.tsx +0 -127
  55. package/src/useLinkProps.tsx +0 -156
  56. package/src/useLinkTo.tsx +0 -31
  57. package/src/useLinking.native.tsx +0 -217
  58. package/src/useLinking.tsx +0 -442
  59. package/src/useLocale.tsx +0 -18
  60. package/src/useRoutePath.tsx +0 -34
  61. package/src/useScrollToTop.tsx +0 -120
  62. package/src/useThenable.tsx +0 -42
@@ -1,54 +0,0 @@
1
- "use strict";
2
-
3
- import { createComponentForStaticNavigation, createPathConfigForStaticNavigation } from '@amazon-devices/react-navigation__core';
4
- import * as React from 'react';
5
- import { NavigationContainer } from "./NavigationContainer.js";
6
- import { jsx as _jsx } from "react/jsx-runtime";
7
- /**
8
- * Create a navigation component from a static navigation config.
9
- * The returned component is a wrapper around `NavigationContainer`.
10
- *
11
- * @param tree Static navigation config.
12
- * @returns Navigation component to use in your app.
13
- */
14
- export function createStaticNavigation(tree) {
15
- const Component = createComponentForStaticNavigation(tree, 'RootNavigator');
16
- function Navigation({
17
- linking,
18
- ...rest
19
- }, ref) {
20
- const linkingConfig = React.useMemo(() => {
21
- const screens = createPathConfigForStaticNavigation(tree, {
22
- initialRouteName: linking?.config?.initialRouteName
23
- }, linking?.enabled === 'auto');
24
- if (!screens) return;
25
- return {
26
- path: linking?.config?.path,
27
- initialRouteName: linking?.config?.initialRouteName,
28
- screens
29
- };
30
- }, [linking?.enabled, linking?.config?.path, linking?.config?.initialRouteName]);
31
- const memoizedLinking = React.useMemo(() => {
32
- if (!linking) {
33
- return undefined;
34
- }
35
- const enabled = typeof linking.enabled === 'boolean' ? linking.enabled : linkingConfig?.screens != null;
36
- return {
37
- ...linking,
38
- enabled,
39
- config: linkingConfig
40
- };
41
- }, [linking, linkingConfig]);
42
- if (linking?.enabled === true && linkingConfig?.screens == null) {
43
- throw new Error('Linking is enabled but no linking configuration was found for the screens.\n\n' + 'To solve this:\n' + "- Specify a 'linking' property for the screens you want to link to.\n" + "- Or set 'linking.enabled' to 'auto' to generate paths automatically.\n\n" + 'See usage guide: https://reactnavigation.org/docs/static-configuration#linking');
44
- }
45
- return /*#__PURE__*/_jsx(NavigationContainer, {
46
- ...rest,
47
- ref: ref,
48
- linking: memoizedLinking,
49
- children: /*#__PURE__*/_jsx(Component, {})
50
- });
51
- }
52
- return /*#__PURE__*/React.forwardRef(Navigation);
53
- }
54
- //# sourceMappingURL=createStaticNavigation.js.map
@@ -1,19 +0,0 @@
1
- "use strict";
2
-
3
- import escapeStringRegexp from 'escape-string-regexp';
4
- export function extractPathFromURL(prefixes, url) {
5
- for (const prefix of prefixes) {
6
- const protocol = prefix.match(/^[^:]+:/)?.[0] ?? '';
7
- const host = prefix.replace(new RegExp(`^${escapeStringRegexp(protocol)}`), '').replace(/\/+/g, '/') // Replace multiple slash (//) with single ones
8
- .replace(/^\//, ''); // Remove extra leading slash
9
-
10
- const prefixRegex = new RegExp(`^${escapeStringRegexp(protocol)}(/)*${host.split('.').map(it => it === '*' ? '[^/]+' : escapeStringRegexp(it)).join('\\.')}`);
11
- const [originAndPath, ...searchParams] = url.split('?');
12
- const normalizedURL = originAndPath.replace(/\/+/g, '/').concat(searchParams.length ? `?${searchParams.join('?')}` : '');
13
- if (prefixRegex.test(normalizedURL)) {
14
- return normalizedURL.replace(prefixRegex, '');
15
- }
16
- }
17
- return undefined;
18
- }
19
- //# sourceMappingURL=extractPathFromURL.js.map
@@ -1,16 +0,0 @@
1
- "use strict";
2
-
3
- import { fonts } from "./fonts.js";
4
- export const DarkTheme = {
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
- };
16
- //# sourceMappingURL=DarkTheme.js.map
@@ -1,16 +0,0 @@
1
- "use strict";
2
-
3
- import { fonts } from "./fonts.js";
4
- export const DefaultTheme = {
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
- };
16
- //# sourceMappingURL=DefaultTheme.js.map
@@ -1,61 +0,0 @@
1
- "use strict";
2
-
3
- import { Platform } from 'react-native';
4
- const WEB_FONT_STACK = 'system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"';
5
- export const fonts = Platform.select({
6
- web: {
7
- regular: {
8
- fontFamily: WEB_FONT_STACK,
9
- fontWeight: '400'
10
- },
11
- medium: {
12
- fontFamily: WEB_FONT_STACK,
13
- fontWeight: '500'
14
- },
15
- bold: {
16
- fontFamily: WEB_FONT_STACK,
17
- fontWeight: '600'
18
- },
19
- heavy: {
20
- fontFamily: WEB_FONT_STACK,
21
- fontWeight: '700'
22
- }
23
- },
24
- ios: {
25
- regular: {
26
- fontFamily: 'System',
27
- fontWeight: '400'
28
- },
29
- medium: {
30
- fontFamily: 'System',
31
- fontWeight: '500'
32
- },
33
- bold: {
34
- fontFamily: 'System',
35
- fontWeight: '600'
36
- },
37
- heavy: {
38
- fontFamily: 'System',
39
- fontWeight: '700'
40
- }
41
- },
42
- default: {
43
- regular: {
44
- fontFamily: 'sans-serif',
45
- fontWeight: 'normal'
46
- },
47
- medium: {
48
- fontFamily: 'sans-serif-medium',
49
- fontWeight: 'normal'
50
- },
51
- bold: {
52
- fontFamily: 'sans-serif',
53
- fontWeight: '600'
54
- },
55
- heavy: {
56
- fontFamily: 'sans-serif',
57
- fontWeight: '700'
58
- }
59
- }
60
- });
61
- //# sourceMappingURL=fonts.js.map
@@ -1,4 +0,0 @@
1
- "use strict";
2
-
3
- export {};
4
- //# sourceMappingURL=types.js.map
@@ -1,7 +0,0 @@
1
- "use strict";
2
-
3
- export function useBackButton(_) {
4
- // No-op
5
- // BackHandler is not available on web
6
- }
7
- //# sourceMappingURL=useBackButton.js.map
@@ -1,21 +0,0 @@
1
- "use strict";
2
-
3
- import * as React from 'react';
4
- import { BackHandler } from 'react-native';
5
- export function useBackButton(ref) {
6
- React.useEffect(() => {
7
- const subscription = BackHandler.addEventListener('hardwareBackPress', () => {
8
- const navigation = ref.current;
9
- if (navigation == null) {
10
- return false;
11
- }
12
- if (navigation.canGoBack()) {
13
- navigation.goBack();
14
- return true;
15
- }
16
- return false;
17
- });
18
- return () => subscription.remove();
19
- }, [ref]);
20
- }
21
- //# sourceMappingURL=useBackButton.native.js.map
@@ -1,26 +0,0 @@
1
- "use strict";
2
-
3
- import * as React from 'react';
4
- /**
5
- * Set the document title for the active screen
6
- */
7
- export function useDocumentTitle(ref, {
8
- enabled = true,
9
- formatter = (options, route) => options?.title ?? route?.name
10
- } = {}) {
11
- React.useEffect(() => {
12
- if (!enabled) {
13
- return;
14
- }
15
- const navigation = ref.current;
16
- if (navigation) {
17
- const title = formatter(navigation.getCurrentOptions(), navigation.getCurrentRoute());
18
- document.title = title;
19
- }
20
- return navigation?.addListener('options', e => {
21
- const title = formatter(e.data.options, navigation?.getCurrentRoute());
22
- document.title = title;
23
- });
24
- });
25
- }
26
- //# sourceMappingURL=useDocumentTitle.js.map
@@ -1,6 +0,0 @@
1
- "use strict";
2
-
3
- export function useDocumentTitle() {
4
- // Noop for native platforms
5
- }
6
- //# sourceMappingURL=useDocumentTitle.native.js.map
@@ -1,85 +0,0 @@
1
- "use strict";
2
-
3
- import { CommonActions, findFocusedRoute, getActionFromState, getPathFromState, getStateFromPath, NavigationHelpersContext, NavigationRouteContext, useStateForPath } from '@amazon-devices/react-navigation__core';
4
- import * as React from 'react';
5
- import { LinkingContext } from "./LinkingContext.js";
6
- /**
7
- * Helpers to build href or action based on the linking options.
8
- *
9
- * @returns `buildHref` to build an `href` for screen and `buildAction` to build an action from an `href`.
10
- */
11
- export function useLinkBuilder() {
12
- const navigation = React.useContext(NavigationHelpersContext);
13
- const route = React.useContext(NavigationRouteContext);
14
- const {
15
- options
16
- } = React.useContext(LinkingContext);
17
- const focusedRouteState = useStateForPath();
18
- const getPathFromStateHelper = options?.getPathFromState ?? getPathFromState;
19
- const getStateFromPathHelper = options?.getStateFromPath ?? getStateFromPath;
20
- const getActionFromStateHelper = options?.getActionFromState ?? getActionFromState;
21
- const buildHref = React.useCallback((name, params) => {
22
- if (options?.enabled === false) {
23
- return undefined;
24
- }
25
-
26
- // Check that we're inside:
27
- // - navigator's context
28
- // - route context of the navigator (could be a screen, tab, etc.)
29
- // - route matches the state for path (from the screen's context)
30
- // This ensures that we're inside a screen
31
- const isScreen = navigation && route?.key && focusedRouteState ? route.key === findFocusedRoute(focusedRouteState)?.key && navigation.getState().routes.some(r => r.key === route.key) : false;
32
- const stateForRoute = {
33
- routes: [{
34
- name,
35
- params
36
- }]
37
- };
38
- const constructState = state => {
39
- if (state) {
40
- const route = state.routes[0];
41
-
42
- // If we're inside a screen and at the innermost route
43
- // We need to replace the state with the provided one
44
- // This assumes that we're navigating to a sibling route
45
- if (isScreen && !route.state) {
46
- return stateForRoute;
47
- }
48
-
49
- // Otherwise, dive into the nested state of the route
50
- return {
51
- routes: [{
52
- ...route,
53
- state: constructState(route.state)
54
- }]
55
- };
56
- }
57
-
58
- // Once there is no more nested state, we're at the innermost route
59
- // We can add a state based on provided parameters
60
- // This assumes that we're navigating to a child of this route
61
- // In this case, the helper is used in a navigator for its routes
62
- return stateForRoute;
63
- };
64
- const state = constructState(focusedRouteState);
65
- const path = getPathFromStateHelper(state, options?.config);
66
- return path;
67
- }, [options?.enabled, options?.config, route?.key, navigation, focusedRouteState, getPathFromStateHelper]);
68
- const buildAction = React.useCallback(href => {
69
- if (!href.startsWith('/')) {
70
- throw new Error(`The href must start with '/' (${href}).`);
71
- }
72
- const state = getStateFromPathHelper(href, options?.config);
73
- if (state) {
74
- const action = getActionFromStateHelper(state, options?.config);
75
- return action ?? CommonActions.reset(state);
76
- } else {
77
- throw new Error('Failed to parse the href to a navigation state.');
78
- }
79
- }, [options?.config, getStateFromPathHelper, getActionFromStateHelper]);
80
- return {
81
- buildHref,
82
- buildAction
83
- };
84
- }
85
- //# sourceMappingURL=useLinkBuilder.js.map
@@ -1,93 +0,0 @@
1
- "use strict";
2
-
3
- import { getPathFromState, NavigationContainerRefContext, NavigationHelpersContext } from '@amazon-devices/react-navigation__core';
4
- import * as React from 'react';
5
- import { Platform } from 'react-native';
6
- import { LinkingContext } from "./LinkingContext.js";
7
- const getStateFromParams = params => {
8
- if (params?.state) {
9
- return params.state;
10
- }
11
- if (params?.screen) {
12
- return {
13
- routes: [{
14
- name: params.screen,
15
- params: params.params,
16
- // @ts-expect-error this is fine 🔥
17
- state: params.screen ? getStateFromParams(params.params) : undefined
18
- }]
19
- };
20
- }
21
- return undefined;
22
- };
23
-
24
- /**
25
- * Hook to get props for an anchor tag so it can work with in page navigation.
26
- *
27
- * @param props.screen Name of the screen to navigate to (e.g. `'Feeds'`).
28
- * @param props.params Params to pass to the screen to navigate to (e.g. `{ sort: 'hot' }`).
29
- * @param props.href Optional absolute path to use for the href (e.g. `/feeds/hot`).
30
- * @param props.action Optional action to use for in-page navigation. By default, the path is parsed to an action based on linking config.
31
- */
32
- export function useLinkProps({
33
- screen,
34
- params,
35
- href,
36
- action
37
- }) {
38
- const root = React.useContext(NavigationContainerRefContext);
39
- const navigation = React.useContext(NavigationHelpersContext);
40
- const {
41
- options
42
- } = React.useContext(LinkingContext);
43
- const onPress = e => {
44
- let shouldHandle = false;
45
- if (Platform.OS !== 'web' || !e) {
46
- e?.preventDefault?.();
47
- shouldHandle = true;
48
- } else {
49
- // ignore clicks with modifier keys
50
- const hasModifierKey = 'metaKey' in e && e.metaKey || 'altKey' in e && e.altKey || 'ctrlKey' in e && e.ctrlKey || 'shiftKey' in e && e.shiftKey;
51
-
52
- // only handle left clicks
53
- const isLeftClick = 'button' in e ? e.button == null || e.button === 0 : true;
54
-
55
- // let browser handle "target=_blank" etc.
56
- const isSelfTarget = e.currentTarget && 'target' in e.currentTarget ? [undefined, null, '', 'self'].includes(e.currentTarget.target) : true;
57
- if (!hasModifierKey && isLeftClick && isSelfTarget) {
58
- e.preventDefault?.();
59
- shouldHandle = true;
60
- }
61
- }
62
- if (shouldHandle) {
63
- if (action) {
64
- if (navigation) {
65
- navigation.dispatch(action);
66
- } else if (root) {
67
- root.dispatch(action);
68
- } else {
69
- throw new Error("Couldn't find a navigation object. Is your component inside NavigationContainer?");
70
- }
71
- } else {
72
- // @ts-expect-error This is already type-checked by the prop types
73
- navigation?.navigate(screen, params);
74
- }
75
- }
76
- };
77
- const getPathFromStateHelper = options?.getPathFromState ?? getPathFromState;
78
- return {
79
- href: href ?? (Platform.OS === 'web' && screen != null ? getPathFromStateHelper({
80
- routes: [{
81
- // @ts-expect-error this is fine 🔥
82
- name: screen,
83
- // @ts-expect-error this is fine 🔥
84
- params: params,
85
- // @ts-expect-error this is fine 🔥
86
- state: getStateFromParams(params)
87
- }]
88
- }, options?.config) : undefined),
89
- role: 'link',
90
- onPress
91
- };
92
- }
93
- //# sourceMappingURL=useLinkProps.js.map
@@ -1,26 +0,0 @@
1
- "use strict";
2
-
3
- import { NavigationContainerRefContext } from '@amazon-devices/react-navigation__core';
4
- import * as React from 'react';
5
- import { useLinkBuilder } from "./useLinkBuilder.js";
6
-
7
- /**
8
- * Helper to navigate to a screen using a href based on the linking options.
9
- *
10
- * @returns function that receives the href to navigate to.
11
- */
12
- export function useLinkTo() {
13
- const navigation = React.useContext(NavigationContainerRefContext);
14
- const {
15
- buildAction
16
- } = useLinkBuilder();
17
- const linkTo = React.useCallback(href => {
18
- if (navigation === undefined) {
19
- throw new Error("Couldn't find a navigation object. Is your component inside NavigationContainer?");
20
- }
21
- const action = buildAction(href);
22
- navigation.dispatch(action);
23
- }, [buildAction, navigation]);
24
- return linkTo;
25
- }
26
- //# sourceMappingURL=useLinkTo.js.map