@momo-kits/foundation 0.81.40 → 0.81.41-beta.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/Application/Components.tsx +106 -70
- package/Application/Navigator.ts +21 -0
- package/Application/types.ts +8 -3
- package/Application/utils.tsx +15 -0
- package/package.json +2 -2
|
@@ -173,53 +173,57 @@ const HeaderLeft: React.FC<HeaderBackProps> = ({
|
|
|
173
173
|
useEffect(() => {
|
|
174
174
|
const backHandler = BackHandler.addEventListener(
|
|
175
175
|
'hardwareBackPress',
|
|
176
|
-
|
|
176
|
+
goBackSafe,
|
|
177
177
|
);
|
|
178
178
|
|
|
179
179
|
return () => backHandler.remove();
|
|
180
180
|
}, []);
|
|
181
181
|
|
|
182
|
-
const
|
|
183
|
-
const
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
}
|
|
196
|
-
if (canGoBack) {
|
|
197
|
-
if (preventBack) {
|
|
198
|
-
navigator?.showModal({
|
|
199
|
-
screen: () => (
|
|
200
|
-
<PopupNotify
|
|
201
|
-
{...preventBack}
|
|
202
|
-
primary={{
|
|
203
|
-
title: preventBack.primary.title,
|
|
204
|
-
onPress: () => {
|
|
205
|
-
preventBack?.primary.onPress();
|
|
206
|
-
navigator?.ref.current?.goBack();
|
|
207
|
-
},
|
|
208
|
-
}}
|
|
209
|
-
/>
|
|
210
|
-
),
|
|
182
|
+
const goBackSafe = () => {
|
|
183
|
+
const goBack = () => {
|
|
184
|
+
const canGoBack = navigator?.ref.current?.canGoBack();
|
|
185
|
+
if (!canGoBack && navigator?.trackingInfo) {
|
|
186
|
+
const currentRoute = navigator?.ref?.current.getCurrentRoute();
|
|
187
|
+
navigator?.maxApi?.trackEvent?.('service_icon_clicked', {
|
|
188
|
+
feature_code: navigator.trackingInfo.code,
|
|
189
|
+
app_id: navigator.trackingInfo.appId,
|
|
190
|
+
miniapp_version: navigator.trackingInfo.buildNumber,
|
|
191
|
+
flow_partner_id: navigator.trackingInfo.flowPartnerId,
|
|
192
|
+
screen_name: currentRoute?.params?.screen?.name ?? currentRoute?.name,
|
|
193
|
+
trigger_id: '111154000000000000',
|
|
194
|
+
icon_name: 'back',
|
|
211
195
|
});
|
|
212
|
-
}
|
|
196
|
+
}
|
|
197
|
+
if (canGoBack) {
|
|
213
198
|
navigator?.ref.current?.goBack();
|
|
199
|
+
} else if (navigator?.maxApi) {
|
|
200
|
+
navigator?.maxApi?.dismiss(navigator.dismissData);
|
|
201
|
+
} else {
|
|
202
|
+
const currentTime = new Date().getTime();
|
|
203
|
+
const requestId = `navigationBackPress#${currentTime}`;
|
|
204
|
+
DeviceEventEmitter.emit('dismiss', {requestId});
|
|
214
205
|
}
|
|
215
|
-
|
|
216
|
-
|
|
206
|
+
onPressLeftHeader?.();
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
if (preventBack) {
|
|
210
|
+
navigator?.showModal({
|
|
211
|
+
screen: () => (
|
|
212
|
+
<PopupNotify
|
|
213
|
+
{...preventBack}
|
|
214
|
+
primary={{
|
|
215
|
+
title: preventBack.primary.title,
|
|
216
|
+
onPress: () => {
|
|
217
|
+
preventBack?.primary.onPress();
|
|
218
|
+
goBack();
|
|
219
|
+
},
|
|
220
|
+
}}
|
|
221
|
+
/>
|
|
222
|
+
),
|
|
223
|
+
});
|
|
217
224
|
} else {
|
|
218
|
-
|
|
219
|
-
const requestId = `navigationBackPress#${currentTime}`;
|
|
220
|
-
DeviceEventEmitter.emit('dismiss', {requestId});
|
|
225
|
+
goBack();
|
|
221
226
|
}
|
|
222
|
-
onPressLeftHeader?.();
|
|
223
227
|
return true;
|
|
224
228
|
};
|
|
225
229
|
|
|
@@ -228,7 +232,7 @@ const HeaderLeft: React.FC<HeaderBackProps> = ({
|
|
|
228
232
|
<NavigationButton
|
|
229
233
|
icon="ic_back"
|
|
230
234
|
tintColor={tintColor}
|
|
231
|
-
onPress={
|
|
235
|
+
onPress={goBackSafe}
|
|
232
236
|
accessibilityLabel={`${accessibilityLabel}Back`}
|
|
233
237
|
useBorder={useBorder}
|
|
234
238
|
/>
|
|
@@ -343,10 +347,14 @@ const HeaderRightAction: React.FC<any> = ({children, ...restProps}) => {
|
|
|
343
347
|
return <View style={styles.headerRightButton}>{renderAction()}</View>;
|
|
344
348
|
};
|
|
345
349
|
|
|
346
|
-
const HeaderToolkitAction: React.FC<any> = ({
|
|
350
|
+
const HeaderToolkitAction: React.FC<any> = ({
|
|
351
|
+
tintColor,
|
|
352
|
+
pinnedTool,
|
|
353
|
+
preventBack,
|
|
354
|
+
}) => {
|
|
347
355
|
const {theme, navigator} = useContext(ApplicationContext);
|
|
348
|
-
const [toolConfig, setToolConfig] = useState<
|
|
349
|
-
const {appCode,
|
|
356
|
+
const [toolConfig, setToolConfig] = useState<any>();
|
|
357
|
+
const {appCode, onAction} = toolConfig ?? {};
|
|
350
358
|
|
|
351
359
|
let backgroundColor;
|
|
352
360
|
if (tintColor != Colors.black_01) {
|
|
@@ -357,20 +365,21 @@ const HeaderToolkitAction: React.FC<any> = ({tintColor}) => {
|
|
|
357
365
|
if (navigator?.toolkitConfig) {
|
|
358
366
|
setToolConfig(navigator?.toolkitConfig);
|
|
359
367
|
} else {
|
|
360
|
-
navigator?.requestApi('
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
368
|
+
navigator?.requestApi('getToolkitConfig', [undefined], (config: any) => {
|
|
369
|
+
navigator.toolkitConfig = {
|
|
370
|
+
configs: [
|
|
371
|
+
...config?.miniappTools?.customTools,
|
|
372
|
+
...config?.defaultTools,
|
|
373
|
+
],
|
|
374
|
+
appCode: config?.appCode,
|
|
375
|
+
};
|
|
376
|
+
setToolConfig({
|
|
377
|
+
configs: [
|
|
378
|
+
...config?.miniappTools?.customTools,
|
|
379
|
+
...config?.defaultTools,
|
|
380
|
+
],
|
|
381
|
+
appCode: config?.appCode,
|
|
382
|
+
});
|
|
374
383
|
});
|
|
375
384
|
}
|
|
376
385
|
}, []);
|
|
@@ -413,39 +422,66 @@ const HeaderToolkitAction: React.FC<any> = ({tintColor}) => {
|
|
|
413
422
|
};
|
|
414
423
|
}, [appCode]);
|
|
415
424
|
|
|
416
|
-
const onUtilityTool = () => {
|
|
417
|
-
onAction?.('onUtilityTool');
|
|
418
|
-
navigator?.requestApi(type, undefined, undefined);
|
|
419
|
-
};
|
|
420
|
-
|
|
421
425
|
const onMore = () => {
|
|
422
426
|
onAction?.('onMore');
|
|
423
|
-
navigator?.requestApi(
|
|
427
|
+
navigator?.requestApi(
|
|
428
|
+
'showTools',
|
|
429
|
+
[toolConfig],
|
|
430
|
+
(res: {item: {action?: string; key: string}}) => {
|
|
431
|
+
const {item} = res;
|
|
432
|
+
navigator?.toolkitCallback?.(item);
|
|
433
|
+
},
|
|
434
|
+
);
|
|
424
435
|
};
|
|
425
436
|
|
|
426
437
|
const onClose = () => {
|
|
427
|
-
|
|
428
|
-
|
|
438
|
+
if (preventBack) {
|
|
439
|
+
navigator?.showModal({
|
|
440
|
+
screen: () => (
|
|
441
|
+
<PopupNotify
|
|
442
|
+
{...preventBack}
|
|
443
|
+
primary={{
|
|
444
|
+
title: preventBack.primary.title,
|
|
445
|
+
onPress: () => {
|
|
446
|
+
preventBack?.primary.onPress();
|
|
447
|
+
navigator?.requestApi('dismiss', undefined, undefined);
|
|
448
|
+
},
|
|
449
|
+
}}
|
|
450
|
+
/>
|
|
451
|
+
),
|
|
452
|
+
});
|
|
453
|
+
} else {
|
|
454
|
+
navigator?.requestApi('dismiss', undefined, undefined);
|
|
455
|
+
}
|
|
429
456
|
};
|
|
430
457
|
|
|
431
|
-
const
|
|
432
|
-
|
|
458
|
+
const renderPinnedTool = () => {
|
|
459
|
+
const pinTool = toolConfig?.configs?.find(
|
|
460
|
+
(i: any) => i.key === pinnedTool.key,
|
|
461
|
+
);
|
|
462
|
+
const {badgeValue, showBadge} = pinnedTool;
|
|
463
|
+
const badgeType = showBadge && badgeValue ? 'number' : 'dot';
|
|
464
|
+
const validatedBadgeValue = isNaN(Number(badgeValue)) ? badgeValue : null;
|
|
465
|
+
const {icon} = pinTool || '';
|
|
466
|
+
if (pinTool && pinnedTool)
|
|
433
467
|
return (
|
|
434
468
|
<NavigationButton
|
|
435
469
|
accessibilityLabel={'UtilityTool'}
|
|
436
|
-
icon={
|
|
470
|
+
icon={icon as string}
|
|
437
471
|
tintColor={tintColor}
|
|
438
|
-
|
|
472
|
+
badgeValue={validatedBadgeValue}
|
|
473
|
+
badgeType={badgeType}
|
|
474
|
+
onPress={() => {
|
|
475
|
+
navigator?.toolkitCallback?.(pinnedTool.key);
|
|
476
|
+
}}
|
|
439
477
|
/>
|
|
440
478
|
);
|
|
441
|
-
}
|
|
442
|
-
return null;
|
|
443
479
|
};
|
|
444
480
|
|
|
445
481
|
if (toolConfig) {
|
|
446
482
|
return (
|
|
447
483
|
<View style={styles.headerRightButton}>
|
|
448
|
-
{
|
|
484
|
+
{renderPinnedTool()}
|
|
449
485
|
<View
|
|
450
486
|
style={[
|
|
451
487
|
styles.toolkitContainer,
|
package/Application/Navigator.ts
CHANGED
|
@@ -13,6 +13,7 @@ class Navigator {
|
|
|
13
13
|
maxApi?: any;
|
|
14
14
|
trackingInfo?: TrackingInfo;
|
|
15
15
|
dismissData?: any;
|
|
16
|
+
toolkitCallback?: (item: any) => void;
|
|
16
17
|
|
|
17
18
|
constructor(navigation: any) {
|
|
18
19
|
this.ref = navigation;
|
|
@@ -77,6 +78,20 @@ class Navigator {
|
|
|
77
78
|
this.ref.current.dispatch(StackActions.popToTop());
|
|
78
79
|
};
|
|
79
80
|
|
|
81
|
+
/**
|
|
82
|
+
* navigate
|
|
83
|
+
* @param name
|
|
84
|
+
* @param params
|
|
85
|
+
*/
|
|
86
|
+
navigate = (name: string, params: any) => {
|
|
87
|
+
this.ref.current.dispatch(
|
|
88
|
+
CommonActions.navigate({
|
|
89
|
+
name,
|
|
90
|
+
params,
|
|
91
|
+
}),
|
|
92
|
+
);
|
|
93
|
+
};
|
|
94
|
+
|
|
80
95
|
/**
|
|
81
96
|
* reset a navigation flow with new screen
|
|
82
97
|
* @param params
|
|
@@ -107,6 +122,12 @@ class Navigator {
|
|
|
107
122
|
this.maxApi[func]?.(...args, callback);
|
|
108
123
|
}
|
|
109
124
|
};
|
|
125
|
+
|
|
126
|
+
setToolkitCallback = (
|
|
127
|
+
callback: (item: {key: string; action: string}) => void,
|
|
128
|
+
) => {
|
|
129
|
+
this.toolkitCallback = callback;
|
|
130
|
+
};
|
|
110
131
|
}
|
|
111
132
|
|
|
112
133
|
export default Navigator;
|
package/Application/types.ts
CHANGED
|
@@ -132,12 +132,19 @@ export type NavigationButtonProps = {
|
|
|
132
132
|
badgeValue?: number | string;
|
|
133
133
|
};
|
|
134
134
|
|
|
135
|
+
export type PinnedToolType = {
|
|
136
|
+
key: string;
|
|
137
|
+
badgeValue?: number;
|
|
138
|
+
showBadge?: boolean;
|
|
139
|
+
};
|
|
140
|
+
|
|
135
141
|
export interface NavigationOptions extends StackNavigationOptions {
|
|
136
142
|
preventBack?: PopupNotifyProps;
|
|
137
143
|
onPressLeftHeader?: () => void;
|
|
138
144
|
surface?: boolean;
|
|
139
145
|
hiddenBack?: boolean;
|
|
140
146
|
customTitle?: TitleCustomProps;
|
|
147
|
+
pinnedTool?: PinnedToolType;
|
|
141
148
|
}
|
|
142
149
|
|
|
143
150
|
export interface HeaderBackProps extends NavigationButtonProps {
|
|
@@ -166,9 +173,7 @@ export type TitleCustomProps = {
|
|
|
166
173
|
export type HeaderToolkitProps = {
|
|
167
174
|
[key: string]: any;
|
|
168
175
|
appCode: string;
|
|
169
|
-
|
|
170
|
-
type: string;
|
|
171
|
-
onAction?: (action: string) => void;
|
|
176
|
+
configs: any[];
|
|
172
177
|
};
|
|
173
178
|
|
|
174
179
|
export type HeaderAnimatedProps = {
|
package/Application/utils.tsx
CHANGED
|
@@ -126,6 +126,21 @@ const getOptions = (params: NavigationOptions, theme: Theme) => {
|
|
|
126
126
|
};
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
+
if (params.pinnedTool) {
|
|
130
|
+
options = {
|
|
131
|
+
...options,
|
|
132
|
+
headerRight: (props: any) => {
|
|
133
|
+
return (
|
|
134
|
+
<HeaderToolkitAction
|
|
135
|
+
preventBack={params.preventBack}
|
|
136
|
+
pinnedTool={params.pinnedTool}
|
|
137
|
+
{...props}
|
|
138
|
+
/>
|
|
139
|
+
);
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
129
144
|
return {
|
|
130
145
|
...params,
|
|
131
146
|
...options,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@momo-kits/foundation",
|
|
3
|
-
"version": "0.81.
|
|
3
|
+
"version": "0.81.41-beta.10",
|
|
4
4
|
"description": "React Native Component Kits",
|
|
5
5
|
"main": "index.ts",
|
|
6
6
|
"scripts": {
|
|
@@ -43,4 +43,4 @@
|
|
|
43
43
|
},
|
|
44
44
|
"author": "@momo-kits/foundation",
|
|
45
45
|
"license": "ISC"
|
|
46
|
-
}
|
|
46
|
+
}
|