@momo-kits/foundation 0.81.41-beta.5 → 0.81.41

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.
@@ -173,53 +173,57 @@ const HeaderLeft: React.FC<HeaderBackProps> = ({
173
173
  useEffect(() => {
174
174
  const backHandler = BackHandler.addEventListener(
175
175
  'hardwareBackPress',
176
- goBack,
176
+ goBackSafe,
177
177
  );
178
178
 
179
179
  return () => backHandler.remove();
180
180
  }, []);
181
181
 
182
- const goBack = () => {
183
- const canGoBack = navigator?.ref.current?.canGoBack();
184
- if (!canGoBack && navigator?.trackingInfo) {
185
- const currentRoute = navigator?.ref?.current.getCurrentRoute();
186
- navigator?.maxApi?.trackEvent('service_icon_clicked', {
187
- feature_code: navigator.trackingInfo.code,
188
- app_id: navigator.trackingInfo.appId,
189
- miniapp_version: navigator.trackingInfo.buildNumber,
190
- flow_partner_id: navigator.trackingInfo.flowPartnerId,
191
- screen_name: currentRoute?.params?.screen?.name ?? currentRoute?.name,
192
- trigger_id: '111154000000000000',
193
- icon_name: 'back',
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
- } else {
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
- } else if (navigator?.maxApi) {
216
- navigator?.maxApi?.dismiss(navigator.dismissData);
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
- const currentTime = new Date().getTime();
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={goBack}
235
+ onPress={goBackSafe}
232
236
  accessibilityLabel={`${accessibilityLabel}Back`}
233
237
  useBorder={useBorder}
234
238
  />
@@ -345,8 +349,8 @@ const HeaderRightAction: React.FC<any> = ({children, ...restProps}) => {
345
349
 
346
350
  const HeaderToolkitAction: React.FC<any> = ({tintColor}) => {
347
351
  const {theme, navigator} = useContext(ApplicationContext);
348
- const [toolConfig, setToolConfig] = useState<any>();
349
- const {appCode, onAction} = toolConfig ?? {};
352
+ const [toolConfig, setToolConfig] = useState<HeaderToolkitProps>();
353
+ const {appCode, hidden, type, onAction} = toolConfig ?? {};
350
354
 
351
355
  let backgroundColor;
352
356
  if (tintColor != Colors.black_01) {
@@ -364,19 +368,10 @@ const HeaderToolkitAction: React.FC<any> = ({tintColor}) => {
364
368
  [undefined],
365
369
  (config: any) => {
366
370
  navigator.toolkitConfig = {
367
- configs: [
368
- ...config?.toolkitConfig?.customTools,
369
- ...config?.toolkitFeatureConfig,
370
- ],
371
+ ...config?.utilityToolConfig,
371
372
  appCode: config?.appCode,
372
373
  };
373
- setToolConfig({
374
- configs: [
375
- ...config?.toolkitConfig?.customTools,
376
- ...config?.toolkitFeatureConfig,
377
- ],
378
- appCode: config?.appCode,
379
- });
374
+ setToolConfig(navigator?.toolkitConfig);
380
375
  },
381
376
  );
382
377
  }
@@ -422,16 +417,14 @@ const HeaderToolkitAction: React.FC<any> = ({tintColor}) => {
422
417
  };
423
418
  }, [appCode]);
424
419
 
420
+ const onUtilityTool = () => {
421
+ onAction?.('onUtilityTool');
422
+ navigator?.requestApi(type, undefined, undefined);
423
+ };
424
+
425
425
  const onMore = () => {
426
426
  onAction?.('onMore');
427
- navigator?.requestApi(
428
- 'showTools',
429
- [toolConfig],
430
- (res: {item: {action?: string; key: string}}) => {
431
- const {item} = res;
432
- navigator?.toolkitCallback?.(item);
433
- },
434
- );
427
+ navigator?.requestApi('showToolkit', [toolConfig], undefined);
435
428
  };
436
429
 
437
430
  const onClose = () => {
@@ -439,28 +432,24 @@ const HeaderToolkitAction: React.FC<any> = ({tintColor}) => {
439
432
  navigator?.requestApi('dismiss', undefined, undefined);
440
433
  };
441
434
 
442
- const renderPinnedTool = () => {
443
- const pinTool = toolConfig?.configs?.find(
444
- (i: any) => i.key === navigator?.pinnedTool,
445
- );
446
- const {icon} = pinTool || '';
447
- if (pinTool && navigator?.pinnedTool)
435
+ const renderUtilityTool = () => {
436
+ if (hidden === false) {
448
437
  return (
449
438
  <NavigationButton
450
439
  accessibilityLabel={'UtilityTool'}
451
- icon={icon as string}
440
+ icon={type as string}
452
441
  tintColor={tintColor}
453
- onPress={() => {
454
- navigator?.toolkitCallback?.(navigator?.pinnedTool);
455
- }}
442
+ onPress={onUtilityTool}
456
443
  />
457
444
  );
445
+ }
446
+ return null;
458
447
  };
459
448
 
460
449
  if (toolConfig) {
461
450
  return (
462
451
  <View style={styles.headerRightButton}>
463
- {renderPinnedTool()}
452
+ {renderUtilityTool()}
464
453
  <View
465
454
  style={[
466
455
  styles.toolkitContainer,
@@ -13,8 +13,6 @@ class Navigator {
13
13
  maxApi?: any;
14
14
  trackingInfo?: TrackingInfo;
15
15
  dismissData?: any;
16
- pinnedTool?: string;
17
- toolkitCallback?: (item: any) => void;
18
16
 
19
17
  constructor(navigation: any) {
20
18
  this.ref = navigation;
@@ -79,6 +77,20 @@ class Navigator {
79
77
  this.ref.current.dispatch(StackActions.popToTop());
80
78
  };
81
79
 
80
+ /**
81
+ * navigate
82
+ * @param name
83
+ * @param params
84
+ */
85
+ navigate = (name: string, params: any) => {
86
+ this.ref.current.dispatch(
87
+ CommonActions.navigate({
88
+ name,
89
+ params,
90
+ }),
91
+ );
92
+ };
93
+
82
94
  /**
83
95
  * reset a navigation flow with new screen
84
96
  * @param params
@@ -109,16 +121,6 @@ class Navigator {
109
121
  this.maxApi[func]?.(...args, callback);
110
122
  }
111
123
  };
112
-
113
- setPinnedTool = (key: string) => {
114
- this.pinnedTool = key;
115
- };
116
-
117
- setToolkitCallback = (
118
- callback: (item: {key: string; action: string}) => void,
119
- ) => {
120
- this.toolkitCallback = callback;
121
- };
122
124
  }
123
125
 
124
126
  export default Navigator;
@@ -166,7 +166,9 @@ export type TitleCustomProps = {
166
166
  export type HeaderToolkitProps = {
167
167
  [key: string]: any;
168
168
  appCode: string;
169
- configs: any[];
169
+ hidden: boolean;
170
+ type: string;
171
+ onAction?: (action: string) => void;
170
172
  };
171
173
 
172
174
  export type HeaderAnimatedProps = {
@@ -45,7 +45,9 @@ const InputMoney = forwardRef(
45
45
  return formatNumberToMoney(valueFormat, 'đ');
46
46
  };
47
47
 
48
- const [value, setValue] = useState(validateText(defaultValue));
48
+ const [value, setValue] = useState(
49
+ defaultValue ? validateText(defaultValue) : '',
50
+ );
49
51
 
50
52
  const onClearText = () => {
51
53
  inputRef?.current?.clear();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/foundation",
3
- "version": "0.81.41-beta.5",
3
+ "version": "0.81.41",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {