Skip to content

Commit

Permalink
Merge pull request #53873 from huult/53848-transaction-freeze-on-repl…
Browse files Browse the repository at this point in the history
…ace-receipt

[CP Staging] Add shouldCallDirectly for closeModal logic

(cherry picked from commit b29b3e4)

(CP triggered by Beamanator)
  • Loading branch information
Beamanator authored and OSBotify committed Dec 10, 2024
1 parent 737cae1 commit 766a454
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions src/components/AttachmentModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 766a454

Please sign in to comment.