@momo-kits/foundation 0.110.1-optimize.7 → 0.110.1-optimize.9

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,16 +1,14 @@
1
- import React, {useCallback, useContext, useEffect, useRef} from 'react';
1
+ import React, {useRef, useEffect, useCallback, useContext} from 'react';
2
2
  import {
3
3
  Animated,
4
4
  Dimensions,
5
- Easing,
6
5
  KeyboardAvoidingView,
7
- Modal,
8
6
  PanResponder,
9
7
  Platform,
10
- Pressable,
11
8
  StyleSheet,
12
9
  TouchableOpacity,
13
10
  View,
11
+ Modal,
14
12
  } from 'react-native';
15
13
  import {useSafeAreaInsets} from 'react-native-safe-area-context';
16
14
  import {ApplicationContext} from './index';
@@ -35,7 +33,6 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
35
33
  useKeyboardAvoidingView = true,
36
34
  keyboardVerticalOffset,
37
35
  }: BottomSheetParams = props.route.params;
38
-
39
36
  const pan = useRef(
40
37
  new Animated.ValueXY({
41
38
  y: heightDevice,
@@ -43,9 +40,6 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
43
40
  })
44
41
  ).current;
45
42
 
46
- const customEasingOpen = Easing.bezier(0.05, 0.7, 0.1, 1);
47
- const customEasingClose = Easing.bezier(0.3, 0.0, 0.8, 0.15);
48
-
49
43
  const panResponder = useRef(
50
44
  PanResponder.create({
51
45
  onStartShouldSetPanResponder: () => draggable,
@@ -72,7 +66,6 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
72
66
  },
73
67
  })
74
68
  ).current;
75
-
76
69
  let Container: any = View;
77
70
  if (useNativeModal) {
78
71
  Container = Modal;
@@ -89,10 +82,8 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
89
82
  Animated.timing(pan, {
90
83
  toValue: {x: 0, y: 0},
91
84
  useNativeDriver: false,
92
- easing: customEasingOpen,
93
- duration: 500,
85
+ duration: 150,
94
86
  }).start();
95
-
96
87
  return () => {
97
88
  props.route.params?.onDismiss?.(action.current);
98
89
  };
@@ -111,8 +102,7 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
111
102
  Animated.timing(pan, {
112
103
  toValue: {x: 0, y: heightDevice},
113
104
  useNativeDriver: false,
114
- easing: customEasingClose,
115
- duration: 300,
105
+ duration: 200,
116
106
  }).start(() => {
117
107
  navigator?.pop();
118
108
  });
@@ -181,7 +171,7 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
181
171
  onRequestClose={() => {
182
172
  onDismiss();
183
173
  }}
184
- style={StyleSheet.absoluteFillObject}>
174
+ style={styles.overlay}>
185
175
  <KeyboardAvoidingView
186
176
  behavior={Platform.select({
187
177
  ios: 'padding',
@@ -190,30 +180,15 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
190
180
  keyboardVerticalOffset={keyboardVerticalOffset ?? -20}
191
181
  enabled={useKeyboardAvoidingView}
192
182
  style={[Styles.flex, {justifyContent: 'flex-end'}]}>
193
- <Pressable
194
- style={StyleSheet.absoluteFillObject}
183
+ <TouchableOpacity
184
+ style={Styles.flex}
185
+ activeOpacity={1}
195
186
  onPress={() => {
196
187
  action.current = 'touch';
197
188
  onDismiss();
198
- }}>
199
- <Animated.View
200
- style={[
201
- styles.overlay,
202
- {
203
- opacity: pan.y.interpolate({
204
- inputRange: [0, heightDevice],
205
- outputRange: [1, 0],
206
- extrapolate: 'clamp',
207
- }),
208
- },
209
- ]}
210
- />
211
- </Pressable>
212
-
213
- <Animated.View
214
- style={{
215
- transform: pan.getTranslateTransform(),
216
- }}>
189
+ }}
190
+ />
191
+ <Animated.View style={{transform: pan.getTranslateTransform()}}>
217
192
  {renderHeader()}
218
193
  <View style={{backgroundColor: backgroundColor}}>
219
194
  <Screen
@@ -233,8 +208,8 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
233
208
 
234
209
  const styles = StyleSheet.create({
235
210
  overlay: {
236
- flex: 1,
237
- backgroundColor: 'rgba(0, 0, 0, 0.6)',
211
+ ...StyleSheet.absoluteFillObject,
212
+ justifyContent: 'flex-end',
238
213
  },
239
214
  indicator: {
240
215
  width: 40,
@@ -43,14 +43,23 @@ const HeaderBackground: React.FC<HeaderBackgroundProps> = ({
43
43
  <View style={Styles.flex}>
44
44
  <Animated.View
45
45
  style={[
46
- Styles.flex,
47
46
  useShadowHeader ? styles.shadowHeader : styles.dividerHeader,
48
47
  {
49
48
  backgroundColor: theme.colors.background.surface,
50
49
  opacity: opacityBackground,
51
- overflow: 'hidden',
50
+ height: '100%',
51
+ width: '100%',
52
52
  },
53
- ]}>
53
+ ]}
54
+ />
55
+ <Animated.View
56
+ style={{
57
+ position: 'absolute',
58
+ zIndex: 1,
59
+ height: '100%',
60
+ width: '100%',
61
+ overflow: 'hidden',
62
+ }}>
54
63
  {theme?.assets?.headerBackground && (
55
64
  <Image
56
65
  style={styles.headerBackground}
@@ -99,8 +99,18 @@ const HeaderExtendHeader: React.FC<{
99
99
  ? styles.shadowHeader
100
100
  : styles.dividerHeader,
101
101
  {
102
+ position: 'absolute',
103
+ width: '100%',
104
+ zIndex: 1,
105
+ height: heightHeader,
102
106
  backgroundColor: theme.colors.background.surface,
103
107
  opacity: opacityBackground,
108
+ },
109
+ ]}
110
+ />
111
+ <Animated.View
112
+ style={[
113
+ {
104
114
  position: 'absolute',
105
115
  width: '100%',
106
116
  height: heightHeader,
@@ -136,7 +146,6 @@ const HeaderExtendHeader: React.FC<{
136
146
  </LinearGradientAnimated>
137
147
  )}
138
148
  </Animated.View>
139
-
140
149
  <Animated.View
141
150
  style={{
142
151
  justifyContent: 'flex-end',
@@ -185,6 +194,16 @@ const HeaderExtendHeader: React.FC<{
185
194
  height: heightHeader,
186
195
  backgroundColor: theme.colors.background.surface,
187
196
  opacity: opacityBackground,
197
+ },
198
+ ]}
199
+ />
200
+ <Animated.View
201
+ style={[
202
+ {
203
+ position: 'absolute',
204
+ width: '100%',
205
+ zIndex: 1,
206
+ height: heightHeader,
188
207
  overflow: 'hidden',
189
208
  },
190
209
  ]}>
@@ -1,6 +1,6 @@
1
1
  import {BackHandler, StyleSheet, View} from 'react-native';
2
2
  import {HeaderBackProps} from '../types';
3
- import React, {useContext, useEffect} from 'react';
3
+ import React, {useCallback, useContext, useEffect} from 'react';
4
4
  import {ApplicationContext, MiniAppContext} from '../index';
5
5
  import {PopupNotify} from '../../Popup';
6
6
  import {NavigationButton} from './NavigationButton';
@@ -17,26 +17,26 @@ const HeaderLeft: React.FC<HeaderBackProps> = ({
17
17
  const context = useContext<any>(MiniAppContext);
18
18
  const {navigator} = useContext(ApplicationContext);
19
19
 
20
- const goBackSafe = () => {
21
- const goBack = () => {
22
- const canGoBack = navigator?.ref?.current?.canGoBack?.();
23
- const currentRoute = navigator?.ref?.current?.getCurrentRoute?.();
24
- context?.autoTracking?.({
25
- ...context,
26
- componentName: 'IconButton',
27
- componentId: 'navigation_back',
28
- screenName: currentRoute?.params?.screen?.name ?? currentRoute?.name,
29
- });
20
+ const goBack = useCallback(() => {
21
+ const canGoBack = navigator?.ref?.current?.canGoBack?.();
22
+ const currentRoute = navigator?.ref?.current?.getCurrentRoute?.();
23
+ context?.autoTracking?.({
24
+ ...context,
25
+ componentName: 'IconButton',
26
+ componentId: 'navigation_back',
27
+ screenName: currentRoute?.params?.screen?.name ?? currentRoute?.name,
28
+ });
30
29
 
31
- if (canGoBack) {
32
- navigator?.ref?.current?.goBack?.();
33
- } else if (navigator?.maxApi) {
34
- navigator?.maxApi?.dismiss?.(navigator?.dismissData);
35
- } else {
36
- (global as any)?.miniAppApi?.dispatch?.('dismiss', context);
37
- }
38
- };
30
+ if (canGoBack) {
31
+ navigator?.ref?.current?.goBack?.();
32
+ } else if (navigator?.maxApi) {
33
+ navigator?.maxApi?.dismiss?.(navigator?.dismissData);
34
+ } else {
35
+ (global as any)?.miniAppApi?.dispatch?.('dismiss', context);
36
+ }
37
+ }, [navigator, context]);
39
38
 
39
+ const goBackSafe = useCallback(() => {
40
40
  if (preventBack) {
41
41
  navigator?.showModal({
42
42
  screen: () => (
@@ -61,7 +61,7 @@ const HeaderLeft: React.FC<HeaderBackProps> = ({
61
61
  }
62
62
  }
63
63
  return true;
64
- };
64
+ }, [preventBack, onPressLeftHeader, onBackHandler, goBack]);
65
65
 
66
66
  useEffect(() => {
67
67
  const backHandler = BackHandler.addEventListener(
@@ -1,10 +1,10 @@
1
1
  import React, {useContext, useEffect, useRef} from 'react';
2
2
  import {
3
- Animated,
4
3
  KeyboardAvoidingView,
5
4
  Platform,
6
5
  Pressable,
7
6
  StyleSheet,
7
+ View,
8
8
  } from 'react-native';
9
9
 
10
10
  import {ApplicationContext} from './index';
@@ -22,11 +22,8 @@ const ModalScreen: React.FC<any> = props => {
22
22
 
23
23
  const Modal: React.FC<ModalParams> = props => {
24
24
  const {navigator} = useContext(ApplicationContext);
25
- const {screen, barrierDismissible, modalStyle} = props.route.params;
25
+ const {screen, barrierDismissible} = props.route.params;
26
26
  const Component = useRef(screen).current;
27
- const opacity = useRef(new Animated.Value(0)).current;
28
- const scale = useRef(new Animated.Value(0.8)).current;
29
-
30
27
  const navigation = new Navigation(props.navigation);
31
28
  const params = {
32
29
  ...props.route.params,
@@ -35,68 +32,65 @@ const Modal: React.FC<ModalParams> = props => {
35
32
  delete params.screen;
36
33
 
37
34
  useEffect(() => {
38
- Animated.parallel([
39
- Animated.timing(opacity, {
40
- toValue: 1,
41
- duration: 400,
42
- useNativeDriver: true,
43
- }),
44
- Animated.spring(scale, {
45
- toValue: 1,
46
- useNativeDriver: true,
47
- }),
48
- ]).start();
49
-
50
35
  return () => {
51
36
  props.route.params?.onDismiss?.();
52
37
  };
53
- }, [opacity, scale]);
38
+ }, []);
54
39
 
55
40
  const onDismiss = () => {
56
41
  if (barrierDismissible) {
57
42
  return;
58
43
  }
59
- Animated.parallel([
60
- Animated.timing(opacity, {
61
- toValue: 0,
62
- duration: 250,
63
- useNativeDriver: true,
64
- }),
65
- Animated.timing(scale, {
66
- toValue: 0.8,
67
- duration: 250,
68
- useNativeDriver: true,
69
- }),
70
- ]).start(() => {
71
- navigator?.pop();
72
- });
44
+ navigator?.pop();
73
45
  };
74
46
 
75
47
  return (
76
48
  <KeyboardAvoidingView
77
- style={Styles.flexCenter}
49
+ style={Styles.flex}
78
50
  behavior={Platform.OS === 'ios' ? 'padding' : 'height'}>
79
- <Pressable style={StyleSheet.absoluteFillObject} onPress={onDismiss}>
80
- <Animated.View style={[styles.overlayContent, {opacity}]} />
81
- </Pressable>
82
- <Animated.View
83
- style={[
84
- {
85
- opacity,
86
- transform: [{scale}],
87
- },
88
- modalStyle,
89
- ]}>
90
- <Component {...params} />
91
- </Animated.View>
51
+ <View style={styles.container}>
52
+ <Pressable
53
+ style={styles.modalSpaceHorizontal}
54
+ onPress={() => onDismiss()}
55
+ />
56
+ <View style={styles.modalCenterStage}>
57
+ <Pressable
58
+ style={styles.modalSpaceVertical}
59
+ onPress={() => onDismiss()}
60
+ />
61
+ <View style={styles.modalContent}>
62
+ <Component {...params} />
63
+ </View>
64
+ <Pressable
65
+ style={styles.modalSpaceVertical}
66
+ onPress={() => onDismiss()}
67
+ />
68
+ </View>
69
+ <Pressable
70
+ style={styles.modalSpaceHorizontal}
71
+ onPress={() => onDismiss()}
72
+ />
73
+ </View>
92
74
  </KeyboardAvoidingView>
93
75
  );
94
76
  };
95
77
 
96
78
  const styles = StyleSheet.create({
97
- overlayContent: {
79
+ container: {flex: 1, flexDirection: 'row'},
80
+ modalContent: {
81
+ maxWidth: '100%',
82
+ maxHeight: '80%',
83
+ },
84
+ modalCenterStage: {
85
+ maxWidth: '90%',
86
+ },
87
+ modalSpaceHorizontal: {
88
+ flex: 1,
89
+ minWidth: '5%',
90
+ },
91
+ modalSpaceVertical: {
98
92
  flex: 1,
99
- backgroundColor: 'rgba(0, 0, 0, 0.6)',
93
+ minHeight: '10%',
100
94
  },
101
95
  });
102
96
 
@@ -1,7 +1,7 @@
1
1
  import {EventArg} from '@react-navigation/core';
2
2
  import {StackNavigationOptions} from '@react-navigation/stack';
3
3
  import React, {ReactNode} from 'react';
4
- import {Animated, ViewProps, ViewStyle} from 'react-native';
4
+ import {Animated, ViewProps} from 'react-native';
5
5
  import {PopupNotifyProps} from '../Popup/types';
6
6
  import Localize from './Localize';
7
7
  import Navigation from './Navigation';
@@ -122,7 +122,6 @@ export type ModalParams = {
122
122
  screen: React.ComponentType;
123
123
  onDismiss?: () => void;
124
124
  barrierDismissible?: boolean;
125
- modalStyle?: ViewStyle;
126
125
  };
127
126
 
128
127
  export type BottomSheetParams = {
@@ -55,6 +55,21 @@ const getModalOptions = (): StackNavigationOptions => {
55
55
  cardStyle: {backgroundColor: 'transparent'},
56
56
  cardOverlayEnabled: true,
57
57
  animationEnabled: false,
58
+ cardStyleInterpolator: ({current: {progress}}) => ({
59
+ cardStyle: {
60
+ opacity: progress.interpolate({
61
+ inputRange: [0, 0.5, 0.9, 1],
62
+ outputRange: [0, 0.25, 0.7, 1],
63
+ }),
64
+ },
65
+ overlayStyle: {
66
+ opacity: progress.interpolate({
67
+ inputRange: [0, 0.5, 0.9, 1],
68
+ outputRange: [0, 0.2, 0.4, 0.6],
69
+ extrapolate: 'clamp',
70
+ }),
71
+ },
72
+ }),
58
73
  };
59
74
  };
60
75
 
@@ -154,10 +169,19 @@ const exportHeaderTitle = (
154
169
  return {};
155
170
  };
156
171
 
172
+ const formatNameLength = (name = '') => {
173
+ let formattedName = name;
174
+ if (formattedName.length > 100) {
175
+ formattedName = formattedName.substring(0, 100);
176
+ }
177
+ return formattedName;
178
+ };
179
+
157
180
  export {
158
181
  getStackOptions,
159
182
  getDialogOptions,
160
183
  getModalOptions,
161
184
  getOptions,
162
185
  exportHeaderTitle,
186
+ formatNameLength,
163
187
  };
@@ -1,11 +1,5 @@
1
1
  import React, {useContext, useEffect, useRef, useState} from 'react';
2
- import {
3
- Dimensions,
4
- ScrollView,
5
- StyleSheet,
6
- TouchableOpacity,
7
- View,
8
- } from 'react-native';
2
+ import {ScrollView, StyleSheet, TouchableOpacity, View} from 'react-native';
9
3
  import {ApplicationContext, MiniAppContext} from '../Application';
10
4
  import {Button} from '../Button';
11
5
  import {Radius, Spacing, Styles} from '../Consts';
@@ -28,8 +22,6 @@ const PopupNotify: React.FC<PopupNotifyProps> = ({
28
22
  const context = useContext<any>(MiniAppContext);
29
23
  const {theme, navigator, translate} = useContext(ApplicationContext);
30
24
  const [scrollContent, setScrollContent] = useState(false);
31
- const {width: widthDevice} = Dimensions.get('window');
32
-
33
25
  const closeAction = useRef('touch_outside');
34
26
  let descriptionStyle = {};
35
27
  let Description: any = View;
@@ -198,10 +190,7 @@ const PopupNotify: React.FC<PopupNotifyProps> = ({
198
190
  accessibilityLabel={'popup_notify'}
199
191
  style={[
200
192
  styles.container,
201
- {
202
- backgroundColor: theme.colors.background.surface,
203
- width: widthDevice - Spacing.XL * 2,
204
- },
193
+ {backgroundColor: theme.colors.background.surface},
205
194
  ]}>
206
195
  {!!image && <Image source={{uri: image}} style={styles.image} />}
207
196
  <View style={styles.content}>
@@ -245,6 +234,7 @@ const PopupNotify: React.FC<PopupNotifyProps> = ({
245
234
  const styles = StyleSheet.create({
246
235
  container: {
247
236
  borderRadius: Radius.L,
237
+ minWidth: '100%',
248
238
  },
249
239
  image: {
250
240
  borderTopLeftRadius: Radius.L,
@@ -1,5 +1,5 @@
1
1
  import React, {useContext, useEffect, useRef} from 'react';
2
- import {Dimensions, StyleSheet, TouchableOpacity, View} from 'react-native';
2
+ import {StyleSheet, TouchableOpacity, View} from 'react-native';
3
3
  import {PopupPromotionProps} from './types';
4
4
  import {ApplicationContext, MiniAppContext} from '../Application';
5
5
  import {Image} from '../Image';
@@ -13,7 +13,6 @@ const PopupPromotion: React.FC<PopupPromotionProps> = ({
13
13
  }) => {
14
14
  const context = useContext<any>(MiniAppContext);
15
15
  const {theme, navigator} = useContext(ApplicationContext);
16
- const {width: widthDevice} = Dimensions.get('window');
17
16
  const closeAction = useRef('touch_outside');
18
17
 
19
18
  /**
@@ -84,12 +83,7 @@ const PopupPromotion: React.FC<PopupPromotionProps> = ({
84
83
  source={{
85
84
  uri: image,
86
85
  }}
87
- style={[
88
- styles.container,
89
- {
90
- width: widthDevice - Spacing.XL * 2,
91
- },
92
- ]}
86
+ style={styles.container}
93
87
  />
94
88
  {buildCloseIcon()}
95
89
  </View>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/foundation",
3
- "version": "0.110.1-optimize.7",
3
+ "version": "0.110.1-optimize.9",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {},