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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/libs/AttachmentModalHandler/index.ios.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {InteractionManager} from 'react-native';
import type AttachmentModalHandler from './types';

const attachmentModalHandler: AttachmentModalHandler = {
handleModalClose: (onCloseCallback) => {
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;
9 changes: 6 additions & 3 deletions src/pages/ReportAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type {StackScreenProps} from '@react-navigation/stack';
import React, {useMemo} from 'react';
import {useOnyx} from 'react-native-onyx';
import AttachmentModal from '@components/AttachmentModal';
import attachmentModalHandler from '@libs/AttachmentModalHandler';
import Navigation from '@libs/Navigation/Navigation';
import type {AuthScreensParamList} from '@libs/Navigation/types';
import * as ReportUtils from '@libs/ReportUtils';
Expand Down Expand Up @@ -37,14 +38,16 @@ function ReportAvatar({route}: ReportAvatarProps) {
};
}, [report, policy]);

const onModalClose = () => {
Navigation.goBack(ROUTES.REPORT_WITH_ID_DETAILS.getRoute(report?.reportID ?? '-1'));
};

return (
<AttachmentModal
headerTitle={attachment.headerTitle}
defaultOpen
source={attachment.source}
onModalClose={() => {
Navigation.goBack(ROUTES.REPORT_WITH_ID_DETAILS.getRoute(report?.reportID ?? '-1'));
}}
onModalClose={() => attachmentModalHandler.handleModalClose(onModalClose)}
isWorkspaceAvatar={attachment.isWorkspaceAvatar}
maybeIcon
originalFileName={attachment.originalFileName}
Expand Down
3 changes: 2 additions & 1 deletion src/pages/TransactionReceiptPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type {StackScreenProps} from '@react-navigation/stack';
import React, {useEffect} from 'react';
import {useOnyx} from 'react-native-onyx';
import AttachmentModal from '@components/AttachmentModal';
import attachmentModalHandler from '@libs/AttachmentModalHandler';
import Navigation from '@libs/Navigation/Navigation';
import type {AuthScreensParamList, RootStackParamList, State} from '@libs/Navigation/types';
import * as ReceiptUtils from '@libs/ReceiptUtils';
Expand Down Expand Up @@ -75,7 +76,7 @@ function TransactionReceipt({route}: TransactionReceiptProps) {
isTrackExpenseAction={isTrackExpenseAction}
originalFileName={receiptURIs?.filename}
defaultOpen
onModalClose={onModalClose}
onModalClose={() => attachmentModalHandler.handleModalClose(onModalClose)}
isLoading={!transaction && reportMetadata?.isLoadingInitialReportActions}
shouldShowNotFoundPage={shouldShowNotFoundPage}
/>
Expand Down
13 changes: 8 additions & 5 deletions src/pages/home/report/ReportAttachments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, {useCallback} from 'react';
import {useOnyx} from 'react-native-onyx';
import AttachmentModal from '@components/AttachmentModal';
import type {Attachment} from '@components/Attachments/types';
import attachmentModalHandler from '@libs/AttachmentModalHandler';
import ComposerFocusManager from '@libs/ComposerFocusManager';
import Navigation from '@libs/Navigation/Navigation';
import type {AuthScreensParamList} from '@libs/Navigation/types';
Expand Down Expand Up @@ -42,6 +43,12 @@ function ReportAttachments({route}: ReportAttachmentsProps) {
[reportID, type, accountID],
);

const onModalClose = () => {
Navigation.dismissModal();
// This enables Composer refocus when the attachments modal is closed by the browser navigation
ComposerFocusManager.setReadyToFocus();
};

return (
<AttachmentModal
accountID={Number(accountID)}
Expand All @@ -50,11 +57,7 @@ function ReportAttachments({route}: ReportAttachmentsProps) {
defaultOpen
report={report}
source={source}
onModalClose={() => {
Navigation.dismissModal();
// This enables Composer refocus when the attachments modal is closed by the browser navigation
ComposerFocusManager.setReadyToFocus();
}}
onModalClose={() => attachmentModalHandler.handleModalClose(onModalClose)}
onCarouselAttachmentChange={onCarouselAttachmentChange}
shouldShowNotFoundPage={!isLoadingApp && type !== CONST.ATTACHMENT_TYPE.SEARCH && !report?.reportID}
isAuthTokenRequired={!!isAuthTokenRequired}
Expand Down
9 changes: 6 additions & 3 deletions src/pages/settings/Profile/ProfileAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, {useEffect} from 'react';
import type {OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
import AttachmentModal from '@components/AttachmentModal';
import attachmentModalHandler from '@libs/AttachmentModalHandler';
import Navigation from '@libs/Navigation/Navigation';
import type {AuthScreensParamList} from '@libs/Navigation/types';
import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils';
Expand Down Expand Up @@ -35,14 +36,16 @@ function ProfileAvatar({route, personalDetails, personalDetailsMetadata, isLoadi
PersonalDetails.openPublicProfilePage(accountID);
}, [accountID, avatarURL]);

const onModalClose = () => {
Navigation.goBack();
};

return (
<AttachmentModal
headerTitle={displayName}
defaultOpen
source={UserUtils.getFullSizeAvatar(avatarURL, accountID)}
onModalClose={() => {
Navigation.goBack();
}}
onModalClose={() => attachmentModalHandler.handleModalClose(onModalClose)}
originalFileName={personalDetail?.originalFileName ?? ''}
isLoading={!!isLoading}
shouldShowNotFoundPage={!avatarURL}
Expand Down
6 changes: 5 additions & 1 deletion src/pages/workspace/WorkspaceAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React from 'react';
import type {OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
import AttachmentModal from '@components/AttachmentModal';
import attachmentModalHandler from '@libs/AttachmentModalHandler';
import Navigation from '@libs/Navigation/Navigation';
import type {AuthScreensParamList} from '@libs/Navigation/types';
import * as ReportUtils from '@libs/ReportUtils';
Expand All @@ -20,13 +21,16 @@ type WorkspaceAvatarProps = WorkspaceAvatarOnyxProps & StackScreenProps<AuthScre

function WorkspaceAvatar({policy, isLoadingApp = true}: WorkspaceAvatarProps) {
const avatarURL = policy?.avatarURL ?? '' ? policy?.avatarURL ?? '' : ReportUtils.getDefaultWorkspaceAvatar(policy?.name ?? '');
const onModalClose = () => {
Navigation.goBack();
};

return (
<AttachmentModal
headerTitle={policy?.name ?? ''}
defaultOpen
source={UserUtils.getFullSizeAvatar(avatarURL, 0)}
onModalClose={Navigation.goBack}
onModalClose={() => attachmentModalHandler.handleModalClose(onModalClose)}
isWorkspaceAvatar
originalFileName={policy?.originalFileName ?? policy?.id}
shouldShowNotFoundPage={!Object.keys(policy ?? {}).length && !isLoadingApp}
Expand Down
Loading