@momo-kits/foundation 0.111.1-optimize.1 → 0.111.1-optimize.3

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,8 +1,6 @@
1
1
  import React, {useCallback, useContext, useEffect, useRef} from 'react';
2
2
  import {
3
- Animated,
4
3
  Dimensions,
5
- Easing,
6
4
  KeyboardAvoidingView,
7
5
  Modal,
8
6
  PanResponder,
@@ -19,6 +17,7 @@ import {Colors, Radius, Spacing, Styles} from '../Consts';
19
17
  import {Text} from '../Text';
20
18
  import {Icon} from '../Icon';
21
19
  import {useHeaderHeight} from '@react-navigation/stack';
20
+ import Animated, {Easing, Extrapolate} from 'react-native-reanimated';
22
21
 
23
22
  const BottomSheet: React.FC<BottomSheetParams> = props => {
24
23
  const {theme, navigator} = useContext(ApplicationContext);
@@ -40,37 +39,46 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
40
39
  keyboardVerticalOffset,
41
40
  }: BottomSheetParams = props.route.params;
42
41
 
43
- const pan = useRef(
44
- new Animated.ValueXY({
45
- y: heightDevice,
46
- x: 0,
47
- })
48
- ).current;
49
-
50
42
  const customEasingOpen = Easing.bezier(0.05, 0.7, 0.1, 1);
51
43
  const customEasingClose = Easing.bezier(0.3, 0.0, 0.8, 0.15);
52
44
 
45
+ const translateY = useRef(new Animated.Value(heightDevice)).current;
46
+
47
+ const openAnimation = Animated.timing(translateY, {
48
+ toValue: 0,
49
+ duration: 350,
50
+ easing: customEasingOpen,
51
+ });
52
+
53
+ const closeAnimation = Animated.timing(translateY, {
54
+ toValue: heightDevice,
55
+ duration: 200,
56
+ easing: customEasingClose,
57
+ });
58
+
53
59
  const panResponder = useRef(
54
60
  PanResponder.create({
55
61
  onStartShouldSetPanResponder: () => draggable,
56
- onMoveShouldSetPanResponder: (_, gestureState) => {
57
- return draggable && gestureState.dy > 0;
58
- },
59
- onPanResponderMove: (e, gestureState) => {
60
- gestureState.dy > 0 &&
61
- Animated.event([null, {dy: pan.y}], {useNativeDriver: false})(
62
- e,
63
- gestureState
64
- );
62
+ onMoveShouldSetPanResponder: (_, gestureState) =>
63
+ draggable && gestureState.dy > 0,
64
+ onPanResponderMove: (_, gestureState) => {
65
+ if (gestureState.dy > 0) {
66
+ translateY.setValue(gestureState.dy);
67
+ }
65
68
  },
66
69
  onPanResponderRelease: (_, gestureState) => {
67
70
  if (gestureState.dy > 100) {
68
71
  action.current = 'gesture';
69
72
  onDismiss();
70
73
  } else {
71
- Animated.spring(pan, {
72
- toValue: {x: 0, y: 0},
73
- useNativeDriver: false,
74
+ Animated.spring(translateY, {
75
+ toValue: 0,
76
+ damping: 20,
77
+ mass: 1,
78
+ stiffness: 100,
79
+ overshootClamping: false,
80
+ restSpeedThreshold: 0.001,
81
+ restDisplacementThreshold: 0.001,
74
82
  }).start();
75
83
  }
76
84
  },
@@ -90,13 +98,8 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
90
98
  * emit dismiss event
91
99
  */
92
100
  useEffect(() => {
93
- Animated.timing(pan, {
94
- toValue: {x: 0, y: 0},
95
- useNativeDriver: false,
96
- easing: customEasingOpen,
97
- duration: 350,
98
- }).start();
99
-
101
+ translateY.setValue(heightDevice);
102
+ openAnimation.start();
100
103
  return () => {
101
104
  props.route.params?.onDismiss?.(action.current);
102
105
  };
@@ -109,16 +112,11 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
109
112
  if (barrierDismissible && !force) {
110
113
  return;
111
114
  }
112
- setTimeout(() => {
113
- callback?.();
114
- }, 300);
115
- Animated.timing(pan, {
116
- toValue: {x: 0, y: heightDevice},
117
- useNativeDriver: false,
118
- easing: customEasingClose,
119
- duration: 200,
120
- }).start(() => {
121
- navigator?.pop();
115
+ closeAnimation.start(() => {
116
+ setImmediate(() => {
117
+ navigator?.pop();
118
+ callback?.();
119
+ });
122
120
  });
123
121
  };
124
122
 
@@ -205,10 +203,10 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
205
203
  style={[
206
204
  styles.overlay,
207
205
  {
208
- opacity: pan.y.interpolate({
206
+ opacity: translateY.interpolate({
209
207
  inputRange: [0, heightDevice],
210
208
  outputRange: [1, 0],
211
- extrapolate: 'clamp',
209
+ extrapolate: Extrapolate.CLAMP,
212
210
  }),
213
211
  },
214
212
  ]}
@@ -217,7 +215,7 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
217
215
 
218
216
  <Animated.View
219
217
  style={{
220
- transform: pan.getTranslateTransform(),
218
+ transform: [{translateY}],
221
219
  }}>
222
220
  {renderHeader()}
223
221
  <View style={{backgroundColor: backgroundColor}}>
@@ -92,7 +92,7 @@ const HeaderToolkitAction: React.FC<any> = ({
92
92
  */
93
93
  const checkAppIsFavorite = useCallback(
94
94
  () =>
95
- navigator?.maxApi?.dispatchFunction(
95
+ navigator?.maxApi?.dispatchFunction?.(
96
96
  'isFavoriteApp',
97
97
  {code: context?.code},
98
98
  (result: boolean) => {
@@ -143,14 +143,15 @@ const HeaderToolkitAction: React.FC<any> = ({
143
143
  */
144
144
  const onPressShortcut = () => {
145
145
  const currentRoute = navigator?.ref?.current?.getCurrentRoute?.();
146
+ const expected = !isFavorite;
146
147
  context?.autoTracking?.({
147
148
  ...context,
148
149
  componentName: 'IconButton',
149
- componentId: 'navigation_shortcut',
150
+ componentId: `${expected ? 'pin' : 'unpin'}_shortcut`,
150
151
  screenName: currentRoute?.params?.screen?.name ?? currentRoute?.name,
151
152
  });
152
153
  setIsLoading(true);
153
- navigator?.maxApi?.dispatchFunction(
154
+ navigator?.maxApi?.dispatchFunction?.(
154
155
  'onToolAction',
155
156
  {
156
157
  item: {
@@ -160,7 +161,7 @@ const HeaderToolkitAction: React.FC<any> = ({
160
161
  },
161
162
  ({success}: {success: boolean}) => {
162
163
  if (success) {
163
- setIsFavorite(!isFavorite);
164
+ setIsFavorite(expected);
164
165
  }
165
166
  }
166
167
  );
@@ -221,7 +222,7 @@ const HeaderToolkitAction: React.FC<any> = ({
221
222
  screenName: currentRoute?.params?.screen?.name ?? currentRoute?.name,
222
223
  });
223
224
 
224
- navigator?.maxApi?.dispatchFunction(
225
+ navigator?.maxApi?.dispatchFunction?.(
225
226
  'showTools',
226
227
  tools,
227
228
  context,
@@ -8,7 +8,7 @@ import {
8
8
  } from 'react-native';
9
9
  import {ApplicationContext, MiniAppContext} from '../index';
10
10
  import {exportFontFamily, scaleSize, Text} from '../../Text';
11
- import {Colors, Spacing, Radius, Styles} from '../../Consts';
11
+ import {Colors, Radius, Spacing, Styles} from '../../Consts';
12
12
  import {TitleJourneyProps, TitleLocationProps, TitleUserProps} from '../types';
13
13
  import {Image} from '../../Image';
14
14
  import {Icon} from '../../Icon';
@@ -79,7 +79,7 @@ const TitleUser: React.FC<TitleUserProps> = ({
79
79
  isLoading,
80
80
  }) => {
81
81
  const {theme} = useContext(ApplicationContext);
82
- const maxWidth = icons?.length === 2 ? '73%' : '100%';
82
+ const maxWidth = Dimensions.get('window').width - scaleSize(172);
83
83
  const getShortName = (name: string) => {
84
84
  const words = name.split(' ');
85
85
  const lastTwoWords = words.slice(-2);
@@ -246,20 +246,20 @@ const TitleUser: React.FC<TitleUserProps> = ({
246
246
  };
247
247
 
248
248
  const renderVerifyIcon = () => {
249
- const renderIcons = () => {
250
- if (icons && icons.length > 0) {
251
- return icons.map(icon => (
252
- <Image
253
- source={{
254
- uri: icon,
255
- }}
256
- style={styles.verifiedIcon}
257
- />
258
- ));
259
- }
260
- };
261
-
262
- return <View style={Styles.row}>{renderIcons()}</View>;
249
+ if (icons && icons.length > 0) {
250
+ return (
251
+ <View style={[Styles.row]}>
252
+ {icons.map(icon => (
253
+ <Image
254
+ source={{
255
+ uri: icon,
256
+ }}
257
+ style={styles.verifiedIcon}
258
+ />
259
+ ))}
260
+ </View>
261
+ );
262
+ }
263
263
  };
264
264
 
265
265
  const renderShimmer = () => {
@@ -295,19 +295,21 @@ const TitleUser: React.FC<TitleUserProps> = ({
295
295
  if (isLoading) {
296
296
  return renderShimmer();
297
297
  }
298
+
298
299
  return (
299
300
  <TouchableOpacity
300
301
  style={styles.headerTitleContainer}
301
302
  onPress={onPress}
302
303
  disabled={onPress === undefined}>
303
- <View style={[Styles.row, Styles.flex]}>
304
+ <View
305
+ style={[Styles.row, {maxWidth: maxWidth - (icons?.length ?? 0) * 16}]}>
304
306
  <View>
305
307
  {renderImage()}
306
308
  {!!dotColor && (
307
309
  <View style={[styles.dotAvatar, {backgroundColor: dotColor}]} />
308
310
  )}
309
311
  </View>
310
- <View style={[Styles.flex, {marginLeft: 6, maxWidth: maxWidth}]}>
312
+ <View style={[Styles.flex, {marginLeft: 6}]}>
311
313
  <View style={Styles.row}>
312
314
  <Text
313
315
  typography="action_xs_bold"
@@ -493,7 +495,7 @@ const styles = StyleSheet.create({
493
495
  },
494
496
  headerTitleContainer: {
495
497
  justifyContent: 'center',
496
- maxWidth: Dimensions.get('window').width - 190,
498
+ maxWidth: Dimensions.get('window').width - scaleSize(172),
497
499
  },
498
500
  circle: {
499
501
  width: 32,
@@ -11,6 +11,7 @@ import {
11
11
  HeaderTitle,
12
12
  NavigationButton,
13
13
  } from './Components';
14
+ import {setAutomationID} from './utils';
14
15
 
15
16
  const Context = createContext({});
16
17
  const ApplicationContext = createContext(defaultContext);
@@ -32,4 +33,5 @@ export {
32
33
  Screen,
33
34
  BottomTab,
34
35
  HeaderAnimated,
36
+ setAutomationID,
35
37
  };
@@ -12,7 +12,7 @@ import {
12
12
  } from './Components';
13
13
  import {HeaderTitleProps, NavigationOptions} from './types';
14
14
  import {Colors} from '../Consts';
15
- import {Animated} from 'react-native';
15
+ import {Animated, Platform} from 'react-native';
16
16
 
17
17
  /**
18
18
  * default options for stack screen
@@ -26,32 +26,6 @@ const getStackOptions = (): StackNavigationOptions => {
26
26
  headerRight: (props: any) => <HeaderRight {...props} />,
27
27
  headerTintColor: Colors.black_17,
28
28
  gestureEnabled: false,
29
- cardStyleInterpolator: ({current: {progress}, layouts}) => ({
30
- cardStyle: {
31
- transform: [
32
- {
33
- translateX: progress.interpolate({
34
- inputRange: [0, 1],
35
- outputRange: [layouts.screen.width, 0],
36
- }),
37
- },
38
- ],
39
- },
40
- }),
41
- transitionSpec: {
42
- open: {
43
- animation: 'timing',
44
- config: {
45
- duration: 300,
46
- },
47
- },
48
- close: {
49
- animation: 'timing',
50
- config: {
51
- duration: 300,
52
- },
53
- },
54
- },
55
29
  };
56
30
  };
57
31
 
@@ -180,10 +154,25 @@ const exportHeaderTitle = (
180
154
  return {};
181
155
  };
182
156
 
157
+ const setAutomationID = (accessibilityLabel = '') => {
158
+ if (Platform.OS === 'ios') {
159
+ return {
160
+ accessible: true,
161
+ testID: accessibilityLabel,
162
+ accessibilityLabel: undefined,
163
+ };
164
+ } else {
165
+ return {
166
+ accessibilityLabel,
167
+ };
168
+ }
169
+ };
170
+
183
171
  export {
184
172
  getStackOptions,
185
173
  getDialogOptions,
186
174
  getModalOptions,
187
175
  getOptions,
188
176
  exportHeaderTitle,
177
+ setAutomationID,
189
178
  };
package/Text/index.tsx CHANGED
@@ -2,8 +2,8 @@ import React, {useContext} from 'react';
2
2
  import {Text as RNText, TextProps as RNTextProps} from 'react-native';
3
3
  import styles from './styles';
4
4
  import {Typography, TypographyWeight} from './types';
5
- import {ApplicationContext} from '../Application';
6
- import {getAccessibilityID, scaleSize} from './utils';
5
+ import {ApplicationContext, setAutomationID} from '../Application';
6
+ import {scaleSize} from './utils';
7
7
 
8
8
  const SFProText: TypographyWeight = {
9
9
  100: 'Thin',
@@ -155,7 +155,7 @@ const Text: React.FC<TextProps> = ({
155
155
  return (
156
156
  <RNText
157
157
  {...rest}
158
- {...getAccessibilityID(rest.accessibilityLabel)}
158
+ {...setAutomationID(rest.accessibilityLabel)}
159
159
  style={[
160
160
  style,
161
161
  textStyle,
package/Text/utils.ts CHANGED
@@ -1,4 +1,4 @@
1
- import {Dimensions, Platform} from 'react-native';
1
+ import {Dimensions} from 'react-native';
2
2
 
3
3
  const deviceWidth = Dimensions.get('window').width;
4
4
  const DEFAULT_SCREEN_SIZE = 375;
@@ -11,17 +11,5 @@ const scaleSize = (size: number) => {
11
11
 
12
12
  return size;
13
13
  };
14
- const getAccessibilityID = (accessibilityLabel = '') => {
15
- if (Platform.OS === 'ios') {
16
- return {
17
- accessible: true,
18
- testID: accessibilityLabel,
19
- accessibilityLabel: undefined,
20
- };
21
- } else {
22
- return {
23
- accessibilityLabel,
24
- };
25
- }
26
- };
27
- export {scaleSize, getAccessibilityID};
14
+
15
+ export {scaleSize};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/foundation",
3
- "version": "0.111.1-optimize.1",
3
+ "version": "0.111.1-optimize.3",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {},
@@ -9,15 +9,16 @@
9
9
  ],
10
10
  "dependencies": {
11
11
  "@gorhom/bottom-sheet": "2.4.1",
12
+ "react-native-modalize": "2.1.1",
12
13
  "react-native-safe-area-context": "3.1.4",
13
14
  "react-native-linear-gradient": "2.8.3",
14
15
  "react-native-gesture-handler": "1.10.3",
15
- "react-native-modalize": "2.1.1",
16
16
  "react-native-fast-image": "8.1.5",
17
17
  "@react-navigation/bottom-tabs": "https://gitlab.mservice.com.vn/momo-platform/react-native-bottom-tabs.git",
18
18
  "@react-navigation/core": "5.16.1",
19
19
  "@react-navigation/native": "5.9.8",
20
20
  "@react-navigation/routers": "5.7.4",
21
+ "react-native-reanimated": "git+https://gitlab.mservice.com.vn/momo-platform/react-native-reanimated.git#v1.13.4_gradle_7",
21
22
  "lottie-react-native": "git+https://gitlab.mservice.com.vn/momo-platform/momo-lottie-react-native.git",
22
23
  "@react-navigation/stack": "https://gitlab.mservice.com.vn/momo-platform/react-navigation-stack.git"
23
24
  },
@@ -42,6 +43,8 @@
42
43
  "react-scanner": "^1.1.0",
43
44
  "@types/color": "3.0.6"
44
45
  },
45
- "author": "@momo-kits/foundation",
46
- "license": "ISC"
46
+ "publishConfig": {
47
+ "registry": "https://registry.npmjs.org/"
48
+ },
49
+ "license": "MoMo"
47
50
  }
package/publish.sh CHANGED
@@ -1,19 +1,18 @@
1
1
  #!/bin/bash
2
2
 
3
- npm config set registry https://registry.npmjs.org/
4
3
 
5
4
  if [ "$1" == "stable" ]; then
6
5
  npm version $(npm view @momo-kits/foundation@stable version)
7
6
  npm version patch
8
- npm publish --registry https://registry.npmjs.org/ --tag stable --access=public
7
+ npm publish --tag stable --access=public
9
8
  elif [ "$1" == "latest" ]; then
10
9
  npm version $(npm view @momo-kits/foundation@latest version)
11
10
  npm version prerelease --preid=rc
12
- npm publish --registry https://registry.npmjs.org/ --tag latest --access=public
11
+ npm publish --tag latest --access=public
13
12
  else
14
13
  npm version $(npm view @momo-kits/foundation@beta version)
15
14
  npm version prerelease --preid=beta
16
- npm publish --registry https://registry.npmjs.org/ --tag beta --access=public
15
+ npm publish --tag beta --access=public
17
16
  fi
18
17
  PACKAGE_NAME=$(npm pkg get name)
19
18
  NEW_PACKAGE_VERSION=$(npm pkg get version)