react-native-tab-view 4.0.0-alpha.8 → 4.0.0-rc.0
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/lib/commonjs/Pager.android.js.map +1 -1
- package/lib/commonjs/Pager.ios.js.map +1 -1
- package/lib/commonjs/Pager.js.map +1 -1
- package/lib/commonjs/PagerViewAdapter.js +24 -24
- package/lib/commonjs/PagerViewAdapter.js.map +1 -1
- package/lib/commonjs/PanResponderAdapter.js +27 -29
- package/lib/commonjs/PanResponderAdapter.js.map +1 -1
- package/lib/commonjs/PlatformPressable.js +20 -22
- package/lib/commonjs/PlatformPressable.js.map +1 -1
- package/lib/commonjs/SceneMap.js +16 -20
- package/lib/commonjs/SceneMap.js.map +1 -1
- package/lib/commonjs/SceneView.js +11 -12
- package/lib/commonjs/SceneView.js.map +1 -1
- package/lib/commonjs/TabBar.js +87 -106
- package/lib/commonjs/TabBar.js.map +1 -1
- package/lib/commonjs/TabBarIndicator.js +40 -20
- package/lib/commonjs/TabBarIndicator.js.map +1 -1
- package/lib/commonjs/TabBarItem.js +44 -36
- package/lib/commonjs/TabBarItem.js.map +1 -1
- package/lib/commonjs/TabBarItemLabel.js +7 -8
- package/lib/commonjs/TabBarItemLabel.js.map +1 -1
- package/lib/commonjs/TabView.js +37 -42
- package/lib/commonjs/TabView.js.map +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/useAnimatedValue.js +1 -1
- package/lib/commonjs/useAnimatedValue.js.map +1 -1
- package/lib/module/Pager.android.js.map +1 -1
- package/lib/module/Pager.ios.js.map +1 -1
- package/lib/module/Pager.js.map +1 -1
- package/lib/module/PagerViewAdapter.js +22 -22
- package/lib/module/PagerViewAdapter.js.map +1 -1
- package/lib/module/PanResponderAdapter.js +25 -28
- package/lib/module/PanResponderAdapter.js.map +1 -1
- package/lib/module/PlatformPressable.js +19 -21
- package/lib/module/PlatformPressable.js.map +1 -1
- package/lib/module/SceneMap.js +15 -19
- package/lib/module/SceneMap.js.map +1 -1
- package/lib/module/SceneView.js +10 -11
- package/lib/module/SceneView.js.map +1 -1
- package/lib/module/TabBar.js +85 -104
- package/lib/module/TabBar.js.map +1 -1
- package/lib/module/TabBarIndicator.js +40 -20
- package/lib/module/TabBarIndicator.js.map +1 -1
- package/lib/module/TabBarItem.js +43 -35
- package/lib/module/TabBarItem.js.map +1 -1
- package/lib/module/TabBarItemLabel.js +6 -7
- package/lib/module/TabBarItemLabel.js.map +1 -1
- package/lib/module/TabView.js +36 -41
- package/lib/module/TabView.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/useAnimatedValue.js.map +1 -1
- package/lib/typescript/src/PagerViewAdapter.d.ts.map +1 -1
- package/lib/typescript/src/PanResponderAdapter.d.ts.map +1 -1
- package/lib/typescript/src/PlatformPressable.d.ts.map +1 -1
- package/lib/typescript/src/TabBarIndicator.d.ts.map +1 -1
- package/lib/typescript/src/TabBarItem.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +6 -6
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/useAnimatedValue.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/PagerViewAdapter.tsx +16 -16
- package/src/PanResponderAdapter.tsx +12 -15
- package/src/PlatformPressable.tsx +4 -1
- package/src/TabBar.tsx +2 -2
- package/src/TabBarIndicator.tsx +37 -7
- package/src/TabBarItem.tsx +8 -2
- package/src/types.tsx +5 -6
package/src/TabBarIndicator.tsx
CHANGED
|
@@ -2,6 +2,7 @@ import * as React from 'react';
|
|
|
2
2
|
import {
|
|
3
3
|
Animated,
|
|
4
4
|
Easing,
|
|
5
|
+
Platform,
|
|
5
6
|
type StyleProp,
|
|
6
7
|
StyleSheet,
|
|
7
8
|
type ViewStyle,
|
|
@@ -32,14 +33,29 @@ const getTranslateX = (
|
|
|
32
33
|
routes: Route[],
|
|
33
34
|
getTabWidth: GetTabWidth,
|
|
34
35
|
direction: LocaleDirection,
|
|
35
|
-
gap?: number
|
|
36
|
+
gap?: number,
|
|
37
|
+
width?: number | string
|
|
36
38
|
) => {
|
|
37
39
|
const inputRange = routes.map((_, i) => i);
|
|
38
40
|
|
|
39
41
|
// every index contains widths at all previous indices
|
|
40
42
|
const outputRange = routes.reduce<number[]>((acc, _, i) => {
|
|
41
|
-
if (
|
|
42
|
-
|
|
43
|
+
if (typeof width === 'number') {
|
|
44
|
+
if (i === 0) return [getTabWidth(i) / 2 - width / 2];
|
|
45
|
+
|
|
46
|
+
let sumTabWidth = 0;
|
|
47
|
+
for (let j = 0; j < i; j++) {
|
|
48
|
+
sumTabWidth += getTabWidth(j);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return [
|
|
52
|
+
...acc,
|
|
53
|
+
sumTabWidth + getTabWidth(i) / 2 + (gap ? gap * i : 0) - width / 2,
|
|
54
|
+
];
|
|
55
|
+
} else {
|
|
56
|
+
if (i === 0) return [0];
|
|
57
|
+
return [...acc, acc[i - 1] + getTabWidth(i - 1) + (gap ?? 0)];
|
|
58
|
+
}
|
|
43
59
|
}, []);
|
|
44
60
|
|
|
45
61
|
const translateX = position.interpolate({
|
|
@@ -105,7 +121,7 @@ export function TabBarIndicator<T extends Route>({
|
|
|
105
121
|
if (layout.width) {
|
|
106
122
|
const translateX =
|
|
107
123
|
routes.length > 1
|
|
108
|
-
? getTranslateX(position, routes, getTabWidth, direction, gap)
|
|
124
|
+
? getTranslateX(position, routes, getTabWidth, direction, gap, width)
|
|
109
125
|
: 0;
|
|
110
126
|
|
|
111
127
|
transform.push({ translateX });
|
|
@@ -130,13 +146,27 @@ export function TabBarIndicator<T extends Route>({
|
|
|
130
146
|
);
|
|
131
147
|
}
|
|
132
148
|
|
|
149
|
+
const styleList: StyleProp<ViewStyle> = [];
|
|
150
|
+
|
|
151
|
+
// scaleX doesn't work properly on chrome and opera for linux and android
|
|
152
|
+
if (Platform.OS === 'web' && width === 'auto') {
|
|
153
|
+
styleList.push(
|
|
154
|
+
{ width: transform[1].scaleX },
|
|
155
|
+
{ left: transform[0].translateX }
|
|
156
|
+
);
|
|
157
|
+
} else {
|
|
158
|
+
styleList.push(
|
|
159
|
+
{ width: width === 'auto' ? 1 : width },
|
|
160
|
+
{ start: `${(100 / routes.length) * navigationState.index}%` },
|
|
161
|
+
{ transform }
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
|
|
133
165
|
return (
|
|
134
166
|
<Animated.View
|
|
135
167
|
style={[
|
|
136
168
|
styles.indicator,
|
|
137
|
-
|
|
138
|
-
{ start: `${(100 / routes.length) * navigationState.index}%` },
|
|
139
|
-
{ transform },
|
|
169
|
+
styleList,
|
|
140
170
|
width === 'auto' ? { opacity: opacity } : null,
|
|
141
171
|
style,
|
|
142
172
|
]}
|
package/src/TabBarItem.tsx
CHANGED
|
@@ -2,6 +2,7 @@ import * as React from 'react';
|
|
|
2
2
|
import {
|
|
3
3
|
Animated,
|
|
4
4
|
type LayoutChangeEvent,
|
|
5
|
+
Platform,
|
|
5
6
|
type PressableAndroidRippleConfig,
|
|
6
7
|
type StyleProp,
|
|
7
8
|
StyleSheet,
|
|
@@ -176,7 +177,7 @@ const TabBarItemInternal = <T extends Route>({
|
|
|
176
177
|
focused,
|
|
177
178
|
color: focused ? activeColor : inactiveColor,
|
|
178
179
|
style: labelStyle,
|
|
179
|
-
|
|
180
|
+
labelText,
|
|
180
181
|
allowFontScaling: labelAllowFontScaling,
|
|
181
182
|
route,
|
|
182
183
|
})
|
|
@@ -240,7 +241,7 @@ const TabBarItemInternal = <T extends Route>({
|
|
|
240
241
|
</Animated.View>
|
|
241
242
|
</View>
|
|
242
243
|
{customBadge != null ? (
|
|
243
|
-
<View style={styles.badge}>{customBadge()}</View>
|
|
244
|
+
<View style={styles.badge}>{customBadge({ route })}</View>
|
|
244
245
|
) : null}
|
|
245
246
|
</View>
|
|
246
247
|
</PlatformPressable>
|
|
@@ -295,5 +296,10 @@ const styles = StyleSheet.create({
|
|
|
295
296
|
// The label is not pressable on Windows
|
|
296
297
|
// Adding backgroundColor: 'transparent' seems to fix it
|
|
297
298
|
backgroundColor: 'transparent',
|
|
299
|
+
...Platform.select({
|
|
300
|
+
// Roundness for iPad hover effect
|
|
301
|
+
ios: { borderRadius: 10 },
|
|
302
|
+
default: null,
|
|
303
|
+
}),
|
|
298
304
|
},
|
|
299
305
|
});
|
package/src/types.tsx
CHANGED
|
@@ -3,27 +3,26 @@ import type { PagerViewProps } from 'react-native-pager-view';
|
|
|
3
3
|
|
|
4
4
|
export type TabDescriptor<T extends Route> = {
|
|
5
5
|
accessibilityLabel?: string;
|
|
6
|
-
labelStyle?: StyleProp<TextStyle>;
|
|
7
6
|
accessible?: boolean;
|
|
8
7
|
testID?: string;
|
|
9
8
|
labelText?: string;
|
|
10
9
|
labelAllowFontScaling?: boolean;
|
|
11
10
|
href?: string;
|
|
12
11
|
label?: (props: {
|
|
12
|
+
route: T;
|
|
13
|
+
labelText?: string;
|
|
13
14
|
focused: boolean;
|
|
14
15
|
color: string;
|
|
15
|
-
style?: StyleProp<TextStyle>;
|
|
16
16
|
allowFontScaling?: boolean;
|
|
17
|
-
|
|
18
|
-
route: T;
|
|
17
|
+
style?: StyleProp<TextStyle>;
|
|
19
18
|
}) => React.ReactElement;
|
|
20
19
|
icon?: (props: {
|
|
20
|
+
route: T;
|
|
21
21
|
focused: boolean;
|
|
22
22
|
color: string;
|
|
23
23
|
size: number;
|
|
24
|
-
route: T;
|
|
25
24
|
}) => React.ReactElement;
|
|
26
|
-
badge?: () => React.ReactElement;
|
|
25
|
+
badge?: (props: { route: T }) => React.ReactElement;
|
|
27
26
|
};
|
|
28
27
|
|
|
29
28
|
export type LocaleDirection = 'ltr' | 'rtl';
|