@momo-kits/foundation 0.77.8-beta.1 → 0.77.8-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.
@@ -1,5 +1,6 @@
1
1
  import React, {useContext, useEffect, useState} from 'react';
2
2
  import {
3
+ Alert,
3
4
  Animated,
4
5
  DeviceEventEmitter,
5
6
  StatusBar,
@@ -7,13 +8,14 @@ import {
7
8
  TouchableOpacity,
8
9
  View,
9
10
  } from 'react-native';
10
- import {ApplicationContext, NavigationButton} from './index';
11
+ import {ApplicationContext} from './index';
11
12
  import {Colors, Radius, Spacing, Styles} from '../Consts';
12
13
  import {Image} from '../Image';
13
14
  import {
14
15
  HeaderBackgroundProps,
15
16
  HeaderBackProps,
16
17
  HeaderToolkitProps,
18
+ NavigationButtonProps,
17
19
  TitleCustomProps,
18
20
  } from './types';
19
21
  import {scaleSize, Text} from '../Text';
@@ -21,6 +23,14 @@ import {Icon} from '../Icon';
21
23
  import {PopupNotify} from '../Popup';
22
24
 
23
25
  const styles = StyleSheet.create({
26
+ navigationButton: {
27
+ height: 28,
28
+ width: 28,
29
+ borderRadius: 14,
30
+ borderColor: '#00000066',
31
+ justifyContent: 'center',
32
+ alignItems: 'center',
33
+ },
24
34
  headerBackground: {
25
35
  width: '100%',
26
36
  height: undefined,
@@ -77,6 +87,39 @@ const styles = StyleSheet.create({
77
87
  },
78
88
  });
79
89
 
90
+ const NavigationButton: React.FC<NavigationButtonProps> = ({
91
+ icon,
92
+ tintColor,
93
+ onPress,
94
+ backgroundColor,
95
+ useBorder = true,
96
+ accessibilityLabel,
97
+ }) => {
98
+ const {theme} = useContext(ApplicationContext);
99
+ if (!backgroundColor && tintColor != Colors.black_01) {
100
+ backgroundColor = theme.colors.background.surface;
101
+ }
102
+
103
+ return (
104
+ <TouchableOpacity
105
+ accessibilityLabel={`NavigationButton/${accessibilityLabel}`}
106
+ style={[
107
+ styles.navigationButton,
108
+ {
109
+ backgroundColor: backgroundColor ?? '#00000066',
110
+ borderWidth: useBorder && backgroundColor ? 0.5 : 0,
111
+ },
112
+ ]}
113
+ onPress={onPress}>
114
+ <Icon
115
+ source={icon}
116
+ color={tintColor ?? theme.colors.text.default}
117
+ size={20}
118
+ />
119
+ </TouchableOpacity>
120
+ );
121
+ };
122
+
80
123
  const HeaderTitle: React.FC<any> = ({accessibilityLabel = '', ...props}) => {
81
124
  const {theme} = useContext(ApplicationContext);
82
125
  const opacity = props.animatedValue?.interpolate({
@@ -100,6 +143,7 @@ const HeaderTitle: React.FC<any> = ({accessibilityLabel = '', ...props}) => {
100
143
  const HeaderLeft: React.FC<HeaderBackProps> = ({
101
144
  tintColor,
102
145
  preventBack,
146
+ onPressLeftHeader,
103
147
  useBorder,
104
148
  backgroundColor,
105
149
  accessibilityLabel = '',
@@ -131,6 +175,7 @@ const HeaderLeft: React.FC<HeaderBackProps> = ({
131
175
  const requestId = `navigationBackPress#${currentTime}`;
132
176
  DeviceEventEmitter.emit('dismiss', {requestId});
133
177
  }
178
+ onPressLeftHeader?.();
134
179
  };
135
180
 
136
181
  return (
@@ -220,8 +265,9 @@ const HeaderCustom: React.FC<TitleCustomProps> = ({
220
265
  const HeaderRightAction: React.FC<any> = ({children, ...restProps}) => {
221
266
  const validType = (item: any) => {
222
267
  if (__DEV__ && item.type !== NavigationButton) {
223
- console.warn(
224
- 'element type of NavigationButton, Please migrate to use NavigationButton of kits.',
268
+ Alert.alert(
269
+ 'Rule',
270
+ 'HeaderRightAction contains element type of NavigationButton, Please check again.',
225
271
  );
226
272
  return <View />;
227
273
  }
@@ -366,6 +412,7 @@ const HeaderToolkitAction: React.FC<any> = ({tintColor}) => {
366
412
  };
367
413
 
368
414
  export {
415
+ NavigationButton,
369
416
  HeaderTitle,
370
417
  HeaderLeft,
371
418
  HeaderBackground,
@@ -8,7 +8,6 @@ import {
8
8
  } from 'react-native';
9
9
  import {SafeAreaView, useSafeAreaInsets} from 'react-native-safe-area-context';
10
10
  import {BottomSheetBackdrop, BottomSheetModal} from '@gorhom/bottom-sheet';
11
- import {BottomSheetModalMethods} from '@gorhom/bottom-sheet/lib/typescript/types';
12
11
  import Navigation from './Navigation';
13
12
  import {BottomSheetParams, ModalParams} from './types';
14
13
  import {Radius, Spacing, Styles} from '../Consts';
@@ -97,7 +96,7 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
97
96
 
98
97
  const snapPoints = useMemo(() => ['50%', '90%'], []);
99
98
  const {bottom} = useSafeAreaInsets();
100
- const bottomSheetRef = useRef<BottomSheetModalMethods>(null);
99
+ const bottomSheetRef = useRef(null);
101
100
  const mountedRef = useRef(true);
102
101
 
103
102
  useEffect(() => {
@@ -1,4 +1,5 @@
1
1
  import {NavigationProp} from '@react-navigation/native';
2
+ import {Alert} from 'react-native';
2
3
  import {NavigationOptions, Theme} from './types';
3
4
  import {HeaderRightAction} from './index';
4
5
  import {getOptions} from './utils';
@@ -18,8 +19,9 @@ class Navigation {
18
19
  const headerRight = params.headerRight?.();
19
20
  const type = headerRight?.type;
20
21
  if (type !== HeaderRightAction && type !== HeaderToolkitAction) {
21
- console.warn(
22
- 'headerRight not return element type of HeaderRightAction | HeaderToolkitAction, Please migrate to use of kits.',
22
+ Alert.alert(
23
+ 'Rule',
24
+ 'headerRight contains element type of HeaderRightAction | HeaderToolkitAction, Please check again.',
23
25
  );
24
26
  delete params.headerRight;
25
27
  }
@@ -28,6 +30,7 @@ class Navigation {
28
30
  };
29
31
 
30
32
  setOptions = (params: NavigationOptions) => {
33
+ console.log(params);
31
34
  if (__DEV__) {
32
35
  params = this.filterParams(params);
33
36
  }
@@ -1,7 +1,6 @@
1
1
  import {NavigationContainer} from './NavigationContainer';
2
2
  import Screen from '../Layout/Screen';
3
- import NavigationButton from './NavigationButton';
4
- import {HeaderRightAction} from './Components';
3
+ import {HeaderRightAction, NavigationButton} from './Components';
5
4
  import BottomTab from './BottomTab';
6
5
  import {createContext} from 'react';
7
6
  import {defaultContext} from '../Consts';
@@ -121,6 +121,7 @@ export type NavigationButtonProps = {
121
121
 
122
122
  export type NavigationOptions = {
123
123
  preventBack?: PopupNotifyProps;
124
+ onPressLeftHeader?: () => void;
124
125
  surface?: boolean;
125
126
  headerTransparent?: boolean;
126
127
  hiddenBack?: boolean;
@@ -134,6 +135,7 @@ export type NavigationOptions = {
134
135
 
135
136
  export interface HeaderBackProps extends NavigationButtonProps {
136
137
  preventBack?: PopupNotifyProps;
138
+ onPressLeftHeader?: () => void;
137
139
  accessibilityLabel?: string;
138
140
  }
139
141
 
@@ -76,6 +76,19 @@ const getOptions = (params: NavigationOptions, theme: Theme) => {
76
76
  let titleProps = {};
77
77
  let options = {};
78
78
 
79
+ if (typeof params.onPressLeftHeader === 'function') {
80
+ options = {
81
+ ...options,
82
+ headerLeft: (props: any) => (
83
+ <HeaderLeft
84
+ {...props}
85
+ preventBack={params.preventBack}
86
+ onPressLeftHeader={params.onPressLeftHeader}
87
+ />
88
+ ),
89
+ };
90
+ }
91
+
79
92
  if (params.preventBack) {
80
93
  options = {
81
94
  ...options,
package/Button/index.tsx CHANGED
@@ -62,13 +62,13 @@ export interface ButtonProps extends TouchableOpacityProps {
62
62
  }
63
63
 
64
64
  const Button: FC<ButtonProps> = ({
65
- type,
66
- size,
67
- useTintColor,
68
- full,
65
+ type = 'primary',
66
+ size = 'large',
67
+ useTintColor = true,
68
+ full = false,
69
69
  iconRight,
70
70
  iconLeft,
71
- title,
71
+ title = 'Button',
72
72
  onPress,
73
73
  ...rest
74
74
  }) => {
@@ -266,13 +266,4 @@ const Button: FC<ButtonProps> = ({
266
266
  );
267
267
  };
268
268
 
269
- Button.defaultProps = {
270
- type: 'primary',
271
- size: 'large',
272
- full: true,
273
- disabled: false,
274
- title: 'Button',
275
- useTintColor: true,
276
- };
277
-
278
269
  export {Button};
package/Layout/Screen.tsx CHANGED
@@ -176,7 +176,7 @@ const Screen: React.FC<ScreenProps> = ({
176
176
  <View
177
177
  style={{
178
178
  paddingTop: Spacing.S,
179
- paddingBottom: insets.bottom + Spacing.S,
179
+ paddingBottom: Math.min(insets.bottom, 20) + Spacing.S,
180
180
  backgroundColor: theme.colors.background.surface,
181
181
  }}>
182
182
  <Section>{Footer}</Section>
package/Loader/utils.ts CHANGED
@@ -2,7 +2,6 @@ export const hexToRGBA = (hex: string) => {
2
2
  const normalizedHex = hex.startsWith('#') ? hex.slice(1) : hex;
3
3
 
4
4
  if (!/^([0-9A-Fa-f]{3}){1,2}$/.test(normalizedHex)) {
5
- console.log(hex);
6
5
  throw new Error('Invalid HEX color.');
7
6
  }
8
7
 
@@ -110,9 +110,10 @@ const PopupNotify: React.FC<PopupNotifyProps> = ({
110
110
  */
111
111
  const buildCloseIcon = () => {
112
112
  return (
113
- <View style={styles.iconCloseContainer}>
114
- <TouchableOpacity
115
- onPress={() => onAction(onIconClose)}
113
+ <TouchableOpacity
114
+ style={styles.iconCloseContainer}
115
+ onPress={() => onAction(onIconClose)}>
116
+ <View
116
117
  style={[
117
118
  styles.iconClose,
118
119
  {
@@ -125,8 +126,8 @@ const PopupNotify: React.FC<PopupNotifyProps> = ({
125
126
  color={theme.colors.background.surface}
126
127
  size={14}
127
128
  />
128
- </TouchableOpacity>
129
- </View>
129
+ </View>
130
+ </TouchableOpacity>
130
131
  );
131
132
  };
132
133
 
@@ -191,8 +192,9 @@ const styles = StyleSheet.create({
191
192
  },
192
193
  iconCloseContainer: {
193
194
  position: 'absolute',
194
- top: -Spacing.S,
195
- right: -Spacing.S,
195
+ top: -Spacing.M,
196
+ right: -Spacing.M,
197
+ padding: Spacing.XS,
196
198
  },
197
199
  iconClose: {
198
200
  width: 20,
@@ -20,18 +20,21 @@ const PopupPromotion: React.FC<PopupPromotionProps> = ({image, onClose}) => {
20
20
  navigator?.pop();
21
21
  onClose?.();
22
22
  }}
23
- style={[
24
- styles.iconClose,
25
- {
26
- backgroundColor: theme.colors.text.default,
27
- borderColor: theme.colors.background.surface,
28
- },
29
- ]}>
30
- <Icon
31
- source="navigation_close"
32
- color={theme.colors.background.surface}
33
- size={14}
34
- />
23
+ style={styles.iconButton}>
24
+ <View
25
+ style={[
26
+ styles.iconClose,
27
+ {
28
+ backgroundColor: theme.colors.text.default,
29
+ borderColor: theme.colors.background.surface,
30
+ },
31
+ ]}>
32
+ <Icon
33
+ source="navigation_close"
34
+ color={theme.colors.background.surface}
35
+ size={14}
36
+ />
37
+ </View>
35
38
  </TouchableOpacity>
36
39
  </View>
37
40
  );
@@ -58,7 +61,10 @@ const styles = StyleSheet.create({
58
61
  width: '100%',
59
62
  flexDirection: 'row',
60
63
  justifyContent: 'center',
61
- marginTop: Spacing.L,
64
+ marginTop: Spacing.S,
65
+ },
66
+ iconButton: {
67
+ padding: 8,
62
68
  },
63
69
  iconClose: {
64
70
  width: 20,
@@ -0,0 +1,51 @@
1
+ const scanner = require('react-scanner');
2
+ const path = require('path');
3
+
4
+ const scan = async config => {
5
+ return await scanner.run(config);
6
+ };
7
+
8
+ const calcSum = array => {
9
+ return array.reduce((a, b) => a + b, 0);
10
+ };
11
+
12
+ const calculateAdoptionRate = (kitJsonPath, miniappJsonPath) => {
13
+ const kitJson = require(kitJsonPath);
14
+ const miniAppJson = require(miniappJsonPath);
15
+ const numOfKitComponents = calcSum(Object.values(kitJson));
16
+ const numOfMiniAppComponents = calcSum(Object.values(miniAppJson));
17
+ const adoptionRate = (numOfKitComponents / numOfMiniAppComponents) * 100;
18
+ console.log("Number of kit's components: ", numOfKitComponents);
19
+ console.log("Number of miniapp's components: ", numOfMiniAppComponents);
20
+ console.log('Adoption rate: ', adoptionRate);
21
+ };
22
+
23
+ const main = async () => {
24
+ const [scanPath, kitJsonRelativePath, miniappJsonRelativePath] =
25
+ process.argv.slice(2);
26
+
27
+ const kitJsonPath = path.resolve(process.cwd(), kitJsonRelativePath);
28
+ const miniappJsonPath = path.resolve(process.cwd(), miniappJsonRelativePath);
29
+
30
+ const config1 = {
31
+ crawlFrom: scanPath,
32
+ includeSubComponents: true,
33
+ importedFrom: /@momo-kits\/.+/,
34
+ processors: [['count-components', {outputTo: kitJsonPath}]],
35
+ rootDir: './',
36
+ };
37
+
38
+ const config2 = {
39
+ crawlFrom: scanPath,
40
+ includeSubComponents: true,
41
+ processors: [['count-components', {outputTo: miniappJsonPath}]],
42
+ rootDir: './',
43
+ };
44
+
45
+ await scan(config1);
46
+ await scan(config2);
47
+
48
+ calculateAdoptionRate(kitJsonPath, miniappJsonPath);
49
+ };
50
+
51
+ main().catch(console.error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/foundation",
3
- "version": "0.77.8-beta.01",
3
+ "version": "0.77.8-beta.02",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {
@@ -10,14 +10,16 @@
10
10
  "@momo-kits/foundation"
11
11
  ],
12
12
  "dependencies": {
13
+ "@gorhom/bottom-sheet": "2.4.1",
13
14
  "react-native-safe-area-context": "3.1.4",
14
15
  "react-native-linear-gradient": "2.5.6",
16
+ "react-native-gesture-handler": "1.10.3",
17
+ "react-native-fast-image": "8.1.5",
15
18
  "@react-navigation/bottom-tabs": "git+https://gitlab.com/dung.huynh1/react-navigation-bottom-tabs.git#main",
16
19
  "@react-navigation/core": "5.16.1",
17
20
  "@react-navigation/native": "5.9.8",
18
21
  "@react-navigation/routers": "5.7.4",
19
- "@react-navigation/stack": "git+https://gitlab.com/dung.huynh1/react-navigation-stack.git#main",
20
- "@gorhom/bottom-sheet": "2.4.1"
22
+ "@react-navigation/stack": "git+https://gitlab.com/dung.huynh1/react-navigation-stack.git#main"
21
23
  },
22
24
  "peerDependencies": {
23
25
  "react-native": "*"
@@ -34,7 +36,8 @@
34
36
  "jest": "^26.6.3",
35
37
  "metro-react-native-babel-preset": "^0.64.0",
36
38
  "react-test-renderer": "17.0.1",
37
- "typescript": "^4.0.3"
39
+ "typescript": "^4.0.3",
40
+ "react-scanner": "^1.1.0"
38
41
  },
39
42
  "author": "@momo-kits/foundation",
40
43
  "license": "ISC"
@@ -1,54 +0,0 @@
1
- import {Platform, StyleSheet, TouchableOpacity as TouchRN} from 'react-native';
2
- import {TouchableOpacity as TouchGesture} from 'react-native-gesture-handler';
3
- import React, {useContext} from 'react';
4
- import {NavigationButtonProps} from './types';
5
- import {ApplicationContext} from './index';
6
- import {Icon} from '../Icon';
7
- import {Colors} from '../Consts';
8
-
9
- const TouchableOpacity = Platform.OS === 'ios' ? TouchRN : TouchGesture;
10
- const NavigationButton: React.FC<NavigationButtonProps> = ({
11
- icon,
12
- tintColor,
13
- onPress,
14
- backgroundColor,
15
- useBorder = true,
16
- accessibilityLabel,
17
- }) => {
18
- const {theme} = useContext(ApplicationContext);
19
- if (!backgroundColor && tintColor != Colors.black_01) {
20
- backgroundColor = theme.colors.background.surface;
21
- }
22
-
23
- return (
24
- <TouchableOpacity
25
- accessibilityLabel={`NavigationButton/${accessibilityLabel}`}
26
- style={[
27
- styles.container,
28
- {
29
- backgroundColor: backgroundColor ?? '#00000066',
30
- borderWidth: useBorder && backgroundColor ? 0.5 : 0,
31
- },
32
- ]}
33
- onPress={onPress}>
34
- <Icon
35
- source={icon}
36
- color={tintColor ?? theme.colors.text.default}
37
- size={20}
38
- />
39
- </TouchableOpacity>
40
- );
41
- };
42
-
43
- const styles = StyleSheet.create({
44
- container: {
45
- height: 28,
46
- width: 28,
47
- borderRadius: 14,
48
- borderColor: '#00000066',
49
- justifyContent: 'center',
50
- alignItems: 'center',
51
- },
52
- });
53
-
54
- export default NavigationButton;