@momo-kits/tab-view 0.92.6-rc.9 → 0.92.8-beta.0

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 CHANGED
@@ -30,6 +30,11 @@ const TabView: FC<TabViewProps> = ({
30
30
  const {theme} = useContext(ApplicationContext);
31
31
  const _onPressTabItem = (index: number) => {
32
32
  pagerRef.current?.setPage(index);
33
+
34
+ if (!lazy.includes(index)) {
35
+ lazy.push(index);
36
+ }
37
+
33
38
  onPressTabItem?.(index);
34
39
  setSelectedIndex(index);
35
40
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/tab-view",
3
- "version": "0.92.6-rc.9",
3
+ "version": "0.92.8-beta.0",
4
4
  "private": false,
5
5
  "main": "index.tsx",
6
6
  "dependencies": {},
@@ -14,4 +14,4 @@
14
14
  "@momo-platform/versions": "4.1.11"
15
15
  },
16
16
  "license": "MoMo"
17
- }
17
+ }
package/publish.sh CHANGED
@@ -1,29 +1,28 @@
1
1
  #!/bin/bash
2
+
3
+ # Prepare dist files
2
4
  rm -rf dist
3
5
  mkdir dist
4
-
5
- cp . ./dist
6
-
7
- # GET VERSION from mck_package.json
8
- VERSIONSTRING=( v$(jq .version package.json) )
9
- VERSION=(${VERSIONSTRING//[\"]/})
10
- echo VERSION: $VERSION
11
-
12
- rsync -r --verbose --exclude '*.mdx' --exclude '*Demo.js' --exclude 'props-type.js' --exclude 'prop-types.js' ./* dist
13
-
14
- # #babel component to dist
15
- #babel ./dist -d dist --copy-files
16
-
17
- #copy option
18
- #cp -r ./src/ dist
19
-
20
-
21
- #npm login
22
- #publish dist to npm
6
+ rsync -r --exclude=/dist ./* dist
23
7
  cd dist
24
- npm publish --tag beta --access=public
8
+
9
+ if [ "$1" == "stable" ]; then
10
+ npm version $(npm view @momo-kits/tab-view@stable version)
11
+ npm version patch
12
+ npm publish --tag stable --access=public
13
+ elif [ "$1" == "latest" ]; then
14
+ npm version $(npm view @momo-kits/tab-view@latest version)
15
+ npm version prerelease --preid=rc
16
+ npm publish --tag latest --access=public
17
+ else
18
+ npm version $(npm view @momo-kits/tab-view@beta version)
19
+ npm version prerelease --preid=beta
20
+ npm publish --tag beta --access=public
21
+ fi
22
+
23
+ PACKAGE_NAME=$(npm pkg get name)
24
+ NEW_PACKAGE_VERSION=$(npm pkg get version)
25
+
26
+ # Clean up
25
27
  cd ..
26
28
  rm -rf dist
27
-
28
-
29
- ##curl -X POST -H 'Content-Type: application/json' 'https://chat.googleapis.com/v1/spaces/AAAAbP8987c/messages?key=AIzaSyDdI0hCZtE6vySjMm-WEfRq3CPzqKqqsHI&token=UGSFRvk_oYb9uGsAgs31bVvMm6jDkmD8zihGm3eyaQA%3D&threadKey=JoaXTEYaNNkl' -d '{"text": "@momo-kits/tab-view new version release: '*"$VERSION"*' https://www.npmjs.com/package/@momo-kits/tab-view"}'
package/styles.ts CHANGED
@@ -52,6 +52,9 @@ export default StyleSheet.create({
52
52
  flexDirection: 'row',
53
53
  justifyContent: 'center',
54
54
  alignItems: 'center',
55
+ paddingHorizontal: Spacing.S,
56
+ paddingTop: Spacing.S,
57
+ paddingBottom: Spacing.M,
55
58
  },
56
59
  cardTabOverlay: {
57
60
  flexDirection: 'row',
@@ -65,7 +68,8 @@ export default StyleSheet.create({
65
68
  height: '100%',
66
69
  alignItems: 'center',
67
70
  justifyContent: 'center',
68
- paddingTop: Spacing.XS,
71
+ paddingVertical: Spacing.M,
72
+ paddingHorizontal: Spacing.S,
69
73
  flexDirection: 'row',
70
74
  },
71
75
  dotSmall: {
@@ -65,19 +65,18 @@ const CardTabBar: FC<TabBarProps> = ({
65
65
  width: containerWidth / tabs.length,
66
66
  borderTopRightRadius: Radius.M,
67
67
  borderTopLeftRadius: Radius.M,
68
+ paddingHorizontal: tabs.length === 3 ? Spacing.S : Spacing.M,
68
69
  },
69
70
  ]}>
70
71
  {!!tabs[selectedIndex]?.renderIcon &&
71
- !['string', 'boolean', 'number'].includes(
72
- typeof tabs[selectedIndex]?.renderIcon,
73
- ) && (
72
+ typeof tabs[selectedIndex]?.renderIcon === 'function' && (
74
73
  <View
75
74
  style={[
76
75
  styles.icon,
77
76
  styles.iconHolder,
78
77
  {marginRight: Spacing.XS},
79
78
  ]}>
80
- {tabs[selectedIndex]?.renderIcon}
79
+ {tabs[selectedIndex]?.renderIcon?.(true)}
81
80
  </View>
82
81
  )}
83
82
  {!tabs[selectedIndex]?.renderIcon && !!tabs[selectedIndex]?.icon && (
@@ -90,7 +89,7 @@ const CardTabBar: FC<TabBarProps> = ({
90
89
  <Text
91
90
  color={selectedColor}
92
91
  numberOfLines={1}
93
- style={styles.textCenter}
92
+ style={[styles.textCenter, {flexShrink: 1}]}
94
93
  typography={'header_s_semibold'}>
95
94
  {tabs[selectedIndex]?.title || ''}
96
95
  </Text>
@@ -104,7 +103,10 @@ const CardTabBar: FC<TabBarProps> = ({
104
103
  )}
105
104
  {!tabs[selectedIndex]?.showDot && tabs[selectedIndex]?.badgeValue && (
106
105
  <View>
107
- <Badge label={tabs[selectedIndex]?.badgeValue} />
106
+ <Badge
107
+ label={tabs[selectedIndex]?.badgeValue}
108
+ style={{marginLeft: Spacing.XS}}
109
+ />
108
110
  </View>
109
111
  )}
110
112
  </View>
@@ -11,12 +11,14 @@ const ScrollableTabBar: FC<TabBarProps> = ({
11
11
  selectedIndex,
12
12
  selectedColor,
13
13
  unselectedColor,
14
+ direction,
14
15
  }) => {
15
16
  const {theme} = useContext(ApplicationContext);
16
17
  const [itemWidthMap, setItemWidthMap] = useState<
17
18
  {width: number; x: number}[]
18
19
  >([]);
19
20
  const animatedWidth = useRef(new Animated.Value(0)).current;
21
+ const animX = useRef(new Animated.Value(0)).current;
20
22
  const scrollViewRef = useRef<ScrollView>(null);
21
23
 
22
24
  useEffect(() => {
@@ -24,11 +26,18 @@ const ScrollableTabBar: FC<TabBarProps> = ({
24
26
  scrollToIndex(selectedIndex);
25
27
  }, [selectedIndex, itemWidthMap]);
26
28
  const moveIndicator = () => {
27
- Animated.timing(animatedWidth, {
28
- toValue: itemWidthMap[selectedIndex]?.width || 0,
29
- duration: 250,
30
- useNativeDriver: false,
31
- }).start();
29
+ Animated.parallel([
30
+ Animated.timing(animatedWidth, {
31
+ toValue: itemWidthMap[selectedIndex]?.width || 0,
32
+ duration: 250,
33
+ useNativeDriver: false,
34
+ }),
35
+ Animated.timing(animX, {
36
+ toValue: itemWidthMap[selectedIndex]?.x || 0,
37
+ duration: 250,
38
+ useNativeDriver: false,
39
+ }),
40
+ ]).start();
32
41
  };
33
42
 
34
43
  const onLayout = (e: LayoutChangeEvent, index: number) => {
@@ -66,6 +75,7 @@ const ScrollableTabBar: FC<TabBarProps> = ({
66
75
  tab={item}
67
76
  selectedColor={selectedColor}
68
77
  unselectedColor={unselectedColor}
78
+ direction={direction}
69
79
  />
70
80
  </View>
71
81
  );
@@ -88,7 +98,7 @@ const ScrollableTabBar: FC<TabBarProps> = ({
88
98
  style={[
89
99
  styles.indicator,
90
100
  {
91
- left: itemWidthMap[selectedIndex]?.x || 0,
101
+ left: animX,
92
102
  width: animatedWidth,
93
103
  backgroundColor: selectedColor,
94
104
  },
@@ -2,7 +2,7 @@ import React, {FC} from 'react';
2
2
  import {TouchableOpacity, View} from 'react-native';
3
3
  import {TabItemProps} from '../types';
4
4
  import styles from '../styles';
5
- import {Badge, BadgeDot, Icon, Spacing, Text,} from '@momo-kits/foundation';
5
+ import {Badge, BadgeDot, Icon, Spacing, Text} from '@momo-kits/foundation';
6
6
 
7
7
  const CardTabItem: FC<TabItemProps> = ({
8
8
  tab,
@@ -42,7 +42,7 @@ const CardTabItem: FC<TabItemProps> = ({
42
42
  )}
43
43
  <Text
44
44
  numberOfLines={1}
45
- style={styles.textCenter}
45
+ style={[styles.textCenter, {flexShrink: 1}]}
46
46
  typography={'body_default_regular'}>
47
47
  {title}
48
48
  </Text>
@@ -56,7 +56,7 @@ const CardTabItem: FC<TabItemProps> = ({
56
56
  )}
57
57
  {!showDot && badgeValue && (
58
58
  <View>
59
- <Badge label={badgeValue} />
59
+ <Badge label={badgeValue} style={{marginLeft: Spacing.XS}} />
60
60
  </View>
61
61
  )}
62
62
  </TouchableOpacity>
@@ -1,8 +1,7 @@
1
- import React, {FC, useContext} from 'react';
1
+ import React, {FC} from 'react';
2
2
  import {TouchableOpacity, View} from 'react-native';
3
3
  import {TabItemProps} from '../types';
4
4
  import {
5
- ApplicationContext,
6
5
  Badge,
7
6
  BadgeDot,
8
7
  Icon,
@@ -22,7 +21,6 @@ const TabItem: FC<TabItemProps> = ({
22
21
  selectedColor,
23
22
  unselectedColor,
24
23
  }) => {
25
- const {theme} = useContext(ApplicationContext);
26
24
  const {
27
25
  title,
28
26
  icon,
@@ -47,28 +45,29 @@ const TabItem: FC<TabItemProps> = ({
47
45
  height: scaleSize(48),
48
46
  flexDirection: 'row',
49
47
  overflow: 'hidden',
48
+ paddingVertical: Spacing.M,
49
+ paddingHorizontal: Spacing.M,
50
50
  },
51
51
  ]}
52
52
  onPress={onPressTabItem}>
53
- {renderIcon &&
54
- !['string', 'boolean', 'number'].includes(typeof renderIcon) && (
55
- <View
56
- style={[
57
- styles.icon,
58
- styles.iconHolder,
59
- {marginRight: Spacing.XS},
60
- ]}>
61
- {renderIcon}
62
- </View>
63
- )}
53
+ {renderIcon && typeof renderIcon === 'function' && (
54
+ <View
55
+ style={[styles.icon, styles.iconHolder, {marginRight: Spacing.S}]}>
56
+ {renderIcon(active)}
57
+ </View>
58
+ )}
64
59
  {!renderIcon && !!icon && (
65
60
  <Icon
66
- style={[styles.icon, {marginRight: Spacing.XS}]}
61
+ style={[styles.icon, {marginRight: Spacing.S}]}
67
62
  source={icon}
68
63
  color={color}
69
64
  />
70
65
  )}
71
- <Text numberOfLines={1} typography={typography} color={color}>
66
+ <Text
67
+ numberOfLines={1}
68
+ typography={typography}
69
+ color={color}
70
+ style={{flexShrink: 1}}>
72
71
  {title}
73
72
  </Text>
74
73
  {showDot && (
@@ -76,7 +75,7 @@ const TabItem: FC<TabItemProps> = ({
76
75
  )}
77
76
  {!showDot && badgeValue && (
78
77
  <View>
79
- <Badge label={badgeValue} />
78
+ <Badge label={badgeValue} style={{marginLeft: Spacing.XS}} />
80
79
  </View>
81
80
  )}
82
81
  </TouchableOpacity>
@@ -93,21 +92,22 @@ const TabItem: FC<TabItemProps> = ({
93
92
  height: scaleSize(68),
94
93
  flexDirection: 'column',
95
94
  overflow: 'hidden',
95
+ paddingHorizontal: Spacing.M,
96
+ paddingVertical: Spacing.M,
96
97
  },
97
98
  ]}
98
99
  onPress={onPressTabItem}>
99
100
  <View>
100
- {renderIcon &&
101
- !['string', 'boolean', 'number'].includes(typeof renderIcon) && (
102
- <View
103
- style={[
104
- styles.icon,
105
- styles.iconHolder,
106
- {marginBottom: Spacing.XS},
107
- ]}>
108
- {renderIcon}
109
- </View>
110
- )}
101
+ {renderIcon && typeof renderIcon === 'function' && (
102
+ <View
103
+ style={[
104
+ styles.icon,
105
+ styles.iconHolder,
106
+ {marginBottom: Spacing.XS},
107
+ ]}>
108
+ {renderIcon(active)}
109
+ </View>
110
+ )}
111
111
  {!renderIcon && !!icon && (
112
112
  <Icon
113
113
  style={[
package/types.ts CHANGED
@@ -1,4 +1,4 @@
1
- import {ReactElement, ReactNode} from 'react';
1
+ import {ReactElement} from 'react';
2
2
  import {PagerViewProps} from 'react-native-pager-view';
3
3
  import {Animated} from 'react-native';
4
4
 
@@ -13,7 +13,7 @@ export type Tab = {
13
13
  */
14
14
  icon?: string;
15
15
 
16
- renderIcon?: ReactNode;
16
+ renderIcon?: (active: boolean) => ReactElement;
17
17
 
18
18
  /**
19
19
  * The main component or content to be displayed when this tab is active.