@momo-kits/foundation 0.103.1-optimize.4 → 0.103.1-optimize.6

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.
@@ -149,7 +149,7 @@ const HeaderLeft: React.FC<HeaderBackProps> = ({
149
149
  const goBackSafe = () => {
150
150
  const goBack = () => {
151
151
  const canGoBack = navigator?.ref?.current?.canGoBack?.();
152
- const currentRoute = navigator?.ref?.current?.getCurrentRoute?.();
152
+ const currentRoute: any = navigator?.ref?.current?.getCurrentRoute?.();
153
153
  const params = {
154
154
  appId: context.appId,
155
155
  code: context.code,
@@ -337,7 +337,6 @@ const HeaderRight: React.FC<any> = ({type, children, onLayout, ...props}) => {
337
337
  const HeaderToolkitAction: React.FC<any> = ({
338
338
  tintColor,
339
339
  pinnedTool,
340
- runtimeTools = [],
341
340
  preventClose,
342
341
  }) => {
343
342
  const {navigator} = useContext(ApplicationContext);
@@ -374,13 +373,15 @@ const HeaderToolkitAction: React.FC<any> = ({
374
373
  const onMore = () => {
375
374
  onAction?.('onMore');
376
375
  navigator?.maxApi?.dispatchFunction?.(
377
- 'showTools',
378
- {runtimeTools},
379
- (res: {item: {action?: string; key: string}}) => {
380
- const {item} = res;
381
- navigator?.toolkitCallback?.(item.key);
382
- getToolkitConfig();
383
- }
376
+ 'showToolkit',
377
+ {
378
+ tools: miniContext?.toolkitConfig?.oldTools ?? [
379
+ 'addFavorite',
380
+ 'addShortcut',
381
+ 'share',
382
+ ],
383
+ },
384
+ () => {}
384
385
  );
385
386
  };
386
387
 
@@ -4,7 +4,7 @@ import defaultLanguage from '../Assets/language.json';
4
4
 
5
5
  class Localize {
6
6
  private assets: LocalizationObject;
7
- private readonly currentLanguage: 'en' | 'vi';
7
+ private currentLanguage: 'en' | 'vi';
8
8
 
9
9
  constructor(assets: LocalizationObject) {
10
10
  this.assets = {
@@ -21,6 +21,10 @@ class Localize {
21
21
  return this.currentLanguage;
22
22
  }
23
23
 
24
+ get getAssets() {
25
+ return this.assets;
26
+ }
27
+
24
28
  translate(key: string) {
25
29
  return this.assets[this.currentLanguage]?.[key] || key;
26
30
  }
@@ -1,95 +1,170 @@
1
- import {CommonActions, StackActions} from '@react-navigation/native';
1
+ import {
2
+ CommonActions,
3
+ NavigationContainerRef,
4
+ StackActions,
5
+ } from '@react-navigation/native';
2
6
  import {
3
7
  BottomSheetParams,
4
8
  HeaderToolkitProps,
5
9
  ModalParams,
10
+ NavigatorCallbackParamsType,
6
11
  ScreenParams,
7
12
  } from './types';
13
+ import React from 'react';
14
+ import {
15
+ NavigationActionCallbackErrorEnum,
16
+ NavigationActionCallbackStatusEnum,
17
+ } from './constants';
8
18
 
9
19
  class Navigator {
10
- ref?: any;
11
- isReady?: any;
20
+ ref: React.RefObject<NavigationContainerRef>;
21
+ isReady: React.MutableRefObject<boolean>;
12
22
  toolkitConfig?: HeaderToolkitProps;
13
23
  maxApi?: any;
14
- dismissData?: any;
24
+ dismissData?: unknown;
15
25
  toolkitCallback?: (key: string) => void;
16
26
 
17
- constructor(navigation: any, isReady: any) {
27
+ constructor(
28
+ navigation: React.RefObject<NavigationContainerRef>,
29
+ isReady: React.MutableRefObject<boolean>
30
+ ) {
18
31
  this.ref = navigation;
19
32
  this.isReady = isReady;
20
33
  }
21
34
 
35
+ private validateRefAndRunAction = (params: {
36
+ action: (navigationRef: NavigationContainerRef) => void;
37
+ callback?: (params: NavigatorCallbackParamsType) => void;
38
+ }) => {
39
+ try {
40
+ if (this.isReady.current && this.ref.current) {
41
+ params.action(this.ref.current);
42
+ params.callback?.({status: NavigationActionCallbackStatusEnum.Success});
43
+ } else {
44
+ params.callback?.({
45
+ status: NavigationActionCallbackStatusEnum.Failed,
46
+ type: NavigationActionCallbackErrorEnum.NotReady,
47
+ });
48
+ }
49
+ } catch (error) {
50
+ params.callback?.({
51
+ status: NavigationActionCallbackStatusEnum.Failed,
52
+ type: NavigationActionCallbackErrorEnum.Error,
53
+ });
54
+ }
55
+ };
56
+
22
57
  /**
23
58
  * push new stack screen
24
59
  * @param params
25
60
  */
26
- push = (params: ScreenParams) => {
27
- if (this.isReady.current) {
28
- this.ref.current?.dispatch?.(StackActions.push('Stack', params));
29
- }
61
+ push = (
62
+ params: ScreenParams,
63
+ callback?: (params: NavigatorCallbackParamsType) => void
64
+ ) => {
65
+ this.validateRefAndRunAction({
66
+ action: navigationRef => {
67
+ navigationRef.dispatch(StackActions.push('Stack', params));
68
+ },
69
+ callback,
70
+ });
30
71
  };
31
72
 
32
73
  /**
33
74
  * replace current screen with new screen
34
75
  * @param params
35
76
  */
36
- replace = (params: ScreenParams) => {
37
- if (this.isReady.current) {
38
- this.ref.current?.dispatch?.(StackActions.replace('Stack', params));
39
- }
77
+ replace = (
78
+ params: ScreenParams,
79
+ callback?: (params: NavigatorCallbackParamsType) => void
80
+ ) => {
81
+ this.validateRefAndRunAction({
82
+ action: navigationRef => {
83
+ navigationRef.dispatch(StackActions.replace('Stack', params));
84
+ },
85
+ callback,
86
+ });
40
87
  };
41
88
  /**
42
89
  * pop to dismiss a screen
43
90
  * @param count
44
91
  */
45
- pop = (count?: number) => {
46
- if (this.isReady.current) {
47
- this.ref.current?.dispatch?.(StackActions.pop(count ?? 1));
48
- }
92
+ pop = (
93
+ count?: number,
94
+ callback?: (params: NavigatorCallbackParamsType) => void
95
+ ) => {
96
+ this.validateRefAndRunAction({
97
+ action: navigationRef => {
98
+ navigationRef.dispatch(StackActions.pop(count ?? 1));
99
+ },
100
+ callback,
101
+ });
49
102
  };
50
103
 
51
104
  /**
52
105
  * present a new screen, show from bottom iOS
53
106
  * @param params
54
107
  */
55
- present = (params: ScreenParams) => {
56
- if (this.isReady.current) {
57
- this.ref.current?.dispatch?.(StackActions.push('Dialog', params));
58
- }
108
+ present = (
109
+ params: ScreenParams,
110
+ callback?: (params: NavigatorCallbackParamsType) => void
111
+ ) => {
112
+ this.validateRefAndRunAction({
113
+ action: navigationRef => {
114
+ navigationRef.dispatch(StackActions.push('Dialog', params));
115
+ },
116
+ callback,
117
+ });
59
118
  };
60
119
 
61
120
  /**
62
121
  * show a modal popup
63
122
  * @param params
64
123
  */
65
- showModal = (params: ModalParams) => {
66
- if (this.isReady.current) {
67
- this.ref.current?.dispatch?.(StackActions.push('Modal', params));
68
- }
124
+ showModal = (
125
+ params: ModalParams,
126
+ callback?: (params: NavigatorCallbackParamsType) => void
127
+ ) => {
128
+ this.validateRefAndRunAction({
129
+ action: navigationRef => {
130
+ navigationRef.dispatch(StackActions.push('Modal', params));
131
+ },
132
+ callback,
133
+ });
69
134
  };
70
135
 
71
136
  /**
72
137
  * show a bottom sheet
73
138
  * @param params
139
+ * @param callback
74
140
  */
75
- showBottomSheet = (params: BottomSheetParams) => {
76
- if (this.isReady.current) {
77
- this.ref.current?.dispatch?.(
78
- StackActions.push('Modal', {
79
- ...params,
80
- isBottomSheet: true,
81
- })
82
- );
83
- }
141
+ showBottomSheet = (
142
+ params: BottomSheetParams,
143
+ callback?: (params: NavigatorCallbackParamsType) => void
144
+ ) => {
145
+ this.validateRefAndRunAction({
146
+ action: navigationRef => {
147
+ navigationRef.dispatch(
148
+ StackActions.push('Modal', {
149
+ ...params,
150
+ isBottomSheet: true,
151
+ })
152
+ );
153
+ },
154
+ callback,
155
+ });
84
156
  };
85
157
 
86
158
  /**
87
159
  * pop all screen route
88
160
  */
89
- popToTop = () => {
90
- if (this.isReady.current) {
91
- this.ref.current?.dispatch?.(StackActions.popToTop());
92
- }
161
+ popToTop = (callback?: (params: NavigatorCallbackParamsType) => void) => {
162
+ this.validateRefAndRunAction({
163
+ action: navigationRef => {
164
+ navigationRef.dispatch(StackActions.popToTop());
165
+ },
166
+ callback,
167
+ });
93
168
  };
94
169
 
95
170
  /**
@@ -97,43 +172,56 @@ class Navigator {
97
172
  * @param name
98
173
  * @param params
99
174
  */
100
- navigate = (name: string, params: any) => {
101
- if (this.isReady.current) {
102
- this.ref.current?.dispatch?.(
103
- CommonActions.navigate({
104
- name,
105
- params,
106
- })
107
- );
108
- }
175
+ navigate = (
176
+ name: string,
177
+ params: any,
178
+ callback?: (params: NavigatorCallbackParamsType) => void
179
+ ) => {
180
+ this.validateRefAndRunAction({
181
+ action: navigationRef => {
182
+ navigationRef.dispatch(
183
+ CommonActions.navigate({
184
+ name,
185
+ params,
186
+ })
187
+ );
188
+ },
189
+ callback,
190
+ });
109
191
  };
110
192
 
111
193
  /**
112
194
  * reset a navigation flow with new screen
113
195
  * @param params
114
196
  */
115
- reset = (params: ScreenParams) => {
116
- if (this.isReady.current) {
117
- this.ref.current?.dispatch?.(
118
- CommonActions.reset({
119
- index: 0,
120
- routes: [
121
- {
122
- name: 'Stack',
123
- key: `Stack_${new Date().getTime()}`,
124
- params,
125
- },
126
- ],
127
- })
128
- );
129
- }
197
+ reset = (
198
+ params: ScreenParams,
199
+ callback?: (params: NavigatorCallbackParamsType) => void
200
+ ) => {
201
+ this.validateRefAndRunAction({
202
+ action: navigationRef => {
203
+ navigationRef.dispatch(
204
+ CommonActions.reset({
205
+ index: 0,
206
+ routes: [
207
+ {
208
+ name: 'Stack',
209
+ key: `Stack_${new Date().getTime()}`,
210
+ params,
211
+ },
212
+ ],
213
+ })
214
+ );
215
+ },
216
+ callback,
217
+ });
130
218
  };
131
219
 
132
220
  /**
133
221
  * dismiss a feature data
134
222
  * @param data
135
223
  */
136
- setDismissData = (data: any) => {
224
+ setDismissData = (data: unknown) => {
137
225
  this.dismissData = data;
138
226
  };
139
227
 
@@ -0,0 +1,9 @@
1
+ export enum NavigationActionCallbackStatusEnum {
2
+ Success = 'success',
3
+ Failed = 'failed',
4
+ }
5
+
6
+ export enum NavigationActionCallbackErrorEnum {
7
+ NotReady = 'not_ready',
8
+ Error = 'error',
9
+ }
@@ -6,6 +6,10 @@ import {PopupNotifyProps} from '../Popup/types';
6
6
  import Localize from './Localize';
7
7
  import Navigation from './Navigation';
8
8
  import Navigator from './Navigator';
9
+ import {
10
+ NavigationActionCallbackErrorEnum,
11
+ NavigationActionCallbackStatusEnum,
12
+ } from './constants';
9
13
 
10
14
  type Screen = React.ComponentType<NavigationScreenProps>;
11
15
 
@@ -243,3 +247,16 @@ export type AnimatedHeader = {
243
247
  component?: (props?: any) => React.ReactElement;
244
248
  headerTitle?: (props?: any) => React.ReactElement;
245
249
  };
250
+
251
+ type NavigatorActionSuccessCallbackType = {
252
+ status: NavigationActionCallbackStatusEnum.Success;
253
+ };
254
+
255
+ type NavigatorActionFailCallbackType = {
256
+ status: NavigationActionCallbackStatusEnum.Failed;
257
+ type: NavigationActionCallbackErrorEnum;
258
+ };
259
+
260
+ export type NavigatorCallbackParamsType =
261
+ | NavigatorActionSuccessCallbackType
262
+ | NavigatorActionFailCallbackType;
@@ -33,7 +33,7 @@ const PopupNotify: React.FC<PopupNotifyProps> = ({
33
33
  * tracking
34
34
  */
35
35
  useEffect(() => {
36
- const routes = navigator?.ref.current?.getRootState()?.routes || [];
36
+ const routes: any = navigator?.ref.current?.getRootState()?.routes || [];
37
37
  const routesLength = routes.length;
38
38
  let screen_name = routes?.[0]?.params?.screen?.name;
39
39
  if (routesLength > 1) {
@@ -19,7 +19,7 @@ const PopupPromotion: React.FC<PopupPromotionProps> = ({
19
19
  * tracking
20
20
  */
21
21
  useEffect(() => {
22
- const routes = navigator?.ref.current?.getRootState()?.routes || [];
22
+ const routes: any = navigator?.ref.current?.getRootState()?.routes || [];
23
23
  const routesLength = routes.length;
24
24
  let screen_name = routes?.[0]?.params?.screen?.name;
25
25
  if (routesLength > 1) {
package/Tag/index.tsx CHANGED
@@ -31,6 +31,8 @@ const Tag: FC<TagProps> = ({
31
31
  size = 'large',
32
32
  style,
33
33
  customColor,
34
+ accessibilityLabelContainer,
35
+ accessibilityLabelText,
34
36
  }) => {
35
37
  let labelColor = textColor[color];
36
38
  let tagColor = backgroundColor[color];
@@ -60,7 +62,9 @@ const Tag: FC<TagProps> = ({
60
62
  }
61
63
 
62
64
  return (
63
- <View style={[style, sizeStyle, {backgroundColor: tagColor}]}>
65
+ <View
66
+ style={[style, sizeStyle, {backgroundColor: tagColor}]}
67
+ accessibilityLabel={accessibilityLabelContainer}>
64
68
  {!!icon && (
65
69
  <Icon
66
70
  style={styles.icon}
@@ -69,7 +73,10 @@ const Tag: FC<TagProps> = ({
69
73
  color={labelColor}
70
74
  />
71
75
  )}
72
- <Text color={labelColor} typography={'label_s_medium'}>
76
+ <Text
77
+ color={labelColor}
78
+ typography={'label_s_medium'}
79
+ accessibilityLabel={accessibilityLabelText}>
73
80
  {label}
74
81
  </Text>
75
82
  </View>
package/Tag/types.ts CHANGED
@@ -33,4 +33,16 @@ export type TagProps = {
33
33
  * that can be applied to the Tag component.
34
34
  */
35
35
  customColor?: string;
36
+
37
+ /**
38
+ * Overrides the text that's read by the screen reader when the user interacts with the element. By default, the
39
+ * label is constructed by traversing all the children and accumulating all the Text nodes separated by space.
40
+ */
41
+ accessibilityLabelContainer?: string;
42
+
43
+ /**
44
+ * Overrides the text that's read by the screen reader when the user interacts with the element. By default, the
45
+ * label is constructed by traversing all the children and accumulating all the Text nodes separated by space.
46
+ */
47
+ accessibilityLabelText?: string;
36
48
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/foundation",
3
- "version": "0.103.1-optimize.4",
3
+ "version": "0.103.1-optimize.6",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {},