@momo-kits/tab-view 0.103.2 → 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 +25 -2
- package/package.json +6 -3
- 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 +9 -1
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';
|
|
@@ -17,7 +18,11 @@ import PagerView, {
|
|
|
17
18
|
PagerViewOnPageScrollEvent,
|
|
18
19
|
PagerViewOnPageSelectedEvent,
|
|
19
20
|
} from 'react-native-pager-view';
|
|
20
|
-
import {
|
|
21
|
+
import {
|
|
22
|
+
ApplicationContext,
|
|
23
|
+
MiniAppContext,
|
|
24
|
+
ScreenContext,
|
|
25
|
+
} from '@momo-kits/foundation';
|
|
21
26
|
|
|
22
27
|
const TabComponent: ForwardRefRenderFunction<TabViewRef, TabViewProps> = (
|
|
23
28
|
{
|
|
@@ -31,6 +36,8 @@ const TabComponent: ForwardRefRenderFunction<TabViewRef, TabViewProps> = (
|
|
|
31
36
|
selectedColor,
|
|
32
37
|
unselectedColor,
|
|
33
38
|
style,
|
|
39
|
+
accessibilityLabel,
|
|
40
|
+
accessibilityLabelForSelectedCard,
|
|
34
41
|
},
|
|
35
42
|
ref
|
|
36
43
|
) => {
|
|
@@ -43,6 +50,18 @@ const TabComponent: ForwardRefRenderFunction<TabViewRef, TabViewProps> = (
|
|
|
43
50
|
const scrollX = useRef(new Animated.Value(startPage));
|
|
44
51
|
const lazy = useRef([selectedIndex]).current;
|
|
45
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
|
+
|
|
46
65
|
const _onPressTabItem = (index: number) => {
|
|
47
66
|
onPressTabItem?.(index);
|
|
48
67
|
pagerRef.current?.setPage(index);
|
|
@@ -93,7 +112,10 @@ const TabComponent: ForwardRefRenderFunction<TabViewRef, TabViewProps> = (
|
|
|
93
112
|
}));
|
|
94
113
|
|
|
95
114
|
return (
|
|
96
|
-
<View
|
|
115
|
+
<View
|
|
116
|
+
onLayout={onLayout}
|
|
117
|
+
style={[styles.tabView, {flex: 1}]}
|
|
118
|
+
accessibilityLabel={componentId}>
|
|
97
119
|
<Animated.View style={style}>
|
|
98
120
|
<TabBarComponent
|
|
99
121
|
onPressTabItem={_onPressTabItem}
|
|
@@ -104,6 +126,7 @@ const TabComponent: ForwardRefRenderFunction<TabViewRef, TabViewProps> = (
|
|
|
104
126
|
direction={direction}
|
|
105
127
|
selectedColor={selectedColor ?? theme.colors.primary}
|
|
106
128
|
unselectedColor={unselectedColor ?? theme.colors.text.default}
|
|
129
|
+
accessibilityLabelForSelectedCard={accessibilityLabelForSelectedCard}
|
|
107
130
|
/>
|
|
108
131
|
</Animated.View>
|
|
109
132
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@momo-kits/tab-view",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.104.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"main": "index.tsx",
|
|
6
6
|
"dependencies": {},
|
|
@@ -13,5 +13,8 @@
|
|
|
13
13
|
"devDependencies": {
|
|
14
14
|
"@momo-platform/versions": "4.1.11"
|
|
15
15
|
},
|
|
16
|
-
"license": "MoMo"
|
|
17
|
-
|
|
16
|
+
"license": "MoMo",
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"registry": "https://registry.npmjs.org/"
|
|
19
|
+
}
|
|
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
|
/**
|
|
@@ -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 = {
|