From 766a4544ee1ba019fa3332d6b7395f3fbf5c66f9 Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Tue, 10 Dec 2024 11:04:53 -0700 Subject: [PATCH] Merge pull request #53873 from huult/53848-transaction-freeze-on-replace-receipt [CP Staging] Add shouldCallDirectly for closeModal logic (cherry picked from commit b29b3e425c4bf8a8a54adeb4d4434e9c845beeba) (CP triggered by Beamanator) --- src/components/AttachmentModal.tsx | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/components/AttachmentModal.tsx b/src/components/AttachmentModal.tsx index 689e8826b60e..0ad6dfbb8f7f 100644 --- a/src/components/AttachmentModal.tsx +++ b/src/components/AttachmentModal.tsx @@ -379,17 +379,28 @@ function AttachmentModal({ ); /** - * close the modal + * Closes the modal. + * @param {boolean} [shouldCallDirectly] If true, directly calls `onModalClose`. + * This is useful when you plan to continue navigating to another page after closing the modal, to avoid freezing the app due to navigating to another page first and dismissing the modal later. + * If `shouldCallDirectly` is false or undefined, it calls `attachmentModalHandler.handleModalClose` to close the modal. + * This ensures smooth modal closing behavior without causing delays in closing. */ - const closeModal = useCallback(() => { - setIsModalOpen(false); + const closeModal = useCallback( + (shouldCallDirectly?: boolean) => { + setIsModalOpen(false); - if (typeof onModalClose === 'function') { - attachmentModalHandler.handleModalClose(onModalClose); - } + if (typeof onModalClose === 'function') { + if (shouldCallDirectly) { + onModalClose(); + return; + } + attachmentModalHandler.handleModalClose(onModalClose); + } - // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps - }, [onModalClose]); + // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps + }, + [onModalClose], + ); /** * open the modal @@ -419,7 +430,7 @@ function AttachmentModal({ icon: Expensicons.Camera, text: translate('common.replace'), onSelected: () => { - closeModal(); + closeModal(true); Navigation.navigate( ROUTES.MONEY_REQUEST_STEP_SCAN.getRoute( CONST.IOU.ACTION.EDIT,