@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.
- package/SystemModules/amzn__react-navigation__native-8.private.modules.txt +38 -33
- package/kepler-compatibility.json +4 -2
- package/lib/module/index.js +0 -19
- package/oss-attribution/attribution.txt +50 -0
- package/oss-attribution/licenseInfos.json +18 -0
- package/package.json +1 -1
- package/src/index.tsx +1 -17
- package/SystemBundles/0fc5c971c5cf41a0dab235bcc6d58e5c06d9aaff650fa9815b525f8b9bb70a03.bundle +0 -9116
- package/SystemBundles/0fc5c971c5cf41a0dab235bcc6d58e5c06d9aaff650fa9815b525f8b9bb70a03.map +0 -3543
- package/lib/module/Link.js +0 -62
- package/lib/module/LinkingContext.js +0 -11
- package/lib/module/LocaleDirContext.js +0 -6
- package/lib/module/NavigationContainer.js +0 -128
- package/lib/module/ServerContainer.js +0 -55
- package/lib/module/ServerContext.js +0 -5
- package/lib/module/UnhandledLinkingContext.js +0 -14
- package/lib/module/__stubs__/createStackNavigator.js +0 -18
- package/lib/module/__stubs__/window.js +0 -75
- package/lib/module/createMemoryHistory.js +0 -216
- package/lib/module/createStaticNavigation.js +0 -54
- package/lib/module/extractPathFromURL.js +0 -19
- package/lib/module/theming/DarkTheme.js +0 -16
- package/lib/module/theming/DefaultTheme.js +0 -16
- package/lib/module/theming/fonts.js +0 -61
- package/lib/module/types.js +0 -4
- package/lib/module/useBackButton.js +0 -7
- package/lib/module/useBackButton.native.js +0 -21
- package/lib/module/useDocumentTitle.js +0 -26
- package/lib/module/useDocumentTitle.native.js +0 -6
- package/lib/module/useLinkBuilder.js +0 -85
- package/lib/module/useLinkProps.js +0 -93
- package/lib/module/useLinkTo.js +0 -26
- package/lib/module/useLinking.js +0 -320
- package/lib/module/useLinking.native.js +0 -148
- package/lib/module/useLocale.js +0 -18
- package/lib/module/useRoutePath.js +0 -30
- package/lib/module/useScrollToTop.js +0 -91
- package/lib/module/useThenable.js +0 -36
- package/src/Link.tsx +0 -69
- package/src/LinkingContext.tsx +0 -16
- package/src/LocaleDirContext.tsx +0 -7
- package/src/NavigationContainer.tsx +0 -211
- package/src/ServerContainer.tsx +0 -57
- package/src/ServerContext.tsx +0 -12
- package/src/UnhandledLinkingContext.tsx +0 -18
- package/src/__stubs__/createStackNavigator.tsx +0 -46
- package/src/__stubs__/window.tsx +0 -77
- package/src/createMemoryHistory.tsx +0 -229
- package/src/createStaticNavigation.tsx +0 -109
- package/src/extractPathFromURL.tsx +0 -29
- package/src/theming/DarkTheme.tsx +0 -15
- package/src/theming/DefaultTheme.tsx +0 -15
- package/src/theming/fonts.tsx +0 -63
- package/src/types.tsx +0 -191
- package/src/useBackButton.native.tsx +0 -33
- package/src/useBackButton.tsx +0 -11
- package/src/useDocumentTitle.native.tsx +0 -3
- package/src/useDocumentTitle.tsx +0 -41
- package/src/useLinkBuilder.tsx +0 -127
- package/src/useLinkProps.tsx +0 -156
- package/src/useLinkTo.tsx +0 -31
- package/src/useLinking.native.tsx +0 -217
- package/src/useLinking.tsx +0 -442
- package/src/useLocale.tsx +0 -18
- package/src/useRoutePath.tsx +0 -34
- package/src/useScrollToTop.tsx +0 -120
- package/src/useThenable.tsx +0 -42
package/src/Link.tsx
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { useTheme } from '@amazon-devices/react-navigation__core';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import {
|
|
4
|
-
type GestureResponderEvent,
|
|
5
|
-
Platform,
|
|
6
|
-
Text,
|
|
7
|
-
type TextProps,
|
|
8
|
-
} from 'react-native';
|
|
9
|
-
|
|
10
|
-
import { type LinkProps, useLinkProps } from './useLinkProps';
|
|
11
|
-
|
|
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
|
-
};
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Component to render link to another screen using a path.
|
|
27
|
-
* Uses an anchor tag on the web.
|
|
28
|
-
*
|
|
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`).
|
|
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.
|
|
33
|
-
* @param props.children Child elements to render the content.
|
|
34
|
-
*/
|
|
35
|
-
export function Link<ParamList extends ReactNavigation.RootParamList>({
|
|
36
|
-
screen,
|
|
37
|
-
params,
|
|
38
|
-
action,
|
|
39
|
-
href,
|
|
40
|
-
style,
|
|
41
|
-
...rest
|
|
42
|
-
}: Props<ParamList>) {
|
|
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 });
|
|
46
|
-
|
|
47
|
-
const onPress = (
|
|
48
|
-
e: React.MouseEvent<HTMLAnchorElement, MouseEvent> | GestureResponderEvent
|
|
49
|
-
) => {
|
|
50
|
-
if ('onPress' in rest) {
|
|
51
|
-
rest.onPress?.(e);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// Let user prevent default behavior
|
|
55
|
-
if (!e.defaultPrevented) {
|
|
56
|
-
props.onPress(e);
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
return React.createElement(Text, {
|
|
61
|
-
...props,
|
|
62
|
-
...rest,
|
|
63
|
-
...Platform.select({
|
|
64
|
-
web: { onClick: onPress } as any,
|
|
65
|
-
default: { onPress },
|
|
66
|
-
}),
|
|
67
|
-
style: [{ color: colors.primary }, fonts.regular, style],
|
|
68
|
-
});
|
|
69
|
-
}
|
package/src/LinkingContext.tsx
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { ParamListBase } from '@amazon-devices/react-navigation__core';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
|
|
4
|
-
import type { LinkingOptions } from './types';
|
|
5
|
-
|
|
6
|
-
const MISSING_CONTEXT_ERROR = "Couldn't find a LinkingContext context.";
|
|
7
|
-
|
|
8
|
-
export const LinkingContext = React.createContext<{
|
|
9
|
-
options?: LinkingOptions<ParamListBase>;
|
|
10
|
-
}>({
|
|
11
|
-
get options(): any {
|
|
12
|
-
throw new Error(MISSING_CONTEXT_ERROR);
|
|
13
|
-
},
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
LinkingContext.displayName = 'LinkingContext';
|
package/src/LocaleDirContext.tsx
DELETED
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BaseNavigationContainer,
|
|
3
|
-
getActionFromState,
|
|
4
|
-
getPathFromState,
|
|
5
|
-
getStateFromPath,
|
|
6
|
-
type NavigationContainerProps,
|
|
7
|
-
type NavigationContainerRef,
|
|
8
|
-
type NavigationState,
|
|
9
|
-
type ParamListBase,
|
|
10
|
-
ThemeProvider,
|
|
11
|
-
validatePathConfig,
|
|
12
|
-
} from '@amazon-devices/react-navigation__core';
|
|
13
|
-
import * as React from 'react';
|
|
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';
|
|
30
|
-
|
|
31
|
-
declare global {
|
|
32
|
-
var REACT_NAVIGATION_DEVTOOLS: WeakMap<
|
|
33
|
-
NavigationContainerRef<any>,
|
|
34
|
-
{ readonly linking: LinkingOptions<any> }
|
|
35
|
-
>;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
globalThis.REACT_NAVIGATION_DEVTOOLS = new WeakMap();
|
|
39
|
-
|
|
40
|
-
type Props<ParamList extends {}> = NavigationContainerProps & {
|
|
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
|
-
*/
|
|
57
|
-
linking?: LinkingOptions<ParamList>;
|
|
58
|
-
/**
|
|
59
|
-
* Fallback element to render until initial state is resolved from deep linking.
|
|
60
|
-
*
|
|
61
|
-
* Defaults to `null`.
|
|
62
|
-
*/
|
|
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
|
-
*/
|
|
70
|
-
documentTitle?: DocumentTitleOptions;
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
function NavigationContainerInner(
|
|
74
|
-
{
|
|
75
|
-
direction = I18nManager.getConstants().isRTL ? 'rtl' : 'ltr',
|
|
76
|
-
theme = DefaultTheme,
|
|
77
|
-
linking,
|
|
78
|
-
fallback = null,
|
|
79
|
-
documentTitle,
|
|
80
|
-
onReady,
|
|
81
|
-
onStateChange,
|
|
82
|
-
...rest
|
|
83
|
-
}: Props<ParamListBase>,
|
|
84
|
-
ref?: React.Ref<NavigationContainerRef<ParamListBase> | null>
|
|
85
|
-
) {
|
|
86
|
-
const isLinkingEnabled = linking ? linking.enabled !== false : false;
|
|
87
|
-
|
|
88
|
-
if (linking?.config) {
|
|
89
|
-
validatePathConfig(linking.config);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const refContainer =
|
|
93
|
-
React.useRef<NavigationContainerRef<ParamListBase>>(null);
|
|
94
|
-
|
|
95
|
-
useBackButton(refContainer);
|
|
96
|
-
useDocumentTitle(refContainer, documentTitle);
|
|
97
|
-
|
|
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?.();
|
|
129
|
-
});
|
|
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
|
-
);
|
|
144
|
-
// Add additional linking related info to the ref
|
|
145
|
-
// This will be used by the devtools
|
|
146
|
-
React.useEffect(() => {
|
|
147
|
-
if (refContainer.current) {
|
|
148
|
-
REACT_NAVIGATION_DEVTOOLS.set(refContainer.current, {
|
|
149
|
-
get linking() {
|
|
150
|
-
return {
|
|
151
|
-
...linking,
|
|
152
|
-
enabled: isLinkingEnabled,
|
|
153
|
-
prefixes: linking?.prefixes ?? [],
|
|
154
|
-
getStateFromPath: linking?.getStateFromPath ?? getStateFromPath,
|
|
155
|
-
getPathFromState: linking?.getPathFromState ?? getPathFromState,
|
|
156
|
-
getActionFromState:
|
|
157
|
-
linking?.getActionFromState ?? getActionFromState,
|
|
158
|
-
};
|
|
159
|
-
},
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
const [isResolved, initialState] = useThenable(getInitialState);
|
|
165
|
-
|
|
166
|
-
// FIXME
|
|
167
|
-
// @ts-expect-error not sure why this is not working
|
|
168
|
-
React.useImperativeHandle(ref, () => refContainer.current);
|
|
169
|
-
|
|
170
|
-
const isLinkingReady =
|
|
171
|
-
rest.initialState != null || !isLinkingEnabled || isResolved;
|
|
172
|
-
|
|
173
|
-
if (!isLinkingReady) {
|
|
174
|
-
return (
|
|
175
|
-
<LocaleDirContext.Provider value={direction}>
|
|
176
|
-
<ThemeProvider value={theme}>{fallback}</ThemeProvider>
|
|
177
|
-
</LocaleDirContext.Provider>
|
|
178
|
-
);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
return (
|
|
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>
|
|
198
|
-
);
|
|
199
|
-
}
|
|
200
|
-
|
|
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>(
|
|
208
|
-
props: Props<RootParamList> & {
|
|
209
|
-
ref?: React.Ref<NavigationContainerRef<RootParamList>>;
|
|
210
|
-
}
|
|
211
|
-
) => React.ReactElement;
|
package/src/ServerContainer.tsx
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { CurrentRenderContext } from '@amazon-devices/react-navigation__core';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
|
|
4
|
-
import { ServerContext, type ServerContextType } from './ServerContext';
|
|
5
|
-
import type { ServerContainerRef } from './types';
|
|
6
|
-
|
|
7
|
-
type Props = ServerContextType & {
|
|
8
|
-
children: React.ReactNode;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Container component for server rendering.
|
|
13
|
-
*
|
|
14
|
-
* @param props.location Location object to base the initial URL for SSR.
|
|
15
|
-
* @param props.children Child elements to render the content.
|
|
16
|
-
* @param props.ref Ref object which contains helper methods.
|
|
17
|
-
*/
|
|
18
|
-
export const ServerContainer = React.forwardRef(function ServerContainer(
|
|
19
|
-
{ children, location }: Props,
|
|
20
|
-
ref: React.Ref<ServerContainerRef>
|
|
21
|
-
) {
|
|
22
|
-
React.useEffect(() => {
|
|
23
|
-
console.error(
|
|
24
|
-
"'ServerContainer' should only be used on the server with 'react-dom/server' for SSR."
|
|
25
|
-
);
|
|
26
|
-
}, []);
|
|
27
|
-
|
|
28
|
-
// eslint-disable-next-line @eslint-react/no-unstable-context-value
|
|
29
|
-
const current: { options?: object } = {};
|
|
30
|
-
|
|
31
|
-
if (ref) {
|
|
32
|
-
const value = {
|
|
33
|
-
getCurrentOptions() {
|
|
34
|
-
return current.options;
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
// We write to the `ref` during render instead of `React.useImperativeHandle`
|
|
39
|
-
// This is because `useImperativeHandle` will update the ref after 'commit',
|
|
40
|
-
// and there's no 'commit' phase during SSR.
|
|
41
|
-
// Mutating ref during render is unsafe in concurrent mode, but we don't care about it for SSR.
|
|
42
|
-
if (typeof ref === 'function') {
|
|
43
|
-
ref(value);
|
|
44
|
-
} else {
|
|
45
|
-
ref.current = value;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return (
|
|
50
|
-
// eslint-disable-next-line @eslint-react/no-unstable-context-value
|
|
51
|
-
<ServerContext.Provider value={{ location }}>
|
|
52
|
-
<CurrentRenderContext.Provider value={current}>
|
|
53
|
-
{children}
|
|
54
|
-
</CurrentRenderContext.Provider>
|
|
55
|
-
</ServerContext.Provider>
|
|
56
|
-
);
|
|
57
|
-
});
|
package/src/ServerContext.tsx
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
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';
|
|
@@ -1,46 +0,0 @@
|
|
|
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
|
-
}
|
package/src/__stubs__/window.tsx
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
let location = new URL('', 'http://example.com');
|
|
2
|
-
|
|
3
|
-
let listeners: (() => void)[] = [];
|
|
4
|
-
let entries = [{ state: null, href: location.href }];
|
|
5
|
-
let index = 0;
|
|
6
|
-
|
|
7
|
-
let currentState: any = null;
|
|
8
|
-
|
|
9
|
-
const history = {
|
|
10
|
-
get state() {
|
|
11
|
-
return currentState;
|
|
12
|
-
},
|
|
13
|
-
|
|
14
|
-
pushState(state: any, _: string, path: string) {
|
|
15
|
-
location = new URL(path, location.origin);
|
|
16
|
-
|
|
17
|
-
currentState = state;
|
|
18
|
-
entries = entries.slice(0, index + 1);
|
|
19
|
-
entries.push({ state, href: location.href });
|
|
20
|
-
index = entries.length - 1;
|
|
21
|
-
},
|
|
22
|
-
|
|
23
|
-
replaceState(state: any, _: string, path: string) {
|
|
24
|
-
location = new URL(path, location.origin);
|
|
25
|
-
|
|
26
|
-
currentState = state;
|
|
27
|
-
entries[index] = { state, href: location.href };
|
|
28
|
-
},
|
|
29
|
-
|
|
30
|
-
go(n: number) {
|
|
31
|
-
setTimeout(() => {
|
|
32
|
-
if (
|
|
33
|
-
(n > 0 && n < entries.length - index) ||
|
|
34
|
-
(n < 0 && Math.abs(n) <= index)
|
|
35
|
-
) {
|
|
36
|
-
index += n;
|
|
37
|
-
const entry = entries[index];
|
|
38
|
-
location = new URL(entry.href);
|
|
39
|
-
currentState = entry.state;
|
|
40
|
-
listeners.forEach((cb) => cb());
|
|
41
|
-
}
|
|
42
|
-
}, 0);
|
|
43
|
-
},
|
|
44
|
-
|
|
45
|
-
back() {
|
|
46
|
-
this.go(-1);
|
|
47
|
-
},
|
|
48
|
-
|
|
49
|
-
forward() {
|
|
50
|
-
this.go(1);
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const addEventListener = (type: 'popstate', listener: () => void) => {
|
|
55
|
-
if (type === 'popstate') {
|
|
56
|
-
listeners.push(listener);
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
const removeEventListener = (type: 'popstate', listener: () => void) => {
|
|
61
|
-
if (type === 'popstate') {
|
|
62
|
-
listeners = listeners.filter((cb) => cb !== listener);
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
export const window = {
|
|
67
|
-
document: { title: '' },
|
|
68
|
-
get location() {
|
|
69
|
-
return location;
|
|
70
|
-
},
|
|
71
|
-
history,
|
|
72
|
-
addEventListener,
|
|
73
|
-
removeEventListener,
|
|
74
|
-
get window() {
|
|
75
|
-
return window;
|
|
76
|
-
},
|
|
77
|
-
};
|