@amazon-devices/react-navigation__react-native-tab-view 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 +649 -0
- package/SystemBundles/c5889b273a6efc2a3c30241851055c37630fbf3381df86d403967369775f0536.bundle +14497 -0
- package/SystemBundles/c5889b273a6efc2a3c30241851055c37630fbf3381df86d403967369775f0536.map +1 -0
- package/SystemModules/amzn__react-navigation__react-native-tab-view-2.modules.txt +41 -0
- package/SystemModules/amzn__react-navigation__react-native-tab-view-2.private.modules.txt +98 -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/Pager.android.js +14 -0
- package/lib/commonjs/Pager.android.js.map +1 -0
- package/lib/commonjs/Pager.ios.js +14 -0
- package/lib/commonjs/Pager.ios.js.map +1 -0
- package/lib/commonjs/Pager.js +14 -0
- package/lib/commonjs/Pager.js.map +1 -0
- package/lib/commonjs/PagerViewAdapter.js +132 -0
- package/lib/commonjs/PagerViewAdapter.js.map +1 -0
- package/lib/commonjs/PanResponderAdapter.js +204 -0
- package/lib/commonjs/PanResponderAdapter.js.map +1 -0
- package/lib/commonjs/PlatformPressable.js +43 -0
- package/lib/commonjs/PlatformPressable.js.map +1 -0
- package/lib/commonjs/SceneMap.js +29 -0
- package/lib/commonjs/SceneMap.js.map +1 -0
- package/lib/commonjs/SceneView.js +78 -0
- package/lib/commonjs/SceneView.js.map +1 -0
- package/lib/commonjs/TabBar.js +405 -0
- package/lib/commonjs/TabBar.js.map +1 -0
- package/lib/commonjs/TabBarIndicator.js +110 -0
- package/lib/commonjs/TabBarIndicator.js.map +1 -0
- package/lib/commonjs/TabBarItem.js +227 -0
- package/lib/commonjs/TabBarItem.js.map +1 -0
- package/lib/commonjs/TabView.js +122 -0
- package/lib/commonjs/TabView.js.map +1 -0
- package/lib/commonjs/index.js +42 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/types.js +6 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/commonjs/useAnimatedValue.js +18 -0
- package/lib/commonjs/useAnimatedValue.js.map +1 -0
- package/lib/module/Pager.android.js +2 -0
- package/lib/module/Pager.android.js.map +1 -0
- package/lib/module/Pager.ios.js +2 -0
- package/lib/module/Pager.ios.js.map +1 -0
- package/lib/module/Pager.js +2 -0
- package/lib/module/Pager.js.map +1 -0
- package/lib/module/PagerViewAdapter.js +123 -0
- package/lib/module/PagerViewAdapter.js.map +1 -0
- package/lib/module/PanResponderAdapter.js +195 -0
- package/lib/module/PanResponderAdapter.js.map +1 -0
- package/lib/module/PlatformPressable.js +35 -0
- package/lib/module/PlatformPressable.js.map +1 -0
- package/lib/module/SceneMap.js +21 -0
- package/lib/module/SceneMap.js.map +1 -0
- package/lib/module/SceneView.js +70 -0
- package/lib/module/SceneView.js.map +1 -0
- package/lib/module/TabBar.js +396 -0
- package/lib/module/TabBar.js.map +1 -0
- package/lib/module/TabBarIndicator.js +101 -0
- package/lib/module/TabBarIndicator.js.map +1 -0
- package/lib/module/TabBarItem.js +218 -0
- package/lib/module/TabBarItem.js.map +1 -0
- package/lib/module/TabView.js +113 -0
- package/lib/module/TabView.js.map +1 -0
- package/lib/module/index.js +6 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/useAnimatedValue.js +10 -0
- package/lib/module/useAnimatedValue.js.map +1 -0
- package/lib/typescript/src/Pager.android.d.ts +2 -0
- package/lib/typescript/src/Pager.android.d.ts.map +1 -0
- package/lib/typescript/src/Pager.d.ts +2 -0
- package/lib/typescript/src/Pager.d.ts.map +1 -0
- package/lib/typescript/src/Pager.ios.d.ts +2 -0
- package/lib/typescript/src/Pager.ios.d.ts.map +1 -0
- package/lib/typescript/src/PagerViewAdapter.d.ts +15 -0
- package/lib/typescript/src/PagerViewAdapter.d.ts.map +1 -0
- package/lib/typescript/src/PanResponderAdapter.d.ts +16 -0
- package/lib/typescript/src/PanResponderAdapter.d.ts.map +1 -0
- package/lib/typescript/src/PlatformPressable.d.ts +16 -0
- package/lib/typescript/src/PlatformPressable.d.ts.map +1 -0
- package/lib/typescript/src/SceneMap.d.ts +10 -0
- package/lib/typescript/src/SceneMap.d.ts.map +1 -0
- package/lib/typescript/src/SceneView.d.ts +16 -0
- package/lib/typescript/src/SceneView.d.ts.map +1 -0
- package/lib/typescript/src/TabBar.d.ts +44 -0
- package/lib/typescript/src/TabBar.d.ts.map +1 -0
- package/lib/typescript/src/TabBarIndicator.d.ts +13 -0
- package/lib/typescript/src/TabBarIndicator.d.ts.map +1 -0
- package/lib/typescript/src/TabBarItem.d.ts +37 -0
- package/lib/typescript/src/TabBarItem.d.ts.map +1 -0
- package/lib/typescript/src/TabView.d.ts +27 -0
- package/lib/typescript/src/TabView.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +11 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +42 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/lib/typescript/src/useAnimatedValue.d.ts +3 -0
- package/lib/typescript/src/useAnimatedValue.d.ts.map +1 -0
- package/package.json +1 -0
- package/src/Pager.android.tsx +1 -0
- package/src/Pager.ios.tsx +1 -0
- package/src/Pager.tsx +1 -0
- package/src/PagerViewAdapter.tsx +180 -0
- package/src/PanResponderAdapter.tsx +340 -0
- package/src/PlatformPressable.tsx +42 -0
- package/src/SceneMap.tsx +30 -0
- package/src/SceneView.tsx +107 -0
- package/src/TabBar.tsx +639 -0
- package/src/TabBarIndicator.tsx +153 -0
- package/src/TabBarItem.tsx +319 -0
- package/src/TabView.tsx +155 -0
- package/src/index.tsx +10 -0
- package/src/types.tsx +59 -0
- package/src/useAnimatedValue.tsx +12 -0
package/src/SceneMap.tsx
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
import type { SceneRendererProps } from './types';
|
|
4
|
+
|
|
5
|
+
type SceneProps = {
|
|
6
|
+
route: any;
|
|
7
|
+
} & Omit<SceneRendererProps, 'layout'>;
|
|
8
|
+
|
|
9
|
+
const SceneComponent = React.memo(
|
|
10
|
+
<T extends { component: React.ComponentType<any> } & SceneProps>({
|
|
11
|
+
component,
|
|
12
|
+
...rest
|
|
13
|
+
}: T) => {
|
|
14
|
+
return React.createElement(component, rest);
|
|
15
|
+
}
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
export default function SceneMap<T extends any>(scenes: {
|
|
19
|
+
[key: string]: React.ComponentType<T>;
|
|
20
|
+
}) {
|
|
21
|
+
return ({ route, jumpTo, position }: SceneProps) => (
|
|
22
|
+
<SceneComponent
|
|
23
|
+
key={route.key}
|
|
24
|
+
component={scenes[route.key]}
|
|
25
|
+
route={route}
|
|
26
|
+
jumpTo={jumpTo}
|
|
27
|
+
position={position}
|
|
28
|
+
/>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { StyleProp, StyleSheet, View, ViewStyle } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import type {
|
|
5
|
+
EventEmitterProps,
|
|
6
|
+
NavigationState,
|
|
7
|
+
Route,
|
|
8
|
+
SceneRendererProps,
|
|
9
|
+
} from './types';
|
|
10
|
+
|
|
11
|
+
type Props<T extends Route> = SceneRendererProps &
|
|
12
|
+
EventEmitterProps & {
|
|
13
|
+
navigationState: NavigationState<T>;
|
|
14
|
+
lazy: boolean;
|
|
15
|
+
lazyPreloadDistance: number;
|
|
16
|
+
index: number;
|
|
17
|
+
children: (props: { loading: boolean }) => React.ReactNode;
|
|
18
|
+
style?: StyleProp<ViewStyle>;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export default function SceneView<T extends Route>({
|
|
22
|
+
children,
|
|
23
|
+
navigationState,
|
|
24
|
+
lazy,
|
|
25
|
+
layout,
|
|
26
|
+
index,
|
|
27
|
+
lazyPreloadDistance,
|
|
28
|
+
addEnterListener,
|
|
29
|
+
style,
|
|
30
|
+
}: Props<T>) {
|
|
31
|
+
const [isLoading, setIsLoading] = React.useState(
|
|
32
|
+
Math.abs(navigationState.index - index) > lazyPreloadDistance
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
if (
|
|
36
|
+
isLoading &&
|
|
37
|
+
Math.abs(navigationState.index - index) <= lazyPreloadDistance
|
|
38
|
+
) {
|
|
39
|
+
// Always render the route when it becomes focused
|
|
40
|
+
setIsLoading(false);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
React.useEffect(() => {
|
|
44
|
+
const handleEnter = (value: number) => {
|
|
45
|
+
// If we're entering the current route, we need to load it
|
|
46
|
+
if (value === index) {
|
|
47
|
+
setIsLoading((prevState) => {
|
|
48
|
+
if (prevState) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
return prevState;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
let unsubscribe: (() => void) | undefined;
|
|
57
|
+
let timer: NodeJS.Timeout;
|
|
58
|
+
|
|
59
|
+
if (lazy && isLoading) {
|
|
60
|
+
// If lazy mode is enabled, listen to when we enter screens
|
|
61
|
+
unsubscribe = addEnterListener(handleEnter);
|
|
62
|
+
} else if (isLoading) {
|
|
63
|
+
// If lazy mode is not enabled, render the scene with a delay if not loaded already
|
|
64
|
+
// This improves the initial startup time as the scene is no longer blocking
|
|
65
|
+
timer = setTimeout(() => setIsLoading(false), 0);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return () => {
|
|
69
|
+
unsubscribe?.();
|
|
70
|
+
clearTimeout(timer);
|
|
71
|
+
};
|
|
72
|
+
}, [addEnterListener, index, isLoading, lazy]);
|
|
73
|
+
|
|
74
|
+
const focused = navigationState.index === index;
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<View
|
|
78
|
+
accessibilityElementsHidden={!focused}
|
|
79
|
+
importantForAccessibility={focused ? 'auto' : 'no-hide-descendants'}
|
|
80
|
+
style={[
|
|
81
|
+
styles.route,
|
|
82
|
+
// If we don't have the layout yet, make the focused screen fill the container
|
|
83
|
+
// This avoids delay before we are able to render pages side by side
|
|
84
|
+
layout.width
|
|
85
|
+
? { width: layout.width }
|
|
86
|
+
: focused
|
|
87
|
+
? StyleSheet.absoluteFill
|
|
88
|
+
: null,
|
|
89
|
+
style,
|
|
90
|
+
]}
|
|
91
|
+
>
|
|
92
|
+
{
|
|
93
|
+
// Only render the route only if it's either focused or layout is available
|
|
94
|
+
// When layout is not available, we must not render unfocused routes
|
|
95
|
+
// so that the focused route can fill the screen
|
|
96
|
+
focused || layout.width ? children({ loading: isLoading }) : null
|
|
97
|
+
}
|
|
98
|
+
</View>
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const styles = StyleSheet.create({
|
|
103
|
+
route: {
|
|
104
|
+
flex: 1,
|
|
105
|
+
overflow: 'hidden',
|
|
106
|
+
},
|
|
107
|
+
});
|