@momo-kits/foundation 0.81.41-beta.8 → 0.81.41-beta.9

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
  />
@@ -343,7 +347,11 @@ 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> = ({tintColor, pinnedTool}) => {
350
+ const HeaderToolkitAction: React.FC<any> = ({
351
+ tintColor,
352
+ pinnedTool,
353
+ preventBack,
354
+ }) => {
347
355
  const {theme, navigator} = useContext(ApplicationContext);
348
356
  const [toolConfig, setToolConfig] = useState<any>();
349
357
  const {appCode, onAction} = toolConfig ?? {};
@@ -427,8 +435,24 @@ const HeaderToolkitAction: React.FC<any> = ({tintColor, pinnedTool}) => {
427
435
  };
428
436
 
429
437
  const onClose = () => {
430
- onAction?.('onClose');
431
- navigator?.requestApi('dismiss', undefined, undefined);
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
+ }
432
456
  };
433
457
 
434
458
  const renderPinnedTool = () => {
@@ -78,6 +78,20 @@ class Navigator {
78
78
  this.ref.current.dispatch(StackActions.popToTop());
79
79
  };
80
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
+
81
95
  /**
82
96
  * reset a navigation flow with new screen
83
97
  * @param params
@@ -132,7 +132,7 @@ const getOptions = (params: NavigationOptions, theme: Theme) => {
132
132
  headerRight: (props: any) => {
133
133
  return (
134
134
  <HeaderToolkitAction
135
- preventBack={params.preventBack ? params.preventBack : null}
135
+ preventBack={params.preventBack}
136
136
  pinnedTool={params.pinnedTool}
137
137
  {...props}
138
138
  />
@@ -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.8",
3
+ "version": "0.81.41-beta.9",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {