@momo-kits/tab-view 0.167.1-duotest.1 → 0.167.1-rc.2

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/assets/Path.tsx CHANGED
@@ -7,15 +7,14 @@ interface PathSvgProps extends ViewProps {
7
7
  }
8
8
 
9
9
  const PathSvg: FC<PathSvgProps> = ({style, pathWidth}) => {
10
- const width = pathWidth;
11
10
  const height = 44;
12
- const viewBox = `0 0 ${width} ${height}`;
13
11
 
14
12
  return (
15
13
  <Svg
16
- width={width}
14
+ width={pathWidth}
17
15
  height={height}
18
- viewBox={viewBox}
16
+ viewBox={`0 0 28 ${height}`}
17
+ preserveAspectRatio="none"
19
18
  fill="none"
20
19
  style={style}>
21
20
  <Path
package/index.tsx CHANGED
@@ -43,8 +43,7 @@ const TabComponent: ForwardRefRenderFunction<TabViewRef, TabViewProps> = (
43
43
  },
44
44
  ref,
45
45
  ) => {
46
- const startPage =
47
- initialPage > tabs.length - 1 ? tabs.length - 1 : initialPage;
46
+ const startPage = Math.min(initialPage, tabs.length - 1);
48
47
  const [selectedIndex, setSelectedIndex] = useState(startPage);
49
48
  const [tabBarWidth, setTabBarWidth] = useState(0);
50
49
  const isCardTab = type === 'card';
@@ -142,7 +141,7 @@ const TabComponent: ForwardRefRenderFunction<TabViewRef, TabViewProps> = (
142
141
  return (
143
142
  <View
144
143
  onLayout={onLayout}
145
- style={[styles.tabView, fitContent ? {} : { flex: 1 }]}
144
+ style={[styles.tabView, !fitContent && styles.flex1]}
146
145
  accessibilityLabel={componentId}
147
146
  >
148
147
  <Animated.View style={style}>
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
- "name": "@momo-kits/tab-view",
3
- "version": "0.167.1-duotest.1",
4
- "private": false,
5
- "main": "index.tsx",
6
- "peerDependencies": {
7
- "@momo-kits/foundation": "latest",
8
- "react": "*",
9
- "react-native": "*"
10
- },
11
- "license": "MoMo",
12
- "publishConfig": {
13
- "registry": "https://registry.npmjs.org/"
14
- },
15
- "dependencies": {}
16
- }
2
+ "name": "@momo-kits/tab-view",
3
+ "version": "0.167.1-rc.2",
4
+ "private": false,
5
+ "main": "index.tsx",
6
+ "peerDependencies": {
7
+ "@momo-kits/foundation": "latest",
8
+ "react": "*",
9
+ "react-native": "*"
10
+ },
11
+ "license": "MoMo",
12
+ "publishConfig": {
13
+ "registry": "https://registry.npmjs.org/"
14
+ },
15
+ "dependencies": {}
16
+ }
package/styles.ts CHANGED
@@ -93,4 +93,20 @@ export default StyleSheet.create({
93
93
  left: Spacing.S,
94
94
  zIndex: 2,
95
95
  },
96
+ flex1: { flex: 1 },
97
+ shrink: { flexShrink: 1 },
98
+ relative: { position: 'relative' },
99
+ relativeRow: { position: 'relative', flexDirection: 'row' },
100
+ tabItemRow: {
101
+ flexDirection: 'row',
102
+ overflow: 'hidden',
103
+ paddingVertical: Spacing.M,
104
+ paddingHorizontal: Spacing.M,
105
+ },
106
+ tabItemColumn: {
107
+ flexDirection: 'column',
108
+ overflow: 'hidden',
109
+ paddingHorizontal: Spacing.M,
110
+ paddingVertical: Spacing.M,
111
+ },
96
112
  });
@@ -31,6 +31,15 @@ const CardTabBar: FC<TabBarProps> = ({
31
31
  const pathWidth = tabs.length > 2 ? 22 : 28;
32
32
  const backSpace = isFirst ? 0 : pathWidth;
33
33
  const isWeb = Platform.OS === 'web';
34
+ const overlayLeft = itemWidth * selectedIndex;
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 };
34
43
 
35
44
  const renderIconTabBar = () => {
36
45
  return (
@@ -80,26 +89,10 @@ const CardTabBar: FC<TabBarProps> = ({
80
89
  Platform.OS === 'ios' && Shadow.Light,
81
90
  {
82
91
  width: containerWidth / tabs.length,
83
- left: isWeb
84
- ? itemWidth * selectedIndex
85
- : itemWidth * selectedIndex - backSpace,
92
+ left: isWeb ? overlayLeft : overlayLeft - backSpace,
86
93
  },
87
94
  ]}>
88
- {!isFirst && (
89
- <PathSvg
90
- style={
91
- isWeb
92
- ? {
93
- position: 'absolute',
94
- left: 8 - pathWidth,
95
- top: 0,
96
- transform: [{rotateY: '180deg'}],
97
- }
98
- : {transform: [{rotateY: '180deg'}], left: 8}
99
- }
100
- pathWidth={pathWidth}
101
- />
102
- )}
95
+ {!isFirst && <PathSvg style={leftPathStyle} pathWidth={pathWidth} />}
103
96
  <View
104
97
  accessibilityLabel={
105
98
  accessibilityLabelForSelectedCard ??
@@ -119,7 +112,7 @@ const CardTabBar: FC<TabBarProps> = ({
119
112
  <Text
120
113
  color={selectedColor}
121
114
  numberOfLines={1}
122
- style={[styles.textCenter, {flexShrink: 1}]}
115
+ style={[styles.textCenter, styles.shrink]}
123
116
  typography={'header_s_semibold'}>
124
117
  {tabs[selectedIndex]?.title || ''}
125
118
  </Text>
@@ -140,16 +133,7 @@ const CardTabBar: FC<TabBarProps> = ({
140
133
  </View>
141
134
  )}
142
135
  </View>
143
- {!isLast && (
144
- <PathSvg
145
- style={
146
- isWeb
147
- ? {position: 'absolute', right: 8 - pathWidth, top: 0}
148
- : {right: 8}
149
- }
150
- pathWidth={pathWidth}
151
- />
152
- )}
136
+ {!isLast && <PathSvg style={rightPathStyle} pathWidth={pathWidth} />}
153
137
  </View>
154
138
  </View>
155
139
  );
@@ -185,7 +185,7 @@ const ScrollableTabBar: FC<TabBarProps> = ({
185
185
  ref={scrollViewRef}
186
186
  horizontal
187
187
  showsHorizontalScrollIndicator={false}
188
- contentContainerStyle={{ position: 'relative' }}
188
+ contentContainerStyle={styles.relative}
189
189
  style={[
190
190
  styles.tabBar,
191
191
  {
@@ -197,7 +197,7 @@ const ScrollableTabBar: FC<TabBarProps> = ({
197
197
  <View
198
198
  ref={contentRef}
199
199
  collapsable={false}
200
- style={{ position: 'relative', flexDirection: 'row' }}
200
+ style={styles.relativeRow}
201
201
  >
202
202
  {tabs.map((item, index) => renderItem({ item, index }))}
203
203
  <Animated.View
@@ -5,13 +5,11 @@ import styles from '../styles';
5
5
  import {
6
6
  Badge,
7
7
  BadgeDot,
8
- Colors,
9
8
  Icon,
10
9
  MiniAppContext,
11
10
  ScreenContext,
12
11
  Spacing,
13
12
  Text,
14
- useScaleSize,
15
13
  } from '@momo-kits/foundation';
16
14
 
17
15
  const CardTabItem: FC<TabItemProps> = ({
@@ -87,7 +85,7 @@ const CardTabItem: FC<TabItemProps> = ({
87
85
  {renderIconTabItem()}
88
86
  <Text
89
87
  numberOfLines={1}
90
- style={[styles.textCenter, { flexShrink: 1 }]}
88
+ style={[styles.textCenter, styles.shrink]}
91
89
  typography={'body_default_regular'}
92
90
  accessibilityLabel={`${componentId}|text`}
93
91
  >
@@ -33,9 +33,10 @@ const TabItem: FC<TabItemProps> = ({
33
33
  accessibilityLabel,
34
34
  } = tab;
35
35
  const scaledHeight = useScaleSize(68);
36
- const typography: Typography = active
37
- ? 'header_s_semibold'
38
- : 'body_default_regular';
36
+ let typography: Typography = 'body_default_regular';
37
+ if (active) {
38
+ typography = 'header_s_semibold';
39
+ }
39
40
  const color = active ? selectedColor : unselectedColor;
40
41
  const dotStyle = dotSize === 'large' ? styles.dot : styles.dotSmall;
41
42
  const app = useContext<any>(MiniAppContext);
@@ -59,13 +60,10 @@ const TabItem: FC<TabItemProps> = ({
59
60
  accessibilityState={{ checked: active }}
60
61
  style={[
61
62
  styles.tabItem,
63
+ styles.tabItemRow,
62
64
  {
63
65
  width,
64
66
  height: size48,
65
- flexDirection: 'row',
66
- overflow: 'hidden',
67
- paddingVertical: Spacing.M,
68
- paddingHorizontal: Spacing.M,
69
67
  },
70
68
  ]}
71
69
  onPress={onPressTabItem}
@@ -88,7 +86,7 @@ const TabItem: FC<TabItemProps> = ({
88
86
  numberOfLines={1}
89
87
  typography={typography}
90
88
  color={color}
91
- style={{ flexShrink: 1 }}
89
+ style={styles.shrink}
92
90
  accessibilityLabel={`${componentId}|text`}
93
91
  >
94
92
  {title}
@@ -114,13 +112,10 @@ const TabItem: FC<TabItemProps> = ({
114
112
  <TouchableOpacity
115
113
  style={[
116
114
  styles.tabItem,
115
+ styles.tabItemColumn,
117
116
  {
118
117
  width,
119
118
  height: scaledHeight,
120
- flexDirection: 'column',
121
- overflow: 'hidden',
122
- paddingHorizontal: Spacing.M,
123
- paddingVertical: Spacing.M,
124
119
  },
125
120
  ]}
126
121
  onPress={onPressTabItem}