@amazon-devices/react-navigation__native 2.0.1758683737
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/LICENSE +7 -0
- package/README.md +5 -0
- package/SystemBundles/6132afb62bda3afb78ba1a1aca51924df73e9dbcc77106aa0f97a0ef68b04ebb.bundle +15196 -0
- package/SystemBundles/6132afb62bda3afb78ba1a1aca51924df73e9dbcc77106aa0f97a0ef68b04ebb.map +1 -0
- package/SystemModules/amzn__react-navigation__native-2.modules.txt +76 -0
- package/SystemModules/amzn__react-navigation__native-2.private.modules.txt +101 -0
- package/SystemModules/keplerscript-system-bundle-config.json +7 -0
- package/THIRD_PARTY_NOTICES.txt +24 -0
- package/kepler-compatibility.json +8 -0
- package/kepler-transformed-package-info.json +3 -0
- package/lib/commonjs/Link.js +50 -0
- package/lib/commonjs/Link.js.map +1 -0
- package/lib/commonjs/LinkingContext.js +15 -0
- package/lib/commonjs/LinkingContext.js.map +1 -0
- package/lib/commonjs/NavigationContainer.js +109 -0
- package/lib/commonjs/NavigationContainer.js.map +1 -0
- package/lib/commonjs/ServerContainer.js +54 -0
- package/lib/commonjs/ServerContainer.js.map +1 -0
- package/lib/commonjs/ServerContext.js +12 -0
- package/lib/commonjs/ServerContext.js.map +1 -0
- package/lib/commonjs/createMemoryHistory.js +220 -0
- package/lib/commonjs/createMemoryHistory.js.map +1 -0
- package/lib/commonjs/extractPathFromURL.js +25 -0
- package/lib/commonjs/extractPathFromURL.js.map +1 -0
- package/lib/commonjs/index.js +129 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/theming/DarkTheme.js +19 -0
- package/lib/commonjs/theming/DarkTheme.js.map +1 -0
- package/lib/commonjs/theming/DefaultTheme.js +19 -0
- package/lib/commonjs/theming/DefaultTheme.js.map +1 -0
- package/lib/commonjs/theming/ThemeContext.js +15 -0
- package/lib/commonjs/theming/ThemeContext.js.map +1 -0
- package/lib/commonjs/theming/ThemeProvider.js +20 -0
- package/lib/commonjs/theming/ThemeProvider.js.map +1 -0
- package/lib/commonjs/theming/useTheme.js +16 -0
- package/lib/commonjs/theming/useTheme.js.map +1 -0
- package/lib/commonjs/types.js +6 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/commonjs/useBackButton.js +11 -0
- package/lib/commonjs/useBackButton.js.map +1 -0
- package/lib/commonjs/useBackButton.native.js +27 -0
- package/lib/commonjs/useBackButton.native.js.map +1 -0
- package/lib/commonjs/useDocumentTitle.js +32 -0
- package/lib/commonjs/useDocumentTitle.js.map +1 -0
- package/lib/commonjs/useDocumentTitle.native.js +10 -0
- package/lib/commonjs/useDocumentTitle.native.js.map +1 -0
- package/lib/commonjs/useLinkBuilder.js +63 -0
- package/lib/commonjs/useLinkBuilder.js.map +1 -0
- package/lib/commonjs/useLinkProps.js +97 -0
- package/lib/commonjs/useLinkProps.js.map +1 -0
- package/lib/commonjs/useLinkTo.js +45 -0
- package/lib/commonjs/useLinkTo.js.map +1 -0
- package/lib/commonjs/useLinking.js +303 -0
- package/lib/commonjs/useLinking.js.map +1 -0
- package/lib/commonjs/useLinking.native.js +152 -0
- package/lib/commonjs/useLinking.native.js.map +1 -0
- package/lib/commonjs/useScrollToTop.js +95 -0
- package/lib/commonjs/useScrollToTop.js.map +1 -0
- package/lib/commonjs/useThenable.js +41 -0
- package/lib/commonjs/useThenable.js.map +1 -0
- package/lib/module/Link.js +41 -0
- package/lib/module/Link.js.map +1 -0
- package/lib/module/LinkingContext.js +7 -0
- package/lib/module/LinkingContext.js.map +1 -0
- package/lib/module/NavigationContainer.js +100 -0
- package/lib/module/NavigationContainer.js.map +1 -0
- package/lib/module/ServerContainer.js +45 -0
- package/lib/module/ServerContainer.js.map +1 -0
- package/lib/module/ServerContext.js +4 -0
- package/lib/module/ServerContext.js.map +1 -0
- package/lib/module/createMemoryHistory.js +214 -0
- package/lib/module/createMemoryHistory.js.map +1 -0
- package/lib/module/extractPathFromURL.js +18 -0
- package/lib/module/extractPathFromURL.js.map +1 -0
- package/lib/module/index.js +15 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/theming/DarkTheme.js +13 -0
- package/lib/module/theming/DarkTheme.js.map +1 -0
- package/lib/module/theming/DefaultTheme.js +13 -0
- package/lib/module/theming/DefaultTheme.js.map +1 -0
- package/lib/module/theming/ThemeContext.js +6 -0
- package/lib/module/theming/ThemeContext.js.map +1 -0
- package/lib/module/theming/ThemeProvider.js +11 -0
- package/lib/module/theming/ThemeProvider.js.map +1 -0
- package/lib/module/theming/useTheme.js +7 -0
- package/lib/module/theming/useTheme.js.map +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/useBackButton.js +5 -0
- package/lib/module/useBackButton.js.map +1 -0
- package/lib/module/useBackButton.native.js +19 -0
- package/lib/module/useBackButton.native.js.map +1 -0
- package/lib/module/useDocumentTitle.js +24 -0
- package/lib/module/useDocumentTitle.js.map +1 -0
- package/lib/module/useDocumentTitle.native.js +4 -0
- package/lib/module/useDocumentTitle.native.js.map +1 -0
- package/lib/module/useLinkBuilder.js +54 -0
- package/lib/module/useLinkBuilder.js.map +1 -0
- package/lib/module/useLinkProps.js +88 -0
- package/lib/module/useLinkProps.js.map +1 -0
- package/lib/module/useLinkTo.js +36 -0
- package/lib/module/useLinkTo.js.map +1 -0
- package/lib/module/useLinking.js +292 -0
- package/lib/module/useLinking.js.map +1 -0
- package/lib/module/useLinking.native.js +143 -0
- package/lib/module/useLinking.native.js.map +1 -0
- package/lib/module/useScrollToTop.js +87 -0
- package/lib/module/useScrollToTop.js.map +1 -0
- package/lib/module/useThenable.js +33 -0
- package/lib/module/useThenable.js.map +1 -0
- package/lib/typescript/src/Link.d.ts +24 -0
- package/lib/typescript/src/Link.d.ts.map +1 -0
- package/lib/typescript/src/LinkingContext.d.ts +8 -0
- package/lib/typescript/src/LinkingContext.d.ts.map +1 -0
- package/lib/typescript/src/NavigationContainer.d.ts +26 -0
- package/lib/typescript/src/NavigationContainer.d.ts.map +1 -0
- package/lib/typescript/src/ServerContainer.d.ts +15 -0
- package/lib/typescript/src/ServerContainer.d.ts.map +1 -0
- package/lib/typescript/src/ServerContext.d.ts +10 -0
- package/lib/typescript/src/ServerContext.d.ts.map +1 -0
- package/lib/typescript/src/__mocks__/window.d.ts +19 -0
- package/lib/typescript/src/__mocks__/window.d.ts.map +1 -0
- package/lib/typescript/src/createMemoryHistory.d.ts +25 -0
- package/lib/typescript/src/createMemoryHistory.d.ts.map +1 -0
- package/lib/typescript/src/extractPathFromURL.d.ts +2 -0
- package/lib/typescript/src/extractPathFromURL.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +15 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/theming/DarkTheme.d.ts +4 -0
- package/lib/typescript/src/theming/DarkTheme.d.ts.map +1 -0
- package/lib/typescript/src/theming/DefaultTheme.d.ts +4 -0
- package/lib/typescript/src/theming/DefaultTheme.d.ts.map +1 -0
- package/lib/typescript/src/theming/ThemeContext.d.ts +5 -0
- package/lib/typescript/src/theming/ThemeContext.d.ts.map +1 -0
- package/lib/typescript/src/theming/ThemeProvider.d.ts +9 -0
- package/lib/typescript/src/theming/ThemeProvider.d.ts.map +1 -0
- package/lib/typescript/src/theming/useTheme.d.ts +2 -0
- package/lib/typescript/src/theming/useTheme.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +127 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/lib/typescript/src/useBackButton.d.ts +4 -0
- package/lib/typescript/src/useBackButton.d.ts.map +1 -0
- package/lib/typescript/src/useBackButton.native.d.ts +4 -0
- package/lib/typescript/src/useBackButton.native.d.ts.map +1 -0
- package/lib/typescript/src/useDocumentTitle.d.ts +8 -0
- package/lib/typescript/src/useDocumentTitle.d.ts.map +1 -0
- package/lib/typescript/src/useDocumentTitle.native.d.ts +2 -0
- package/lib/typescript/src/useDocumentTitle.native.d.ts.map +1 -0
- package/lib/typescript/src/useLinkBuilder.d.ts +6 -0
- package/lib/typescript/src/useLinkBuilder.d.ts.map +1 -0
- package/lib/typescript/src/useLinkProps.d.ts +21 -0
- package/lib/typescript/src/useLinkProps.d.ts.map +1 -0
- package/lib/typescript/src/useLinkTo.d.ts +9 -0
- package/lib/typescript/src/useLinkTo.d.ts.map +1 -0
- package/lib/typescript/src/useLinking.d.ts +55 -0
- package/lib/typescript/src/useLinking.d.ts.map +1 -0
- package/lib/typescript/src/useLinking.native.d.ts +51 -0
- package/lib/typescript/src/useLinking.native.d.ts.map +1 -0
- package/lib/typescript/src/useScrollToTop.d.ts +27 -0
- package/lib/typescript/src/useScrollToTop.d.ts.map +1 -0
- package/lib/typescript/src/useThenable.d.ts +2 -0
- package/lib/typescript/src/useThenable.d.ts.map +1 -0
- package/package.json +1 -0
- package/src/Link.tsx +53 -0
- package/src/LinkingContext.tsx +12 -0
- package/src/NavigationContainer.tsx +152 -0
- package/src/ServerContainer.tsx +56 -0
- package/src/ServerContext.tsx +14 -0
- package/src/__mocks__/window.tsx +77 -0
- package/src/createMemoryHistory.tsx +224 -0
- package/src/extractPathFromURL.tsx +29 -0
- package/src/index.tsx +14 -0
- package/src/theming/DarkTheme.tsx +15 -0
- package/src/theming/DefaultTheme.tsx +15 -0
- package/src/theming/ThemeContext.tsx +10 -0
- package/src/theming/ThemeProvider.tsx +15 -0
- package/src/theming/useTheme.tsx +9 -0
- package/src/types.tsx +145 -0
- package/src/useBackButton.native.tsx +33 -0
- package/src/useBackButton.tsx +11 -0
- package/src/useDocumentTitle.native.tsx +3 -0
- package/src/useDocumentTitle.tsx +41 -0
- package/src/useLinkBuilder.tsx +82 -0
- package/src/useLinkProps.tsx +126 -0
- package/src/useLinkTo.tsx +71 -0
- package/src/useLinking.native.tsx +215 -0
- package/src/useLinking.tsx +395 -0
- package/src/useScrollToTop.tsx +116 -0
- package/src/useThenable.tsx +41 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import {
|
|
2
|
+
EventArg,
|
|
3
|
+
NavigationProp,
|
|
4
|
+
useNavigation,
|
|
5
|
+
useRoute,
|
|
6
|
+
} from '@amazon-devices/react-navigation__core';
|
|
7
|
+
import * as React from 'react';
|
|
8
|
+
import type { ScrollView } from 'react-native';
|
|
9
|
+
|
|
10
|
+
type ScrollOptions = { x?: number; y?: number; animated?: boolean };
|
|
11
|
+
|
|
12
|
+
type ScrollableView =
|
|
13
|
+
| { scrollToTop(): void }
|
|
14
|
+
| { scrollTo(options: ScrollOptions): void }
|
|
15
|
+
| { scrollToOffset(options: { offset?: number; animated?: boolean }): void }
|
|
16
|
+
| { scrollResponderScrollTo(options: ScrollOptions): void };
|
|
17
|
+
|
|
18
|
+
type ScrollableWrapper =
|
|
19
|
+
| { getScrollResponder(): React.ReactNode | ScrollView }
|
|
20
|
+
| { getNode(): ScrollableView }
|
|
21
|
+
| ScrollableView;
|
|
22
|
+
|
|
23
|
+
function getScrollableNode(ref: React.RefObject<ScrollableWrapper>) {
|
|
24
|
+
if (ref.current == null) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (
|
|
29
|
+
'scrollToTop' in ref.current ||
|
|
30
|
+
'scrollTo' in ref.current ||
|
|
31
|
+
'scrollToOffset' in ref.current ||
|
|
32
|
+
'scrollResponderScrollTo' in ref.current
|
|
33
|
+
) {
|
|
34
|
+
// This is already a scrollable node.
|
|
35
|
+
return ref.current;
|
|
36
|
+
} else if ('getScrollResponder' in ref.current) {
|
|
37
|
+
// If the view is a wrapper like FlatList, SectionList etc.
|
|
38
|
+
// We need to use `getScrollResponder` to get access to the scroll responder
|
|
39
|
+
return ref.current.getScrollResponder();
|
|
40
|
+
} else if ('getNode' in ref.current) {
|
|
41
|
+
// When a `ScrollView` is wraped in `Animated.createAnimatedComponent`
|
|
42
|
+
// we need to use `getNode` to get the ref to the actual scrollview.
|
|
43
|
+
// Note that `getNode` is deprecated in newer versions of react-native
|
|
44
|
+
// this is why we check if we already have a scrollable node above.
|
|
45
|
+
return ref.current.getNode();
|
|
46
|
+
} else {
|
|
47
|
+
return ref.current;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export default function useScrollToTop(
|
|
52
|
+
ref: React.RefObject<ScrollableWrapper>
|
|
53
|
+
) {
|
|
54
|
+
const navigation = useNavigation();
|
|
55
|
+
const route = useRoute();
|
|
56
|
+
|
|
57
|
+
React.useEffect(() => {
|
|
58
|
+
let tabNavigations: NavigationProp<ReactNavigation.RootParamList>[] = [];
|
|
59
|
+
let currentNavigation = navigation;
|
|
60
|
+
|
|
61
|
+
// If the screen is nested inside multiple tab navigators, we should scroll to top for any of them
|
|
62
|
+
// So we need to find all the parent tab navigators and add the listeners there
|
|
63
|
+
while (currentNavigation) {
|
|
64
|
+
if (currentNavigation.getState().type === 'tab') {
|
|
65
|
+
tabNavigations.push(currentNavigation);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
currentNavigation = currentNavigation.getParent();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (tabNavigations.length === 0) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const unsubscribers = tabNavigations.map((tab) => {
|
|
76
|
+
return tab.addListener(
|
|
77
|
+
// We don't wanna import tab types here to avoid extra deps
|
|
78
|
+
// in addition, there are multiple tab implementations
|
|
79
|
+
// @ts-expect-error
|
|
80
|
+
'tabPress',
|
|
81
|
+
(e: EventArg<'tabPress', true>) => {
|
|
82
|
+
// We should scroll to top only when the screen is focused
|
|
83
|
+
const isFocused = navigation.isFocused();
|
|
84
|
+
|
|
85
|
+
// In a nested stack navigator, tab press resets the stack to first screen
|
|
86
|
+
// So we should scroll to top only when we are on first screen
|
|
87
|
+
const isFirst =
|
|
88
|
+
tabNavigations.includes(navigation) ||
|
|
89
|
+
navigation.getState().routes[0].key === route.key;
|
|
90
|
+
|
|
91
|
+
// Run the operation in the next frame so we're sure all listeners have been run
|
|
92
|
+
// This is necessary to know if preventDefault() has been called
|
|
93
|
+
requestAnimationFrame(() => {
|
|
94
|
+
const scrollable = getScrollableNode(ref) as ScrollableWrapper;
|
|
95
|
+
|
|
96
|
+
if (isFocused && isFirst && scrollable && !e.defaultPrevented) {
|
|
97
|
+
if ('scrollToTop' in scrollable) {
|
|
98
|
+
scrollable.scrollToTop();
|
|
99
|
+
} else if ('scrollTo' in scrollable) {
|
|
100
|
+
scrollable.scrollTo({ y: 0, animated: true });
|
|
101
|
+
} else if ('scrollToOffset' in scrollable) {
|
|
102
|
+
scrollable.scrollToOffset({ offset: 0, animated: true });
|
|
103
|
+
} else if ('scrollResponderScrollTo' in scrollable) {
|
|
104
|
+
scrollable.scrollResponderScrollTo({ y: 0, animated: true });
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
return () => {
|
|
113
|
+
unsubscribers.forEach((unsubscribe) => unsubscribe());
|
|
114
|
+
};
|
|
115
|
+
}, [navigation, ref, route.key]);
|
|
116
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
export default function useThenable<T>(create: () => PromiseLike<T>) {
|
|
4
|
+
const [promise] = React.useState(create);
|
|
5
|
+
|
|
6
|
+
let initialState: [boolean, T | undefined] = [false, undefined];
|
|
7
|
+
|
|
8
|
+
// Check if our thenable is synchronous
|
|
9
|
+
promise.then((result) => {
|
|
10
|
+
initialState = [true, result];
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const [state, setState] = React.useState(initialState);
|
|
14
|
+
const [resolved] = state;
|
|
15
|
+
|
|
16
|
+
React.useEffect(() => {
|
|
17
|
+
let cancelled = false;
|
|
18
|
+
|
|
19
|
+
const resolve = async () => {
|
|
20
|
+
let result;
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
result = await promise;
|
|
24
|
+
} finally {
|
|
25
|
+
if (!cancelled) {
|
|
26
|
+
setState([true, result]);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
if (!resolved) {
|
|
32
|
+
resolve();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return () => {
|
|
36
|
+
cancelled = true;
|
|
37
|
+
};
|
|
38
|
+
}, [promise, resolved]);
|
|
39
|
+
|
|
40
|
+
return state;
|
|
41
|
+
}
|