@momo-kits/tab-view 0.169.4 → 0.169.6
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 +7 -5
- package/index.tsx +6 -4
- package/package.json +1 -1
- package/tabBar/CardTabBar.tsx +39 -31
- package/tabBar/SrollableTabBar.tsx +5 -5
- package/tabBar/TabBar.tsx +8 -6
- package/tabItem/CardTabItem.tsx +1 -0
- package/tabItem/TabItem.tsx +4 -0
package/assets/Path.tsx
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import React, {FC} from 'react';
|
|
2
|
-
import {ViewProps} from 'react-native';
|
|
3
|
-
import Svg, {Path} from 'react-native-svg';
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
|
+
import { ViewProps } from 'react-native';
|
|
3
|
+
import Svg, { Path } from 'react-native-svg';
|
|
4
4
|
|
|
5
5
|
interface PathSvgProps extends ViewProps {
|
|
6
6
|
pathWidth: number;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
/** Curved edge linking the raised card tab to the bar, `pathWidth` wide. */
|
|
10
|
+
const PathSvg: FC<PathSvgProps> = ({ style, pathWidth }) => {
|
|
10
11
|
const height = 44;
|
|
11
12
|
|
|
12
13
|
return (
|
|
@@ -16,7 +17,8 @@ const PathSvg: FC<PathSvgProps> = ({style, pathWidth}) => {
|
|
|
16
17
|
viewBox={`0 0 28 ${height}`}
|
|
17
18
|
preserveAspectRatio="none"
|
|
18
19
|
fill="none"
|
|
19
|
-
style={style}
|
|
20
|
+
style={style}
|
|
21
|
+
>
|
|
20
22
|
<Path
|
|
21
23
|
d="M0 0H0.60765C6.47582 0 11.4819 4.23831 12.4602 10.0244C13.9248 18.6872 15.9294 30.37 16.6925 34C17.9536 40 22.259 44 27.9996 44H0V0Z"
|
|
22
24
|
fill="white"
|
package/index.tsx
CHANGED
|
@@ -67,7 +67,7 @@ const TabComponent: ForwardRefRenderFunction<TabViewRef, TabViewProps> = (
|
|
|
67
67
|
|
|
68
68
|
const _onPressTabItem = (index: number) => {
|
|
69
69
|
onPressTabItem?.(index);
|
|
70
|
-
|
|
70
|
+
|
|
71
71
|
if (!fitContent) {
|
|
72
72
|
pagerRef.current?.setPage(index);
|
|
73
73
|
}
|
|
@@ -159,9 +159,7 @@ const TabComponent: ForwardRefRenderFunction<TabViewRef, TabViewProps> = (
|
|
|
159
159
|
</Animated.View>
|
|
160
160
|
|
|
161
161
|
{fitContent ? (
|
|
162
|
-
<View>
|
|
163
|
-
{tabs[selectedIndex]?.component}
|
|
164
|
-
</View>
|
|
162
|
+
<View>{tabs[selectedIndex]?.component}</View>
|
|
165
163
|
) : (
|
|
166
164
|
<PagerView
|
|
167
165
|
{...pagerProps}
|
|
@@ -183,6 +181,10 @@ const TabComponent: ForwardRefRenderFunction<TabViewRef, TabViewProps> = (
|
|
|
183
181
|
);
|
|
184
182
|
};
|
|
185
183
|
|
|
184
|
+
/**
|
|
185
|
+
* Tab bar (default, scrollable or card) over pages mounted on first visit.
|
|
186
|
+
* `fitContent` swaps the PagerView for the selected tab only, sized to content.
|
|
187
|
+
*/
|
|
186
188
|
const TabView = forwardRef(TabComponent);
|
|
187
189
|
|
|
188
190
|
export { CardTabBar, ScrollableTabBar, TabBar, TabView };
|
package/package.json
CHANGED
package/tabBar/CardTabBar.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import React, {FC, useContext} from 'react';
|
|
2
|
-
import {Platform, View} from 'react-native';
|
|
3
|
-
import {TabBarProps} from '../types';
|
|
1
|
+
import React, { FC, useContext } from 'react';
|
|
2
|
+
import { Platform, View } from 'react-native';
|
|
3
|
+
import { TabBarProps } from '../types';
|
|
4
4
|
import styles from '../styles';
|
|
5
5
|
import {
|
|
6
6
|
ApplicationContext,
|
|
@@ -15,6 +15,10 @@ import {
|
|
|
15
15
|
import CardTabItem from '../tabItem/CardTabItem';
|
|
16
16
|
import PathSvg from '../assets/Path';
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Card-style tabs: the selected tab is redrawn as a raised card on an overlay,
|
|
20
|
+
* joined to its neighbours by curved path edges.
|
|
21
|
+
*/
|
|
18
22
|
const CardTabBar: FC<TabBarProps> = ({
|
|
19
23
|
tabs,
|
|
20
24
|
onPressTabItem,
|
|
@@ -24,7 +28,10 @@ const CardTabBar: FC<TabBarProps> = ({
|
|
|
24
28
|
unselectedColor,
|
|
25
29
|
accessibilityLabelForSelectedCard,
|
|
26
30
|
}) => {
|
|
27
|
-
const {theme} = useContext(ApplicationContext);
|
|
31
|
+
const { theme } = useContext(ApplicationContext);
|
|
32
|
+
const selectedTab = tabs[selectedIndex];
|
|
33
|
+
const tabLabel = selectedTab?.accessibilityLabel;
|
|
34
|
+
const selectedCardLabel = accessibilityLabelForSelectedCard ?? tabLabel;
|
|
28
35
|
const itemWidth = containerWidth / tabs.length;
|
|
29
36
|
const isFirst = selectedIndex === 0;
|
|
30
37
|
const isLast = selectedIndex === tabs.length - 1;
|
|
@@ -42,24 +49,25 @@ const CardTabBar: FC<TabBarProps> = ({
|
|
|
42
49
|
const rightPathStyle = { ...pathPosition, right: pathInset };
|
|
43
50
|
|
|
44
51
|
const renderIconTabBar = () => {
|
|
52
|
+
const hasRenderIcon = typeof selectedTab?.renderIcon === 'function';
|
|
45
53
|
return (
|
|
46
54
|
<>
|
|
47
|
-
{
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
{!
|
|
55
|
+
{hasRenderIcon && (
|
|
56
|
+
<View
|
|
57
|
+
style={[
|
|
58
|
+
styles.icon,
|
|
59
|
+
styles.iconHolder,
|
|
60
|
+
{ marginRight: Spacing.XS },
|
|
61
|
+
]}
|
|
62
|
+
>
|
|
63
|
+
{selectedTab?.renderIcon?.(true)}
|
|
64
|
+
</View>
|
|
65
|
+
)}
|
|
66
|
+
{!selectedTab?.renderIcon && !!selectedTab?.icon && (
|
|
59
67
|
<Icon
|
|
60
68
|
color={selectedColor}
|
|
61
|
-
source={
|
|
62
|
-
style={[styles.icon, {marginRight: Spacing.XS}]}
|
|
69
|
+
source={selectedTab?.icon as string}
|
|
70
|
+
style={[styles.icon, { marginRight: Spacing.XS }]}
|
|
63
71
|
/>
|
|
64
72
|
)}
|
|
65
73
|
</>
|
|
@@ -91,13 +99,11 @@ const CardTabBar: FC<TabBarProps> = ({
|
|
|
91
99
|
width: containerWidth / tabs.length,
|
|
92
100
|
left: isWeb ? overlayLeft : overlayLeft - backSpace,
|
|
93
101
|
},
|
|
94
|
-
]}
|
|
102
|
+
]}
|
|
103
|
+
>
|
|
95
104
|
{!isFirst && <PathSvg style={leftPathStyle} pathWidth={pathWidth} />}
|
|
96
105
|
<View
|
|
97
|
-
accessibilityLabel={
|
|
98
|
-
accessibilityLabelForSelectedCard ??
|
|
99
|
-
tabs[selectedIndex]?.accessibilityLabel
|
|
100
|
-
}
|
|
106
|
+
accessibilityLabel={selectedCardLabel}
|
|
101
107
|
style={[
|
|
102
108
|
styles.overlayTextWrapper,
|
|
103
109
|
{
|
|
@@ -107,28 +113,30 @@ const CardTabBar: FC<TabBarProps> = ({
|
|
|
107
113
|
borderTopLeftRadius: Radius.M,
|
|
108
114
|
paddingHorizontal: tabs.length === 3 ? Spacing.S : Spacing.M,
|
|
109
115
|
},
|
|
110
|
-
]}
|
|
116
|
+
]}
|
|
117
|
+
>
|
|
111
118
|
{renderIconTabBar()}
|
|
112
119
|
<Text
|
|
113
120
|
color={selectedColor}
|
|
114
121
|
numberOfLines={1}
|
|
115
122
|
style={[styles.textCenter, styles.shrink]}
|
|
116
|
-
typography={'header_s_semibold'}
|
|
117
|
-
|
|
123
|
+
typography={'header_s_semibold'}
|
|
124
|
+
>
|
|
125
|
+
{selectedTab?.title || ''}
|
|
118
126
|
</Text>
|
|
119
|
-
{
|
|
127
|
+
{selectedTab?.showDot && (
|
|
120
128
|
<BadgeDot
|
|
121
|
-
size={
|
|
129
|
+
size={selectedTab?.dotSize ?? 'small'}
|
|
122
130
|
style={{
|
|
123
131
|
marginLeft: Spacing.XS,
|
|
124
132
|
}}
|
|
125
133
|
/>
|
|
126
134
|
)}
|
|
127
|
-
{!
|
|
135
|
+
{!selectedTab?.showDot && selectedTab?.badgeValue && (
|
|
128
136
|
<View>
|
|
129
137
|
<Badge
|
|
130
|
-
label={
|
|
131
|
-
style={{marginLeft: Spacing.XS}}
|
|
138
|
+
label={selectedTab?.badgeValue}
|
|
139
|
+
style={{ marginLeft: Spacing.XS }}
|
|
132
140
|
/>
|
|
133
141
|
</View>
|
|
134
142
|
)}
|
|
@@ -13,6 +13,10 @@ import styles from '../styles';
|
|
|
13
13
|
import { ApplicationContext } from '@momo-kits/foundation';
|
|
14
14
|
import TabItem from '../tabItem/TabItem';
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Scrollable tabs sized to their titles. Measures each item so the indicator
|
|
18
|
+
* animates to the selected tab and the bar scrolls it into view.
|
|
19
|
+
*/
|
|
16
20
|
const ScrollableTabBar: FC<TabBarProps> = ({
|
|
17
21
|
tabs = [],
|
|
18
22
|
onPressTabItem,
|
|
@@ -194,11 +198,7 @@ const ScrollableTabBar: FC<TabBarProps> = ({
|
|
|
194
198
|
},
|
|
195
199
|
]}
|
|
196
200
|
>
|
|
197
|
-
<View
|
|
198
|
-
ref={contentRef}
|
|
199
|
-
collapsable={false}
|
|
200
|
-
style={styles.relativeRow}
|
|
201
|
-
>
|
|
201
|
+
<View ref={contentRef} collapsable={false} style={styles.relativeRow}>
|
|
202
202
|
{tabs.map((item, index) => renderItem({ item, index }))}
|
|
203
203
|
<Animated.View
|
|
204
204
|
style={[
|
package/tabBar/TabBar.tsx
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import React, {FC, useContext} from 'react';
|
|
2
|
-
import {Animated, View} from 'react-native';
|
|
3
|
-
import {TabBarProps} from '../types';
|
|
1
|
+
import React, { FC, useContext } from 'react';
|
|
2
|
+
import { Animated, View } from 'react-native';
|
|
3
|
+
import { TabBarProps } from '../types';
|
|
4
4
|
import TabItem from '../tabItem/TabItem';
|
|
5
5
|
import styles from '../styles';
|
|
6
|
-
import {ApplicationContext, Spacing} from '@momo-kits/foundation';
|
|
6
|
+
import { ApplicationContext, Spacing } from '@momo-kits/foundation';
|
|
7
7
|
|
|
8
|
+
/** Equal-width tabs with an underline that follows the pager via `scrollX`. */
|
|
8
9
|
const TabBar: FC<TabBarProps> = ({
|
|
9
10
|
tabs = [],
|
|
10
11
|
selectedIndex,
|
|
@@ -15,7 +16,7 @@ const TabBar: FC<TabBarProps> = ({
|
|
|
15
16
|
selectedColor,
|
|
16
17
|
unselectedColor,
|
|
17
18
|
}) => {
|
|
18
|
-
const {theme} = useContext(ApplicationContext);
|
|
19
|
+
const { theme } = useContext(ApplicationContext);
|
|
19
20
|
const itemWidth = containerWidth / tabs.length;
|
|
20
21
|
|
|
21
22
|
return (
|
|
@@ -26,7 +27,8 @@ const TabBar: FC<TabBarProps> = ({
|
|
|
26
27
|
borderColor: theme.colors.border.default,
|
|
27
28
|
backgroundColor: theme.colors.background.surface,
|
|
28
29
|
},
|
|
29
|
-
]}
|
|
30
|
+
]}
|
|
31
|
+
>
|
|
30
32
|
{tabs.map((tab, index) => {
|
|
31
33
|
return (
|
|
32
34
|
<TabItem
|
package/tabItem/CardTabItem.tsx
CHANGED
package/tabItem/TabItem.tsx
CHANGED
|
@@ -14,6 +14,10 @@ import {
|
|
|
14
14
|
} from '@momo-kits/foundation';
|
|
15
15
|
import styles from '../styles';
|
|
16
16
|
|
|
17
|
+
/**
|
|
18
|
+
* One tab of the default and scrollable bars: icon beside (`direction='row'`)
|
|
19
|
+
* or above the title, plus a dot or badge.
|
|
20
|
+
*/
|
|
17
21
|
const TabItem: FC<TabItemProps> = ({
|
|
18
22
|
tab,
|
|
19
23
|
active,
|