@momo-kits/tab-view 0.125.5-beta.1 → 0.150.1-beta.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/index.tsx +14 -58
- package/package.json +18 -19
- package/publish.sh +3 -12
- package/styles.ts +0 -1
- package/tabBar/CardTabBar.tsx +1 -0
- package/tabBar/SrollableTabBar.tsx +32 -29
- package/tabItem/CardTabItem.tsx +1 -1
- package/tabItem/TabItem.tsx +6 -6
- package/types.ts +0 -7
package/index.tsx
CHANGED
|
@@ -38,9 +38,8 @@ const TabComponent: ForwardRefRenderFunction<TabViewRef, TabViewProps> = (
|
|
|
38
38
|
style,
|
|
39
39
|
accessibilityLabel,
|
|
40
40
|
accessibilityLabelForSelectedCard,
|
|
41
|
-
autoHeight = false,
|
|
42
41
|
},
|
|
43
|
-
ref
|
|
42
|
+
ref,
|
|
44
43
|
) => {
|
|
45
44
|
const startPage =
|
|
46
45
|
initialPage > tabs.length - 1 ? tabs.length - 1 : initialPage;
|
|
@@ -49,8 +48,6 @@ const TabComponent: ForwardRefRenderFunction<TabViewRef, TabViewProps> = (
|
|
|
49
48
|
const isCardTab = type === 'card';
|
|
50
49
|
const pagerRef = useRef<PagerView>(null);
|
|
51
50
|
const scrollX = useRef(new Animated.Value(startPage));
|
|
52
|
-
const heightsRef = useRef<number[]>([]);
|
|
53
|
-
const animatedHeight = useRef(new Animated.Value(0)).current;
|
|
54
51
|
const lazy = useRef([selectedIndex]).current;
|
|
55
52
|
const {theme} = useContext(ApplicationContext);
|
|
56
53
|
const app = useContext<any>(MiniAppContext);
|
|
@@ -65,16 +62,6 @@ const TabComponent: ForwardRefRenderFunction<TabViewRef, TabViewProps> = (
|
|
|
65
62
|
return id;
|
|
66
63
|
}, [componentName, accessibilityLabel, app, screen]);
|
|
67
64
|
|
|
68
|
-
const selectedHeight = heightsRef.current[selectedIndex] || 0;
|
|
69
|
-
const hasMeasuredSelected = autoHeight && selectedHeight > 0;
|
|
70
|
-
|
|
71
|
-
const containerStyle = useMemo(() => {
|
|
72
|
-
if (hasMeasuredSelected) {
|
|
73
|
-
return [styles.tabView, {flex: 0}];
|
|
74
|
-
}
|
|
75
|
-
return styles.tabView;
|
|
76
|
-
}, [hasMeasuredSelected]);
|
|
77
|
-
|
|
78
65
|
const _onPressTabItem = (index: number) => {
|
|
79
66
|
onPressTabItem?.(index);
|
|
80
67
|
pagerRef.current?.setPage(index);
|
|
@@ -95,10 +82,6 @@ const TabComponent: ForwardRefRenderFunction<TabViewRef, TabViewProps> = (
|
|
|
95
82
|
lazy.push(position);
|
|
96
83
|
}
|
|
97
84
|
setSelectedIndex(position);
|
|
98
|
-
if (autoHeight) {
|
|
99
|
-
const h = heightsRef.current[position];
|
|
100
|
-
animatedHeight.setValue(h);
|
|
101
|
-
}
|
|
102
85
|
pagerProps?.onPageSelected?.(e);
|
|
103
86
|
};
|
|
104
87
|
|
|
@@ -111,33 +94,15 @@ const TabComponent: ForwardRefRenderFunction<TabViewRef, TabViewProps> = (
|
|
|
111
94
|
const onPageScroll = (e: PagerViewOnPageScrollEvent) => {
|
|
112
95
|
const {position, offset} = e.nativeEvent;
|
|
113
96
|
scrollX.current.setValue(position + offset);
|
|
114
|
-
if (autoHeight) {
|
|
115
|
-
const current = heightsRef.current[position] ?? 0;
|
|
116
|
-
const rawNext = heightsRef.current[position + 1];
|
|
117
|
-
const next =
|
|
118
|
-
typeof rawNext === 'number' && rawNext > 0 ? rawNext : current;
|
|
119
|
-
const value = current + (next - current) * offset;
|
|
120
|
-
animatedHeight.setValue(value);
|
|
121
|
-
}
|
|
122
97
|
pagerProps?.onPageScroll?.(e);
|
|
123
98
|
};
|
|
124
99
|
|
|
125
|
-
const onLayoutPage = (index: number) => (e: LayoutChangeEvent) => {
|
|
126
|
-
const height = e.nativeEvent.layout.height;
|
|
127
|
-
heightsRef.current[index] = height;
|
|
128
|
-
if (autoHeight) {
|
|
129
|
-
if (index === selectedIndex) {
|
|
130
|
-
animatedHeight.setValue(height);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
|
|
135
100
|
const renderScreen = useCallback(
|
|
136
101
|
(tab: Tab, index: number) => {
|
|
137
|
-
if (!lazy.includes(index)) return <View />;
|
|
138
|
-
return <View
|
|
102
|
+
if (!lazy.includes(index)) return <View key={`TabView-page-${index}`} />;
|
|
103
|
+
return <View key={`TabView-page-${index}`}>{tab.component}</View>;
|
|
139
104
|
},
|
|
140
|
-
[
|
|
105
|
+
[lazy],
|
|
141
106
|
);
|
|
142
107
|
|
|
143
108
|
useImperativeHandle(ref, () => ({
|
|
@@ -149,7 +114,7 @@ const TabComponent: ForwardRefRenderFunction<TabViewRef, TabViewProps> = (
|
|
|
149
114
|
return (
|
|
150
115
|
<View
|
|
151
116
|
onLayout={onLayout}
|
|
152
|
-
style={
|
|
117
|
+
style={[styles.tabView, {flex: 1}]}
|
|
153
118
|
accessibilityLabel={componentId}>
|
|
154
119
|
<Animated.View style={style}>
|
|
155
120
|
<TabBarComponent
|
|
@@ -165,24 +130,15 @@ const TabComponent: ForwardRefRenderFunction<TabViewRef, TabViewProps> = (
|
|
|
165
130
|
/>
|
|
166
131
|
</Animated.View>
|
|
167
132
|
|
|
168
|
-
<
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
{...pagerProps}
|
|
178
|
-
onPageScroll={onPageScroll}
|
|
179
|
-
ref={pagerRef}
|
|
180
|
-
onPageSelected={onPageSelected}
|
|
181
|
-
style={styles.pagerView}
|
|
182
|
-
initialPage={startPage}>
|
|
183
|
-
{tabs.map((tab, index) => renderScreen(tab, index))}
|
|
184
|
-
</PagerView>
|
|
185
|
-
</Animated.View>
|
|
133
|
+
<PagerView
|
|
134
|
+
{...pagerProps}
|
|
135
|
+
onPageScroll={onPageScroll}
|
|
136
|
+
ref={pagerRef}
|
|
137
|
+
onPageSelected={onPageSelected}
|
|
138
|
+
style={styles.pagerView}
|
|
139
|
+
initialPage={startPage}>
|
|
140
|
+
{tabs.map((tab, index) => renderScreen(tab, index))}
|
|
141
|
+
</PagerView>
|
|
186
142
|
</View>
|
|
187
143
|
);
|
|
188
144
|
};
|
package/package.json
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
}
|
|
2
|
+
"name": "@momo-kits/tab-view",
|
|
3
|
+
"version": "0.150.1-beta.2",
|
|
4
|
+
"private": false,
|
|
5
|
+
"main": "index.tsx",
|
|
6
|
+
"peerDependencies": {
|
|
7
|
+
"@momo-kits/foundation": "latest",
|
|
8
|
+
"react": "*",
|
|
9
|
+
"react-native": "*"
|
|
10
|
+
},
|
|
11
|
+
"devDependencies": {
|
|
12
|
+
"@momo-platform/versions": "4.1.11"
|
|
13
|
+
},
|
|
14
|
+
"license": "MoMo",
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"registry": "https://registry.npmjs.org/"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {}
|
|
19
|
+
}
|
package/publish.sh
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
#!/bin/bash
|
|
2
2
|
|
|
3
|
-
# Prepare dist files
|
|
4
|
-
rm -rf dist
|
|
5
|
-
mkdir dist
|
|
6
|
-
rsync -r --exclude=/dist ./* dist
|
|
7
|
-
cd dist
|
|
8
|
-
|
|
9
|
-
|
|
10
3
|
if [ "$1" == "stable" ]; then
|
|
11
4
|
npm version $(npm view @momo-kits/foundation@stable version)
|
|
12
5
|
npm version patch
|
|
@@ -14,15 +7,13 @@ if [ "$1" == "stable" ]; then
|
|
|
14
7
|
elif [ "$1" == "latest" ]; then
|
|
15
8
|
npm version $(npm view @momo-kits/foundation@latest version)
|
|
16
9
|
npm publish --tag latest --access=public
|
|
17
|
-
|
|
10
|
+
elif [ "$1" == "beta" ]; then
|
|
18
11
|
npm version $(npm view @momo-kits/tab-view@beta version)
|
|
19
12
|
npm version prerelease --preid=beta
|
|
20
13
|
npm publish --tag beta --access=public
|
|
14
|
+
else
|
|
15
|
+
npm publish --tag alpha --access=public
|
|
21
16
|
fi
|
|
22
17
|
|
|
23
18
|
PACKAGE_NAME=$(npm pkg get name)
|
|
24
19
|
NEW_PACKAGE_VERSION=$(npm pkg get version)
|
|
25
|
-
|
|
26
|
-
# Clean up
|
|
27
|
-
cd ..
|
|
28
|
-
rm -rf dist
|
package/styles.ts
CHANGED
package/tabBar/CardTabBar.tsx
CHANGED
|
@@ -6,10 +6,10 @@ import React, {
|
|
|
6
6
|
useState,
|
|
7
7
|
useCallback,
|
|
8
8
|
} from 'react';
|
|
9
|
-
import {Animated, LayoutChangeEvent, ScrollView, View} from 'react-native';
|
|
10
|
-
import {Tab, TabBarProps} from '../types';
|
|
9
|
+
import { Animated, LayoutChangeEvent, ScrollView, View } from 'react-native';
|
|
10
|
+
import { Tab, TabBarProps } from '../types';
|
|
11
11
|
import styles from '../styles';
|
|
12
|
-
import {ApplicationContext} from '@momo-kits/foundation';
|
|
12
|
+
import { ApplicationContext } from '@momo-kits/foundation';
|
|
13
13
|
import TabItem from '../tabItem/TabItem';
|
|
14
14
|
|
|
15
15
|
const ScrollableTabBar: FC<TabBarProps> = ({
|
|
@@ -20,9 +20,9 @@ const ScrollableTabBar: FC<TabBarProps> = ({
|
|
|
20
20
|
unselectedColor,
|
|
21
21
|
direction,
|
|
22
22
|
}) => {
|
|
23
|
-
const {theme} = useContext(ApplicationContext);
|
|
23
|
+
const { theme } = useContext(ApplicationContext);
|
|
24
24
|
const [itemWidthMap, setItemWidthMap] = useState<
|
|
25
|
-
{width: number; x: number}[]
|
|
25
|
+
{ width: number; x: number }[]
|
|
26
26
|
>([]);
|
|
27
27
|
const animatedWidth = useRef(new Animated.Value(0)).current;
|
|
28
28
|
const animX = useRef(new Animated.Value(0)).current;
|
|
@@ -34,7 +34,7 @@ const ScrollableTabBar: FC<TabBarProps> = ({
|
|
|
34
34
|
const setMeasured = useCallback((index: number, width: number, x: number) => {
|
|
35
35
|
setItemWidthMap(prev => {
|
|
36
36
|
const next = prev.slice();
|
|
37
|
-
next[index] = {width, x};
|
|
37
|
+
next[index] = { width, x };
|
|
38
38
|
return next;
|
|
39
39
|
});
|
|
40
40
|
}, []);
|
|
@@ -59,27 +59,27 @@ const ScrollableTabBar: FC<TabBarProps> = ({
|
|
|
59
59
|
_y: number,
|
|
60
60
|
w: number,
|
|
61
61
|
_h: number,
|
|
62
|
-
pageX: number
|
|
62
|
+
pageX: number,
|
|
63
63
|
) => {
|
|
64
64
|
container?.measure?.(
|
|
65
65
|
(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
cPageX: number
|
|
66
|
+
_cx: number,
|
|
67
|
+
_cy: number,
|
|
68
|
+
_cw: number,
|
|
69
|
+
_ch: number,
|
|
70
|
+
cPageX: number,
|
|
71
71
|
) => {
|
|
72
72
|
setMeasured(index, w, pageX - cPageX);
|
|
73
73
|
done?.();
|
|
74
|
-
}
|
|
74
|
+
},
|
|
75
75
|
);
|
|
76
|
-
}
|
|
76
|
+
},
|
|
77
77
|
);
|
|
78
|
-
}
|
|
78
|
+
},
|
|
79
79
|
);
|
|
80
80
|
}
|
|
81
81
|
},
|
|
82
|
-
[setMeasured]
|
|
82
|
+
[setMeasured],
|
|
83
83
|
);
|
|
84
84
|
|
|
85
85
|
const ensureMeasured = useCallback(
|
|
@@ -90,7 +90,7 @@ const ScrollableTabBar: FC<TabBarProps> = ({
|
|
|
90
90
|
}
|
|
91
91
|
measureIndex(index, callback);
|
|
92
92
|
},
|
|
93
|
-
[itemWidthMap, measureIndex]
|
|
93
|
+
[itemWidthMap, measureIndex],
|
|
94
94
|
);
|
|
95
95
|
|
|
96
96
|
const moveIndicator = useCallback(() => {
|
|
@@ -112,10 +112,10 @@ const ScrollableTabBar: FC<TabBarProps> = ({
|
|
|
112
112
|
|
|
113
113
|
const onLayout = useCallback(
|
|
114
114
|
(e: LayoutChangeEvent, index: number) => {
|
|
115
|
-
const {width, x} = e.nativeEvent.layout;
|
|
115
|
+
const { width, x } = e.nativeEvent.layout;
|
|
116
116
|
if (width != null && x != null) setMeasured(index, width, x);
|
|
117
117
|
},
|
|
118
|
-
[setMeasured]
|
|
118
|
+
[setMeasured],
|
|
119
119
|
);
|
|
120
120
|
|
|
121
121
|
const scrollToIndex = useCallback(
|
|
@@ -123,9 +123,9 @@ const ScrollableTabBar: FC<TabBarProps> = ({
|
|
|
123
123
|
const targetIndex = Math.max(0, index - 1);
|
|
124
124
|
const pos = itemWidthMap[targetIndex];
|
|
125
125
|
if (!pos) return;
|
|
126
|
-
scrollViewRef.current?.scrollTo({x: pos.x, animated: true});
|
|
126
|
+
scrollViewRef.current?.scrollTo({ x: pos.x, animated: true });
|
|
127
127
|
},
|
|
128
|
-
[itemWidthMap]
|
|
128
|
+
[itemWidthMap],
|
|
129
129
|
);
|
|
130
130
|
|
|
131
131
|
const _onPressTabItem = useCallback(
|
|
@@ -135,7 +135,7 @@ const ScrollableTabBar: FC<TabBarProps> = ({
|
|
|
135
135
|
onPressTabItem?.(index);
|
|
136
136
|
});
|
|
137
137
|
},
|
|
138
|
-
[ensureMeasured, scrollToIndex, onPressTabItem]
|
|
138
|
+
[ensureMeasured, scrollToIndex, onPressTabItem],
|
|
139
139
|
);
|
|
140
140
|
|
|
141
141
|
useEffect(() => {
|
|
@@ -152,8 +152,8 @@ const ScrollableTabBar: FC<TabBarProps> = ({
|
|
|
152
152
|
});
|
|
153
153
|
}, [selectedIndex, ensureMeasured, moveIndicator, scrollToIndex]);
|
|
154
154
|
|
|
155
|
-
const renderItem = (params: {item: Tab; index: number}) => {
|
|
156
|
-
const {item, index} = params;
|
|
155
|
+
const renderItem = (params: { item: Tab; index: number }) => {
|
|
156
|
+
const { item, index } = params;
|
|
157
157
|
const isActive = selectedIndex === index;
|
|
158
158
|
|
|
159
159
|
return (
|
|
@@ -162,7 +162,8 @@ const ScrollableTabBar: FC<TabBarProps> = ({
|
|
|
162
162
|
ref={el => (itemRefs.current[index] = el)}
|
|
163
163
|
collapsable={false}
|
|
164
164
|
onLayout={e => onLayout(e, index)}
|
|
165
|
-
style={styles.tabItemWrapper}
|
|
165
|
+
style={styles.tabItemWrapper}
|
|
166
|
+
>
|
|
166
167
|
<TabItem
|
|
167
168
|
key={`Tab View Item ${item.title}-${index}`}
|
|
168
169
|
onPressTabItem={() => {
|
|
@@ -183,19 +184,21 @@ const ScrollableTabBar: FC<TabBarProps> = ({
|
|
|
183
184
|
ref={scrollViewRef}
|
|
184
185
|
horizontal
|
|
185
186
|
showsHorizontalScrollIndicator={false}
|
|
186
|
-
contentContainerStyle={{position: 'relative'}}
|
|
187
|
+
contentContainerStyle={{ position: 'relative' }}
|
|
187
188
|
style={[
|
|
188
189
|
styles.tabBar,
|
|
189
190
|
{
|
|
190
191
|
borderColor: theme.colors.border.default,
|
|
191
192
|
backgroundColor: theme.colors.background.surface,
|
|
192
193
|
},
|
|
193
|
-
]}
|
|
194
|
+
]}
|
|
195
|
+
>
|
|
194
196
|
<View
|
|
195
197
|
ref={contentRef}
|
|
196
198
|
collapsable={false}
|
|
197
|
-
style={{position: 'relative', flexDirection: 'row'}}
|
|
198
|
-
|
|
199
|
+
style={{ position: 'relative', flexDirection: 'row' }}
|
|
200
|
+
>
|
|
201
|
+
{tabs.map((item, index) => renderItem({ item, index }))}
|
|
199
202
|
<Animated.View
|
|
200
203
|
style={[
|
|
201
204
|
styles.indicator,
|
package/tabItem/CardTabItem.tsx
CHANGED
|
@@ -42,7 +42,7 @@ const CardTabItem: FC<TabItemProps> = ({
|
|
|
42
42
|
}
|
|
43
43
|
let id = `${app.appId}/${app.code}/${screen.screenName}/${componentName}/${title}`;
|
|
44
44
|
return id;
|
|
45
|
-
}, [
|
|
45
|
+
}, [accessibilityLabel, app.appId, app.code, screen.screenName, title]);
|
|
46
46
|
|
|
47
47
|
const renderIconTabItem = () => {
|
|
48
48
|
return (
|
package/tabItem/TabItem.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import React, {FC, useContext, useMemo} from 'react';
|
|
2
|
-
import {TouchableOpacity, View} from 'react-native';
|
|
3
|
-
import {TabItemProps} from '../types';
|
|
1
|
+
import React, { FC, useContext, useMemo } from 'react';
|
|
2
|
+
import { TouchableOpacity, View } from 'react-native';
|
|
3
|
+
import { TabItemProps } from '../types';
|
|
4
4
|
import {
|
|
5
5
|
Badge,
|
|
6
6
|
BadgeDot,
|
|
@@ -46,9 +46,9 @@ const TabItem: FC<TabItemProps> = ({
|
|
|
46
46
|
if (accessibilityLabel) {
|
|
47
47
|
return accessibilityLabel;
|
|
48
48
|
}
|
|
49
|
-
|
|
50
|
-
return
|
|
51
|
-
}, [
|
|
49
|
+
|
|
50
|
+
return `${app.appId}/${app.code}/${screen.screenName}/${componentName}/${title}`;
|
|
51
|
+
}, [accessibilityLabel, app.appId, app.code, screen.screenName, title]);
|
|
52
52
|
|
|
53
53
|
const renderRowItem = () => {
|
|
54
54
|
return (
|
package/types.ts
CHANGED
|
@@ -111,13 +111,6 @@ export type TabViewProps = {
|
|
|
111
111
|
accessibilityLabel?: string;
|
|
112
112
|
|
|
113
113
|
accessibilityLabelForSelectedCard?: string;
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Optional. If `true`, automatically adjusts the height of the pager to match
|
|
117
|
-
* the currently visible tab's content height. When swiping between tabs, the
|
|
118
|
-
* height smoothly interpolates between the two pages' heights.
|
|
119
|
-
*/
|
|
120
|
-
autoHeight?: boolean;
|
|
121
114
|
};
|
|
122
115
|
|
|
123
116
|
/**
|