@amazon-devices/react-navigation__native 7.0.1758683737 → 8.0.9000000000
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.
- package/SystemBundles/0fc5c971c5cf41a0dab235bcc6d58e5c06d9aaff650fa9815b525f8b9bb70a03.bundle +9116 -0
- package/SystemBundles/0fc5c971c5cf41a0dab235bcc6d58e5c06d9aaff650fa9815b525f8b9bb70a03.map +3543 -0
- package/SystemModules/amzn__react-navigation__native-8.modules.txt +24 -0
- package/SystemModules/amzn__react-navigation__native-8.private.modules.txt +77 -0
- package/SystemModules/keplerscript-system-bundle-config.json +4 -4
- package/kepler-compatibility.json +2 -4
- package/lib/module/Link.js +31 -10
- package/lib/module/Link.js.map +1 -1
- package/lib/module/LinkingContext.js +7 -3
- package/lib/module/LinkingContext.js.map +1 -1
- package/lib/module/LocaleDirContext.js +6 -0
- package/lib/module/LocaleDirContext.js.map +1 -0
- package/lib/module/NavigationContainer.js +87 -59
- package/lib/module/NavigationContainer.js.map +1 -1
- package/lib/module/ServerContainer.js +20 -10
- package/lib/module/ServerContainer.js.map +1 -1
- package/lib/module/ServerContext.js +3 -2
- package/lib/module/ServerContext.js.map +1 -1
- package/lib/module/UnhandledLinkingContext.js +14 -0
- package/lib/module/UnhandledLinkingContext.js.map +1 -0
- package/lib/module/__stubs__/createStackNavigator.js +18 -0
- package/lib/module/__stubs__/createStackNavigator.js.map +1 -0
- package/lib/module/__stubs__/window.js +75 -0
- package/lib/module/__stubs__/window.js.map +1 -0
- package/lib/module/createMemoryHistory.js +19 -17
- package/lib/module/createMemoryHistory.js.map +1 -1
- package/lib/module/createStaticNavigation.js +54 -0
- package/lib/module/createStaticNavigation.js.map +1 -0
- package/lib/module/extractPathFromURL.js +6 -5
- package/lib/module/extractPathFromURL.js.map +1 -1
- package/lib/module/index.js +18 -13
- package/lib/module/index.js.map +1 -1
- package/lib/module/package.json +1 -0
- package/lib/module/theming/DarkTheme.js +6 -3
- package/lib/module/theming/DarkTheme.js.map +1 -1
- package/lib/module/theming/DefaultTheme.js +6 -3
- package/lib/module/theming/DefaultTheme.js.map +1 -1
- package/lib/module/theming/fonts.js +61 -0
- package/lib/module/theming/fonts.js.map +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -1
- package/lib/module/useBackButton.js +3 -1
- package/lib/module/useBackButton.js.map +1 -1
- package/lib/module/useBackButton.native.js +3 -1
- package/lib/module/useBackButton.native.js.map +1 -1
- package/lib/module/useDocumentTitle.js +6 -4
- package/lib/module/useDocumentTitle.js.map +1 -1
- package/lib/module/useDocumentTitle.native.js +4 -2
- package/lib/module/useDocumentTitle.native.js.map +1 -1
- package/lib/module/useLinkBuilder.js +71 -40
- package/lib/module/useLinkBuilder.js.map +1 -1
- package/lib/module/useLinkProps.js +41 -36
- package/lib/module/useLinkProps.js.map +1 -1
- package/lib/module/useLinkTo.js +18 -28
- package/lib/module/useLinkTo.js.map +1 -1
- package/lib/module/useLinking.js +47 -19
- package/lib/module/useLinking.js.map +1 -1
- package/lib/module/useLinking.native.js +33 -28
- package/lib/module/useLinking.native.js.map +1 -1
- package/lib/module/useLocale.js +18 -0
- package/lib/module/useLocale.js.map +1 -0
- package/lib/module/useRoutePath.js +30 -0
- package/lib/module/useRoutePath.js.map +1 -0
- package/lib/module/useScrollToTop.js +11 -7
- package/lib/module/useScrollToTop.js.map +1 -1
- package/lib/module/useThenable.js +4 -1
- package/lib/module/useThenable.js.map +1 -1
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/Link.d.ts +8 -10
- package/lib/typescript/src/Link.d.ts.map +1 -1
- package/lib/typescript/src/LinkingContext.d.ts +2 -3
- package/lib/typescript/src/LinkingContext.d.ts.map +1 -1
- package/lib/typescript/src/LocaleDirContext.d.ts +4 -0
- package/lib/typescript/src/LocaleDirContext.d.ts.map +1 -0
- package/lib/typescript/src/NavigationContainer.d.ts +36 -13
- package/lib/typescript/src/NavigationContainer.d.ts.map +1 -1
- package/lib/typescript/src/ServerContainer.d.ts +2 -3
- package/lib/typescript/src/ServerContainer.d.ts.map +1 -1
- package/lib/typescript/src/ServerContext.d.ts +1 -2
- package/lib/typescript/src/ServerContext.d.ts.map +1 -1
- package/lib/typescript/src/UnhandledLinkingContext.d.ts +6 -0
- package/lib/typescript/src/UnhandledLinkingContext.d.ts.map +1 -0
- package/lib/typescript/src/__stubs__/createStackNavigator.d.ts +13 -0
- package/lib/typescript/src/__stubs__/createStackNavigator.d.ts.map +1 -0
- package/lib/typescript/src/{__mocks__ → __stubs__}/window.d.ts +5 -6
- package/lib/typescript/src/__stubs__/window.d.ts.map +1 -0
- package/lib/typescript/src/createMemoryHistory.d.ts +1 -1
- package/lib/typescript/src/createMemoryHistory.d.ts.map +1 -1
- package/lib/typescript/src/createStaticNavigation.d.ts +34 -0
- package/lib/typescript/src/createStaticNavigation.d.ts.map +1 -0
- package/lib/typescript/src/extractPathFromURL.d.ts +1 -1
- package/lib/typescript/src/extractPathFromURL.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +15 -12
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/theming/DarkTheme.d.ts +1 -2
- package/lib/typescript/src/theming/DarkTheme.d.ts.map +1 -1
- package/lib/typescript/src/theming/DefaultTheme.d.ts +1 -2
- package/lib/typescript/src/theming/DefaultTheme.d.ts.map +1 -1
- package/lib/typescript/src/theming/fonts.d.ts +53 -0
- package/lib/typescript/src/theming/fonts.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +35 -3
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/useBackButton.d.ts +1 -2
- package/lib/typescript/src/useBackButton.d.ts.map +1 -1
- package/lib/typescript/src/useBackButton.native.d.ts +1 -1
- package/lib/typescript/src/useBackButton.native.d.ts.map +1 -1
- package/lib/typescript/src/useDocumentTitle.d.ts +1 -1
- package/lib/typescript/src/useDocumentTitle.d.ts.map +1 -1
- package/lib/typescript/src/useDocumentTitle.native.d.ts +1 -1
- package/lib/typescript/src/useDocumentTitle.native.d.ts.map +1 -1
- package/lib/typescript/src/useLinkBuilder.d.ts +97 -3
- package/lib/typescript/src/useLinkBuilder.d.ts.map +1 -1
- package/lib/typescript/src/useLinkProps.d.ts +23 -10
- package/lib/typescript/src/useLinkProps.d.ts.map +1 -1
- package/lib/typescript/src/useLinkTo.d.ts +6 -8
- package/lib/typescript/src/useLinkTo.d.ts.map +1 -1
- package/lib/typescript/src/useLinking.d.ts +5 -46
- package/lib/typescript/src/useLinking.d.ts.map +1 -1
- package/lib/typescript/src/useLinking.native.d.ts +11 -29
- package/lib/typescript/src/useLinking.native.d.ts.map +1 -1
- package/lib/typescript/src/useLocale.d.ts +7 -0
- package/lib/typescript/src/useLocale.d.ts.map +1 -0
- package/lib/typescript/src/useRoutePath.d.ts +7 -0
- package/lib/typescript/src/useRoutePath.d.ts.map +1 -0
- package/lib/typescript/src/useScrollToTop.d.ts +2 -2
- package/lib/typescript/src/useScrollToTop.d.ts.map +1 -1
- package/lib/typescript/src/useThenable.d.ts +1 -1
- package/lib/typescript/src/useThenable.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/Link.tsx +36 -20
- package/src/LinkingContext.tsx +9 -5
- package/src/LocaleDirContext.tsx +7 -0
- package/src/NavigationContainer.tsx +128 -69
- package/src/ServerContainer.tsx +4 -3
- package/src/ServerContext.tsx +1 -3
- package/src/UnhandledLinkingContext.tsx +18 -0
- package/src/__stubs__/createStackNavigator.tsx +46 -0
- package/src/{__mocks__ → __stubs__}/window.tsx +8 -8
- package/src/createMemoryHistory.tsx +16 -11
- package/src/createStaticNavigation.tsx +109 -0
- package/src/extractPathFromURL.tsx +3 -3
- package/src/index.tsx +15 -12
- package/src/theming/DarkTheme.tsx +3 -3
- package/src/theming/DefaultTheme.tsx +3 -3
- package/src/theming/fonts.tsx +63 -0
- package/src/types.tsx +49 -3
- package/src/useBackButton.native.tsx +2 -2
- package/src/useBackButton.tsx +2 -2
- package/src/useDocumentTitle.native.tsx +2 -2
- package/src/useDocumentTitle.tsx +2 -2
- package/src/useLinkBuilder.tsx +100 -55
- package/src/useLinkProps.tsx +80 -50
- package/src/useLinkTo.tsx +13 -53
- package/src/useLinking.native.tsx +33 -31
- package/src/useLinking.tsx +70 -23
- package/src/useLocale.tsx +18 -0
- package/src/useRoutePath.tsx +34 -0
- package/src/useScrollToTop.tsx +16 -12
- package/src/useThenable.tsx +2 -1
- package/SystemBundles/8f36606502d3b658fa1ffc07fee4da0e39a8ce388742799c9ccdb66b39ef0362.bundle +0 -15196
- package/SystemBundles/8f36606502d3b658fa1ffc07fee4da0e39a8ce388742799c9ccdb66b39ef0362.map +0 -1
- package/SystemModules/amzn__react-navigation__native-7.modules.txt +0 -76
- package/SystemModules/amzn__react-navigation__native-7.private.modules.txt +0 -101
- package/THIRD_PARTY_NOTICES.txt +0 -24
- package/lib/commonjs/Link.js +0 -50
- package/lib/commonjs/Link.js.map +0 -1
- package/lib/commonjs/LinkingContext.js +0 -15
- package/lib/commonjs/LinkingContext.js.map +0 -1
- package/lib/commonjs/NavigationContainer.js +0 -109
- package/lib/commonjs/NavigationContainer.js.map +0 -1
- package/lib/commonjs/ServerContainer.js +0 -54
- package/lib/commonjs/ServerContainer.js.map +0 -1
- package/lib/commonjs/ServerContext.js +0 -12
- package/lib/commonjs/ServerContext.js.map +0 -1
- package/lib/commonjs/createMemoryHistory.js +0 -220
- package/lib/commonjs/createMemoryHistory.js.map +0 -1
- package/lib/commonjs/extractPathFromURL.js +0 -25
- package/lib/commonjs/extractPathFromURL.js.map +0 -1
- package/lib/commonjs/index.js +0 -129
- package/lib/commonjs/index.js.map +0 -1
- package/lib/commonjs/theming/DarkTheme.js +0 -19
- package/lib/commonjs/theming/DarkTheme.js.map +0 -1
- package/lib/commonjs/theming/DefaultTheme.js +0 -19
- package/lib/commonjs/theming/DefaultTheme.js.map +0 -1
- package/lib/commonjs/theming/ThemeContext.js +0 -15
- package/lib/commonjs/theming/ThemeContext.js.map +0 -1
- package/lib/commonjs/theming/ThemeProvider.js +0 -20
- package/lib/commonjs/theming/ThemeProvider.js.map +0 -1
- package/lib/commonjs/theming/useTheme.js +0 -16
- package/lib/commonjs/theming/useTheme.js.map +0 -1
- package/lib/commonjs/types.js +0 -6
- package/lib/commonjs/types.js.map +0 -1
- package/lib/commonjs/useBackButton.js +0 -11
- package/lib/commonjs/useBackButton.js.map +0 -1
- package/lib/commonjs/useBackButton.native.js +0 -27
- package/lib/commonjs/useBackButton.native.js.map +0 -1
- package/lib/commonjs/useDocumentTitle.js +0 -32
- package/lib/commonjs/useDocumentTitle.js.map +0 -1
- package/lib/commonjs/useDocumentTitle.native.js +0 -10
- package/lib/commonjs/useDocumentTitle.native.js.map +0 -1
- package/lib/commonjs/useLinkBuilder.js +0 -63
- package/lib/commonjs/useLinkBuilder.js.map +0 -1
- package/lib/commonjs/useLinkProps.js +0 -97
- package/lib/commonjs/useLinkProps.js.map +0 -1
- package/lib/commonjs/useLinkTo.js +0 -45
- package/lib/commonjs/useLinkTo.js.map +0 -1
- package/lib/commonjs/useLinking.js +0 -303
- package/lib/commonjs/useLinking.js.map +0 -1
- package/lib/commonjs/useLinking.native.js +0 -152
- package/lib/commonjs/useLinking.native.js.map +0 -1
- package/lib/commonjs/useScrollToTop.js +0 -95
- package/lib/commonjs/useScrollToTop.js.map +0 -1
- package/lib/commonjs/useThenable.js +0 -41
- package/lib/commonjs/useThenable.js.map +0 -1
- package/lib/module/theming/ThemeContext.js +0 -6
- package/lib/module/theming/ThemeContext.js.map +0 -1
- package/lib/module/theming/ThemeProvider.js +0 -11
- package/lib/module/theming/ThemeProvider.js.map +0 -1
- package/lib/module/theming/useTheme.js +0 -7
- package/lib/module/theming/useTheme.js.map +0 -1
- package/lib/typescript/src/__mocks__/window.d.ts.map +0 -1
- package/lib/typescript/src/theming/ThemeContext.d.ts +0 -5
- package/lib/typescript/src/theming/ThemeContext.d.ts.map +0 -1
- package/lib/typescript/src/theming/ThemeProvider.d.ts +0 -9
- package/lib/typescript/src/theming/ThemeProvider.d.ts.map +0 -1
- package/lib/typescript/src/theming/useTheme.d.ts +0 -2
- package/lib/typescript/src/theming/useTheme.d.ts.map +0 -1
- package/src/theming/ThemeContext.tsx +0 -10
- package/src/theming/ThemeProvider.tsx +0 -15
- package/src/theming/useTheme.tsx +0 -9
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export declare function useThenable<T>(create: () => PromiseLike<T>): [boolean, T | undefined];
|
|
2
2
|
//# sourceMappingURL=useThenable.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useThenable.d.ts","sourceRoot":"","sources":["../../../src/useThenable.tsx"],"names":[],"mappings":"AAEA,
|
|
1
|
+
{"version":3,"file":"useThenable.d.ts","sourceRoot":"","sources":["../../../src/useThenable.tsx"],"names":[],"mappings":"AAEA,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC,CAAC,CAAC,4BAuC1D"}
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name": "@amazon-devices/react-navigation__native", "description": "React Native integration for React Navigation", "version": "
|
|
1
|
+
{"name": "@amazon-devices/react-navigation__native", "description": "React Native integration for React Navigation", "version": "8.0.9000000000+7.1.22", "keywords": ["react-native", "react-navigation", "ios", "android"], "license": "See license in LICENSE", "repository": {"type": "git", "url": "https://github.com/react-navigation/react-navigation.git", "directory": "packages/native"}, "bugs": {"url": "https://github.com/react-navigation/react-navigation/issues"}, "homepage": "https://reactnavigation.org", "main": "./lib/module/index.js", "types": "./lib/typescript/src/index.d.ts", "exports": {".": {"source": "./src/index.tsx", "types": "./lib/typescript/src/index.d.ts", "default": "./lib/module/index.js"}, "./package.json": "./package.json"}, "files": ["src", "lib", "!**/__tests__", "kepler-compatibility.json", "SystemModules", "SystemBundles", "kepler-transformed-package-info.json"], "sideEffects": false, "kepler": {"temporary-alias-for-package": {"name": "@react-navigation/native", "version": "7.0.14"}}, "publishConfig": {"access": "public"}, "scripts": {"clean": "del lib"}, "dependencies": {"@amazon-devices/react-navigation__routers": "^8.0.1", "@amazon-devices/react-navigation__core": "^8.0.1", "escape-string-regexp": "^4.0.0", "fast-deep-equal": "^3.1.3", "nanoid": "^3.3.11", "use-latest-callback": "^0.2.4"}, "devDependencies": {"@jest/globals": "^30.0.0", "@testing-library/react-native": "^13.2.0", "@types/react": "~19.0.10", "@types/react-dom": "~19.1.3", "del-cli": "^6.0.0", "react": "19.0.0", "react-dom": "19.0.0", "react-native": "0.79.3", "react-native-builder-bob": "^0.40.12", "react-test-renderer": "19.0.0", "typescript": "^5.8.3"}, "peerDependencies": {"react": ">= 18.2.0", "react-native": "*"}, "react-native-builder-bob": {"source": "src", "output": "lib", "targets": [["module", {"esm": true}], ["typescript", {"project": "tsconfig.build.json"}]]}}
|
package/src/Link.tsx
CHANGED
|
@@ -1,36 +1,48 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useTheme } from '@amazon-devices/react-navigation__core';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
type GestureResponderEvent,
|
|
5
|
+
Platform,
|
|
6
|
+
Text,
|
|
7
|
+
type TextProps,
|
|
8
|
+
} from 'react-native';
|
|
4
9
|
|
|
5
|
-
import useLinkProps from './useLinkProps';
|
|
6
|
-
import type { To } from './useLinkTo';
|
|
10
|
+
import { type LinkProps, useLinkProps } from './useLinkProps';
|
|
7
11
|
|
|
8
|
-
type Props<ParamList extends ReactNavigation.RootParamList> =
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
type Props<ParamList extends ReactNavigation.RootParamList> =
|
|
13
|
+
LinkProps<ParamList> &
|
|
14
|
+
Omit<TextProps, 'disabled'> & {
|
|
15
|
+
target?: string;
|
|
16
|
+
onPress?: (
|
|
17
|
+
e:
|
|
18
|
+
| React.MouseEvent<HTMLAnchorElement, MouseEvent>
|
|
19
|
+
| GestureResponderEvent
|
|
20
|
+
) => void;
|
|
21
|
+
disabled?: boolean | null;
|
|
22
|
+
children: React.ReactNode;
|
|
23
|
+
};
|
|
19
24
|
|
|
20
25
|
/**
|
|
21
26
|
* Component to render link to another screen using a path.
|
|
22
27
|
* Uses an anchor tag on the web.
|
|
23
28
|
*
|
|
24
|
-
* @param props.
|
|
29
|
+
* @param props.screen Name of the screen to navigate to (e.g. `'Feeds'`).
|
|
30
|
+
* @param props.params Params to pass to the screen to navigate to (e.g. `{ sort: 'hot' }`).
|
|
31
|
+
* @param props.href Optional absolute path to use for the href (e.g. `/feeds/hot`).
|
|
25
32
|
* @param props.action Optional action to use for in-page navigation. By default, the path is parsed to an action based on linking config.
|
|
26
33
|
* @param props.children Child elements to render the content.
|
|
27
34
|
*/
|
|
28
|
-
export
|
|
29
|
-
|
|
35
|
+
export function Link<ParamList extends ReactNavigation.RootParamList>({
|
|
36
|
+
screen,
|
|
37
|
+
params,
|
|
30
38
|
action,
|
|
39
|
+
href,
|
|
40
|
+
style,
|
|
31
41
|
...rest
|
|
32
42
|
}: Props<ParamList>) {
|
|
33
|
-
const
|
|
43
|
+
const { colors, fonts } = useTheme();
|
|
44
|
+
// @ts-expect-error: This is already type-checked by the prop types
|
|
45
|
+
const props = useLinkProps<ParamList>({ screen, params, action, href });
|
|
34
46
|
|
|
35
47
|
const onPress = (
|
|
36
48
|
e: React.MouseEvent<HTMLAnchorElement, MouseEvent> | GestureResponderEvent
|
|
@@ -39,7 +51,10 @@ export default function Link<ParamList extends ReactNavigation.RootParamList>({
|
|
|
39
51
|
rest.onPress?.(e);
|
|
40
52
|
}
|
|
41
53
|
|
|
42
|
-
|
|
54
|
+
// Let user prevent default behavior
|
|
55
|
+
if (!e.defaultPrevented) {
|
|
56
|
+
props.onPress(e);
|
|
57
|
+
}
|
|
43
58
|
};
|
|
44
59
|
|
|
45
60
|
return React.createElement(Text, {
|
|
@@ -49,5 +64,6 @@ export default function Link<ParamList extends ReactNavigation.RootParamList>({
|
|
|
49
64
|
web: { onClick: onPress } as any,
|
|
50
65
|
default: { onPress },
|
|
51
66
|
}),
|
|
67
|
+
style: [{ color: colors.primary }, fonts.regular, style],
|
|
52
68
|
});
|
|
53
69
|
}
|
package/src/LinkingContext.tsx
CHANGED
|
@@ -3,10 +3,14 @@ import * as React from 'react';
|
|
|
3
3
|
|
|
4
4
|
import type { LinkingOptions } from './types';
|
|
5
5
|
|
|
6
|
-
const
|
|
7
|
-
options: LinkingOptions<ParamListBase> | undefined;
|
|
8
|
-
}>({ options: undefined });
|
|
6
|
+
const MISSING_CONTEXT_ERROR = "Couldn't find a LinkingContext context.";
|
|
9
7
|
|
|
10
|
-
LinkingContext
|
|
8
|
+
export const LinkingContext = React.createContext<{
|
|
9
|
+
options?: LinkingOptions<ParamListBase>;
|
|
10
|
+
}>({
|
|
11
|
+
get options(): any {
|
|
12
|
+
throw new Error(MISSING_CONTEXT_ERROR);
|
|
13
|
+
},
|
|
14
|
+
});
|
|
11
15
|
|
|
12
|
-
|
|
16
|
+
LinkingContext.displayName = 'LinkingContext';
|
|
@@ -3,21 +3,30 @@ import {
|
|
|
3
3
|
getActionFromState,
|
|
4
4
|
getPathFromState,
|
|
5
5
|
getStateFromPath,
|
|
6
|
-
NavigationContainerProps,
|
|
7
|
-
NavigationContainerRef,
|
|
8
|
-
|
|
6
|
+
type NavigationContainerProps,
|
|
7
|
+
type NavigationContainerRef,
|
|
8
|
+
type NavigationState,
|
|
9
|
+
type ParamListBase,
|
|
10
|
+
ThemeProvider,
|
|
9
11
|
validatePathConfig,
|
|
10
12
|
} from '@amazon-devices/react-navigation__core';
|
|
11
13
|
import * as React from 'react';
|
|
12
|
-
|
|
13
|
-
import
|
|
14
|
-
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
import { I18nManager } from 'react-native';
|
|
15
|
+
import useLatestCallback from 'use-latest-callback';
|
|
16
|
+
|
|
17
|
+
import { LinkingContext } from './LinkingContext';
|
|
18
|
+
import { LocaleDirContext } from './LocaleDirContext';
|
|
19
|
+
import { DefaultTheme } from './theming/DefaultTheme';
|
|
20
|
+
import type {
|
|
21
|
+
DocumentTitleOptions,
|
|
22
|
+
LinkingOptions,
|
|
23
|
+
LocaleDirection,
|
|
24
|
+
} from './types';
|
|
25
|
+
import { UnhandledLinkingContext } from './UnhandledLinkingContext';
|
|
26
|
+
import { useBackButton } from './useBackButton';
|
|
27
|
+
import { useDocumentTitle } from './useDocumentTitle';
|
|
28
|
+
import { useLinking } from './useLinking';
|
|
29
|
+
import { useThenable } from './useThenable';
|
|
21
30
|
|
|
22
31
|
declare global {
|
|
23
32
|
var REACT_NAVIGATION_DEVTOOLS: WeakMap<
|
|
@@ -26,37 +35,50 @@ declare global {
|
|
|
26
35
|
>;
|
|
27
36
|
}
|
|
28
37
|
|
|
29
|
-
|
|
38
|
+
globalThis.REACT_NAVIGATION_DEVTOOLS = new WeakMap();
|
|
30
39
|
|
|
31
40
|
type Props<ParamList extends {}> = NavigationContainerProps & {
|
|
32
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Initial state object for the navigation tree.
|
|
43
|
+
*
|
|
44
|
+
* If this is provided, deep link or URLs won't be handled on the initial render.
|
|
45
|
+
*/
|
|
46
|
+
initialState?: NavigationContainerProps['initialState'];
|
|
47
|
+
/**
|
|
48
|
+
* Text direction of the components. Defaults to `'ltr'`.
|
|
49
|
+
*/
|
|
50
|
+
direction?: LocaleDirection;
|
|
51
|
+
/**
|
|
52
|
+
* Options for deep linking.
|
|
53
|
+
*
|
|
54
|
+
* Deep link handling is enabled when this prop is provided,
|
|
55
|
+
* unless `linking.enabled` is `false`.
|
|
56
|
+
*/
|
|
33
57
|
linking?: LinkingOptions<ParamList>;
|
|
58
|
+
/**
|
|
59
|
+
* Fallback element to render until initial state is resolved from deep linking.
|
|
60
|
+
*
|
|
61
|
+
* Defaults to `null`.
|
|
62
|
+
*/
|
|
34
63
|
fallback?: React.ReactNode;
|
|
64
|
+
/**
|
|
65
|
+
* Options to configure the document title on Web.
|
|
66
|
+
*
|
|
67
|
+
* Updating document title is handled by default,
|
|
68
|
+
* unless `documentTitle.enabled` is `false`.
|
|
69
|
+
*/
|
|
35
70
|
documentTitle?: DocumentTitleOptions;
|
|
36
|
-
onReady?: () => void;
|
|
37
71
|
};
|
|
38
72
|
|
|
39
|
-
/**
|
|
40
|
-
* Container component which holds the navigation state designed for React Native apps.
|
|
41
|
-
* This should be rendered at the root wrapping the whole app.
|
|
42
|
-
*
|
|
43
|
-
* @param props.initialState Initial state object for the navigation tree. When deep link handling is enabled, this will override deep links when specified. Make sure that you don't specify an `initialState` when there's a deep link (`Linking.getInitialURL()`).
|
|
44
|
-
* @param props.onReady Callback which is called after the navigation tree mounts.
|
|
45
|
-
* @param props.onStateChange Callback which is called with the latest navigation state when it changes.
|
|
46
|
-
* @param props.theme Theme object for the navigators.
|
|
47
|
-
* @param props.linking Options for deep linking. Deep link handling is enabled when this prop is provided, unless `linking.enabled` is `false`.
|
|
48
|
-
* @param props.fallback Fallback component to render until we have finished getting initial state when linking is enabled. Defaults to `null`.
|
|
49
|
-
* @param props.documentTitle Options to configure the document title on Web. Updating document title is handled by default unless `documentTitle.enabled` is `false`.
|
|
50
|
-
* @param props.children Child elements to render the content.
|
|
51
|
-
* @param props.ref Ref object which refers to the navigation object containing helper methods.
|
|
52
|
-
*/
|
|
53
73
|
function NavigationContainerInner(
|
|
54
74
|
{
|
|
75
|
+
direction = I18nManager.getConstants().isRTL ? 'rtl' : 'ltr',
|
|
55
76
|
theme = DefaultTheme,
|
|
56
77
|
linking,
|
|
57
78
|
fallback = null,
|
|
58
79
|
documentTitle,
|
|
59
80
|
onReady,
|
|
81
|
+
onStateChange,
|
|
60
82
|
...rest
|
|
61
83
|
}: Props<ParamListBase>,
|
|
62
84
|
ref?: React.Ref<NavigationContainerRef<ParamListBase> | null>
|
|
@@ -73,13 +95,52 @@ function NavigationContainerInner(
|
|
|
73
95
|
useBackButton(refContainer);
|
|
74
96
|
useDocumentTitle(refContainer, documentTitle);
|
|
75
97
|
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
98
|
+
const [lastUnhandledLink, setLastUnhandledLink] = React.useState<
|
|
99
|
+
string | undefined
|
|
100
|
+
>();
|
|
101
|
+
|
|
102
|
+
const { getInitialState } = useLinking(
|
|
103
|
+
refContainer,
|
|
104
|
+
{
|
|
105
|
+
enabled: isLinkingEnabled,
|
|
106
|
+
prefixes: [],
|
|
107
|
+
...linking,
|
|
108
|
+
},
|
|
109
|
+
setLastUnhandledLink
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
const linkingContext = React.useMemo(() => ({ options: linking }), [linking]);
|
|
113
|
+
|
|
114
|
+
const unhandledLinkingContext = React.useMemo(
|
|
115
|
+
() => ({ lastUnhandledLink, setLastUnhandledLink }),
|
|
116
|
+
[lastUnhandledLink, setLastUnhandledLink]
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
const onReadyForLinkingHandling = useLatestCallback(() => {
|
|
120
|
+
// If the screen path matches lastUnhandledLink, we do not track it
|
|
121
|
+
const path = refContainer.current?.getCurrentRoute()?.path;
|
|
122
|
+
setLastUnhandledLink((previousLastUnhandledLink) => {
|
|
123
|
+
if (previousLastUnhandledLink === path) {
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
return previousLastUnhandledLink;
|
|
127
|
+
});
|
|
128
|
+
onReady?.();
|
|
81
129
|
});
|
|
82
130
|
|
|
131
|
+
const onStateChangeForLinkingHandling = useLatestCallback(
|
|
132
|
+
(state: Readonly<NavigationState> | undefined) => {
|
|
133
|
+
// If the screen path matches lastUnhandledLink, we do not track it
|
|
134
|
+
const path = refContainer.current?.getCurrentRoute()?.path;
|
|
135
|
+
setLastUnhandledLink((previousLastUnhandledLink) => {
|
|
136
|
+
if (previousLastUnhandledLink === path) {
|
|
137
|
+
return undefined;
|
|
138
|
+
}
|
|
139
|
+
return previousLastUnhandledLink;
|
|
140
|
+
});
|
|
141
|
+
onStateChange?.(state);
|
|
142
|
+
}
|
|
143
|
+
);
|
|
83
144
|
// Add additional linking related info to the ref
|
|
84
145
|
// This will be used by the devtools
|
|
85
146
|
React.useEffect(() => {
|
|
@@ -102,51 +163,49 @@ function NavigationContainerInner(
|
|
|
102
163
|
|
|
103
164
|
const [isResolved, initialState] = useThenable(getInitialState);
|
|
104
165
|
|
|
166
|
+
// FIXME
|
|
167
|
+
// @ts-expect-error not sure why this is not working
|
|
105
168
|
React.useImperativeHandle(ref, () => refContainer.current);
|
|
106
169
|
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
const isReady = rest.initialState != null || !isLinkingEnabled || isResolved;
|
|
170
|
+
const isLinkingReady =
|
|
171
|
+
rest.initialState != null || !isLinkingEnabled || isResolved;
|
|
110
172
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
React.useEffect(() => {
|
|
118
|
-
if (isReady) {
|
|
119
|
-
onReadyRef.current?.();
|
|
120
|
-
}
|
|
121
|
-
}, [isReady]);
|
|
122
|
-
|
|
123
|
-
if (!isReady) {
|
|
124
|
-
// This is temporary until we have Suspense for data-fetching
|
|
125
|
-
// Then the fallback will be handled by a parent `Suspense` component
|
|
126
|
-
return fallback as React.ReactElement;
|
|
173
|
+
if (!isLinkingReady) {
|
|
174
|
+
return (
|
|
175
|
+
<LocaleDirContext.Provider value={direction}>
|
|
176
|
+
<ThemeProvider value={theme}>{fallback}</ThemeProvider>
|
|
177
|
+
</LocaleDirContext.Provider>
|
|
178
|
+
);
|
|
127
179
|
}
|
|
128
180
|
|
|
129
181
|
return (
|
|
130
|
-
<
|
|
131
|
-
<
|
|
132
|
-
<
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
182
|
+
<LocaleDirContext.Provider value={direction}>
|
|
183
|
+
<UnhandledLinkingContext.Provider value={unhandledLinkingContext}>
|
|
184
|
+
<LinkingContext.Provider value={linkingContext}>
|
|
185
|
+
<BaseNavigationContainer
|
|
186
|
+
{...rest}
|
|
187
|
+
theme={theme}
|
|
188
|
+
onReady={onReadyForLinkingHandling}
|
|
189
|
+
onStateChange={onStateChangeForLinkingHandling}
|
|
190
|
+
initialState={
|
|
191
|
+
rest.initialState == null ? initialState : rest.initialState
|
|
192
|
+
}
|
|
193
|
+
ref={refContainer}
|
|
194
|
+
/>
|
|
195
|
+
</LinkingContext.Provider>
|
|
196
|
+
</UnhandledLinkingContext.Provider>
|
|
197
|
+
</LocaleDirContext.Provider>
|
|
141
198
|
);
|
|
142
199
|
}
|
|
143
200
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
201
|
+
/**
|
|
202
|
+
* Container component that manages the navigation state.
|
|
203
|
+
* This should be rendered at the root wrapping the whole app.
|
|
204
|
+
*/
|
|
205
|
+
export const NavigationContainer = React.forwardRef(
|
|
206
|
+
NavigationContainerInner
|
|
207
|
+
) as <RootParamList extends {} = ReactNavigation.RootParamList>(
|
|
147
208
|
props: Props<RootParamList> & {
|
|
148
209
|
ref?: React.Ref<NavigationContainerRef<RootParamList>>;
|
|
149
210
|
}
|
|
150
211
|
) => React.ReactElement;
|
|
151
|
-
|
|
152
|
-
export default NavigationContainer;
|
package/src/ServerContainer.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CurrentRenderContext } from '@amazon-devices/react-navigation__core';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
|
|
4
|
-
import ServerContext,
|
|
4
|
+
import { ServerContext, type ServerContextType } from './ServerContext';
|
|
5
5
|
import type { ServerContainerRef } from './types';
|
|
6
6
|
|
|
7
7
|
type Props = ServerContextType & {
|
|
@@ -15,7 +15,7 @@ type Props = ServerContextType & {
|
|
|
15
15
|
* @param props.children Child elements to render the content.
|
|
16
16
|
* @param props.ref Ref object which contains helper methods.
|
|
17
17
|
*/
|
|
18
|
-
export
|
|
18
|
+
export const ServerContainer = React.forwardRef(function ServerContainer(
|
|
19
19
|
{ children, location }: Props,
|
|
20
20
|
ref: React.Ref<ServerContainerRef>
|
|
21
21
|
) {
|
|
@@ -25,6 +25,7 @@ export default React.forwardRef(function ServerContainer(
|
|
|
25
25
|
);
|
|
26
26
|
}, []);
|
|
27
27
|
|
|
28
|
+
// eslint-disable-next-line @eslint-react/no-unstable-context-value
|
|
28
29
|
const current: { options?: object } = {};
|
|
29
30
|
|
|
30
31
|
if (ref) {
|
|
@@ -41,12 +42,12 @@ export default React.forwardRef(function ServerContainer(
|
|
|
41
42
|
if (typeof ref === 'function') {
|
|
42
43
|
ref(value);
|
|
43
44
|
} else {
|
|
44
|
-
// @ts-expect-error: the TS types are incorrect and say that ref.current is readonly
|
|
45
45
|
ref.current = value;
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
return (
|
|
50
|
+
// eslint-disable-next-line @eslint-react/no-unstable-context-value
|
|
50
51
|
<ServerContext.Provider value={{ location }}>
|
|
51
52
|
<CurrentRenderContext.Provider value={current}>
|
|
52
53
|
{children}
|
package/src/ServerContext.tsx
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
const MISSING_CONTEXT_ERROR =
|
|
4
|
+
"Couldn't find an UnhandledLinkingContext context.";
|
|
5
|
+
|
|
6
|
+
export const UnhandledLinkingContext = React.createContext<{
|
|
7
|
+
lastUnhandledLink: string | undefined;
|
|
8
|
+
setLastUnhandledLink: (lastUnhandledUrl: string | undefined) => void;
|
|
9
|
+
}>({
|
|
10
|
+
get lastUnhandledLink(): any {
|
|
11
|
+
throw new Error(MISSING_CONTEXT_ERROR);
|
|
12
|
+
},
|
|
13
|
+
get setLastUnhandledLink(): any {
|
|
14
|
+
throw new Error(MISSING_CONTEXT_ERROR);
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
UnhandledLinkingContext.displayName = 'UnhandledLinkingContext';
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createNavigatorFactory,
|
|
3
|
+
type DefaultNavigatorOptions,
|
|
4
|
+
type NavigationListBase,
|
|
5
|
+
type ParamListBase,
|
|
6
|
+
type StackNavigationState,
|
|
7
|
+
StackRouter,
|
|
8
|
+
type TypedNavigator,
|
|
9
|
+
useNavigationBuilder,
|
|
10
|
+
} from '@amazon-devices/react-navigation__core';
|
|
11
|
+
|
|
12
|
+
const StackNavigator = (
|
|
13
|
+
props: DefaultNavigatorOptions<
|
|
14
|
+
ParamListBase,
|
|
15
|
+
string | undefined,
|
|
16
|
+
StackNavigationState<ParamListBase>,
|
|
17
|
+
{},
|
|
18
|
+
{},
|
|
19
|
+
unknown
|
|
20
|
+
>
|
|
21
|
+
) => {
|
|
22
|
+
const { state, descriptors, NavigationContent } = useNavigationBuilder(
|
|
23
|
+
StackRouter,
|
|
24
|
+
props
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<NavigationContent>
|
|
29
|
+
{descriptors[state.routes[state.index].key].render()}
|
|
30
|
+
</NavigationContent>
|
|
31
|
+
);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export function createStackNavigator<
|
|
35
|
+
ParamList extends ParamListBase,
|
|
36
|
+
>(): TypedNavigator<{
|
|
37
|
+
ParamList: ParamList;
|
|
38
|
+
NavigatorID: string | undefined;
|
|
39
|
+
State: StackNavigationState<ParamList>;
|
|
40
|
+
ScreenOptions: {};
|
|
41
|
+
EventMap: {};
|
|
42
|
+
NavigationList: NavigationListBase<ParamList>;
|
|
43
|
+
Navigator: typeof StackNavigator;
|
|
44
|
+
}> {
|
|
45
|
+
return createNavigatorFactory(StackNavigator)();
|
|
46
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
let location = new URL('', 'http://example.com');
|
|
2
2
|
|
|
3
3
|
let listeners: (() => void)[] = [];
|
|
4
4
|
let entries = [{ state: null, href: location.href }];
|
|
@@ -12,7 +12,7 @@ const history = {
|
|
|
12
12
|
},
|
|
13
13
|
|
|
14
14
|
pushState(state: any, _: string, path: string) {
|
|
15
|
-
|
|
15
|
+
location = new URL(path, location.origin);
|
|
16
16
|
|
|
17
17
|
currentState = state;
|
|
18
18
|
entries = entries.slice(0, index + 1);
|
|
@@ -21,7 +21,7 @@ const history = {
|
|
|
21
21
|
},
|
|
22
22
|
|
|
23
23
|
replaceState(state: any, _: string, path: string) {
|
|
24
|
-
|
|
24
|
+
location = new URL(path, location.origin);
|
|
25
25
|
|
|
26
26
|
currentState = state;
|
|
27
27
|
entries[index] = { state, href: location.href };
|
|
@@ -35,7 +35,7 @@ const history = {
|
|
|
35
35
|
) {
|
|
36
36
|
index += n;
|
|
37
37
|
const entry = entries[index];
|
|
38
|
-
|
|
38
|
+
location = new URL(entry.href);
|
|
39
39
|
currentState = entry.state;
|
|
40
40
|
listeners.forEach((cb) => cb());
|
|
41
41
|
}
|
|
@@ -63,9 +63,11 @@ const removeEventListener = (type: 'popstate', listener: () => void) => {
|
|
|
63
63
|
}
|
|
64
64
|
};
|
|
65
65
|
|
|
66
|
-
const window = {
|
|
66
|
+
export const window = {
|
|
67
67
|
document: { title: '' },
|
|
68
|
-
location
|
|
68
|
+
get location() {
|
|
69
|
+
return location;
|
|
70
|
+
},
|
|
69
71
|
history,
|
|
70
72
|
addEventListener,
|
|
71
73
|
removeEventListener,
|
|
@@ -73,5 +75,3 @@ const window = {
|
|
|
73
75
|
return window;
|
|
74
76
|
},
|
|
75
77
|
};
|
|
76
|
-
|
|
77
|
-
export default window;
|
|
@@ -10,7 +10,7 @@ type HistoryRecord = {
|
|
|
10
10
|
path: string;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
export
|
|
13
|
+
export function createMemoryHistory() {
|
|
14
14
|
let index = 0;
|
|
15
15
|
let items: HistoryRecord[] = [];
|
|
16
16
|
|
|
@@ -87,6 +87,7 @@ export default function createMemoryHistory() {
|
|
|
87
87
|
// Need to keep the hash part of the path if there was no previous history entry
|
|
88
88
|
// or the previous history entry had the same path
|
|
89
89
|
let pathWithHash = path;
|
|
90
|
+
const hash = pathWithHash.includes('#') ? '' : location.hash;
|
|
90
91
|
|
|
91
92
|
if (!items.length || items.findIndex((item) => item.id === id) < 0) {
|
|
92
93
|
// There are two scenarios for creating an array with only one history record:
|
|
@@ -95,12 +96,13 @@ export default function createMemoryHistory() {
|
|
|
95
96
|
// the page when navigating forward in history.
|
|
96
97
|
// - This is the first time any state modifications are done
|
|
97
98
|
// So we need to push the entry as there's nothing to replace
|
|
98
|
-
|
|
99
|
+
|
|
100
|
+
pathWithHash = pathWithHash + hash;
|
|
99
101
|
items = [{ path: pathWithHash, state, id }];
|
|
100
102
|
index = 0;
|
|
101
103
|
} else {
|
|
102
104
|
if (items[index].path === path) {
|
|
103
|
-
pathWithHash = pathWithHash +
|
|
105
|
+
pathWithHash = pathWithHash + hash;
|
|
104
106
|
}
|
|
105
107
|
items[index] = { path, state, id };
|
|
106
108
|
}
|
|
@@ -174,21 +176,20 @@ export default function createMemoryHistory() {
|
|
|
174
176
|
// But on Firefox, it seems to take much longer, around 50ms from our testing
|
|
175
177
|
// We're using a hacky timeout since there doesn't seem to be way to know for sure
|
|
176
178
|
const timer = setTimeout(() => {
|
|
177
|
-
const
|
|
179
|
+
const foundIndex = pending.findIndex((it) => it.ref === done);
|
|
178
180
|
|
|
179
|
-
if (
|
|
180
|
-
pending[
|
|
181
|
-
pending.splice(
|
|
181
|
+
if (foundIndex > -1) {
|
|
182
|
+
pending[foundIndex].cb();
|
|
183
|
+
pending.splice(foundIndex, 1);
|
|
182
184
|
}
|
|
185
|
+
|
|
186
|
+
index = this.index;
|
|
183
187
|
}, 100);
|
|
184
188
|
|
|
185
189
|
const onPopState = () => {
|
|
186
|
-
const id = window.history.state?.id;
|
|
187
|
-
const currentIndex = items.findIndex((item) => item.id === id);
|
|
188
|
-
|
|
189
190
|
// Fix createMemoryHistory.index variable's value
|
|
190
191
|
// as it may go out of sync when navigating in the browser.
|
|
191
|
-
index =
|
|
192
|
+
index = this.index;
|
|
192
193
|
|
|
193
194
|
const last = pending.pop();
|
|
194
195
|
|
|
@@ -206,6 +207,10 @@ export default function createMemoryHistory() {
|
|
|
206
207
|
// Here we normalize it so that only external changes (e.g. user pressing back/forward) trigger the listener
|
|
207
208
|
listen(listener: () => void) {
|
|
208
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
|
+
|
|
209
214
|
if (pending.length) {
|
|
210
215
|
// This was triggered by `history.go(n)`, we shouldn't call the listener
|
|
211
216
|
return;
|