@momo-kits/tab-view 0.169.4-beta.3 → 0.169.4
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/package.json +1 -1
- package/styles.ts +0 -11
- package/tabBar/CardTabBar.tsx +15 -24
- package/tabBar/SrollableTabBar.tsx +14 -32
- package/tabBar/TabBar.tsx +2 -14
- package/tabItem/CardTabItem.tsx +7 -6
- package/types.ts +2 -2
package/package.json
CHANGED
package/styles.ts
CHANGED
|
@@ -68,18 +68,7 @@ export default StyleSheet.create({
|
|
|
68
68
|
borderTopLeftRadius: Spacing.M,
|
|
69
69
|
borderTopRightRadius: Spacing.M,
|
|
70
70
|
},
|
|
71
|
-
leftPath: {
|
|
72
|
-
position: 'absolute',
|
|
73
|
-
top: 0,
|
|
74
|
-
right: '100%',
|
|
75
|
-
},
|
|
76
|
-
rightPath: {
|
|
77
|
-
position: 'absolute',
|
|
78
|
-
top: 0,
|
|
79
|
-
left: '100%',
|
|
80
|
-
},
|
|
81
71
|
overlayTextWrapper: {
|
|
82
|
-
width: '100%',
|
|
83
72
|
height: '100%',
|
|
84
73
|
alignItems: 'center',
|
|
85
74
|
justifyContent: 'center',
|
package/tabBar/CardTabBar.tsx
CHANGED
|
@@ -15,15 +15,6 @@ import {
|
|
|
15
15
|
import CardTabItem from '../tabItem/CardTabItem';
|
|
16
16
|
import PathSvg from '../assets/Path';
|
|
17
17
|
|
|
18
|
-
type PercentValue = `${number}%`;
|
|
19
|
-
|
|
20
|
-
/** Mirrors the curve drawn for the right side so it fits the left side. */
|
|
21
|
-
const FLIP = { rotateY: '180deg' } as const;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Card-style tab bar with a raised selected card; widths are percentages and only the
|
|
25
|
-
* left offset is measured, because measured lengths are already scaled.
|
|
26
|
-
*/
|
|
27
18
|
const CardTabBar: FC<TabBarProps> = ({
|
|
28
19
|
tabs,
|
|
29
20
|
onPressTabItem,
|
|
@@ -35,21 +26,20 @@ const CardTabBar: FC<TabBarProps> = ({
|
|
|
35
26
|
}) => {
|
|
36
27
|
const {theme} = useContext(ApplicationContext);
|
|
37
28
|
const itemWidth = containerWidth / tabs.length;
|
|
38
|
-
const itemPercent: `${number}%` = `${100 / tabs.length}%`;
|
|
39
29
|
const isFirst = selectedIndex === 0;
|
|
40
30
|
const isLast = selectedIndex === tabs.length - 1;
|
|
41
31
|
const pathWidth = tabs.length > 2 ? 22 : 28;
|
|
32
|
+
const backSpace = isFirst ? 0 : pathWidth;
|
|
33
|
+
const isWeb = Platform.OS === 'web';
|
|
42
34
|
const overlayLeft = itemWidth * selectedIndex;
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
const leftPathStyle =
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
{ transform: [{ translateX: `${-pathShift}%` as PercentValue }] },
|
|
52
|
-
];
|
|
35
|
+
const pathInset = isWeb ? 8 - pathWidth : 8;
|
|
36
|
+
const pathPosition = isWeb ? { position: 'absolute' as const, top: 0 } : {};
|
|
37
|
+
const leftPathStyle = {
|
|
38
|
+
...pathPosition,
|
|
39
|
+
left: pathInset,
|
|
40
|
+
transform: [{ rotateY: '180deg' }],
|
|
41
|
+
};
|
|
42
|
+
const rightPathStyle = { ...pathPosition, right: pathInset };
|
|
53
43
|
|
|
54
44
|
const renderIconTabBar = () => {
|
|
55
45
|
return (
|
|
@@ -87,7 +77,7 @@ const CardTabBar: FC<TabBarProps> = ({
|
|
|
87
77
|
onPressTabItem={() => {
|
|
88
78
|
onPressTabItem?.(index);
|
|
89
79
|
}}
|
|
90
|
-
width={
|
|
80
|
+
width={itemWidth}
|
|
91
81
|
selectedColor={selectedColor}
|
|
92
82
|
unselectedColor={unselectedColor}
|
|
93
83
|
/>
|
|
@@ -98,12 +88,11 @@ const CardTabBar: FC<TabBarProps> = ({
|
|
|
98
88
|
styles.cardTabOverlay,
|
|
99
89
|
Platform.OS === 'ios' && Shadow.Light,
|
|
100
90
|
{
|
|
101
|
-
width:
|
|
102
|
-
left: overlayLeft,
|
|
91
|
+
width: containerWidth / tabs.length,
|
|
92
|
+
left: isWeb ? overlayLeft : overlayLeft - backSpace,
|
|
103
93
|
},
|
|
104
94
|
]}>
|
|
105
95
|
{!isFirst && <PathSvg style={leftPathStyle} pathWidth={pathWidth} />}
|
|
106
|
-
{!isLast && <PathSvg style={rightPathStyle} pathWidth={pathWidth} />}
|
|
107
96
|
<View
|
|
108
97
|
accessibilityLabel={
|
|
109
98
|
accessibilityLabelForSelectedCard ??
|
|
@@ -113,6 +102,7 @@ const CardTabBar: FC<TabBarProps> = ({
|
|
|
113
102
|
styles.overlayTextWrapper,
|
|
114
103
|
{
|
|
115
104
|
backgroundColor: theme.colors.background.surface,
|
|
105
|
+
width: containerWidth / tabs.length,
|
|
116
106
|
borderTopRightRadius: Radius.M,
|
|
117
107
|
borderTopLeftRadius: Radius.M,
|
|
118
108
|
paddingHorizontal: tabs.length === 3 ? Spacing.S : Spacing.M,
|
|
@@ -143,6 +133,7 @@ const CardTabBar: FC<TabBarProps> = ({
|
|
|
143
133
|
</View>
|
|
144
134
|
)}
|
|
145
135
|
</View>
|
|
136
|
+
{!isLast && <PathSvg style={rightPathStyle} pathWidth={pathWidth} />}
|
|
146
137
|
</View>
|
|
147
138
|
</View>
|
|
148
139
|
);
|
|
@@ -13,10 +13,6 @@ import styles from '../styles';
|
|
|
13
13
|
import { ApplicationContext } from '@momo-kits/foundation';
|
|
14
14
|
import TabItem from '../tabItem/TabItem';
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
* Scrollable tab bar; the indicator is placed with left/right because measured lengths
|
|
18
|
-
* are already scaled and `width` would scale them again.
|
|
19
|
-
*/
|
|
20
16
|
const ScrollableTabBar: FC<TabBarProps> = ({
|
|
21
17
|
tabs = [],
|
|
22
18
|
onPressTabItem,
|
|
@@ -29,8 +25,7 @@ const ScrollableTabBar: FC<TabBarProps> = ({
|
|
|
29
25
|
const [itemWidthMap, setItemWidthMap] = useState<
|
|
30
26
|
{ width: number; x: number }[]
|
|
31
27
|
>([]);
|
|
32
|
-
const
|
|
33
|
-
const animRight = useRef(new Animated.Value(0)).current;
|
|
28
|
+
const animatedWidth = useRef(new Animated.Value(0)).current;
|
|
34
29
|
const animX = useRef(new Animated.Value(0)).current;
|
|
35
30
|
|
|
36
31
|
const scrollViewRef = useRef<ScrollView>(null);
|
|
@@ -100,12 +95,11 @@ const ScrollableTabBar: FC<TabBarProps> = ({
|
|
|
100
95
|
);
|
|
101
96
|
|
|
102
97
|
const moveIndicator = useCallback(() => {
|
|
103
|
-
if (contentWidth === 0) return;
|
|
104
98
|
const w = itemWidthMap[selectedIndex]?.width ?? 0;
|
|
105
99
|
const x = itemWidthMap[selectedIndex]?.x ?? 0;
|
|
106
100
|
Animated.parallel([
|
|
107
|
-
Animated.timing(
|
|
108
|
-
toValue:
|
|
101
|
+
Animated.timing(animatedWidth, {
|
|
102
|
+
toValue: w,
|
|
109
103
|
duration: 250,
|
|
110
104
|
useNativeDriver: false,
|
|
111
105
|
}),
|
|
@@ -115,7 +109,7 @@ const ScrollableTabBar: FC<TabBarProps> = ({
|
|
|
115
109
|
useNativeDriver: false,
|
|
116
110
|
}),
|
|
117
111
|
]).start();
|
|
118
|
-
}, [
|
|
112
|
+
}, [animatedWidth, animX, itemWidthMap, selectedIndex]);
|
|
119
113
|
|
|
120
114
|
const onLayout = useCallback(
|
|
121
115
|
(e: LayoutChangeEvent, index: number) => {
|
|
@@ -125,15 +119,6 @@ const ScrollableTabBar: FC<TabBarProps> = ({
|
|
|
125
119
|
[setMeasured],
|
|
126
120
|
);
|
|
127
121
|
|
|
128
|
-
const handleContentLayout = useCallback(
|
|
129
|
-
(e: LayoutChangeEvent) => {
|
|
130
|
-
const { width } = e.nativeEvent.layout;
|
|
131
|
-
if (contentWidth === 0) animRight.setValue(width);
|
|
132
|
-
setContentWidth(width);
|
|
133
|
-
},
|
|
134
|
-
[animRight, contentWidth],
|
|
135
|
-
);
|
|
136
|
-
|
|
137
122
|
const scrollToIndex = useCallback(
|
|
138
123
|
(index: number) => {
|
|
139
124
|
const targetIndex = Math.max(0, index - 1);
|
|
@@ -213,21 +198,18 @@ const ScrollableTabBar: FC<TabBarProps> = ({
|
|
|
213
198
|
ref={contentRef}
|
|
214
199
|
collapsable={false}
|
|
215
200
|
style={styles.relativeRow}
|
|
216
|
-
onLayout={handleContentLayout}
|
|
217
201
|
>
|
|
218
202
|
{tabs.map((item, index) => renderItem({ item, index }))}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
/>
|
|
230
|
-
)}
|
|
203
|
+
<Animated.View
|
|
204
|
+
style={[
|
|
205
|
+
styles.indicator,
|
|
206
|
+
{
|
|
207
|
+
left: animX,
|
|
208
|
+
width: animatedWidth,
|
|
209
|
+
backgroundColor: selectedColor,
|
|
210
|
+
},
|
|
211
|
+
]}
|
|
212
|
+
/>
|
|
231
213
|
</View>
|
|
232
214
|
</ScrollView>
|
|
233
215
|
);
|
package/tabBar/TabBar.tsx
CHANGED
|
@@ -5,10 +5,6 @@ import TabItem from '../tabItem/TabItem';
|
|
|
5
5
|
import styles from '../styles';
|
|
6
6
|
import {ApplicationContext, Spacing} from '@momo-kits/foundation';
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* Fixed-width tab bar; widths are percentages and the indicator uses left/right because
|
|
10
|
-
* measured lengths are already scaled and `width` would scale them again.
|
|
11
|
-
*/
|
|
12
8
|
const TabBar: FC<TabBarProps> = ({
|
|
13
9
|
tabs = [],
|
|
14
10
|
selectedIndex,
|
|
@@ -21,7 +17,6 @@ const TabBar: FC<TabBarProps> = ({
|
|
|
21
17
|
}) => {
|
|
22
18
|
const {theme} = useContext(ApplicationContext);
|
|
23
19
|
const itemWidth = containerWidth / tabs.length;
|
|
24
|
-
const itemPercent: `${number}%` = `${100 / tabs.length}%`;
|
|
25
20
|
|
|
26
21
|
return (
|
|
27
22
|
<View
|
|
@@ -36,7 +31,7 @@ const TabBar: FC<TabBarProps> = ({
|
|
|
36
31
|
return (
|
|
37
32
|
<TabItem
|
|
38
33
|
key={`Tab View Item ${tab.title}-${index}`}
|
|
39
|
-
width={
|
|
34
|
+
width={itemWidth}
|
|
40
35
|
onPressTabItem={() => {
|
|
41
36
|
onPressTabItem?.(index);
|
|
42
37
|
}}
|
|
@@ -60,14 +55,7 @@ const TabBar: FC<TabBarProps> = ({
|
|
|
60
55
|
],
|
|
61
56
|
extrapolate: 'clamp',
|
|
62
57
|
}),
|
|
63
|
-
|
|
64
|
-
inputRange: [0, tabs.length - 1],
|
|
65
|
-
outputRange: [
|
|
66
|
-
(tabs.length - 1) * itemWidth + Spacing.XS,
|
|
67
|
-
Spacing.XS,
|
|
68
|
-
],
|
|
69
|
-
extrapolate: 'clamp',
|
|
70
|
-
}),
|
|
58
|
+
width: itemWidth - Spacing.XS * 2,
|
|
71
59
|
backgroundColor: selectedColor,
|
|
72
60
|
},
|
|
73
61
|
]}
|
package/tabItem/CardTabItem.tsx
CHANGED
|
@@ -12,10 +12,6 @@ import {
|
|
|
12
12
|
Text,
|
|
13
13
|
} from '@momo-kits/foundation';
|
|
14
14
|
|
|
15
|
-
/**
|
|
16
|
-
* Card-style tab item; `width` sits on the wrapper because a percentage only resolves
|
|
17
|
-
* on a direct child of the row.
|
|
18
|
-
*/
|
|
19
15
|
const CardTabItem: FC<TabItemProps> = ({
|
|
20
16
|
tab,
|
|
21
17
|
active,
|
|
@@ -74,10 +70,15 @@ const CardTabItem: FC<TabItemProps> = ({
|
|
|
74
70
|
};
|
|
75
71
|
|
|
76
72
|
return (
|
|
77
|
-
<View style={
|
|
73
|
+
<View style={styles.cardTabItemWrapper}>
|
|
78
74
|
<TouchableOpacity
|
|
79
75
|
onPress={onPressTabItem}
|
|
80
|
-
style={
|
|
76
|
+
style={[
|
|
77
|
+
styles.cardTabItem,
|
|
78
|
+
{
|
|
79
|
+
width,
|
|
80
|
+
},
|
|
81
|
+
]}
|
|
81
82
|
accessibilityLabel={componentId}
|
|
82
83
|
accessibilityState={{ checked: active }}
|
|
83
84
|
>
|
package/types.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {ReactElement} from 'react';
|
|
2
2
|
import {PagerViewProps} from 'react-native-pager-view';
|
|
3
|
-
import {Animated,
|
|
3
|
+
import {Animated, ViewStyle} from 'react-native';
|
|
4
4
|
|
|
5
5
|
export type Tab = {
|
|
6
6
|
/**
|
|
@@ -54,7 +54,7 @@ export type TabItemProps = {
|
|
|
54
54
|
/**
|
|
55
55
|
* Optional. Specifies the width of the tab item. Useful for customizing layout and appearance.
|
|
56
56
|
*/
|
|
57
|
-
width?:
|
|
57
|
+
width?: number;
|
|
58
58
|
|
|
59
59
|
/**
|
|
60
60
|
* Optional. Specifies the layout direction for the tab's content, either in a row or column format.
|