@momo-kits/foundation 0.92.1-tracking.2 → 0.92.1-tracking.21

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.
@@ -58,11 +58,9 @@ const BottomTab: React.FC<BottomTabProps> = ({
58
58
  });
59
59
  }, []);
60
60
 
61
- const accessibilityID = getAccessibilityID("tbr_main_bottom")
62
-
63
61
  return (
64
62
  <Tab.Navigator
65
- {...accessibilityID}
63
+ {...getAccessibilityID('tbr_main_bottom')}
66
64
  initialRouteName={initialRouteName}
67
65
  backBehavior={'firstRoute'}
68
66
  tabBarOptions={{
@@ -75,10 +73,9 @@ const BottomTab: React.FC<BottomTabProps> = ({
75
73
  },
76
74
  }}>
77
75
  {tabs.map(item => {
78
- const itemAccessibilityID = getAccessibilityID(`btn_tabbar_${item.name}`)
79
76
  return (
80
77
  <Tab.Screen
81
- {...itemAccessibilityID}
78
+ {...getAccessibilityID(`btn_tabbar_${item.name}`)}
82
79
  key={item.name}
83
80
  name={item.name}
84
81
  component={TabScreen}
@@ -15,7 +15,7 @@ import {
15
15
  View,
16
16
  ViewStyle,
17
17
  } from 'react-native';
18
- import {ApplicationContext, MiniAppContext} from './index';
18
+ import {ApplicationContext} from './index';
19
19
  import {Colors, Radius, Spacing, Styles} from '../Consts';
20
20
  import {Image} from '../Image';
21
21
  import {
@@ -29,7 +29,11 @@ import {scaleSize, Text} from '../Text';
29
29
  import {Icon} from '../Icon';
30
30
  import {PopupNotify} from '../Popup';
31
31
  import {Badge, BadgeDot} from '../Badge';
32
- import {getAccessibilityID} from "./utils";
32
+ import {getAccessibilityID} from './utils';
33
+
34
+ const {
35
+ MiniAppContext,
36
+ } = require('react-native/Libraries/Components/ScreenContext');
33
37
 
34
38
  const NavigationButton: React.FC<NavigationButtonProps> = ({
35
39
  icon,
@@ -38,7 +42,7 @@ const NavigationButton: React.FC<NavigationButtonProps> = ({
38
42
  useBorder = true,
39
43
  badgeType,
40
44
  badgeValue,
41
- accessibilityID = ''
45
+ accessibilityID = '',
42
46
  }) => {
43
47
  const {theme} = useContext(ApplicationContext);
44
48
  let buttonStyle: ViewStyle = {backgroundColor: '#00000066'};
@@ -65,9 +69,10 @@ const NavigationButton: React.FC<NavigationButtonProps> = ({
65
69
  }
66
70
  }, [badgeType, badgeValue]);
67
71
 
68
- const ID = getAccessibilityID(accessibilityID)
69
72
  return (
70
- <View {...ID} style={{width: scaleSize(28)}}>
73
+ <View
74
+ {...getAccessibilityID(accessibilityID)}
75
+ style={{width: scaleSize(28)}}>
71
76
  <TouchableOpacity
72
77
  style={[styles.navigationButton, buttonStyle]}
73
78
  onPress={onPress}>
@@ -93,6 +98,7 @@ const HeaderTitle: React.FC<any> = props => {
93
98
  return (
94
99
  <Animated.Text
95
100
  {...props}
101
+ {...getAccessibilityID('title_navigation_header')}
96
102
  style={[
97
103
  styles.title,
98
104
  {fontFamily: `${theme.font}-Bold`, opacity, color: props.tintColor},
@@ -107,7 +113,7 @@ const HeaderLeft: React.FC<HeaderBackProps> = ({
107
113
  onPressLeftHeader,
108
114
  useBorder,
109
115
  }) => {
110
- const context = useContext(MiniAppContext);
116
+ const context = useContext<any>(MiniAppContext);
111
117
  const {navigator} = useContext(ApplicationContext);
112
118
 
113
119
  useEffect(() => {
@@ -131,7 +137,7 @@ const HeaderLeft: React.FC<HeaderBackProps> = ({
131
137
  icon_name: 'back',
132
138
  };
133
139
  navigator?.maxApi?.showToastDebug?.({
134
- appId: context.appId,
140
+ appId: `auto - ${context.appId}`,
135
141
  message: 'service_icon_clicked',
136
142
  params,
137
143
  });
@@ -170,9 +176,9 @@ const HeaderLeft: React.FC<HeaderBackProps> = ({
170
176
  return true;
171
177
  };
172
178
  return (
173
- <View style={styles.headerLeft}>
179
+ <View style={styles.headerLeft}>
174
180
  <NavigationButton
175
- accessibilityID = "btn_navigation_back"
181
+ accessibilityID="btn_navigation_back"
176
182
  icon="ic_back"
177
183
  tintColor={tintColor}
178
184
  onPress={goBackSafe}
@@ -246,7 +252,10 @@ const HeaderCustom: React.FC<TitleCustomProps> = ({
246
252
  )}
247
253
  </View>
248
254
  <View style={[Styles.flex, {paddingHorizontal: 8}]}>
249
- <Text typography="header_default_bold" color={tintColor}>
255
+ <Text
256
+ {...getAccessibilityID('title_navigation_header')}
257
+ typography="header_default_bold"
258
+ color={tintColor}>
250
259
  {title}
251
260
  </Text>
252
261
  <Text typography="description_default_regular" color={tintColor}>
@@ -293,10 +302,10 @@ const HeaderToolkitAction: React.FC<any> = ({
293
302
  tintColor,
294
303
  pinnedTool,
295
304
  runtimeTools = [],
296
- preventBack,
305
+ preventClose,
297
306
  }) => {
298
307
  const {theme, navigator} = useContext(ApplicationContext);
299
- const miniContext = useContext(MiniAppContext);
308
+ const miniContext = useContext<any>(MiniAppContext);
300
309
  const [toolConfig, setToolConfig] = useState<any>();
301
310
  const {onAction} = toolConfig ?? {};
302
311
 
@@ -340,15 +349,15 @@ const HeaderToolkitAction: React.FC<any> = ({
340
349
  };
341
350
 
342
351
  const onClose = () => {
343
- if (preventBack) {
352
+ if (preventClose) {
344
353
  navigator?.showModal({
345
354
  screen: () => (
346
355
  <PopupNotify
347
- {...preventBack}
356
+ {...preventClose}
348
357
  primary={{
349
- title: preventBack.primary.title,
358
+ title: preventClose.primary.title,
350
359
  onPress: () => {
351
- preventBack?.primary.onPress();
360
+ preventClose?.primary.onPress();
352
361
  navigator?.maxApi?.dispatchFunction?.(
353
362
  'dismiss',
354
363
  undefined,
@@ -372,7 +381,7 @@ const HeaderToolkitAction: React.FC<any> = ({
372
381
  if (pinTool)
373
382
  return (
374
383
  <NavigationButton
375
- accessibilityID = "btn_navigation_pin"
384
+ accessibilityID="btn_navigation_pin"
376
385
  icon={pinTool.icon as string}
377
386
  tintColor={tintColor}
378
387
  badgeValue={badgeValue}
@@ -403,14 +412,14 @@ const HeaderToolkitAction: React.FC<any> = ({
403
412
  },
404
413
  ]}>
405
414
  <TouchableOpacity
406
- {...getAccessibilityID("btn_navigation_more")}
407
- onPress={onMore}>
415
+ {...getAccessibilityID('btn_navigation_more')}
416
+ onPress={onMore}>
408
417
  <Icon color={tintColor} source="navigation_more_horiz" size={20} />
409
418
  </TouchableOpacity>
410
419
  <View style={[styles.divider, {backgroundColor: tintColor}]} />
411
420
  <TouchableOpacity
412
- {...getAccessibilityID("btn_navigation_close")}
413
- onPress={onClose}>
421
+ {...getAccessibilityID('btn_navigation_close')}
422
+ onPress={onClose}>
414
423
  <Icon
415
424
  color={tintColor}
416
425
  source="16_navigation_close_circle"
@@ -428,7 +437,7 @@ const HeaderToolkitAction: React.FC<any> = ({
428
437
  const HeaderAnimated: React.FC<HeaderAnimatedProps> = ({
429
438
  animatedValue,
430
439
  image,
431
- onPress,
440
+ children,
432
441
  }) => {
433
442
  const scale = animatedValue.interpolate({
434
443
  inputRange: [-300, 0, 300],
@@ -447,21 +456,21 @@ const HeaderAnimated: React.FC<HeaderAnimatedProps> = ({
447
456
  });
448
457
 
449
458
  return (
450
- <TouchableOpacity onPress={onPress}>
451
- <Animated.View
452
- style={{
453
- height: 210,
454
- opacity: opacity,
455
- transform: [{scale}, {translateY}],
456
- }}>
459
+ <Animated.View
460
+ style={{
461
+ height: 210,
462
+ opacity: opacity,
463
+ transform: [{scale}, {translateY}],
464
+ }}>
465
+ {children ?? (
457
466
  <Image
458
467
  source={{
459
468
  uri: image,
460
469
  }}
461
470
  style={{width: '100%', height: '100%'}}
462
471
  />
463
- </Animated.View>
464
- </TouchableOpacity>
472
+ )}
473
+ </Animated.View>
465
474
  );
466
475
  };
467
476
 
@@ -1,29 +1,21 @@
1
- import React, {useContext, useEffect, useMemo, useRef, useState} from 'react';
1
+ import React, {useContext, useEffect, useRef} from 'react';
2
2
  import {
3
- Dimensions,
4
- Keyboard,
5
3
  KeyboardAvoidingView,
6
4
  Platform,
7
5
  Pressable,
8
6
  StyleSheet,
7
+ TouchableOpacity,
9
8
  View,
10
9
  } from 'react-native';
10
+ import {Modalize} from 'react-native-modalize';
11
11
  import {SafeAreaView, useSafeAreaInsets} from 'react-native-safe-area-context';
12
- import {
13
- BottomSheetBackdrop,
14
- BottomSheetModal,
15
- BottomSheetView,
16
- } from '@gorhom/bottom-sheet';
12
+
13
+ import {ApplicationContext} from '.';
14
+ import {Radius, Spacing, Styles} from '../Consts';
15
+ import {Icon} from '../Icon';
16
+ import {Text} from '../Text';
17
17
  import Navigation from './Navigation';
18
18
  import {BottomSheetParams, ModalParams} from './types';
19
- import {Radius, Spacing, Styles} from '../Consts';
20
- import {
21
- ApplicationContext,
22
- HeaderRightAction,
23
- NavigationButton,
24
- NavigationContainer,
25
- } from './index';
26
- import {HeaderBackground, HeaderLeft, HeaderTitle} from './Components';
27
19
 
28
20
  const ModalScreen: React.FC<any> = props => {
29
21
  /**
@@ -92,141 +84,88 @@ const Modal: React.FC<ModalParams> = props => {
92
84
  };
93
85
 
94
86
  const BottomSheet: React.FC<BottomSheetParams> = props => {
95
- const insets = useSafeAreaInsets();
96
87
  const {theme, navigator} = useContext(ApplicationContext);
97
- const [keyboardSnap, setKeyboardSnap] = useState(0);
98
- const {screen, options, snapPoint, indicatorColor}: BottomSheetParams =
99
- props.route.params;
100
- const Component = useRef(screen).current;
88
+ const {
89
+ screen: Screen,
90
+ options,
91
+ footerComponent,
92
+ flatListProps,
93
+ }: BottomSheetParams = props.route.params;
94
+
101
95
  const navigation = new Navigation(props.navigation, theme);
96
+
102
97
  const params = {
103
98
  ...props.route.params,
104
99
  navigation,
105
100
  };
106
101
 
107
102
  delete params.screen;
108
-
109
- const snapPoints = useMemo(() => {
110
- if (snapPoint) {
111
- const current = parseInt(snapPoint) + keyboardSnap * 100;
112
- return [`${current}%`];
113
- }
114
- return ['50%', '70%', '90%'];
115
- }, [keyboardSnap]);
116
-
117
- const bottomSheetRef = useRef<any>(null);
118
- const mountedRef = useRef(true);
119
-
120
- let backgroundColor = theme.colors.background.default;
121
- let bottomInset = keyboardSnap * Dimensions.get('window').height;
122
- if (bottomInset > 16) {
123
- bottomInset -= 16;
124
- }
125
- if (options?.surface) {
126
- backgroundColor = theme.colors.background.surface;
127
- }
103
+ const modalizeRef = useRef<Modalize>(null);
128
104
 
129
105
  useEffect(() => {
130
- const keyboardDidShow = Keyboard.addListener('keyboardDidShow', e => {
131
- setKeyboardSnap(
132
- e.endCoordinates.height / Dimensions.get('window').height,
133
- );
134
- bottomSheetRef.current?.expand();
135
- });
136
-
137
- const keyboardDidHide = Keyboard.addListener('keyboardDidHide', () => {
138
- setKeyboardSnap(0);
139
- });
140
-
141
- bottomSheetRef.current?.present();
142
- return () => {
143
- mountedRef.current = false;
144
- keyboardDidShow.remove();
145
- keyboardDidHide.remove();
146
- };
106
+ modalizeRef.current?.open();
147
107
  }, []);
148
108
 
149
- const backdropComponent = (backdropProps: any) => (
150
- <BottomSheetBackdrop
151
- disappearsOnIndex={-1}
152
- appearsOnIndex={0}
153
- {...backdropProps}
154
- />
155
- );
109
+ const handleClose = () => {
110
+ modalizeRef?.current?.close();
111
+ };
156
112
 
157
113
  return (
158
114
  <SafeAreaView style={Styles.flex}>
159
- <BottomSheetModal
160
- ref={bottomSheetRef}
161
- snapPoints={snapPoints}
162
- onDismiss={() => {
163
- if (mountedRef.current) {
164
- navigator?.pop();
165
- }
115
+ <Modalize
116
+ keyboardAvoidingOffset={-20}
117
+ adjustToContentHeight
118
+ closeOnOverlayTap
119
+ closeSnapPointStraightEnabled
120
+ onClosed={() => {
121
+ navigator?.pop();
166
122
  }}
167
- bottomInset={Platform.OS === 'ios' ? bottomInset : 0}
168
- handleComponent={null}
169
- backdropComponent={backdropComponent}>
170
- <BottomSheetView>
171
- <View style={[styles.sheetContainer, {backgroundColor}]}>
172
- <View style={styles.indicatorContainer}>
173
- <View
174
- style={[
175
- styles.indicator,
176
- {backgroundColor: theme.colors.text.disable},
177
- ]}
178
- />
179
- </View>
180
- <NavigationContainer
181
- maxApi={navigator?.maxApi}
182
- theme={{
183
- ...theme,
184
- assets: {...theme.assets, headerBackground: undefined},
185
- }}
186
- screen={props => <Component {...props} {...params} />}
187
- options={{
188
- ...options,
189
- ...{
190
- headerLeft: (props: any) => {
191
- if (props.canGoBack) {
192
- return <HeaderLeft {...props} useBorder={false} />;
193
- }
194
- },
195
- headerTitle: (props: any) => {
196
- return <HeaderTitle {...props} />;
197
- },
198
- headerTintColor: theme.colors.text.default,
199
- headerBackground: () => (
200
- <HeaderBackground backgroundColor={backgroundColor} />
201
- ),
202
- headerTransparent: false,
203
- },
204
- headerTitleAlign: 'center',
205
- headerRight: props => (
206
- <HeaderRightAction>
207
- <NavigationButton
208
- {...props}
209
- icon="24_navigation_close"
210
- useBorder={false}
211
- onPress={() => bottomSheetRef.current?.dismiss()}
212
- />
213
- </HeaderRightAction>
214
- ),
215
- }}
216
- />
217
- <View
218
- style={{
219
- height: Math.min(insets.bottom, 20),
220
- backgroundColor: indicatorColor ?? backgroundColor,
221
- }}
222
- />
223
- </View>
224
- </BottomSheetView>
225
- </BottomSheetModal>
123
+ ref={modalizeRef}
124
+ withHandle={false}
125
+ flatListProps={flatListProps}
126
+ HeaderComponent={headerDefault(
127
+ options?.title ?? options?.customTitle?.title ?? '',
128
+ handleClose,
129
+ )}
130
+ FooterComponent={footerDefault(footerComponent)}>
131
+ <View style={styles.bottomSheetContainer}>
132
+ <Screen {...props} {...params} />
133
+ </View>
134
+ </Modalize>
226
135
  </SafeAreaView>
227
136
  );
228
137
  };
229
138
 
139
+ const headerDefault = (title: string, onClose: () => void) => {
140
+ return (
141
+ <View style={styles.header}>
142
+ <Text
143
+ style={styles.textOption}
144
+ numberOfLines={2}
145
+ typography="header_default_bold">
146
+ {title ?? ''}
147
+ </Text>
148
+ <TouchableOpacity style={styles.buttonClose} onPress={onClose}>
149
+ <Icon source="navigation_close" />
150
+ </TouchableOpacity>
151
+ </View>
152
+ );
153
+ };
154
+
155
+ const footerDefault = (footerComponent: React.ReactNode) => {
156
+ const insets = useSafeAreaInsets();
157
+ if (!footerComponent) return;
158
+ return (
159
+ <View
160
+ style={{
161
+ marginBottom: Math.min(insets.bottom, 21) + Spacing.S,
162
+ paddingHorizontal: 12,
163
+ }}>
164
+ {footerComponent}
165
+ </View>
166
+ );
167
+ };
168
+
230
169
  const styles = StyleSheet.create({
231
170
  container: {flex: 1, flexDirection: 'row'},
232
171
  modalContent: {
@@ -263,6 +202,43 @@ const styles = StyleSheet.create({
263
202
  height: 4,
264
203
  borderRadius: Radius.S,
265
204
  },
205
+ bottomSheetContainer: {
206
+ width: '100%',
207
+ backgroundColor: 'white',
208
+ borderTopRightRadius: 16,
209
+ borderTopLeftRadius: 16,
210
+ },
211
+ header: {
212
+ height: 50,
213
+ width: '100%',
214
+ alignItems: 'center',
215
+ justifyContent: 'center',
216
+ },
217
+ textOption: {
218
+ fontSize: 16,
219
+ color: '#303233',
220
+ textAlign: 'center',
221
+ fontWeight: 'bold',
222
+ paddingHorizontal: 60,
223
+ },
224
+ imageOption: {
225
+ height: 1,
226
+ backgroundColor: '#ebebeb',
227
+ width: '100%',
228
+ position: 'absolute',
229
+ bottom: 1,
230
+ },
231
+ buttonClose: {
232
+ padding: 12,
233
+ position: 'absolute',
234
+ right: 0,
235
+ },
236
+ icon: {
237
+ width: 24,
238
+ height: 24,
239
+ tintColor: '#303233',
240
+ backgroundColor: 'red',
241
+ },
266
242
  });
267
243
 
268
244
  export default ModalScreen;
@@ -1,10 +1,10 @@
1
1
  import React, {useContext, useEffect, useRef, useState} from 'react';
2
- import {BottomSheetModalProvider} from '@gorhom/bottom-sheet';
3
2
  import {SafeAreaProvider} from 'react-native-safe-area-context';
4
3
  import {
5
4
  NavigationContainer as ReactNavigationContainer,
6
5
  NavigationContainerRef,
7
6
  } from '@react-navigation/native';
7
+ import {BottomSheetModalProvider} from '@gorhom/bottom-sheet';
8
8
  import {createStackNavigator} from '@react-navigation/stack';
9
9
  import {DeviceEventEmitter} from 'react-native';
10
10
  import StackScreen from './StackScreen';
@@ -12,9 +12,18 @@ import ModalScreen from './ModalScreen';
12
12
  import Navigator from './Navigator';
13
13
  import {getDialogOptions, getModalOptions, getStackOptions} from './utils';
14
14
  import {LocalizationObject, NavigationContainerProps} from './types';
15
- import {ApplicationContext, MiniAppContext} from './index';
15
+ import {ApplicationContext} from './index';
16
16
  import kitLocalization from '../Assets/language.json';
17
17
 
18
+ const {
19
+ MiniAppContext,
20
+ } = require('react-native/Libraries/Components/ScreenContext');
21
+
22
+ /**
23
+ * link for deprecated
24
+ */
25
+ const deprecated = BottomSheetModalProvider;
26
+
18
27
  const Stack = createStackNavigator();
19
28
 
20
29
  const NavigationContainer: React.FC<NavigationContainerProps> = ({
@@ -23,9 +32,8 @@ const NavigationContainer: React.FC<NavigationContainerProps> = ({
23
32
  options,
24
33
  maxApi,
25
34
  localization,
26
- params,
27
35
  }) => {
28
- const context = useContext(MiniAppContext);
36
+ const context = useContext<any>(MiniAppContext);
29
37
  const navigationRef = useRef<NavigationContainerRef>(null);
30
38
  const isReady = useRef(false);
31
39
  const navigator = useRef(new Navigator(navigationRef, isReady));
@@ -69,55 +77,53 @@ const NavigationContainer: React.FC<NavigationContainerProps> = ({
69
77
 
70
78
  return (
71
79
  <SafeAreaProvider>
72
- <BottomSheetModalProvider>
73
- <ApplicationContext.Provider
74
- value={{
75
- navigator: navigator.current,
76
- config: config.current,
77
- theme,
78
- showGrid,
79
- translate,
80
- }}>
81
- <ReactNavigationContainer
82
- theme={{
83
- ...theme,
84
- colors: {
85
- ...theme.colors,
86
- background: theme.colors.background.default,
87
- card: theme.colors.background.surface,
88
- text: theme.colors.text.default,
89
- border: theme.colors.border.default,
90
- notification: theme.colors.error.primary,
91
- },
92
- }}
93
- ref={navigator.current?.ref}
94
- onReady={() => {
95
- isReady.current = true;
96
- }}
97
- independent={true}>
98
- <Stack.Navigator initialRouteName="Stack" headerMode="screen">
99
- <Stack.Screen
100
- name="Stack"
101
- component={StackScreen}
102
- initialParams={{screen, params}}
103
- options={{...getStackOptions(), ...options}}
104
- />
105
- <Stack.Screen
106
- name="Dialog"
107
- component={StackScreen}
108
- options={getDialogOptions()}
109
- initialParams={{screen}}
110
- />
111
- <Stack.Screen
112
- name="Modal"
113
- component={ModalScreen}
114
- options={getModalOptions()}
115
- initialParams={{screen}}
116
- />
117
- </Stack.Navigator>
118
- </ReactNavigationContainer>
119
- </ApplicationContext.Provider>
120
- </BottomSheetModalProvider>
80
+ <ApplicationContext.Provider
81
+ value={{
82
+ navigator: navigator.current,
83
+ config: config.current,
84
+ theme,
85
+ showGrid,
86
+ translate,
87
+ }}>
88
+ <ReactNavigationContainer
89
+ theme={{
90
+ ...theme,
91
+ colors: {
92
+ ...theme.colors,
93
+ background: theme.colors.background.default,
94
+ card: theme.colors.background.surface,
95
+ text: theme.colors.text.default,
96
+ border: theme.colors.border.default,
97
+ notification: theme.colors.error.primary,
98
+ },
99
+ }}
100
+ ref={navigator.current?.ref}
101
+ onReady={() => {
102
+ isReady.current = true;
103
+ }}
104
+ independent={true}>
105
+ <Stack.Navigator initialRouteName="Stack" headerMode="screen">
106
+ <Stack.Screen
107
+ name="Stack"
108
+ component={StackScreen}
109
+ initialParams={{screen}}
110
+ options={{...getStackOptions(), ...options}}
111
+ />
112
+ <Stack.Screen
113
+ name="Dialog"
114
+ component={StackScreen}
115
+ options={getDialogOptions()}
116
+ initialParams={{screen}}
117
+ />
118
+ <Stack.Screen
119
+ name="Modal"
120
+ component={ModalScreen}
121
+ options={getModalOptions()}
122
+ initialParams={{screen}}
123
+ />
124
+ </Stack.Navigator>
125
+ </ReactNavigationContainer>
126
+ </ApplicationContext.Provider>
121
127
  </SafeAreaProvider>
122
128
  );
123
129
  };