@momo-kits/tab-view 0.103.2-rc.8 → 0.104.1
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 +37 -8
- package/package.json +18 -15
- package/publish.sh +1 -0
- package/tabBar/CardTabBar.tsx +5 -1
- package/tabItem/CardTabItem.tsx +38 -12
- package/tabItem/TabItem.tsx +36 -7
- package/types.ts +10 -2
package/index.tsx
CHANGED
|
@@ -4,6 +4,7 @@ import React, {
|
|
|
4
4
|
useCallback,
|
|
5
5
|
useContext,
|
|
6
6
|
useImperativeHandle,
|
|
7
|
+
useMemo,
|
|
7
8
|
useRef,
|
|
8
9
|
useState,
|
|
9
10
|
} from 'react';
|
|
@@ -13,8 +14,15 @@ import TabBar from './tabBar/TabBar';
|
|
|
13
14
|
import styles from './styles';
|
|
14
15
|
import CardTabBar from './tabBar/CardTabBar';
|
|
15
16
|
import ScrollableTabBar from './tabBar/SrollableTabBar';
|
|
16
|
-
import PagerView
|
|
17
|
-
|
|
17
|
+
import PagerView, {
|
|
18
|
+
PagerViewOnPageScrollEvent,
|
|
19
|
+
PagerViewOnPageSelectedEvent,
|
|
20
|
+
} from 'react-native-pager-view';
|
|
21
|
+
import {
|
|
22
|
+
ApplicationContext,
|
|
23
|
+
MiniAppContext,
|
|
24
|
+
ScreenContext,
|
|
25
|
+
} from '@momo-kits/foundation';
|
|
18
26
|
|
|
19
27
|
const TabComponent: ForwardRefRenderFunction<TabViewRef, TabViewProps> = (
|
|
20
28
|
{
|
|
@@ -27,6 +35,9 @@ const TabComponent: ForwardRefRenderFunction<TabViewRef, TabViewProps> = (
|
|
|
27
35
|
direction,
|
|
28
36
|
selectedColor,
|
|
29
37
|
unselectedColor,
|
|
38
|
+
style,
|
|
39
|
+
accessibilityLabel,
|
|
40
|
+
accessibilityLabelForSelectedCard,
|
|
30
41
|
},
|
|
31
42
|
ref
|
|
32
43
|
) => {
|
|
@@ -39,6 +50,18 @@ const TabComponent: ForwardRefRenderFunction<TabViewRef, TabViewProps> = (
|
|
|
39
50
|
const scrollX = useRef(new Animated.Value(startPage));
|
|
40
51
|
const lazy = useRef([selectedIndex]).current;
|
|
41
52
|
const {theme} = useContext(ApplicationContext);
|
|
53
|
+
const app = useContext<any>(MiniAppContext);
|
|
54
|
+
const screen = useContext<any>(ScreenContext);
|
|
55
|
+
const componentName = 'TabView';
|
|
56
|
+
|
|
57
|
+
const componentId = useMemo(() => {
|
|
58
|
+
if (accessibilityLabel) {
|
|
59
|
+
return accessibilityLabel;
|
|
60
|
+
}
|
|
61
|
+
let id = `${app.appId}/${app.code}/${screen.screenName}/${componentName}`;
|
|
62
|
+
return id;
|
|
63
|
+
}, [componentName, accessibilityLabel, app, screen]);
|
|
64
|
+
|
|
42
65
|
const _onPressTabItem = (index: number) => {
|
|
43
66
|
onPressTabItem?.(index);
|
|
44
67
|
pagerRef.current?.setPage(index);
|
|
@@ -53,12 +76,13 @@ const TabComponent: ForwardRefRenderFunction<TabViewRef, TabViewProps> = (
|
|
|
53
76
|
setTabBarWidth(e.nativeEvent.layout.width);
|
|
54
77
|
};
|
|
55
78
|
|
|
56
|
-
const onPageSelected = (e:
|
|
79
|
+
const onPageSelected = (e: PagerViewOnPageSelectedEvent) => {
|
|
57
80
|
const {position} = e.nativeEvent;
|
|
58
81
|
if (!lazy.includes(position)) {
|
|
59
82
|
lazy.push(position);
|
|
60
83
|
}
|
|
61
84
|
setSelectedIndex(position);
|
|
85
|
+
pagerProps?.onPageSelected?.(e);
|
|
62
86
|
};
|
|
63
87
|
|
|
64
88
|
let TabBarComponent = scrollable ? ScrollableTabBar : TabBar;
|
|
@@ -67,9 +91,10 @@ const TabComponent: ForwardRefRenderFunction<TabViewRef, TabViewProps> = (
|
|
|
67
91
|
TabBarComponent = CardTabBar;
|
|
68
92
|
}
|
|
69
93
|
|
|
70
|
-
const onPageScroll = (e:
|
|
94
|
+
const onPageScroll = (e: PagerViewOnPageScrollEvent) => {
|
|
71
95
|
const {position, offset} = e.nativeEvent;
|
|
72
96
|
scrollX.current.setValue(position + offset);
|
|
97
|
+
pagerProps?.onPageScroll?.(e);
|
|
73
98
|
};
|
|
74
99
|
|
|
75
100
|
const renderScreen = useCallback(
|
|
@@ -87,8 +112,11 @@ const TabComponent: ForwardRefRenderFunction<TabViewRef, TabViewProps> = (
|
|
|
87
112
|
}));
|
|
88
113
|
|
|
89
114
|
return (
|
|
90
|
-
<View
|
|
91
|
-
|
|
115
|
+
<View
|
|
116
|
+
onLayout={onLayout}
|
|
117
|
+
style={[styles.tabView, {flex: 1}]}
|
|
118
|
+
accessibilityLabel={componentId}>
|
|
119
|
+
<Animated.View style={style}>
|
|
92
120
|
<TabBarComponent
|
|
93
121
|
onPressTabItem={_onPressTabItem}
|
|
94
122
|
selectedIndex={selectedIndex}
|
|
@@ -98,8 +126,9 @@ const TabComponent: ForwardRefRenderFunction<TabViewRef, TabViewProps> = (
|
|
|
98
126
|
direction={direction}
|
|
99
127
|
selectedColor={selectedColor ?? theme.colors.primary}
|
|
100
128
|
unselectedColor={unselectedColor ?? theme.colors.text.default}
|
|
129
|
+
accessibilityLabelForSelectedCard={accessibilityLabelForSelectedCard}
|
|
101
130
|
/>
|
|
102
|
-
</View>
|
|
131
|
+
</Animated.View>
|
|
103
132
|
|
|
104
133
|
<PagerView
|
|
105
134
|
{...pagerProps}
|
|
@@ -117,4 +146,4 @@ const TabComponent: ForwardRefRenderFunction<TabViewRef, TabViewProps> = (
|
|
|
117
146
|
const TabView = forwardRef(TabComponent);
|
|
118
147
|
|
|
119
148
|
export {CardTabBar, ScrollableTabBar, TabBar, TabView};
|
|
120
|
-
export type {TabViewProps, Tab};
|
|
149
|
+
export type {TabViewProps, TabViewRef, Tab};
|
package/package.json
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
2
|
+
"name": "@momo-kits/tab-view",
|
|
3
|
+
"version": "0.104.1",
|
|
4
|
+
"private": false,
|
|
5
|
+
"main": "index.tsx",
|
|
6
|
+
"dependencies": {},
|
|
7
|
+
"peerDependencies": {
|
|
8
|
+
"@momo-kits/foundation": "latest",
|
|
9
|
+
"prop-types": "^15.7.2",
|
|
10
|
+
"react": "16.9.0",
|
|
11
|
+
"react-native": ">=0.55"
|
|
12
|
+
},
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"@momo-platform/versions": "4.1.11"
|
|
15
|
+
},
|
|
16
|
+
"license": "MoMo",
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"registry": "https://registry.npmjs.org/"
|
|
19
|
+
}
|
|
17
20
|
}
|
package/publish.sh
CHANGED
package/tabBar/CardTabBar.tsx
CHANGED
|
@@ -22,6 +22,7 @@ const CardTabBar: FC<TabBarProps> = ({
|
|
|
22
22
|
selectedIndex,
|
|
23
23
|
selectedColor,
|
|
24
24
|
unselectedColor,
|
|
25
|
+
accessibilityLabelForSelectedCard,
|
|
25
26
|
}) => {
|
|
26
27
|
const {theme} = useContext(ApplicationContext);
|
|
27
28
|
const itemWidth = containerWidth / tabs.length;
|
|
@@ -58,7 +59,10 @@ const CardTabBar: FC<TabBarProps> = ({
|
|
|
58
59
|
<PathSvg style={{transform: [{rotateY: '180deg'}], left: 8}} />
|
|
59
60
|
)}
|
|
60
61
|
<View
|
|
61
|
-
accessibilityLabel={
|
|
62
|
+
accessibilityLabel={
|
|
63
|
+
accessibilityLabelForSelectedCard ??
|
|
64
|
+
tabs[selectedIndex]?.accessibilityLabel
|
|
65
|
+
}
|
|
62
66
|
style={[
|
|
63
67
|
styles.overlayTextWrapper,
|
|
64
68
|
{
|
package/tabItem/CardTabItem.tsx
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
import React, {FC} from 'react';
|
|
1
|
+
import React, {FC, useContext, useMemo} from 'react';
|
|
2
2
|
import {TouchableOpacity, View} from 'react-native';
|
|
3
3
|
import {TabItemProps} from '../types';
|
|
4
4
|
import styles from '../styles';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
Badge,
|
|
7
|
+
BadgeDot,
|
|
8
|
+
Icon,
|
|
9
|
+
MiniAppContext,
|
|
10
|
+
ScreenContext,
|
|
11
|
+
Spacing,
|
|
12
|
+
Text,
|
|
13
|
+
} from '@momo-kits/foundation';
|
|
6
14
|
|
|
7
15
|
const CardTabItem: FC<TabItemProps> = ({
|
|
8
16
|
tab,
|
|
@@ -23,18 +31,31 @@ const CardTabItem: FC<TabItemProps> = ({
|
|
|
23
31
|
} = tab;
|
|
24
32
|
const color = active ? selectedColor : unselectedColor;
|
|
25
33
|
|
|
34
|
+
const app = useContext<any>(MiniAppContext);
|
|
35
|
+
const screen = useContext<any>(ScreenContext);
|
|
36
|
+
|
|
37
|
+
const componentName = 'CardTabItem';
|
|
38
|
+
|
|
39
|
+
const componentId = useMemo(() => {
|
|
40
|
+
if (accessibilityLabel) {
|
|
41
|
+
return accessibilityLabel;
|
|
42
|
+
}
|
|
43
|
+
let id = `${app.appId}/${app.code}/${screen.screenName}/${componentName}/${title}`;
|
|
44
|
+
return id;
|
|
45
|
+
}, [componentName, accessibilityLabel, app, screen]);
|
|
46
|
+
|
|
26
47
|
return (
|
|
27
48
|
<TouchableOpacity
|
|
28
49
|
onPress={onPressTabItem}
|
|
29
50
|
style={[styles.cardTabItem, {width}]}
|
|
30
|
-
accessibilityLabel={
|
|
31
|
-
{
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
51
|
+
accessibilityLabel={componentId}
|
|
52
|
+
accessibilityState={{checked: active}}>
|
|
53
|
+
{typeof renderIcon === 'function' && (
|
|
54
|
+
<View
|
|
55
|
+
style={[styles.icon, styles.iconHolder, {marginRight: Spacing.XS}]}>
|
|
56
|
+
{renderIcon(active)}
|
|
57
|
+
</View>
|
|
58
|
+
)}
|
|
38
59
|
{!renderIcon && !!icon && (
|
|
39
60
|
<Icon
|
|
40
61
|
color={color}
|
|
@@ -45,7 +66,8 @@ const CardTabItem: FC<TabItemProps> = ({
|
|
|
45
66
|
<Text
|
|
46
67
|
numberOfLines={1}
|
|
47
68
|
style={[styles.textCenter, {flexShrink: 1}]}
|
|
48
|
-
typography={'body_default_regular'}
|
|
69
|
+
typography={'body_default_regular'}
|
|
70
|
+
accessibilityLabel={`${componentId}|text`}>
|
|
49
71
|
{title}
|
|
50
72
|
</Text>
|
|
51
73
|
{showDot && (
|
|
@@ -58,7 +80,11 @@ const CardTabItem: FC<TabItemProps> = ({
|
|
|
58
80
|
)}
|
|
59
81
|
{!showDot && badgeValue && (
|
|
60
82
|
<View>
|
|
61
|
-
<Badge
|
|
83
|
+
<Badge
|
|
84
|
+
label={badgeValue}
|
|
85
|
+
style={{marginLeft: Spacing.XS}}
|
|
86
|
+
accessibilityLabel={`${componentId}|badge`}
|
|
87
|
+
/>
|
|
62
88
|
</View>
|
|
63
89
|
)}
|
|
64
90
|
</TouchableOpacity>
|
package/tabItem/TabItem.tsx
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import React, {FC} from 'react';
|
|
1
|
+
import React, {FC, useContext, useMemo} from 'react';
|
|
2
2
|
import {TouchableOpacity, View} from 'react-native';
|
|
3
3
|
import {TabItemProps} from '../types';
|
|
4
4
|
import {
|
|
5
5
|
Badge,
|
|
6
6
|
BadgeDot,
|
|
7
7
|
Icon,
|
|
8
|
+
MiniAppContext,
|
|
8
9
|
scaleSize,
|
|
10
|
+
ScreenContext,
|
|
9
11
|
Spacing,
|
|
10
12
|
Text,
|
|
11
13
|
Typography,
|
|
@@ -35,11 +37,24 @@ const TabItem: FC<TabItemProps> = ({
|
|
|
35
37
|
: 'body_default_regular';
|
|
36
38
|
const color = active ? selectedColor : unselectedColor;
|
|
37
39
|
const dotStyle = dotSize === 'large' ? styles.dot : styles.dotSmall;
|
|
40
|
+
const app = useContext<any>(MiniAppContext);
|
|
41
|
+
const screen = useContext<any>(ScreenContext);
|
|
42
|
+
|
|
43
|
+
const componentName = 'TabItem';
|
|
44
|
+
|
|
45
|
+
const componentId = useMemo(() => {
|
|
46
|
+
if (accessibilityLabel) {
|
|
47
|
+
return accessibilityLabel;
|
|
48
|
+
}
|
|
49
|
+
let id = `${app.appId}/${app.code}/${screen.screenName}/${componentName}/${title}`;
|
|
50
|
+
return id;
|
|
51
|
+
}, [componentName, accessibilityLabel, app, screen]);
|
|
38
52
|
|
|
39
53
|
const renderRowItem = () => {
|
|
40
54
|
return (
|
|
41
55
|
<TouchableOpacity
|
|
42
|
-
accessibilityLabel={
|
|
56
|
+
accessibilityLabel={componentId}
|
|
57
|
+
accessibilityState={{checked: active}}
|
|
43
58
|
style={[
|
|
44
59
|
styles.tabItem,
|
|
45
60
|
{
|
|
@@ -69,7 +84,8 @@ const TabItem: FC<TabItemProps> = ({
|
|
|
69
84
|
numberOfLines={1}
|
|
70
85
|
typography={typography}
|
|
71
86
|
color={color}
|
|
72
|
-
style={{flexShrink: 1}}
|
|
87
|
+
style={{flexShrink: 1}}
|
|
88
|
+
accessibilityLabel={`${componentId}|text`}>
|
|
73
89
|
{title}
|
|
74
90
|
</Text>
|
|
75
91
|
{showDot && (
|
|
@@ -77,7 +93,11 @@ const TabItem: FC<TabItemProps> = ({
|
|
|
77
93
|
)}
|
|
78
94
|
{!showDot && badgeValue && (
|
|
79
95
|
<View>
|
|
80
|
-
<Badge
|
|
96
|
+
<Badge
|
|
97
|
+
label={badgeValue}
|
|
98
|
+
style={{marginLeft: Spacing.XS}}
|
|
99
|
+
accessibilityLabel={`${componentId}|badge`}
|
|
100
|
+
/>
|
|
81
101
|
</View>
|
|
82
102
|
)}
|
|
83
103
|
</TouchableOpacity>
|
|
@@ -99,7 +119,8 @@ const TabItem: FC<TabItemProps> = ({
|
|
|
99
119
|
},
|
|
100
120
|
]}
|
|
101
121
|
onPress={onPressTabItem}
|
|
102
|
-
accessibilityLabel={
|
|
122
|
+
accessibilityLabel={componentId}
|
|
123
|
+
accessibilityState={{checked: active}}>
|
|
103
124
|
<View>
|
|
104
125
|
{renderIcon && typeof renderIcon === 'function' && (
|
|
105
126
|
<View
|
|
@@ -127,10 +148,18 @@ const TabItem: FC<TabItemProps> = ({
|
|
|
127
148
|
<BadgeDot style={dotStyle} size={dotSize} />
|
|
128
149
|
)}
|
|
129
150
|
{(renderIcon || !!icon) && !showDot && badgeValue && (
|
|
130
|
-
<Badge
|
|
151
|
+
<Badge
|
|
152
|
+
label={badgeValue}
|
|
153
|
+
style={styles.badge}
|
|
154
|
+
accessibilityLabel={`${componentId}|badge`}
|
|
155
|
+
/>
|
|
131
156
|
)}
|
|
132
157
|
</View>
|
|
133
|
-
<Text
|
|
158
|
+
<Text
|
|
159
|
+
numberOfLines={1}
|
|
160
|
+
typography={typography}
|
|
161
|
+
color={color}
|
|
162
|
+
accessibilityLabel={`${componentId}|text`}>
|
|
134
163
|
{title}
|
|
135
164
|
</Text>
|
|
136
165
|
</TouchableOpacity>
|
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} from 'react-native';
|
|
3
|
+
import {Animated, ViewStyle} from 'react-native';
|
|
4
4
|
|
|
5
5
|
export type Tab = {
|
|
6
6
|
/**
|
|
@@ -95,7 +95,7 @@ export type TabViewProps = {
|
|
|
95
95
|
/**
|
|
96
96
|
* Optional. Additional properties to pass to the underlying pager view component.
|
|
97
97
|
*/
|
|
98
|
-
pagerProps?: PagerViewProps
|
|
98
|
+
pagerProps?: Omit<PagerViewProps, 'children'>;
|
|
99
99
|
|
|
100
100
|
/**
|
|
101
101
|
* Optional. Specifies the layout direction for the tab's content, either in a row or column format.
|
|
@@ -105,6 +105,12 @@ export type TabViewProps = {
|
|
|
105
105
|
selectedColor?: string;
|
|
106
106
|
|
|
107
107
|
unselectedColor?: string;
|
|
108
|
+
|
|
109
|
+
style?: ViewStyle;
|
|
110
|
+
|
|
111
|
+
accessibilityLabel?: string;
|
|
112
|
+
|
|
113
|
+
accessibilityLabelForSelectedCard?: string;
|
|
108
114
|
};
|
|
109
115
|
|
|
110
116
|
/**
|
|
@@ -144,6 +150,8 @@ export type TabBarProps = {
|
|
|
144
150
|
selectedColor?: string;
|
|
145
151
|
|
|
146
152
|
unselectedColor?: string;
|
|
153
|
+
|
|
154
|
+
accessibilityLabelForSelectedCard?: string;
|
|
147
155
|
};
|
|
148
156
|
|
|
149
157
|
export type TabViewRef = {
|