@amazon-devices/react-navigation__react-native-tab-view 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.
- package/kepler-compatibility.json +2 -1
- package/lib/module/index.js +0 -7
- package/package.json +1 -1
- package/src/index.tsx +1 -15
- package/lib/module/Pager.android.js +0 -4
- package/lib/module/Pager.ios.js +0 -4
- package/lib/module/Pager.js +0 -4
- package/lib/module/PagerViewAdapter.js +0 -130
- package/lib/module/PanResponderAdapter.js +0 -209
- package/lib/module/PlatformPressable.js +0 -61
- package/lib/module/SceneMap.js +0 -24
- package/lib/module/SceneView.js +0 -72
- package/lib/module/TabBar.js +0 -472
- package/lib/module/TabBarIndicator.js +0 -122
- package/lib/module/TabBarItem.js +0 -217
- package/lib/module/TabBarItemLabel.js +0 -33
- package/lib/module/TabView.js +0 -141
- package/lib/module/types.js +0 -4
- package/lib/module/useAnimatedValue.js +0 -12
- package/src/Pager.android.tsx +0 -1
- package/src/Pager.ios.tsx +0 -1
- package/src/Pager.tsx +0 -1
- package/src/PagerViewAdapter.tsx +0 -185
- package/src/PanResponderAdapter.tsx +0 -344
- package/src/PlatformPressable.tsx +0 -91
- package/src/SceneMap.tsx +0 -30
- package/src/SceneView.tsx +0 -106
- package/src/TabBar.tsx +0 -728
- package/src/TabBarIndicator.tsx +0 -190
- package/src/TabBarItem.tsx +0 -308
- package/src/TabBarItemLabel.tsx +0 -42
- package/src/TabView.tsx +0 -198
- package/src/types.tsx +0 -87
- package/src/useAnimatedValue.tsx +0 -12
package/src/TabView.tsx
DELETED
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
I18nManager,
|
|
4
|
-
type LayoutChangeEvent,
|
|
5
|
-
Platform,
|
|
6
|
-
type StyleProp,
|
|
7
|
-
StyleSheet,
|
|
8
|
-
View,
|
|
9
|
-
type ViewStyle,
|
|
10
|
-
} from 'react-native';
|
|
11
|
-
|
|
12
|
-
import { Pager } from './Pager';
|
|
13
|
-
import { SceneView } from './SceneView';
|
|
14
|
-
import { TabBar } from './TabBar';
|
|
15
|
-
import type {
|
|
16
|
-
Layout,
|
|
17
|
-
LocaleDirection,
|
|
18
|
-
NavigationState,
|
|
19
|
-
PagerProps,
|
|
20
|
-
Route,
|
|
21
|
-
SceneRendererProps,
|
|
22
|
-
TabDescriptor,
|
|
23
|
-
} from './types';
|
|
24
|
-
|
|
25
|
-
export type Props<T extends Route> = Omit<PagerProps, 'layoutDirection'> & {
|
|
26
|
-
onIndexChange: (index: number) => void;
|
|
27
|
-
onTabSelect?: (props: { index: number }) => void;
|
|
28
|
-
navigationState: NavigationState<T>;
|
|
29
|
-
renderLazyPlaceholder?: (props: { route: T }) => React.ReactNode;
|
|
30
|
-
renderTabBar?: (
|
|
31
|
-
props: SceneRendererProps & {
|
|
32
|
-
navigationState: NavigationState<T>;
|
|
33
|
-
options: Record<string, TabDescriptor<T>> | undefined;
|
|
34
|
-
}
|
|
35
|
-
) => React.ReactNode;
|
|
36
|
-
tabBarPosition?: 'top' | 'bottom';
|
|
37
|
-
initialLayout?: Partial<Layout>;
|
|
38
|
-
lazy?: ((props: { route: T }) => boolean) | boolean;
|
|
39
|
-
lazyPreloadDistance?: number;
|
|
40
|
-
direction?: LocaleDirection;
|
|
41
|
-
pagerStyle?: StyleProp<ViewStyle>;
|
|
42
|
-
style?: StyleProp<ViewStyle>;
|
|
43
|
-
renderScene: (props: SceneRendererProps & { route: T }) => React.ReactNode;
|
|
44
|
-
options?: Record<string, TabDescriptor<T>>;
|
|
45
|
-
commonOptions?: TabDescriptor<T>;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const renderLazyPlaceholderDefault = () => null;
|
|
49
|
-
|
|
50
|
-
export function TabView<T extends Route>({
|
|
51
|
-
onIndexChange,
|
|
52
|
-
onTabSelect,
|
|
53
|
-
navigationState,
|
|
54
|
-
renderScene,
|
|
55
|
-
initialLayout,
|
|
56
|
-
keyboardDismissMode = 'auto',
|
|
57
|
-
lazy = false,
|
|
58
|
-
lazyPreloadDistance = 0,
|
|
59
|
-
onSwipeStart,
|
|
60
|
-
onSwipeEnd,
|
|
61
|
-
renderLazyPlaceholder = renderLazyPlaceholderDefault,
|
|
62
|
-
// eslint-disable-next-line @eslint-react/no-unstable-default-props
|
|
63
|
-
renderTabBar = (props) => <TabBar {...props} />,
|
|
64
|
-
pagerStyle,
|
|
65
|
-
style,
|
|
66
|
-
direction = I18nManager.getConstants().isRTL ? 'rtl' : 'ltr',
|
|
67
|
-
swipeEnabled = true,
|
|
68
|
-
tabBarPosition = 'top',
|
|
69
|
-
animationEnabled = true,
|
|
70
|
-
overScrollMode,
|
|
71
|
-
options: sceneOptions,
|
|
72
|
-
commonOptions,
|
|
73
|
-
}: Props<T>) {
|
|
74
|
-
if (
|
|
75
|
-
Platform.OS !== 'web' &&
|
|
76
|
-
direction !== (I18nManager.getConstants().isRTL ? 'rtl' : 'ltr')
|
|
77
|
-
) {
|
|
78
|
-
console.warn(
|
|
79
|
-
`The 'direction' prop is set to '${direction}' but the effective value is '${
|
|
80
|
-
I18nManager.getConstants().isRTL ? 'rtl' : 'ltr'
|
|
81
|
-
}'. This is not supported. Make sure to match the 'direction' prop with the writing direction of the app.`
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const [layout, setLayout] = React.useState({
|
|
86
|
-
width: 0,
|
|
87
|
-
height: 0,
|
|
88
|
-
...initialLayout,
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
const jumpToIndex = (index: number) => {
|
|
92
|
-
if (index !== navigationState.index) {
|
|
93
|
-
onIndexChange(index);
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const handleLayout = (e: LayoutChangeEvent) => {
|
|
98
|
-
const { height, width } = e.nativeEvent.layout;
|
|
99
|
-
|
|
100
|
-
setLayout((prevLayout) => {
|
|
101
|
-
if (prevLayout.width === width && prevLayout.height === height) {
|
|
102
|
-
return prevLayout;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return { height, width };
|
|
106
|
-
});
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
const options = Object.fromEntries(
|
|
110
|
-
navigationState.routes.map((route) => [
|
|
111
|
-
route.key,
|
|
112
|
-
{
|
|
113
|
-
...commonOptions,
|
|
114
|
-
...sceneOptions?.[route.key],
|
|
115
|
-
},
|
|
116
|
-
])
|
|
117
|
-
);
|
|
118
|
-
|
|
119
|
-
return (
|
|
120
|
-
<View onLayout={handleLayout} style={[styles.pager, style]}>
|
|
121
|
-
<Pager
|
|
122
|
-
layout={layout}
|
|
123
|
-
navigationState={navigationState}
|
|
124
|
-
keyboardDismissMode={keyboardDismissMode}
|
|
125
|
-
swipeEnabled={swipeEnabled}
|
|
126
|
-
onSwipeStart={onSwipeStart}
|
|
127
|
-
onSwipeEnd={onSwipeEnd}
|
|
128
|
-
onIndexChange={jumpToIndex}
|
|
129
|
-
onTabSelect={onTabSelect}
|
|
130
|
-
animationEnabled={animationEnabled}
|
|
131
|
-
overScrollMode={overScrollMode}
|
|
132
|
-
style={pagerStyle}
|
|
133
|
-
layoutDirection={direction}
|
|
134
|
-
>
|
|
135
|
-
{({ position, render, addEnterListener, jumpTo }) => {
|
|
136
|
-
// All the props here must not change between re-renders
|
|
137
|
-
// This is crucial to optimizing the routes with PureComponent
|
|
138
|
-
const sceneRendererProps = {
|
|
139
|
-
position,
|
|
140
|
-
layout,
|
|
141
|
-
jumpTo,
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
return (
|
|
145
|
-
<React.Fragment>
|
|
146
|
-
{tabBarPosition === 'top' &&
|
|
147
|
-
renderTabBar({
|
|
148
|
-
...sceneRendererProps,
|
|
149
|
-
options,
|
|
150
|
-
navigationState,
|
|
151
|
-
})}
|
|
152
|
-
{render(
|
|
153
|
-
navigationState.routes.map((route, i) => {
|
|
154
|
-
const { sceneStyle } = options?.[route.key] ?? {};
|
|
155
|
-
|
|
156
|
-
return (
|
|
157
|
-
<SceneView
|
|
158
|
-
key={route.key}
|
|
159
|
-
{...sceneRendererProps}
|
|
160
|
-
addEnterListener={addEnterListener}
|
|
161
|
-
index={i}
|
|
162
|
-
lazy={typeof lazy === 'function' ? lazy({ route }) : lazy}
|
|
163
|
-
lazyPreloadDistance={lazyPreloadDistance}
|
|
164
|
-
navigationState={navigationState}
|
|
165
|
-
style={sceneStyle}
|
|
166
|
-
>
|
|
167
|
-
{({ loading }) =>
|
|
168
|
-
loading
|
|
169
|
-
? renderLazyPlaceholder({ route })
|
|
170
|
-
: renderScene({
|
|
171
|
-
...sceneRendererProps,
|
|
172
|
-
route,
|
|
173
|
-
})
|
|
174
|
-
}
|
|
175
|
-
</SceneView>
|
|
176
|
-
);
|
|
177
|
-
})
|
|
178
|
-
)}
|
|
179
|
-
{tabBarPosition === 'bottom' &&
|
|
180
|
-
renderTabBar({
|
|
181
|
-
...sceneRendererProps,
|
|
182
|
-
options,
|
|
183
|
-
navigationState,
|
|
184
|
-
})}
|
|
185
|
-
</React.Fragment>
|
|
186
|
-
);
|
|
187
|
-
}}
|
|
188
|
-
</Pager>
|
|
189
|
-
</View>
|
|
190
|
-
);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
const styles = StyleSheet.create({
|
|
194
|
-
pager: {
|
|
195
|
-
flex: 1,
|
|
196
|
-
overflow: 'hidden',
|
|
197
|
-
},
|
|
198
|
-
});
|
package/src/types.tsx
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import type { Animated, StyleProp, TextStyle, ViewStyle } from 'react-native';
|
|
2
|
-
import type { PagerViewProps } from 'react-native-pager-view';
|
|
3
|
-
|
|
4
|
-
export type TabDescriptor<T extends Route> = {
|
|
5
|
-
accessibilityLabel?: string;
|
|
6
|
-
accessible?: boolean;
|
|
7
|
-
testID?: string;
|
|
8
|
-
labelText?: string;
|
|
9
|
-
labelAllowFontScaling?: boolean;
|
|
10
|
-
href?: string;
|
|
11
|
-
label?: (props: {
|
|
12
|
-
route: T;
|
|
13
|
-
labelText?: string;
|
|
14
|
-
focused: boolean;
|
|
15
|
-
color: string;
|
|
16
|
-
allowFontScaling?: boolean;
|
|
17
|
-
style?: StyleProp<TextStyle>;
|
|
18
|
-
}) => React.ReactNode;
|
|
19
|
-
labelStyle?: StyleProp<TextStyle>;
|
|
20
|
-
icon?: (props: {
|
|
21
|
-
route: T;
|
|
22
|
-
focused: boolean;
|
|
23
|
-
color: string;
|
|
24
|
-
size: number;
|
|
25
|
-
}) => React.ReactNode;
|
|
26
|
-
badge?: (props: { route: T }) => React.ReactElement;
|
|
27
|
-
sceneStyle?: StyleProp<ViewStyle>;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export type LocaleDirection = 'ltr' | 'rtl';
|
|
31
|
-
|
|
32
|
-
export type Route = {
|
|
33
|
-
key: string;
|
|
34
|
-
icon?: string;
|
|
35
|
-
title?: string;
|
|
36
|
-
accessible?: boolean;
|
|
37
|
-
accessibilityLabel?: string;
|
|
38
|
-
testID?: string;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export type Event = {
|
|
42
|
-
defaultPrevented: boolean;
|
|
43
|
-
preventDefault(): void;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export type Scene<T extends Route> = {
|
|
47
|
-
route: T;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export type NavigationState<T extends Route> = {
|
|
51
|
-
index: number;
|
|
52
|
-
routes: T[];
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
export type Layout = {
|
|
56
|
-
width: number;
|
|
57
|
-
height: number;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
export type Listener = (value: number) => void;
|
|
61
|
-
|
|
62
|
-
export type SceneRendererProps = {
|
|
63
|
-
layout: Layout;
|
|
64
|
-
position: Animated.AnimatedInterpolation<number>;
|
|
65
|
-
jumpTo: (key: string) => void;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export type EventEmitterProps = {
|
|
69
|
-
addEnterListener: (listener: Listener) => () => void;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
export type PagerProps = Omit<
|
|
73
|
-
PagerViewProps,
|
|
74
|
-
| 'initialPage'
|
|
75
|
-
| 'scrollEnabled'
|
|
76
|
-
| 'onPageScroll'
|
|
77
|
-
| 'onPageSelected'
|
|
78
|
-
| 'onPageScrollStateChanged'
|
|
79
|
-
| 'keyboardDismissMode'
|
|
80
|
-
| 'children'
|
|
81
|
-
> & {
|
|
82
|
-
keyboardDismissMode?: 'none' | 'on-drag' | 'auto';
|
|
83
|
-
swipeEnabled?: boolean;
|
|
84
|
-
animationEnabled?: boolean;
|
|
85
|
-
onSwipeStart?: () => void;
|
|
86
|
-
onSwipeEnd?: () => void;
|
|
87
|
-
};
|
package/src/useAnimatedValue.tsx
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { Animated } from 'react-native';
|
|
3
|
-
|
|
4
|
-
export function useAnimatedValue(initialValue: number) {
|
|
5
|
-
const lazyRef = React.useRef<Animated.Value>(undefined);
|
|
6
|
-
|
|
7
|
-
if (lazyRef.current === undefined) {
|
|
8
|
-
lazyRef.current = new Animated.Value(initialValue);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
return lazyRef.current as Animated.Value;
|
|
12
|
-
}
|