@momo-kits/foundation 0.92.1-tracking.9 → 0.92.2-tracking.4

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/Image/index.tsx CHANGED
@@ -1,27 +1,42 @@
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
- import FastImage from 'react-native-fast-image';
3
+ import FastImage, {Source} from 'react-native-fast-image';
4
4
  import styles from './styles';
5
5
  import {ApplicationContext} 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";
10
+ import {getAccessibilityID} from '../Application/utils';
11
+
12
+ const {
13
+ ComponentContext,
14
+ } = require('react-native/Libraries/Components/ScreenContext');
11
15
 
12
16
  type Status = 'success' | 'loading' | 'error';
13
17
 
14
18
  const Image: React.FC<ImageProps> = ({
15
19
  style,
16
20
  source,
17
- loading,
21
+ loading = true,
18
22
  children,
23
+ accessibilityLabel,
19
24
  ...rest
20
25
  }) => {
21
26
  const {theme} = useContext(ApplicationContext);
27
+ const component = useContext<any>(ComponentContext);
22
28
  const error = useRef(false);
23
29
  const [status, setStatus] = useState<Status>('success');
24
30
 
31
+ const id = getAccessibilityID(
32
+ `img|${(source as Source).uri}`,
33
+ accessibilityLabel,
34
+ );
35
+
36
+ useEffect(() => {
37
+ component?.addChild?.(id.testID || id.accessibilityLabel);
38
+ }, []);
39
+
25
40
  /**
26
41
  * render content loading | fail | rendered
27
42
  */
@@ -42,11 +57,10 @@ const Image: React.FC<ImageProps> = ({
42
57
  return children;
43
58
  };
44
59
 
45
- const accessibilityID = getAccessibilityID?.(`img|${source}`)
46
60
  return (
47
61
  <FastImage
48
62
  {...rest}
49
- {...accessibilityID}
63
+ {...id}
50
64
  source={source}
51
65
  style={[styles.container, style]}
52
66
  onProgress={() => {
@@ -78,8 +92,4 @@ const Image: React.FC<ImageProps> = ({
78
92
  );
79
93
  };
80
94
 
81
- Image.defaultProps = {
82
- loading: true,
83
- };
84
-
85
95
  export {Image};
package/Image/types.ts CHANGED
@@ -2,4 +2,5 @@ import {FastImageProps} from 'react-native-fast-image';
2
2
 
3
3
  export interface ImageProps extends FastImageProps {
4
4
  loading?: boolean;
5
+ accessibilityLabel?: string;
5
6
  }
package/Input/Input.tsx CHANGED
@@ -1,22 +1,23 @@
1
1
  import React, {forwardRef, useContext, useRef, useState} from 'react';
2
2
  import {
3
3
  NativeSyntheticEvent,
4
+ Platform,
4
5
  TextInput,
5
6
  TextInputFocusEventData,
6
7
  TouchableOpacity,
7
8
  View,
8
9
  } from 'react-native';
9
- import {ApplicationContext, MiniAppContext} from '../Application';
10
+ import {ApplicationContext} from '../Application';
10
11
  import styles from './styles';
11
12
  import {ErrorView, FloatingView, getBorderColor, getSizeStyle} from './common';
12
13
  import {InputProps} from './index';
13
14
  import {Icon} from '../Icon';
14
15
  import {checkTyping} from './utils';
15
16
  import {Loader} from '../Loader';
16
- import {formatComponentName, getAccessibilityID} from '../Application/utils';
17
+ import {formatComponentName} from '../Application/utils';
17
18
 
18
19
  const {
19
- ScreenContext,
20
+ ComponentContext,
20
21
  } = require('react-native/Libraries/Components/ScreenContext');
21
22
 
22
23
  const Input = forwardRef(
@@ -43,20 +44,19 @@ const Input = forwardRef(
43
44
  fontWeight = 'Regular',
44
45
  onPressIcon,
45
46
  secureTextEntry,
47
+ keyboardType,
46
48
  style,
47
49
  params,
48
- componentId,
50
+ accessibilityLabel,
49
51
  ...props
50
52
  }: InputProps,
51
53
  ref,
52
54
  ) => {
53
55
  const {theme} = useContext(ApplicationContext);
54
- const {appId} = useContext(MiniAppContext)
55
56
  const [focused, setFocused] = useState(false);
56
57
  const [haveValue, setHaveValue] = useState(!!value || !!props.defaultValue);
57
58
  const [secureTextInput, setSecureTextInput] = useState(secureTextEntry);
58
59
  const inputRef = (ref as React.RefObject<TextInput>) ?? useRef<TextInput>();
59
- const screenInfo = useContext<any>(ScreenContext);
60
60
 
61
61
  const onClearText = () => {
62
62
  inputRef?.current?.clear();
@@ -121,7 +121,13 @@ const Input = forwardRef(
121
121
  placeholderColor = disabledColor;
122
122
  iconTintColor = disabledColor;
123
123
  }
124
- const accessibilityID = getAccessibilityID?.(`${appId}/${screenInfo.screenName}/input_${floatingValue}${disabled && "_disabled" }`)
124
+
125
+ if (secureTextEntry) {
126
+ keyboardType = Platform.select({
127
+ ios: 'ascii-capable',
128
+ android: 'visible-password',
129
+ });
130
+ }
125
131
 
126
132
  return (
127
133
  <View
@@ -150,8 +156,8 @@ const Input = forwardRef(
150
156
  )}
151
157
  <TextInput
152
158
  {...props}
153
- {...accessibilityID}
154
- editable={!disabled}
159
+ accessibilityLabel={accessibilityLabel}
160
+ editable={props.editable && !disabled}
155
161
  secureTextEntry={secure}
156
162
  textAlignVertical="center"
157
163
  ref={inputRef}
@@ -171,6 +177,7 @@ const Input = forwardRef(
171
177
  placeholder={placeholder}
172
178
  selectionColor={theme.colors.primary}
173
179
  placeholderTextColor={placeholderColor}
180
+ keyboardType={keyboardType}
174
181
  />
175
182
  </View>
176
183
  <View style={styles.iconView}>
@@ -204,22 +211,20 @@ const Input = forwardRef(
204
211
  inputState = 'disabled';
205
212
  }
206
213
 
207
-
208
214
  return (
209
- <ScreenContext.Provider
215
+ <ComponentContext.Provider
210
216
  value={{
211
- ...screenInfo,
212
217
  componentName: 'Input',
213
218
  params,
214
219
  componentLabel: formatComponentName(floatingValue || ''),
215
220
  state: inputState,
216
- componentId,
221
+ componentId: accessibilityLabel,
217
222
  }}>
218
223
  <View style={[style, styles.wrapper]}>
219
224
  {renderInputView()}
220
225
  <ErrorView errorMessage={errorMessage} errorSpacing={errorSpacing} />
221
226
  </View>
222
- </ScreenContext.Provider>
227
+ </ComponentContext.Provider>
223
228
  );
224
229
  },
225
230
  );
@@ -1,16 +1,16 @@
1
1
  import React, {useContext} from 'react';
2
2
  import {TextInput, TouchableOpacity, View} from 'react-native';
3
- import {ApplicationContext, MiniAppContext} from '../Application';
3
+ import {ApplicationContext} 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 {formatComponentName, getAccessibilityID} from '../Application/utils';
10
+ import {formatComponentName} from '../Application/utils';
11
11
 
12
12
  const {
13
- ScreenContext,
13
+ ComponentContext,
14
14
  } = require('react-native/Libraries/Components/ScreenContext');
15
15
 
16
16
  const InputDropDown = ({
@@ -32,13 +32,11 @@ const InputDropDown = ({
32
32
  leadingIconColor,
33
33
  style,
34
34
  params,
35
- componentId,
35
+ accessibilityLabel,
36
36
  ...props
37
37
  }: InputDropDownProps) => {
38
- const {appId} = useContext(MiniAppContext)
39
38
  const {theme} = useContext(ApplicationContext);
40
39
  const full = !!value || !!placeholder;
41
- const screenInfo = useContext<any>(ScreenContext);
42
40
 
43
41
  const renderIcon = (color: string | undefined) => {
44
42
  if (loading) {
@@ -60,7 +58,6 @@ const InputDropDown = ({
60
58
  placeholderColor = disabledColor;
61
59
  iconTintColor = disabledColor;
62
60
  }
63
- const accessibilityID = getAccessibilityID?.(`${appId}/${screenInfo.screenName}/input_${floatingValue}${disabled && "_disabled" }`)
64
61
 
65
62
  return (
66
63
  <View
@@ -90,7 +87,7 @@ const InputDropDown = ({
90
87
  {full && (
91
88
  <TextInput
92
89
  {...props}
93
- {...accessibilityID}
90
+ accessibilityLabel={accessibilityLabel}
94
91
  onPressIn={onPress}
95
92
  editable={false}
96
93
  textAlignVertical="top"
@@ -114,17 +111,14 @@ const InputDropDown = ({
114
111
  );
115
112
  };
116
113
 
117
-
118
-
119
114
  return (
120
- <ScreenContext.Provider
115
+ <ComponentContext.Provider
121
116
  value={{
122
- ...screenInfo,
123
117
  componentName: 'InputOTP',
124
118
  params,
125
119
  state: 'enabled',
126
120
  componentLabel: formatComponentName(floatingValue || ''),
127
- componentId,
121
+ componentId: accessibilityLabel,
128
122
  }}>
129
123
  <TouchableOpacity
130
124
  onPress={onPress}
@@ -132,7 +126,7 @@ const InputDropDown = ({
132
126
  {renderInputView()}
133
127
  <ErrorView errorMessage={errorMessage} errorSpacing={errorSpacing} />
134
128
  </TouchableOpacity>
135
- </ScreenContext.Provider>
129
+ </ComponentContext.Provider>
136
130
  );
137
131
  };
138
132
 
@@ -12,16 +12,16 @@ import {
12
12
  TouchableOpacity,
13
13
  View,
14
14
  } from 'react-native';
15
- import {ApplicationContext, MiniAppContext} from '../Application';
15
+ import {ApplicationContext} 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 {formatComponentName, getAccessibilityID} from '../Application/utils';
21
+ import {formatComponentName} from '../Application/utils';
22
22
 
23
23
  const {
24
- ScreenContext,
24
+ ComponentContext,
25
25
  } = require('react-native/Libraries/Components/ScreenContext');
26
26
 
27
27
  const InputMoney = forwardRef(
@@ -43,16 +43,14 @@ const InputMoney = forwardRef(
43
43
  style,
44
44
  params,
45
45
  defaultValue = '',
46
- componentId,
46
+ accessibilityLabel,
47
47
  ...props
48
48
  }: InputMoneyProps,
49
49
  ref,
50
50
  ) => {
51
51
  const {theme} = useContext(ApplicationContext);
52
- const {appId} = useContext(MiniAppContext)
53
52
  const [focused, setFocused] = useState(false);
54
53
  const inputRef = (ref as React.RefObject<TextInput>) ?? useRef<TextInput>();
55
- const screenInfo = useContext<any>(ScreenContext);
56
54
 
57
55
  const validateText = (text: string) => {
58
56
  const valueFormat = formatMoneyToNumber(text, 'đ');
@@ -104,7 +102,6 @@ const InputMoney = forwardRef(
104
102
  placeholderColor = disabledColor;
105
103
  iconTintColor = disabledColor;
106
104
  }
107
- const accessibilityID = getAccessibilityID?.(`${appId}/${screenInfo.screenName}/input_${floatingValue}${disabled && "_disabled" }`)
108
105
 
109
106
  return (
110
107
  <View
@@ -124,7 +121,7 @@ const InputMoney = forwardRef(
124
121
  <View style={styles.inputView}>
125
122
  <TextInput
126
123
  {...props}
127
- {...accessibilityID}
124
+ accessibilityLabel={accessibilityLabel}
128
125
  editable={!disabled}
129
126
  textAlignVertical="top"
130
127
  ref={inputRef}
@@ -175,23 +172,20 @@ const InputMoney = forwardRef(
175
172
  inputState = 'disabled';
176
173
  }
177
174
 
178
-
179
175
  return (
180
- <ScreenContext.Provider
176
+ <ComponentContext.Provider
181
177
  value={{
182
- ...screenInfo,
183
178
  componentName: 'InputMoney',
184
179
  params,
185
180
  componentLabel: formatComponentName(floatingValue || ''),
186
181
  state: inputState,
187
- componentId,
182
+ componentId: accessibilityLabel,
188
183
  }}>
189
- <View
190
- style={[style, styles.wrapper]}>
184
+ <View style={[style, styles.wrapper]}>
191
185
  {renderInputView()}
192
186
  <ErrorView errorMessage={errorMessage} errorSpacing={errorSpacing} />
193
187
  </View>
194
- </ScreenContext.Provider>
188
+ </ComponentContext.Provider>
195
189
  );
196
190
  },
197
191
  );
@@ -19,17 +19,16 @@ 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, MiniAppContext} from '../Application';
22
+ import {ApplicationContext} from '../Application';
23
23
  import {Spacing} from '../Consts';
24
- import {formatComponentName, getAccessibilityID} from '../Application/utils';
24
+ import {formatComponentName} from '../Application/utils';
25
25
 
26
26
  const {
27
- ScreenContext,
27
+ ComponentContext,
28
28
  } = require('react-native/Libraries/Components/ScreenContext');
29
29
 
30
30
  const OTPCaret: FC<CaretProps> = ({index, length}) => {
31
31
  const DURATION = 300;
32
- const {appId} = useContext(MiniAppContext)
33
32
  const {theme} = useContext(ApplicationContext);
34
33
  const opacity = useRef(new Animated.Value(0)).current;
35
34
 
@@ -86,19 +85,16 @@ const InputOTP = forwardRef(
86
85
  dataType = 'number',
87
86
  params,
88
87
  style,
89
- componentId,
88
+ accessibilityLabel,
90
89
  ...props
91
90
  }: InputOTPProps,
92
91
  ref,
93
92
  ) => {
94
93
  const MAX_LENGTH = 10;
95
- const {appId} = useContext(MiniAppContext)
96
-
97
94
  const [value, setValue] = useState('');
98
95
  const [focused, setFocused] = useState(false);
99
96
  const inputRef = useRef<TextInput>(null);
100
97
  const {theme} = useContext(ApplicationContext);
101
- const screenInfo = useContext<any>(ScreenContext);
102
98
 
103
99
  useImperativeHandle(ref, () => ({
104
100
  onChangeText: (text: string) => {
@@ -191,7 +187,6 @@ const InputOTP = forwardRef(
191
187
  );
192
188
  };
193
189
 
194
- const accessibilityID = getAccessibilityID?.(`${appId}/${screenInfo.screenName}/input_${floatingValue}`)
195
190
  const renderInputView = () => {
196
191
  return (
197
192
  <View
@@ -217,7 +212,7 @@ const InputOTP = forwardRef(
217
212
  <View style={styles.inputView}>
218
213
  <TextInput
219
214
  {...props}
220
- {...accessibilityID}
215
+ accessibilityLabel={accessibilityLabel}
221
216
  ref={inputRef}
222
217
  value={value}
223
218
  onChangeText={_onChangeText}
@@ -234,14 +229,13 @@ const InputOTP = forwardRef(
234
229
  };
235
230
 
236
231
  return (
237
- <ScreenContext.Provider
232
+ <ComponentContext.Provider
238
233
  value={{
239
- ...screenInfo,
240
234
  componentName: 'InputOTP',
241
235
  params,
242
236
  componentLabel: formatComponentName(floatingValue || ''),
243
237
  state: 'enabled',
244
- componentId,
238
+ componentId: accessibilityLabel,
245
239
  }}>
246
240
  <TouchableOpacity
247
241
  activeOpacity={1}
@@ -250,7 +244,7 @@ const InputOTP = forwardRef(
250
244
  {renderInputView()}
251
245
  <ErrorView errorMessage={errorMessage} errorSpacing={errorSpacing} />
252
246
  </TouchableOpacity>
253
- </ScreenContext.Provider>
247
+ </ComponentContext.Provider>
254
248
  );
255
249
  },
256
250
  );
@@ -7,15 +7,14 @@ import {
7
7
  View,
8
8
  } from 'react-native';
9
9
  import {InputSearchProps} from './index';
10
- import {ApplicationContext, MiniAppContext} from '../Application';
10
+ import {ApplicationContext} from '../Application';
11
11
  import styles from './styles';
12
12
  import {Icon} from '../Icon';
13
13
  import {Text} from '../Text';
14
14
  import {checkTyping} from './utils';
15
- import {getAccessibilityID} from "../Application/utils";
16
15
 
17
16
  const {
18
- ScreenContext,
17
+ ComponentContext,
19
18
  } = require('react-native/Libraries/Components/ScreenContext');
20
19
 
21
20
  const InputSearch = forwardRef(
@@ -33,19 +32,17 @@ const InputSearch = forwardRef(
33
32
  style,
34
33
  defaultValue,
35
34
  onPressButtonText,
36
- hasColorBG = true,
37
35
  params,
38
- componentId,
36
+ hasColorBG = false,
37
+ accessibilityLabel,
39
38
  ...props
40
39
  }: InputSearchProps,
41
40
  ref,
42
41
  ) => {
43
42
  const {theme} = useContext(ApplicationContext);
44
- const {appId} = useContext(MiniAppContext)
45
43
  const [focused, setFocused] = useState(false);
46
44
  const [haveValue, setHaveValue] = useState(!!value || !!defaultValue);
47
45
  const inputRef = (ref as React.RefObject<TextInput>) ?? useRef<TextInput>();
48
- const screenInfo = useContext<any>(ScreenContext);
49
46
 
50
47
  const _onFocus = (e: NativeSyntheticEvent<TextInputFocusEventData>) => {
51
48
  setFocused(true);
@@ -66,13 +63,12 @@ const InputSearch = forwardRef(
66
63
  checkTyping(text, haveValue, setHaveValue);
67
64
  onChangeText?.(text);
68
65
  };
69
- const accessibilityID = getAccessibilityID?.(`${appId}/${screenInfo.screenName}/input_search`)
70
66
 
71
67
  const renderInputView = () => {
72
68
  return (
73
69
  <TextInput
74
70
  {...props}
75
- {...accessibilityID}
71
+ accessibilityLabel={accessibilityLabel}
76
72
  textAlignVertical="center"
77
73
  ref={inputRef}
78
74
  style={[
@@ -143,13 +139,12 @@ const InputSearch = forwardRef(
143
139
  : theme.colors.background.surface;
144
140
 
145
141
  return (
146
- <ScreenContext.Provider
142
+ <ComponentContext.Provider
147
143
  value={{
148
- ...screenInfo,
149
144
  componentName: 'InputSearch',
150
145
  params,
151
146
  state: inputState,
152
- componentId,
147
+ componentId: accessibilityLabel,
153
148
  }}>
154
149
  <View style={[style, styles.searchInputContainer]}>
155
150
  <View
@@ -177,7 +172,7 @@ const InputSearch = forwardRef(
177
172
  </TouchableOpacity>
178
173
  )}
179
174
  </View>
180
- </ScreenContext.Provider>
175
+ </ComponentContext.Provider>
181
176
  );
182
177
  },
183
178
  );
@@ -17,11 +17,10 @@ import {
17
17
  } from './common';
18
18
  import {InputTextAreaProps} from './index';
19
19
  import {Icon} from '../Icon';
20
- import {ApplicationContext, MiniAppContext} from '../Application';
21
- import {getAccessibilityID} from "../Application/utils";
20
+ import {ApplicationContext} from '../Application';
22
21
 
23
22
  const {
24
- ScreenContext,
23
+ ComponentContext,
25
24
  } = require('react-native/Libraries/Components/ScreenContext');
26
25
 
27
26
  const InputTextArea = forwardRef(
@@ -43,13 +42,12 @@ const InputTextArea = forwardRef(
43
42
  required,
44
43
  errorSpacing,
45
44
  style,
45
+ accessibilityLabel,
46
46
  ...props
47
47
  }: InputTextAreaProps,
48
48
  ref,
49
49
  ) => {
50
50
  const {theme} = useContext(ApplicationContext);
51
- const screenInfo = useContext<any>(ScreenContext);
52
- const {appId} = useContext(MiniAppContext)
53
51
  const [focused, setFocused] = useState(false);
54
52
  const [inputValue, setInputValue] = useState(defaultValue ?? '');
55
53
  const inputRef = (ref as React.RefObject<TextInput>) ?? useRef<TextInput>();
@@ -94,7 +92,6 @@ const InputTextArea = forwardRef(
94
92
  textColor = disabledColor;
95
93
  placeholderColor = disabledColor;
96
94
  }
97
- const accessibilityID = getAccessibilityID?.(`${appId}/${screenInfo.screenName}/input_${floatingValue}${disabled && "_disabled" }`)
98
95
 
99
96
  return (
100
97
  <View
@@ -117,7 +114,7 @@ const InputTextArea = forwardRef(
117
114
  <View style={styles.textAreaView}>
118
115
  <TextInput
119
116
  {...props}
120
- {...accessibilityID}
117
+ accessibilityLabel={ComponentContext}
121
118
  ref={inputRef}
122
119
  editable={!disabled}
123
120
  textAlignVertical="top"
@@ -157,8 +154,7 @@ const InputTextArea = forwardRef(
157
154
  };
158
155
 
159
156
  return (
160
- <View
161
- style={[style, styles.wrapper]}>
157
+ <View style={[style, styles.wrapper]}>
162
158
  {renderInputView()}
163
159
  <ErrorView errorMessage={errorMessage} errorSpacing={errorSpacing} />
164
160
  </View>
package/Input/index.tsx CHANGED
@@ -82,7 +82,6 @@ export interface InputProps extends TextInputProps {
82
82
  onPressIcon?: () => void;
83
83
 
84
84
  params?: any;
85
- componentId?: string;
86
85
  }
87
86
 
88
87
  type InputPropsWithoutSizeAndIcon = Omit<
@@ -130,8 +129,6 @@ export interface InputSearchProps extends TextInputProps {
130
129
  hasColorBG?: boolean;
131
130
 
132
131
  params?: any;
133
-
134
- componentId?: string;
135
132
  }
136
133
 
137
134
  export interface InputMoneyProps extends InputPropsWithoutPlaceholder {}
@@ -151,6 +148,8 @@ export interface InputOTPProps extends InputPropsWithoutSizeAndIcon {
151
148
  * 'number' - The OTP input will be treated as a number.
152
149
  */
153
150
  dataType?: 'string' | 'number';
151
+
152
+ floatingValue: string;
154
153
  }
155
154
 
156
155
  export type CaretProps = {
@@ -167,7 +166,7 @@ export type CaretProps = {
167
166
  length?: number;
168
167
  };
169
168
 
170
- export interface InputDropDownProps {
169
+ export interface InputDropDownProps extends InputProps {
171
170
  /**
172
171
  * Optional. Defines the size of the InputDropDown component.
173
172
  * 'small' - A smaller, less prominent input.
@@ -262,11 +261,6 @@ export interface InputDropDownProps {
262
261
  [key: string]: any;
263
262
  };
264
263
 
265
- /**
266
- * component id for element tracking.
267
- */
268
- componentId?: string;
269
-
270
264
  /**
271
265
  * Optional. Represents the style of the InputDropDown component.
272
266
  */