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: ProfileAvatar (modal) page has no slide in animation #53475

Merged
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
18 changes: 15 additions & 3 deletions src/components/Modal/BaseModal.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {PortalHost} from '@gorhom/portal';
import React, {forwardRef, useCallback, useEffect, useMemo, useRef} from 'react';
import {View} from 'react-native';
import React, {forwardRef, useCallback, useEffect, useMemo, useRef, useState} from 'react';
import {InteractionManager, View} from 'react-native';
import ReactNativeModal from 'react-native-modal';
import ColorSchemeWrapper from '@components/ColorSchemeWrapper';
import FocusTrapForModal from '@components/FocusTrap/FocusTrapForModal';
Expand All @@ -24,7 +24,7 @@ import type BaseModalProps from './types';

function BaseModal(
{
isVisible,
isVisible: isVisibleProp,
onClose,
shouldSetModalVisibility = true,
onModalHide = () => {},
Expand Down Expand Up @@ -68,6 +68,18 @@ function BaseModal(

const safeAreaInsets = useSafeAreaInsets();

const [isVisible, setIsVisible] = useState(false);
useEffect(() => {
if (isVisibleProp) {
InteractionManager.runAfterInteractions(() => {
setIsVisible(true);
});
return;
}

setIsVisible(false);
}, [isVisibleProp]);

const isVisibleRef = useRef(isVisible);
const wasVisible = usePrevious(isVisible);

Expand Down
37 changes: 13 additions & 24 deletions src/pages/settings/Profile/ProfileAvatar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
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 Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
Expand All @@ -9,39 +8,39 @@ import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils';
import * as UserUtils from '@libs/UserUtils';
import * as ValidationUtils from '@libs/ValidationUtils';
import * as PersonalDetails from '@userActions/PersonalDetails';
import CONST from '@src/CONST';
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}: ProfileAvatarProps) {
const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST);
const [personalDetailsMetadata] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_METADATA);
const [isLoadingApp = true] = useOnyx(ONYXKEYS.IS_LOADING_APP);

function ProfileAvatar({route, personalDetails, personalDetailsMetadata, isLoadingApp = true}: ProfileAvatarProps) {
const personalDetail = personalDetails?.[route.params.accountID];
const avatarURL = personalDetail?.avatar ?? '';
const accountID = Number(route.params.accountID ?? '-1');
const isLoading = personalDetailsMetadata?.[accountID]?.isLoading ?? (isLoadingApp && !Object.keys(personalDetail ?? {}).length);
const displayName = PersonalDetailsUtils.getDisplayNameOrDefault(personalDetail);

useEffect(() => {
if (!ValidationUtils.isValidAccountRoute(Number(accountID)) ?? !!avatarURL) {
if (!ValidationUtils.isValidAccountRoute(Number(accountID)) || !!avatarURL) {
return;
}
PersonalDetails.openPublicProfilePage(accountID);
}, [accountID, avatarURL]);

return (
<AttachmentModal
headerTitle={displayName}
defaultOpen
headerTitle={displayName}
source={UserUtils.getFullSizeAvatar(avatarURL, accountID)}
onModalClose={() => {
Navigation.goBack();
setTimeout(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chrispader I know this is tough, but we are trying not to use setTimeout in the App as its a fragile workaround usually, could you think of any other way to achieve this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

InteractionManager.runAfterInteractions should work there as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i tried but it didn't work. There are no interactions to run this after. Rather we essentially want to run it "before" interactions such as the navigation back (screen unmount)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since react-native-modal also doesn't have a callback for when the close animation is completed, i don't think we can implement this differently without yet again patching the library.

Navigation.goBack();
}, CONST.ANIMATED_TRANSITION);
}}
originalFileName={personalDetail?.originalFileName ?? ''}
isLoading={!!isLoading}
Expand All @@ -52,14 +51,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;
Loading