@momo-kits/foundation 0.92.2 → 0.92.3-tracking.10

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/CheckBox/types.ts CHANGED
@@ -1,6 +1,6 @@
1
- import {ViewStyle} from 'react-native';
1
+ import {TouchableOpacityProps, ViewStyle} from 'react-native';
2
2
 
3
- export type CheckBoxProps = {
3
+ export interface CheckBoxProps extends TouchableOpacityProps {
4
4
  /**
5
5
  * Represents whether the CheckBox is currently checked (`true`) or unchecked (`false`).
6
6
  */
@@ -36,7 +36,5 @@ export type CheckBoxProps = {
36
36
  */
37
37
  style?: ViewStyle;
38
38
 
39
- params?: any
40
-
41
- componentId?: string
42
- };
39
+ params?: any;
40
+ }
package/Icon/index.tsx CHANGED
@@ -5,7 +5,12 @@ import {IconProps} from './types';
5
5
  import {ApplicationContext} from '../Application';
6
6
  import {Image} from '../Image';
7
7
 
8
- const Icon: React.FC<IconProps> = ({source, size, color, style = {}}) => {
8
+ const Icon: React.FC<IconProps> = ({
9
+ source = 'ic_back',
10
+ size = 24,
11
+ color,
12
+ style = {},
13
+ }) => {
9
14
  const {theme} = useContext(ApplicationContext);
10
15
 
11
16
  /**
@@ -20,8 +25,8 @@ const Icon: React.FC<IconProps> = ({source, size, color, style = {}}) => {
20
25
  };
21
26
 
22
27
  const tintColorProps = color !== null && {
23
- tintColor: color ?? theme.colors.text.default
24
- }
28
+ tintColor: color ?? theme.colors.text.default,
29
+ };
25
30
 
26
31
  return (
27
32
  <Image
@@ -33,9 +38,4 @@ const Icon: React.FC<IconProps> = ({source, size, color, style = {}}) => {
33
38
  );
34
39
  };
35
40
 
36
- Icon.defaultProps = {
37
- source: 'ic_back',
38
- size: 24,
39
- };
40
-
41
41
  export {Icon, IconSources, IconBankSources};
@@ -5,15 +5,10 @@ import {
5
5
  TouchableOpacity,
6
6
  TouchableOpacityProps,
7
7
  } from 'react-native';
8
- import {ApplicationContext} from '../Application';
8
+ import {ApplicationContext, ComponentContext} from '../Application';
9
9
  import {Colors} from '../Consts';
10
10
  import {Icon} from '../Icon';
11
11
  import styles from './styles';
12
- import {formatComponentName} from '../Application/utils';
13
-
14
- const {
15
- ScreenContext,
16
- } = require('react-native/Libraries/Components/ScreenContext');
17
12
 
18
13
  export interface IconButtonProps extends TouchableOpacityProps {
19
14
  /**
@@ -33,21 +28,18 @@ export interface IconButtonProps extends TouchableOpacityProps {
33
28
  size?: 'large' | 'small';
34
29
 
35
30
  params?: any;
36
-
37
- componentId?: string;
38
31
  }
39
32
 
40
33
  const IconButton: React.FC<IconButtonProps> = ({
41
- type,
34
+ type = 'primary',
42
35
  icon,
43
36
  size,
44
37
  onPress,
45
38
  params,
46
- componentId,
39
+ accessibilityLabel,
47
40
  ...rest
48
41
  }) => {
49
42
  const {theme} = useContext(ApplicationContext);
50
- const screenInfo = useContext<any>(ScreenContext);
51
43
 
52
44
  /**
53
45
  * get size icon button
@@ -133,30 +125,25 @@ const IconButton: React.FC<IconButtonProps> = ({
133
125
  const iconSize = size === 'small' ? 16 : 24;
134
126
 
135
127
  return (
136
- <ScreenContext.Provider
128
+ <ComponentContext.Provider
137
129
  value={{
138
- ...screenInfo,
139
130
  componentName: 'IconButton',
140
131
  params,
141
132
  state: type === 'disabled' ? 'disabled' : 'enabled',
142
- componentId,
143
- componentValue: formatComponentName(icon),
133
+ componentId: accessibilityLabel,
134
+ componentValue: icon,
144
135
  action: 'click',
145
136
  }}>
146
137
  <TouchableOpacity
147
138
  {...rest}
139
+ accessibilityLabel={accessibilityLabel}
148
140
  activeOpacity={activeOpacity}
149
141
  onPress={onPressButton}
150
142
  style={buttonStyle}>
151
143
  <Icon size={iconSize} source={icon} color={getIconColor()} />
152
144
  </TouchableOpacity>
153
- </ScreenContext.Provider>
145
+ </ComponentContext.Provider>
154
146
  );
155
147
  };
156
148
 
157
- IconButton.defaultProps = {
158
- type: 'primary',
159
- disabled: false,
160
- };
161
-
162
149
  export {IconButton};
package/Image/index.tsx CHANGED
@@ -1,27 +1,38 @@
1
- import React, {useContext, useRef, useState} from 'react';
1
+ import React, {useContext, useEffect, useRef, useState} from 'react';
2
2
  import {StyleSheet, View} from 'react-native';
3
3
  import FastImage, {Source} from 'react-native-fast-image';
4
4
  import styles from './styles';
5
- import {ApplicationContext} from '../Application';
5
+ import {ApplicationContext, ComponentContext} from '../Application';
6
6
  import {Skeleton} from '../Skeleton';
7
7
  import {Icon} from '../Icon';
8
8
  import {Styles} from '../Consts';
9
9
  import {ImageProps} from './types';
10
- import {getAccessibilityID} from '../Application/utils';
11
10
 
12
11
  type Status = 'success' | 'loading' | 'error';
13
12
 
14
13
  const Image: React.FC<ImageProps> = ({
15
14
  style,
16
15
  source,
17
- loading,
16
+ loading = true,
18
17
  children,
18
+ params,
19
+ accessibilityLabel,
19
20
  ...rest
20
21
  }) => {
21
22
  const {theme} = useContext(ApplicationContext);
23
+ const component = useContext<any>(ComponentContext);
22
24
  const error = useRef(false);
23
25
  const [status, setStatus] = useState<Status>('success');
24
26
 
27
+ const test: any = {
28
+ accessibilityLabel: accessibilityLabel || `img|${(source as Source).uri}`,
29
+ };
30
+
31
+ useEffect(() => {
32
+ component?.addChildren?.(test.accessibilityLabel, 'add');
33
+ return () => component?.addChildren(test.accessibilityLabel, 'remove');
34
+ }, []);
35
+
25
36
  /**
26
37
  * render content loading | fail | rendered
27
38
  */
@@ -43,42 +54,46 @@ const Image: React.FC<ImageProps> = ({
43
54
  };
44
55
 
45
56
  return (
46
- <FastImage
47
- {...rest}
48
- {...getAccessibilityID(`img|${(source as Source).uri}`)}
49
- source={source}
50
- style={[styles.container, style]}
51
- onProgress={() => {
52
- error.current = false;
53
- if (status !== 'loading' && loading) {
54
- setStatus('loading');
55
- }
56
- }}
57
- onLoadStart={() => {
58
- error.current = false;
59
- }}
60
- onLoad={() => {
61
- error.current = false;
62
- }}
63
- onLoadEnd={() => {
64
- let current: Status = 'success';
65
- if (error.current) {
66
- current = 'error';
67
- }
68
- if (status !== current) {
69
- setStatus(current);
70
- }
71
- }}
72
- onError={() => {
73
- error.current = true;
57
+ <ComponentContext.Provider
58
+ value={{
59
+ componentName: 'Image',
60
+ params,
61
+ state: loading ? 'loading' : 'loaded',
62
+ componentId: test.accessibilityLabel,
74
63
  }}>
75
- {renderContent()}
76
- </FastImage>
64
+ <FastImage
65
+ {...rest}
66
+ {...test}
67
+ source={source}
68
+ style={[styles.container, style]}
69
+ onProgress={() => {
70
+ error.current = false;
71
+ if (status !== 'loading' && loading) {
72
+ setStatus('loading');
73
+ }
74
+ }}
75
+ onLoadStart={() => {
76
+ error.current = false;
77
+ }}
78
+ onLoad={() => {
79
+ error.current = false;
80
+ }}
81
+ onLoadEnd={() => {
82
+ let current: Status = 'success';
83
+ if (error.current) {
84
+ current = 'error';
85
+ }
86
+ if (status !== current) {
87
+ setStatus(current);
88
+ }
89
+ }}
90
+ onError={() => {
91
+ error.current = true;
92
+ }}>
93
+ {renderContent()}
94
+ </FastImage>
95
+ </ComponentContext.Provider>
77
96
  );
78
97
  };
79
98
 
80
- Image.defaultProps = {
81
- loading: true,
82
- };
83
-
84
99
  export {Image};
package/Image/types.ts CHANGED
@@ -2,4 +2,6 @@ import {FastImageProps} from 'react-native-fast-image';
2
2
 
3
3
  export interface ImageProps extends FastImageProps {
4
4
  loading?: boolean;
5
+ accessibilityLabel?: string;
6
+ params?: any;
5
7
  }
package/Input/Input.tsx CHANGED
@@ -7,23 +7,13 @@ import {
7
7
  TouchableOpacity,
8
8
  View,
9
9
  } from 'react-native';
10
- import {ApplicationContext} from '../Application';
10
+ import {ApplicationContext, ComponentContext} from '../Application';
11
11
  import styles from './styles';
12
12
  import {ErrorView, FloatingView, getBorderColor, getSizeStyle} from './common';
13
13
  import {InputProps} from './index';
14
14
  import {Icon} from '../Icon';
15
15
  import {checkTyping} from './utils';
16
16
  import {Loader} from '../Loader';
17
- import {
18
- formatComponentName,
19
- getAccessibilityID,
20
- cleanNameForTracking,
21
- } from '../Application/utils';
22
-
23
- const {
24
- ScreenContext,
25
- MiniAppContext,
26
- } = require('react-native/Libraries/Components/ScreenContext');
27
17
 
28
18
  const Input = forwardRef(
29
19
  (
@@ -52,18 +42,16 @@ const Input = forwardRef(
52
42
  keyboardType,
53
43
  style,
54
44
  params,
55
- componentId,
45
+ accessibilityLabel,
56
46
  ...props
57
47
  }: InputProps,
58
48
  ref,
59
49
  ) => {
60
50
  const {theme} = useContext(ApplicationContext);
61
- const {appId, code} = useContext<any>(MiniAppContext);
62
51
  const [focused, setFocused] = useState(false);
63
52
  const [haveValue, setHaveValue] = useState(!!value || !!props.defaultValue);
64
53
  const [secureTextInput, setSecureTextInput] = useState(secureTextEntry);
65
54
  const inputRef = (ref as React.RefObject<TextInput>) ?? useRef<TextInput>();
66
- const screenInfo = useContext<any>(ScreenContext);
67
55
 
68
56
  const onClearText = () => {
69
57
  inputRef?.current?.clear();
@@ -122,21 +110,6 @@ const Input = forwardRef(
122
110
  let textColor = theme.colors.text.default;
123
111
  let placeholderColor = theme.colors.text.hint;
124
112
  let iconTintColor = iconColor;
125
- const accessibilityID = disabled
126
- ? getAccessibilityID(
127
- `${appId}/${code}/${
128
- screenInfo.screenName
129
- }/input_${cleanNameForTracking(
130
- floatingValue ?? placeholder,
131
- )}_disabled`,
132
- )
133
- : getAccessibilityID(
134
- `${appId}/${code}/${
135
- screenInfo.screenName
136
- }/input_${cleanNameForTracking(
137
- floatingValue ?? placeholder ?? value,
138
- )}`,
139
- );
140
113
 
141
114
  if (disabled) {
142
115
  textColor = disabledColor;
@@ -178,7 +151,7 @@ const Input = forwardRef(
178
151
  )}
179
152
  <TextInput
180
153
  {...props}
181
- {...accessibilityID}
154
+ accessibilityLabel={accessibilityLabel}
182
155
  editable={props.editable && !disabled}
183
156
  secureTextEntry={secure}
184
157
  textAlignVertical="center"
@@ -234,20 +207,19 @@ const Input = forwardRef(
234
207
  }
235
208
 
236
209
  return (
237
- <ScreenContext.Provider
210
+ <ComponentContext.Provider
238
211
  value={{
239
- ...screenInfo,
240
212
  componentName: 'Input',
241
213
  params,
242
- componentLabel: formatComponentName(floatingValue || ''),
214
+ componentLabel: floatingValue,
243
215
  state: inputState,
244
- componentId,
216
+ componentId: accessibilityLabel,
245
217
  }}>
246
218
  <View style={[style, styles.wrapper]}>
247
219
  {renderInputView()}
248
220
  <ErrorView errorMessage={errorMessage} errorSpacing={errorSpacing} />
249
221
  </View>
250
- </ScreenContext.Provider>
222
+ </ComponentContext.Provider>
251
223
  );
252
224
  },
253
225
  );
@@ -1,22 +1,12 @@
1
1
  import React, {useContext} from 'react';
2
2
  import {TextInput, TouchableOpacity, View} from 'react-native';
3
- import {ApplicationContext} from '../Application';
3
+ import {ApplicationContext, ComponentContext} from '../Application';
4
4
  import styles from './styles';
5
5
  import {ErrorView, FloatingView, getBorderColor, getSizeStyle} from './common';
6
6
  import {InputDropDownProps} from './index';
7
7
  import {Icon} from '../Icon';
8
8
  import {Loader} from '../Loader';
9
9
  import {Styles} from '../Consts';
10
- import {
11
- cleanNameForTracking,
12
- formatComponentName,
13
- getAccessibilityID,
14
- } from '../Application/utils';
15
-
16
- const {
17
- ScreenContext,
18
- MiniAppContext,
19
- } = require('react-native/Libraries/Components/ScreenContext');
20
10
 
21
11
  const InputDropDown = ({
22
12
  value,
@@ -37,13 +27,11 @@ const InputDropDown = ({
37
27
  leadingIconColor,
38
28
  style,
39
29
  params,
40
- componentId,
30
+ accessibilityLabel,
41
31
  ...props
42
32
  }: InputDropDownProps) => {
43
- const {appId, code} = useContext<any>(MiniAppContext);
44
33
  const {theme} = useContext(ApplicationContext);
45
34
  const full = !!value || !!placeholder;
46
- const screenInfo = useContext<any>(ScreenContext);
47
35
 
48
36
  const renderIcon = (color: string | undefined) => {
49
37
  if (loading) {
@@ -59,19 +47,6 @@ const InputDropDown = ({
59
47
  let textColor = theme.colors.text.default;
60
48
  let placeholderColor = theme.colors.text.hint;
61
49
  let iconTintColor = iconColor;
62
- const accessibilityID = disabled
63
- ? getAccessibilityID(
64
- `${appId}/${code}/${
65
- screenInfo.screenName
66
- }/input_${cleanNameForTracking(
67
- floatingValue ?? placeholder,
68
- )}_disabled`,
69
- )
70
- : getAccessibilityID(
71
- `${appId}/${code}/${
72
- screenInfo.screenName
73
- }/input_${cleanNameForTracking(floatingValue ?? placeholder)}`,
74
- );
75
50
 
76
51
  if (disabled) {
77
52
  textColor = disabledColor;
@@ -107,10 +82,9 @@ const InputDropDown = ({
107
82
  {full && (
108
83
  <TextInput
109
84
  {...props}
110
- {...accessibilityID}
85
+ accessibilityLabel={accessibilityLabel}
111
86
  onPressIn={onPress}
112
87
  editable={false}
113
- textAlignVertical="top"
114
88
  style={[
115
89
  styles.input,
116
90
  {
@@ -132,14 +106,13 @@ const InputDropDown = ({
132
106
  };
133
107
 
134
108
  return (
135
- <ScreenContext.Provider
109
+ <ComponentContext.Provider
136
110
  value={{
137
- ...screenInfo,
138
- componentName: 'InputOTP',
111
+ componentName: 'InputDropDown',
139
112
  params,
140
113
  state: 'enabled',
141
- componentLabel: formatComponentName(floatingValue || ''),
142
- componentId,
114
+ componentLabel: floatingValue,
115
+ componentId: accessibilityLabel,
143
116
  }}>
144
117
  <TouchableOpacity
145
118
  onPress={onPress}
@@ -147,7 +120,7 @@ const InputDropDown = ({
147
120
  {renderInputView()}
148
121
  <ErrorView errorMessage={errorMessage} errorSpacing={errorSpacing} />
149
122
  </TouchableOpacity>
150
- </ScreenContext.Provider>
123
+ </ComponentContext.Provider>
151
124
  );
152
125
  };
153
126
 
@@ -12,22 +12,12 @@ import {
12
12
  TouchableOpacity,
13
13
  View,
14
14
  } from 'react-native';
15
- import {ApplicationContext} from '../Application';
15
+ import {ApplicationContext, ComponentContext} from '../Application';
16
16
  import styles from './styles';
17
17
  import {ErrorView, FloatingView, getBorderColor, getSizeStyle} from './common';
18
18
  import {InputMoneyProps} from './index';
19
19
  import {Icon} from '../Icon';
20
20
  import {formatMoneyToNumber, formatNumberToMoney} from './utils';
21
- import {
22
- cleanNameForTracking,
23
- formatComponentName,
24
- getAccessibilityID,
25
- } from '../Application/utils';
26
-
27
- const {
28
- ScreenContext,
29
- MiniAppContext,
30
- } = require('react-native/Libraries/Components/ScreenContext');
31
21
 
32
22
  const InputMoney = forwardRef(
33
23
  (
@@ -48,16 +38,14 @@ const InputMoney = forwardRef(
48
38
  style,
49
39
  params,
50
40
  defaultValue = '',
51
- componentId,
41
+ accessibilityLabel,
52
42
  ...props
53
43
  }: InputMoneyProps,
54
44
  ref,
55
45
  ) => {
56
46
  const {theme} = useContext(ApplicationContext);
57
- const {appId, code} = useContext<any>(MiniAppContext);
58
47
  const [focused, setFocused] = useState(false);
59
48
  const inputRef = (ref as React.RefObject<TextInput>) ?? useRef<TextInput>();
60
- const screenInfo = useContext<any>(ScreenContext);
61
49
 
62
50
  const validateText = (text: string) => {
63
51
  const valueFormat = formatMoneyToNumber(text, 'đ');
@@ -103,17 +91,6 @@ const InputMoney = forwardRef(
103
91
  let textColor = theme.colors.text.default;
104
92
  let placeholderColor = theme.colors.text.hint;
105
93
  let iconTintColor = iconColor;
106
- const accessibilityID = disabled
107
- ? getAccessibilityID(
108
- `${appId}/${code}/${
109
- screenInfo.screenName
110
- }/input_${cleanNameForTracking(floatingValue)}_disabled`,
111
- )
112
- : getAccessibilityID(
113
- `${appId}/${code}/${
114
- screenInfo.screenName
115
- }/input_${cleanNameForTracking(floatingValue)}`,
116
- );
117
94
 
118
95
  if (disabled) {
119
96
  textColor = disabledColor;
@@ -139,9 +116,8 @@ const InputMoney = forwardRef(
139
116
  <View style={styles.inputView}>
140
117
  <TextInput
141
118
  {...props}
142
- {...accessibilityID}
119
+ accessibilityLabel={accessibilityLabel}
143
120
  editable={!disabled}
144
- textAlignVertical="top"
145
121
  ref={inputRef}
146
122
  keyboardType={'number-pad'}
147
123
  style={[
@@ -191,20 +167,19 @@ const InputMoney = forwardRef(
191
167
  }
192
168
 
193
169
  return (
194
- <ScreenContext.Provider
170
+ <ComponentContext.Provider
195
171
  value={{
196
- ...screenInfo,
197
172
  componentName: 'InputMoney',
198
173
  params,
199
- componentLabel: formatComponentName(floatingValue || ''),
174
+ componentLabel: floatingValue,
200
175
  state: inputState,
201
- componentId,
176
+ componentId: accessibilityLabel,
202
177
  }}>
203
178
  <View style={[style, styles.wrapper]}>
204
179
  {renderInputView()}
205
180
  <ErrorView errorMessage={errorMessage} errorSpacing={errorSpacing} />
206
181
  </View>
207
- </ScreenContext.Provider>
182
+ </ComponentContext.Provider>
208
183
  );
209
184
  },
210
185
  );
@@ -19,18 +19,8 @@ import {CaretProps, InputOTPProps} from './index';
19
19
  import {scaleSize, Text} from '../Text';
20
20
  import styles from './styles';
21
21
  import {ErrorView, getBorderColor} from './common';
22
- import {ApplicationContext} from '../Application';
22
+ import {ApplicationContext, ComponentContext} from '../Application';
23
23
  import {Spacing} from '../Consts';
24
- import {
25
- cleanNameForTracking,
26
- formatComponentName,
27
- getAccessibilityID,
28
- } from '../Application/utils';
29
-
30
- const {
31
- ScreenContext,
32
- MiniAppContext,
33
- } = require('react-native/Libraries/Components/ScreenContext');
34
24
 
35
25
  const OTPCaret: FC<CaretProps> = ({index, length}) => {
36
26
  const DURATION = 300;
@@ -90,19 +80,16 @@ const InputOTP = forwardRef(
90
80
  dataType = 'number',
91
81
  params,
92
82
  style,
93
- componentId,
83
+ accessibilityLabel,
94
84
  ...props
95
85
  }: InputOTPProps,
96
86
  ref,
97
87
  ) => {
98
88
  const MAX_LENGTH = 10;
99
- const {appId, code} = useContext<any>(MiniAppContext);
100
-
101
89
  const [value, setValue] = useState('');
102
90
  const [focused, setFocused] = useState(false);
103
91
  const inputRef = useRef<TextInput>(null);
104
92
  const {theme} = useContext(ApplicationContext);
105
- const screenInfo = useContext<any>(ScreenContext);
106
93
 
107
94
  useImperativeHandle(ref, () => ({
108
95
  onChangeText: (text: string) => {
@@ -195,12 +182,6 @@ const InputOTP = forwardRef(
195
182
  );
196
183
  };
197
184
 
198
- const accessibilityID = getAccessibilityID(
199
- `${appId}/${code}/${screenInfo.screenName}/input_${cleanNameForTracking(
200
- floatingValue,
201
- )}`,
202
- );
203
-
204
185
  const renderInputView = () => {
205
186
  return (
206
187
  <View
@@ -226,7 +207,7 @@ const InputOTP = forwardRef(
226
207
  <View style={styles.inputView}>
227
208
  <TextInput
228
209
  {...props}
229
- {...accessibilityID}
210
+ accessibilityLabel={accessibilityLabel}
230
211
  ref={inputRef}
231
212
  value={value}
232
213
  onChangeText={_onChangeText}
@@ -243,14 +224,13 @@ const InputOTP = forwardRef(
243
224
  };
244
225
 
245
226
  return (
246
- <ScreenContext.Provider
227
+ <ComponentContext.Provider
247
228
  value={{
248
- ...screenInfo,
249
229
  componentName: 'InputOTP',
250
230
  params,
251
- componentLabel: formatComponentName(floatingValue || ''),
231
+ componentLabel: floatingValue,
252
232
  state: 'enabled',
253
- componentId,
233
+ componentId: accessibilityLabel,
254
234
  }}>
255
235
  <TouchableOpacity
256
236
  activeOpacity={1}
@@ -259,7 +239,7 @@ const InputOTP = forwardRef(
259
239
  {renderInputView()}
260
240
  <ErrorView errorMessage={errorMessage} errorSpacing={errorSpacing} />
261
241
  </TouchableOpacity>
262
- </ScreenContext.Provider>
242
+ </ComponentContext.Provider>
263
243
  );
264
244
  },
265
245
  );