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: Settings page: remove code preventing rendering before currentUserPersonalDetails is ready #22329

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
61 changes: 61 additions & 0 deletions src/components/CurrentUserPersonalDetailsSkeletonView/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import React from 'react';
import PropTypes from 'prop-types';
import SkeletonViewContentLoader from 'react-content-loader/native';
import {Circle, Rect} from 'react-native-svg';
import {View} from 'react-native';
import * as StyleUtils from '../../styles/StyleUtils';
import CONST from '../../CONST';
import themeColors from '../../styles/themes/default';
import variables from '../../styles/variables';
import styles from '../../styles/styles';

const propTypes = {
/** Whether to animate the skeleton view */
shouldAnimate: PropTypes.bool,
};

const defaultProps = {
shouldAnimate: true,
};

function CurrentUserPersonalDetailsSkeletonView(props) {
const avatarPlaceholderSize = StyleUtils.getAvatarSize(CONST.AVATAR_SIZE.LARGE);
const avatarPlaceholderRadius = avatarPlaceholderSize / 2;
const spaceBetweenAvatarAndHeadline = styles.mb3.marginBottom + styles.mt1.marginTop + (variables.lineHeightXXLarge - variables.fontSizeXLarge) / 2;
const headlineSize = variables.fontSizeXLarge;
Copy link
Contributor

Choose a reason for hiding this comment

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

desktop.mov

There's a little height difference because height of TextView is actually lineHeight, not fontSize.
The correct height should be variables.lineHeightXXLarge.
But according to #18569 (comment), I am not too much concerned about this inconsistency and this is not a blocker.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think there's enough of a height difference that we should address it.

The skeleton has a height of 155:
Screenshot 2023-07-10 at 2 29 30 PM

And once loaded it's 162:
Screenshot 2023-07-10 at 2 28 39 PM

Furthermore, const headlineMarginTop = 16; and const labelMarginTop = 4; are kind of "magic" numbers at the moment and could get out of sync if we were to change the styles of the real components.

I think it'd be better to replace these 2 with something more precise, e.g. instead of headlineMarginTop, do something like:

const spaceBetweenAvatarAndHeadline = styles.mb3.marginBottom + styles.mt1.marginTop + ((variables.lineHeightXXLarge - variables.fontSizeXLarge)/ 2);

and then similarly for labelMarginTop, with some comments explaining the calculations.

Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think there's enough of a height difference that we should address it.

The reason why I didn't persist to fix this because we don't know exact height of TextView when lineHeight is not set. fontSize itself cannot determine the height. i.e. textLabelSupporting. Dynamic calculation (i.e. onLayout callback) is the only way. Or set lineHeight for this purpose, which will change design.

I think it'd be better to replace these 2 with something more precise, e.g. instead of headlineMarginTop, do something like:

I also thought about that but that code feels like unused pattern in our codebase. But I don't see any harm with this and so agree with suggestion.

const spaceBetweenHeadlineAndLabel = styles.mt1.marginTop + (variables.lineHeightXXLarge - variables.fontSizeXLarge) / 2;
const labelSize = variables.fontSizeLabel;
return (
<View style={styles.avatarSectionWrapperSkeleton}>
<SkeletonViewContentLoader
animate={props.shouldAnimate}
backgroundColor={themeColors.highlightBG}
foregroundColor={themeColors.border}
height={avatarPlaceholderSize + spaceBetweenAvatarAndHeadline + headlineSize + spaceBetweenHeadlineAndLabel + labelSize}
>
<Circle
cx="50%"
cy={avatarPlaceholderRadius}
r={avatarPlaceholderRadius}
/>
<Rect
x="20%"
y={avatarPlaceholderSize + spaceBetweenAvatarAndHeadline}
width="60%"
height={headlineSize}
/>
<Rect
x="15%"
y={avatarPlaceholderSize + spaceBetweenAvatarAndHeadline + headlineSize + spaceBetweenHeadlineAndLabel}
width="70%"
height={labelSize}
/>
</SkeletonViewContentLoader>
</View>
);
}

CurrentUserPersonalDetailsSkeletonView.displayName = 'CurrentUserPersonalDetailsSkeletonView';
CurrentUserPersonalDetailsSkeletonView.propTypes = propTypes;
CurrentUserPersonalDetailsSkeletonView.defaultProps = defaultProps;
export default CurrentUserPersonalDetailsSkeletonView;
84 changes: 41 additions & 43 deletions src/pages/settings/InitialSettingsPage.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import lodashGet from 'lodash/get';
import React from 'react';
import {View, ScrollView} from 'react-native';
import {ScrollView, View} from 'react-native';
import PropTypes from 'prop-types';
import _ from 'underscore';
import {withOnyx} from 'react-native-onyx';
import CurrentUserPersonalDetailsSkeletonView from '../../components/CurrentUserPersonalDetailsSkeletonView';
import {withNetwork} from '../../components/OnyxProvider';
import styles from '../../styles/styles';
import Text from '../../components/Text';
Expand All @@ -21,7 +22,7 @@ import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize
import compose from '../../libs/compose';
import CONST from '../../CONST';
import Permissions from '../../libs/Permissions';
import withCurrentUserPersonalDetails, {withCurrentUserPersonalDetailsPropTypes, withCurrentUserPersonalDetailsDefaultProps} from '../../components/withCurrentUserPersonalDetails';
import withCurrentUserPersonalDetails, {withCurrentUserPersonalDetailsDefaultProps, withCurrentUserPersonalDetailsPropTypes} from '../../components/withCurrentUserPersonalDetails';
import * as PaymentMethods from '../../libs/actions/PaymentMethods';
import bankAccountPropTypes from '../../components/bankAccountPropTypes';
import cardPropTypes from '../../components/cardPropTypes';
Expand Down Expand Up @@ -303,13 +304,6 @@ class InitialSettingsPage extends React.Component {
}

render() {
// On the very first sign in or after clearing storage these
// details will not be present on the first render so we'll just
// return nothing for now.
if (_.isEmpty(this.props.currentUserPersonalDetails)) {
return null;
}

return (
<ScreenWrapper includeSafeAreaPaddingBottom={false}>
{({safeAreaPaddingBottomStyle}) => (
Expand All @@ -320,49 +314,53 @@ class InitialSettingsPage extends React.Component {
style={[styles.settingsPageBackground]}
>
<View style={styles.w100}>
<View style={styles.avatarSectionWrapper}>
<Tooltip text={this.props.translate('common.profile')}>
{_.isEmpty(this.props.currentUserPersonalDetails) || _.isUndefined(this.props.currentUserPersonalDetails.displayName) ? (
<CurrentUserPersonalDetailsSkeletonView />
) : (
<View style={styles.avatarSectionWrapper}>
<Tooltip text={this.props.translate('common.profile')}>
<PressableWithoutFeedback
style={[styles.mb3]}
onPress={this.openProfileSettings}
accessibilityLabel={this.props.translate('common.profile')}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.BUTTON}
>
<OfflineWithFeedback pendingAction={lodashGet(this.props.currentUserPersonalDetails, 'pendingFields.avatar', null)}>
<Avatar
imageStyles={[styles.avatarLarge]}
source={UserUtils.getAvatar(this.props.currentUserPersonalDetails.avatar, this.props.session.accountID)}
size={CONST.AVATAR_SIZE.LARGE}
/>
</OfflineWithFeedback>
</PressableWithoutFeedback>
</Tooltip>
<PressableWithoutFeedback
style={[styles.mb3]}
style={[styles.mt1, styles.mw100]}
onPress={this.openProfileSettings}
accessibilityLabel={this.props.translate('common.profile')}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.BUTTON}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.LINK}
>
<OfflineWithFeedback pendingAction={lodashGet(this.props.currentUserPersonalDetails, 'pendingFields.avatar', null)}>
<Avatar
imageStyles={[styles.avatarLarge]}
source={UserUtils.getAvatar(this.props.currentUserPersonalDetails.avatar, this.props.session.accountID)}
size={CONST.AVATAR_SIZE.LARGE}
/>
</OfflineWithFeedback>
<Tooltip text={this.props.translate('common.profile')}>
<Text
style={[styles.textHeadline, styles.pre]}
numberOfLines={1}
>
{this.props.currentUserPersonalDetails.displayName
? this.props.currentUserPersonalDetails.displayName
: this.props.formatPhoneNumber(this.props.session.email)}
</Text>
</Tooltip>
</PressableWithoutFeedback>
</Tooltip>
<PressableWithoutFeedback
style={[styles.mt1, styles.mw100]}
onPress={this.openProfileSettings}
accessibilityLabel={this.props.translate('common.profile')}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.LINK}
>
<Tooltip text={this.props.translate('common.profile')}>
{Boolean(this.props.currentUserPersonalDetails.displayName) && (
<Text
style={[styles.textHeadline, styles.pre]}
style={[styles.textLabelSupporting, styles.mt1]}
numberOfLines={1}
>
{this.props.currentUserPersonalDetails.displayName
? this.props.currentUserPersonalDetails.displayName
: this.props.formatPhoneNumber(this.props.session.email)}
{this.props.formatPhoneNumber(this.props.session.email)}
</Text>
</Tooltip>
</PressableWithoutFeedback>
{Boolean(this.props.currentUserPersonalDetails.displayName) && (
<Text
style={[styles.textLabelSupporting, styles.mt1]}
numberOfLines={1}
>
{this.props.formatPhoneNumber(this.props.session.email)}
</Text>
)}
</View>
)}
</View>
)}
{_.map(this.getDefaultMenuItems(), (item, index) => this.getMenuItem(item, index))}

<ConfirmModal
Expand Down
6 changes: 6 additions & 0 deletions src/styles/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -2356,6 +2356,12 @@ const styles = {
paddingBottom: 20,
},

avatarSectionWrapperSkeleton: {
width: '100%',
paddingHorizontal: 20,
paddingBottom: 20,
},

selectCircle: {
width: variables.componentSizeSmall,
height: variables.componentSizeSmall,
Expand Down