From bd00561971c3b1c0afdae25d5bf0713443860eb6 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Sat, 12 Apr 2025 09:59:57 +0800 Subject: [PATCH 1/5] navigate to replace page when modal hides --- src/components/AttachmentModal.tsx | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/components/AttachmentModal.tsx b/src/components/AttachmentModal.tsx index 157f70a2cf52..7464e03b6a43 100644 --- a/src/components/AttachmentModal.tsx +++ b/src/components/AttachmentModal.tsx @@ -198,6 +198,7 @@ function AttachmentModal({ const [isConfirmButtonDisabled, setIsConfirmButtonDisabled] = useState(false); const [isDownloadButtonReadyToBeShown, setIsDownloadButtonReadyToBeShown] = React.useState(true); const isPDFLoadError = useRef(false); + const isReplaceReceipt = useRef(false); const {windowWidth} = useWindowDimensions(); const {shouldUseNarrowLayout} = useResponsiveLayout(); const nope = useSharedValue(false); @@ -452,17 +453,8 @@ function AttachmentModal({ text: translate('common.replace'), onSelected: () => { closeModal(true); - InteractionManager.runAfterInteractions(() => { - Navigation.navigate( - ROUTES.MONEY_REQUEST_STEP_SCAN.getRoute( - iouAction ?? CONST.IOU.ACTION.EDIT, - iouType, - draftTransactionID ?? transaction?.transactionID, - report?.reportID, - Navigation.getActiveRouteWithoutParams(), - ), - ); - }); + // Set the ref to true, so when the modal is hidden, we will navigate to the scan receipt screen + isReplaceReceipt.current = true; }, }); } @@ -529,6 +521,18 @@ function AttachmentModal({ if (!isPDFLoadError.current) { onModalHide(); } + if (isReplaceReceipt.current) { + Navigation.navigate( + ROUTES.MONEY_REQUEST_STEP_SCAN.getRoute( + iouAction ?? CONST.IOU.ACTION.EDIT, + iouType, + draftTransactionID ?? transaction?.transactionID, + report?.reportID, + Navigation.getActiveRouteWithoutParams(), + ), + ); + isReplaceReceipt.current = false; + } setShouldLoadAttachment(false); if (isPDFLoadError.current) { setIsAttachmentInvalid(true); From 15956832e3e36e8f92b53eac20e72397c030fbd2 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Sat, 12 Apr 2025 10:36:53 +0800 Subject: [PATCH 2/5] remove unused import --- src/components/AttachmentModal.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/AttachmentModal.tsx b/src/components/AttachmentModal.tsx index 7464e03b6a43..7545a3b87dd6 100644 --- a/src/components/AttachmentModal.tsx +++ b/src/components/AttachmentModal.tsx @@ -1,6 +1,6 @@ import {Str} from 'expensify-common'; import React, {memo, useCallback, useEffect, useMemo, useRef, useState} from 'react'; -import {InteractionManager, Keyboard, View} from 'react-native'; +import {Keyboard, View} from 'react-native'; import {GestureHandlerRootView} from 'react-native-gesture-handler'; import {useOnyx} from 'react-native-onyx'; import type {OnyxEntry} from 'react-native-onyx'; From 73bd2e60b4be55d23e6aed0d6ed1926f66096a00 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Sat, 12 Apr 2025 10:42:51 +0800 Subject: [PATCH 3/5] suppress lint --- src/components/AttachmentModal.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/components/AttachmentModal.tsx b/src/components/AttachmentModal.tsx index 7545a3b87dd6..571adf6f9ee6 100644 --- a/src/components/AttachmentModal.tsx +++ b/src/components/AttachmentModal.tsx @@ -448,6 +448,8 @@ function AttachmentModal({ const menuItems = []; if (canEditReceipt) { + // linter keep complain about accessing ref during render + // eslint-disable-next-line react-compiler/react-compiler menuItems.push({ icon: Expensicons.Camera, text: translate('common.replace'), From 9a9dceaa9b63ed694d6879e509a7a9584aafaaf3 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Sat, 12 Apr 2025 10:50:35 +0800 Subject: [PATCH 4/5] tidying up --- src/components/AttachmentModal.tsx | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/components/AttachmentModal.tsx b/src/components/AttachmentModal.tsx index 571adf6f9ee6..a1b0533c80b8 100644 --- a/src/components/AttachmentModal.tsx +++ b/src/components/AttachmentModal.tsx @@ -523,6 +523,14 @@ function AttachmentModal({ if (!isPDFLoadError.current) { onModalHide(); } + setShouldLoadAttachment(false); + if (isPDFLoadError.current) { + setIsAttachmentInvalid(true); + setAttachmentInvalidReasonTitle('attachmentPicker.attachmentError'); + setAttachmentInvalidReason('attachmentPicker.errorWhileSelectingCorruptedAttachment'); + return; + } + if (isReplaceReceipt.current) { Navigation.navigate( ROUTES.MONEY_REQUEST_STEP_SCAN.getRoute( @@ -533,13 +541,7 @@ function AttachmentModal({ Navigation.getActiveRouteWithoutParams(), ), ); - isReplaceReceipt.current = false; - } - setShouldLoadAttachment(false); - if (isPDFLoadError.current) { - setIsAttachmentInvalid(true); - setAttachmentInvalidReasonTitle('attachmentPicker.attachmentError'); - setAttachmentInvalidReason('attachmentPicker.errorWhileSelectingCorruptedAttachment'); + return; } }} propagateSwipe From 316b14897e3c8c0b8d9fb9dc59898534044cef17 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Sat, 12 Apr 2025 10:53:00 +0800 Subject: [PATCH 5/5] lint --- src/components/AttachmentModal.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/AttachmentModal.tsx b/src/components/AttachmentModal.tsx index a1b0533c80b8..1a21d986e4ff 100644 --- a/src/components/AttachmentModal.tsx +++ b/src/components/AttachmentModal.tsx @@ -541,7 +541,6 @@ function AttachmentModal({ Navigation.getActiveRouteWithoutParams(), ), ); - return; } }} propagateSwipe