@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.
- package/Application/Components.tsx +10 -9
- package/Application/Localize.ts +5 -1
- package/Application/Navigator.ts +151 -63
- package/Application/constants.ts +9 -0
- package/Application/types.ts +17 -0
- package/Popup/PopupNotify.tsx +1 -1
- package/Popup/PopupPromotion.tsx +1 -1
- package/Tag/index.tsx +9 -2
- package/Tag/types.ts +12 -0
- package/package.json +1 -1
|
@@ -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
|
-
'
|
|
378
|
-
{
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
376
|
+
'showToolkit',
|
|
377
|
+
{
|
|
378
|
+
tools: miniContext?.toolkitConfig?.oldTools ?? [
|
|
379
|
+
'addFavorite',
|
|
380
|
+
'addShortcut',
|
|
381
|
+
'share',
|
|
382
|
+
],
|
|
383
|
+
},
|
|
384
|
+
() => {}
|
|
384
385
|
);
|
|
385
386
|
};
|
|
386
387
|
|
package/Application/Localize.ts
CHANGED
|
@@ -4,7 +4,7 @@ import defaultLanguage from '../Assets/language.json';
|
|
|
4
4
|
|
|
5
5
|
class Localize {
|
|
6
6
|
private assets: LocalizationObject;
|
|
7
|
-
private
|
|
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
|
}
|
package/Application/Navigator.ts
CHANGED
|
@@ -1,95 +1,170 @@
|
|
|
1
|
-
import {
|
|
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
|
|
11
|
-
isReady
|
|
20
|
+
ref: React.RefObject<NavigationContainerRef>;
|
|
21
|
+
isReady: React.MutableRefObject<boolean>;
|
|
12
22
|
toolkitConfig?: HeaderToolkitProps;
|
|
13
23
|
maxApi?: any;
|
|
14
|
-
dismissData?:
|
|
24
|
+
dismissData?: unknown;
|
|
15
25
|
toolkitCallback?: (key: string) => void;
|
|
16
26
|
|
|
17
|
-
constructor(
|
|
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 = (
|
|
27
|
-
|
|
28
|
-
|
|
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 = (
|
|
37
|
-
|
|
38
|
-
|
|
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 = (
|
|
46
|
-
|
|
47
|
-
|
|
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 = (
|
|
56
|
-
|
|
57
|
-
|
|
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 = (
|
|
66
|
-
|
|
67
|
-
|
|
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 = (
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
|
|
91
|
-
|
|
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 = (
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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 = (
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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:
|
|
224
|
+
setDismissData = (data: unknown) => {
|
|
137
225
|
this.dismissData = data;
|
|
138
226
|
};
|
|
139
227
|
|
package/Application/types.ts
CHANGED
|
@@ -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;
|
package/Popup/PopupNotify.tsx
CHANGED
|
@@ -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) {
|
package/Popup/PopupPromotion.tsx
CHANGED
|
@@ -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
|
|
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
|
|
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
|
};
|