From e367196bf005d17efe6d2f8185c913e57598ebe6 Mon Sep 17 00:00:00 2001 From: Huu Le <20178761+huult@users.noreply.github.com> Date: Tue, 10 Dec 2024 23:39:59 +0700 Subject: [PATCH 1/2] Add shouldCallDirectly for closeModal logic --- src/components/AttachmentModal.tsx | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/components/AttachmentModal.tsx b/src/components/AttachmentModal.tsx index 689e8826b60ea..c378e4d11188f 100644 --- a/src/components/AttachmentModal.tsx +++ b/src/components/AttachmentModal.tsx @@ -381,15 +381,22 @@ function AttachmentModal({ /** * close the modal */ - 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 +426,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, From 04dec5f09a35417a403cdeb858532303a8bf8a7c Mon Sep 17 00:00:00 2001 From: Huu Le <20178761+huult@users.noreply.github.com> Date: Wed, 11 Dec 2024 00:37:29 +0700 Subject: [PATCH 2/2] Add comment to explain shouldCallDirectly --- src/components/AttachmentModal.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/components/AttachmentModal.tsx b/src/components/AttachmentModal.tsx index c378e4d11188f..0ad6dfbb8f7f6 100644 --- a/src/components/AttachmentModal.tsx +++ b/src/components/AttachmentModal.tsx @@ -379,7 +379,11 @@ 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( (shouldCallDirectly?: boolean) => {