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
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
@@ -1,6 +1,7 @@
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 {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
import type {AuthScreensParamList} from '@libs/Navigation/types';
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
@@ -1,6 +1,7 @@
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 {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
import type {AuthScreensParamList, RootStackParamList, State} from '@libs/Navigation/types';
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 @@ -2,6 +2,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 {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/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
38 changes: 13 additions & 25 deletions src/pages/settings/Profile/ProfileAvatar.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, {useEffect} from 'react';
import type {OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
import {useOnyx} from 'react-native-onyx';
import AttachmentModal from '@components/AttachmentModal';
import attachmentModalHandler from '@libs/AttachmentModalHandler';
import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
import type {AuthScreensParamList} from '@libs/Navigation/types';
Expand All @@ -11,17 +11,13 @@ import * as ValidationUtils from '@libs/ValidationUtils';
import * as PersonalDetails from '@userActions/PersonalDetails';
import ONYXKEYS from '@src/ONYXKEYS';
import type SCREENS from '@src/SCREENS';
import type {PersonalDetailsList, PersonalDetailsMetadata} from '@src/types/onyx';

type ProfileAvatarOnyxProps = {
personalDetails: OnyxEntry<PersonalDetailsList>;
personalDetailsMetadata: OnyxEntry<Record<string, PersonalDetailsMetadata>>;
isLoadingApp: OnyxEntry<boolean>;
};
type ProfileAvatarProps = PlatformStackScreenProps<AuthScreensParamList, typeof SCREENS.PROFILE_AVATAR>;

type ProfileAvatarProps = ProfileAvatarOnyxProps & PlatformStackScreenProps<AuthScreensParamList, typeof SCREENS.PROFILE_AVATAR>;

function ProfileAvatar({route, personalDetails, personalDetailsMetadata, isLoadingApp = true}: ProfileAvatarProps) {
function ProfileAvatar({route}: ProfileAvatarProps) {
const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST);
const [personalDetailsMetadata] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_METADATA);
const [isLoadingApp = true] = useOnyx(ONYXKEYS.IS_LOADING_APP);
const personalDetail = personalDetails?.[route.params.accountID];
const avatarURL = personalDetail?.avatar ?? '';
const accountID = Number(route.params.accountID ?? '-1');
Expand All @@ -35,14 +31,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 All @@ -52,14 +50,4 @@ function ProfileAvatar({route, personalDetails, personalDetailsMetadata, isLoadi

ProfileAvatar.displayName = 'ProfileAvatar';

export default withOnyx<ProfileAvatarProps, ProfileAvatarOnyxProps>({
personalDetails: {
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
},
personalDetailsMetadata: {
key: ONYXKEYS.PERSONAL_DETAILS_METADATA,
},
isLoadingApp: {
key: ONYXKEYS.IS_LOADING_APP,
},
})(ProfileAvatar);
export default ProfileAvatar;
30 changes: 11 additions & 19 deletions src/pages/workspace/WorkspaceAvatar.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
import React from 'react';
import type {OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
import {useOnyx} from 'react-native-onyx';
import AttachmentModal from '@components/AttachmentModal';
import attachmentModalHandler from '@libs/AttachmentModalHandler';
import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
import type {AuthScreensParamList} from '@libs/Navigation/types';
import * as ReportUtils from '@libs/ReportUtils';
import * as UserUtils from '@libs/UserUtils';
import ONYXKEYS from '@src/ONYXKEYS';
import type SCREENS from '@src/SCREENS';
import type {Policy} from '@src/types/onyx';

type WorkspaceAvatarOnyxProps = {
policy: OnyxEntry<Policy>;
isLoadingApp: OnyxEntry<boolean>;
};
type WorkspaceAvatarProps = PlatformStackScreenProps<AuthScreensParamList, typeof SCREENS.WORKSPACE_AVATAR>;

type WorkspaceAvatarProps = WorkspaceAvatarOnyxProps & PlatformStackScreenProps<AuthScreensParamList, typeof SCREENS.WORKSPACE_AVATAR>;

function WorkspaceAvatar({policy, isLoadingApp = true}: WorkspaceAvatarProps) {
function WorkspaceAvatar({route}: WorkspaceAvatarProps) {
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${route.params.policyID ?? '-1'}`);
const [isLoadingApp = true] = useOnyx(ONYXKEYS.IS_LOADING_APP);
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 All @@ -38,11 +37,4 @@ function WorkspaceAvatar({policy, isLoadingApp = true}: WorkspaceAvatarProps) {

WorkspaceAvatar.displayName = 'WorkspaceAvatar';

export default withOnyx<WorkspaceAvatarProps, WorkspaceAvatarOnyxProps>({
policy: {
key: ({route}) => `${ONYXKEYS.COLLECTION.POLICY}${route.params.policyID ?? '-1'}`,
},
isLoadingApp: {
key: ONYXKEYS.IS_LOADING_APP,
},
})(WorkspaceAvatar);
export default WorkspaceAvatar;
Loading