Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix resolve delay when dismissing attachment preview #53108

Merged
3 changes: 2 additions & 1 deletion src/components/AttachmentModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import useStyleUtils from '@hooks/useStyleUtils';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import addEncryptedAuthTokenToURL from '@libs/addEncryptedAuthTokenToURL';
import attachmentModalHandler from '@libs/AttachmentModalHandler';
import fileDownload from '@libs/fileDownload';
import * as FileUtils from '@libs/fileDownload/FileUtils';
import Navigation from '@libs/Navigation/Navigation';
Expand Down Expand Up @@ -387,7 +388,7 @@ function AttachmentModal({
setIsModalOpen(false);

if (typeof onModalClose === 'function') {
onModalClose();
attachmentModalHandler.handleModalClose(onModalClose);
}

// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
Expand Down
17 changes: 17 additions & 0 deletions src/libs/AttachmentModalHandler/index.ios.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {InteractionManager} from 'react-native';
import type AttachmentModalHandler from './types';

const attachmentModalHandler: AttachmentModalHandler = {
handleModalClose: (onCloseCallback) => {
// Ensure `AttachmentCarousel` is unmounted before `AttachmentModal` is closed to prevent any delay in the attachment preview when closing the modal.
// This delay causes the attachment preview to slide to the right on iOS, especially when there is an animation involved.
// The issue is tracked in https://github.com/Expensify/App/issues/52937.
// `InteractionManager.runAfterInteractions` ensures that `onCloseCallback` is executed only after all interactions and animations have completed,
// preventing any unintended visual delay or jarring transition when the modal is closed.
InteractionManager.runAfterInteractions(() => {
onCloseCallback?.();
});
},
};

export default attachmentModalHandler;
9 changes: 9 additions & 0 deletions src/libs/AttachmentModalHandler/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type AttachmentModalHandler from './types';

const attachmentModalHandler: AttachmentModalHandler = {
handleModalClose: (onCloseCallback) => {
onCloseCallback?.();
},
};

export default attachmentModalHandler;
5 changes: 5 additions & 0 deletions src/libs/AttachmentModalHandler/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type AttachmentModalHandler = {
handleModalClose: (onCloseCallback?: () => void) => void;
};

export default AttachmentModalHandler;
Loading