Skip to content

Commit

Permalink
Merge pull request #18775 from s77rt/iou-header-polish
Browse files Browse the repository at this point in the history
UI MoneyRequestHeader Polish
  • Loading branch information
luacmartins authored May 16, 2023
2 parents 3df384a + ff1d770 commit bd6743c
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 42 deletions.
10 changes: 8 additions & 2 deletions src/components/Avatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ const propTypes = {
// eslint-disable-next-line react/forbid-prop-types
imageStyles: PropTypes.arrayOf(PropTypes.object),

/** Additional styles to pass to Icon */
// eslint-disable-next-line react/forbid-prop-types
iconAdditionalStyles: PropTypes.arrayOf(PropTypes.object),

/** Extra styles to pass to View wrapper */
containerStyles: stylePropTypes,

Expand Down Expand Up @@ -48,6 +52,7 @@ const propTypes = {
const defaultProps = {
source: null,
imageStyles: [],
iconAdditionalStyles: [],
containerStyles: [],
size: CONST.AVATAR_SIZE.DEFAULT,
fill: themeColors.icon,
Expand All @@ -68,9 +73,9 @@ function Avatar(props) {
const isWorkspace = props.type === CONST.ICON_TYPE_WORKSPACE;
const iconSize = StyleUtils.getAvatarSize(props.size);

const imageStyle = [StyleUtils.getAvatarStyle(props.size), ...props.imageStyles, StyleUtils.getAvatarBorderRadius(props.size, props.type)];
const imageStyle = props.imageStyles ? [StyleUtils.getAvatarStyle(props.size), ...props.imageStyles, StyleUtils.getAvatarBorderRadius(props.size, props.type)] : undefined;

const iconStyle = [StyleUtils.getAvatarStyle(props.size), styles.bgTransparent, ...props.imageStyles];
const iconStyle = props.imageStyles ? [StyleUtils.getAvatarStyle(props.size), styles.bgTransparent, ...props.imageStyles] : undefined;

const iconFillColor = isWorkspace ? StyleUtils.getDefaultWorkspaceAvatarColor(props.name).fill : props.fill;
const fallbackAvatar = isWorkspace ? ReportUtils.getDefaultWorkspaceAvatar(props.name) : props.fallbackIcon;
Expand All @@ -91,6 +96,7 @@ function Avatar(props) {
StyleUtils.getAvatarBorderStyle(props.size, props.type),
isWorkspace ? StyleUtils.getDefaultWorkspaceAvatarColor(props.name) : {},
imageError ? StyleUtils.getBackgroundColorStyle(themeColors.fallbackIconColor) : {},
...props.iconAdditionalStyles,
]}
/>
</View>
Expand Down
4 changes: 3 additions & 1 deletion src/components/AvatarWithDisplayName.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import participantPropTypes from './participantPropTypes';
import withWindowDimensions, {windowDimensionsPropTypes} from './withWindowDimensions';
import withLocalize, {withLocalizePropTypes} from './withLocalize';
import styles from '../styles/styles';
import themeColors from '../styles/themes/default';
import SubscriptAvatar from './SubscriptAvatar';
import * as ReportUtils from '../libs/ReportUtils';
import Avatar from './Avatar';
Expand Down Expand Up @@ -53,9 +54,10 @@ const AvatarWithDisplayName = (props) => {
return (
<View style={[styles.appContentHeaderTitle, styles.flex1]}>
{Boolean(props.report && title) && (
<View style={[styles.flexRow, styles.alignItemsCenter, styles.justifyContentBetween]}>
<View style={[styles.flex1, styles.flexRow, styles.alignItemsCenter, styles.justifyContentBetween]}>
{isExpenseReport ? (
<SubscriptAvatar
backgroundColor={themeColors.highlightBG}
mainAvatar={icons[0]}
secondaryAvatar={icons[1]}
mainTooltip={props.report.ownerEmail}
Expand Down
8 changes: 4 additions & 4 deletions src/components/MoneyRequestHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,17 @@ const MoneyRequestHeader = (props) => {
shouldShowBackButton={props.isSmallScreenWidth}
onBackButtonPress={() => Navigation.navigate(ROUTES.HOME)}
/>
<View style={[styles.ph5, styles.pb5]}>
<View style={[styles.ph5, styles.pb2]}>
<Text style={[styles.textLabelSupporting, styles.lh16]}>{props.translate('common.to')}</Text>
<View style={[styles.flexRow, styles.alignItemsCenter, styles.justifyContentBetween, styles.pv3]}>
<View style={[styles.flexRow, styles.alignItemsCenter, styles.justifyContentBetween]}>
<View style={[styles.flex1, styles.flexRow, styles.alignItemsCenter, styles.justifyContentBetween]}>
<Avatar
source={payeeAvatar}
type={isExpenseReport ? CONST.ICON_TYPE_WORKSPACE : CONST.ICON_TYPE_AVATAR}
name={payeeName}
size={CONST.AVATAR_SIZE.HEADER}
size={CONST.AVATAR_SIZE.DEFAULT}
/>
<View style={[styles.flexColumn, styles.ml3]}>
<View style={[styles.flex1, styles.flexColumn, styles.ml3]}>
<Text
style={[styles.headerText, styles.pre]}
numberOfLines={1}
Expand Down
2 changes: 1 addition & 1 deletion src/components/MultipleAvatars.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const MultipleAvatars = (props) => {
}

const oneAvatarSize = StyleUtils.getAvatarStyle(props.size);
const oneAvatarBorderWidth = StyleUtils.getAvatarBorderWidth(props.size);
const oneAvatarBorderWidth = StyleUtils.getAvatarBorderWidth(props.size).borderWidth;
const overlapSize = oneAvatarSize.width / 3;

if (props.shouldStackHorizontally) {
Expand Down
32 changes: 15 additions & 17 deletions src/components/SubscriptAvatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,21 @@ const SubscriptAvatar = (props) => {
type={props.mainAvatar.type}
/>
</Tooltip>
<View
style={[
props.size === CONST.AVATAR_SIZE.SMALL ? styles.secondAvatarSubscriptCompact : styles.secondAvatarSubscript,
StyleUtils.getBackgroundAndBorderStyle(props.backgroundColor),
StyleUtils.getAvatarBorderStyle(props.size, props.secondaryAvatar.type),
]}
>
<Tooltip text={props.secondaryTooltip}>
<Avatar
source={props.secondaryAvatar.source}
size={props.size === CONST.AVATAR_SIZE.SMALL ? CONST.AVATAR_SIZE.SMALL_SUBSCRIPT : CONST.AVATAR_SIZE.SUBSCRIPT}
fill={themeColors.iconSuccessFill}
name={props.secondaryAvatar.name}
type={props.secondaryAvatar.type}
/>
</Tooltip>
</View>
<Tooltip text={props.secondaryTooltip}>
<Avatar
imageStyles={null}
containerStyles={[props.size === CONST.AVATAR_SIZE.SMALL ? styles.secondAvatarSubscriptCompact : styles.secondAvatarSubscript]}
iconAdditionalStyles={[
StyleUtils.getAvatarBorderWidth(props.size === CONST.AVATAR_SIZE.SMALL ? CONST.AVATAR_SIZE.SMALL_SUBSCRIPT : CONST.AVATAR_SIZE.SUBSCRIPT),
StyleUtils.getBorderColorStyle(props.backgroundColor),
]}
source={props.secondaryAvatar.source}
size={props.size === CONST.AVATAR_SIZE.SMALL ? CONST.AVATAR_SIZE.SMALL_SUBSCRIPT : CONST.AVATAR_SIZE.SUBSCRIPT}
fill={themeColors.iconSuccessFill}
name={props.secondaryAvatar.name}
type={props.secondaryAvatar.type}
/>
</Tooltip>
</View>
);
};
Expand Down
11 changes: 11 additions & 0 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ function getReportParticipantsTitle(logins) {
);
}

/**
* Checks if a report is a chat report.
*
* @param {Object} report
* @returns {Boolean}
*/
function isChatReport(report) {
return lodashGet(report, 'type') === CONST.REPORT.TYPE.CHAT;
}

/**
* Checks if a report is an Expense report.
*
Expand Down Expand Up @@ -2218,6 +2228,7 @@ export {
getAllPolicyReports,
getIOUReportActionMessage,
getDisplayNameForParticipant,
isChatReport,
isExpenseReport,
isIOUReport,
isTaskReport,
Expand Down
6 changes: 3 additions & 3 deletions src/pages/home/report/ReportActionItemCreated.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ const defaultProps = {
};

const ReportActionItemCreated = (props) => {
const icons = ReportUtils.getIcons(props.report, props.personalDetails);

if (ReportUtils.isMoneyRequestReport(props.report.reportID) || ReportUtils.isTaskReport(props.report)) {
if (!ReportUtils.isChatReport(props.report)) {
return null;
}

const icons = ReportUtils.getIcons(props.report, props.personalDetails);

return (
<OfflineWithFeedback
pendingAction={lodashGet(props.report, 'pendingFields.addWorkspaceRoom') || lodashGet(props.report, 'pendingFields.createChat')}
Expand Down
25 changes: 20 additions & 5 deletions src/styles/StyleUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const workspaceColorOptions = [
const avatarBorderSizes = {
[CONST.AVATAR_SIZE.SMALL_SUBSCRIPT]: variables.componentBorderRadiusSmall,
[CONST.AVATAR_SIZE.MID_SUBSCRIPT]: variables.componentBorderRadiusSmall,
[CONST.AVATAR_SIZE.SUBSCRIPT]: variables.componentBorderRadiusSmall,
[CONST.AVATAR_SIZE.SUBSCRIPT]: variables.componentBorderRadiusMedium,
[CONST.AVATAR_SIZE.SMALLER]: variables.componentBorderRadiusMedium,
[CONST.AVATAR_SIZE.SMALL]: variables.componentBorderRadiusMedium,
[CONST.AVATAR_SIZE.HEADER]: variables.componentBorderRadiusMedium,
Expand Down Expand Up @@ -85,7 +85,7 @@ function getAvatarStyle(size) {
/**
* Get Font size of '+1' text on avatar overlay
* @param {String} size
* @returns {Number}
* @returns {Object}
*/
function getAvatarExtraFontSizeStyle(size) {
const AVATAR_SIZES = {
Expand All @@ -107,12 +107,12 @@ function getAvatarExtraFontSizeStyle(size) {
/**
* Get Bordersize of Avatar based on avatar size
* @param {String} size
* @returns {Number}
* @returns {Object}
*/
function getAvatarBorderWidth(size) {
const AVATAR_SIZES = {
[CONST.AVATAR_SIZE.DEFAULT]: 3,
[CONST.AVATAR_SIZE.SMALL_SUBSCRIPT]: 2,
[CONST.AVATAR_SIZE.SMALL_SUBSCRIPT]: 1,
[CONST.AVATAR_SIZE.MID_SUBSCRIPT]: 2,
[CONST.AVATAR_SIZE.SUBSCRIPT]: 2,
[CONST.AVATAR_SIZE.SMALL]: 3,
Expand All @@ -121,7 +121,9 @@ function getAvatarBorderWidth(size) {
[CONST.AVATAR_SIZE.MEDIUM]: 3,
[CONST.AVATAR_SIZE.LARGE_BORDERED]: 4,
};
return AVATAR_SIZES[size];
return {
borderWidth: AVATAR_SIZES[size],
};
}

/**
Expand Down Expand Up @@ -349,6 +351,18 @@ function getBackgroundColorStyle(backgroundColor) {
};
}

/**
* Returns a style with the specified borderColor
*
* @param {String} borderColor
* @returns {Object}
*/
function getBorderColorStyle(borderColor) {
return {
borderColor,
};
}

/**
* Returns the width style for the wordmark logo on the sign in page
*
Expand Down Expand Up @@ -1122,6 +1136,7 @@ export {
getAutoGrowHeightInputStyle,
getBackgroundAndBorderStyle,
getBackgroundColorStyle,
getBorderColorStyle,
getBackgroundColorWithOpacityStyle,
getBadgeColorStyle,
getButtonBackgroundColorStyle,
Expand Down
10 changes: 2 additions & 8 deletions src/styles/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -1780,20 +1780,14 @@ const styles = {

secondAvatarSubscript: {
position: 'absolute',
right: -4,
bottom: -2,
borderWidth: 2,
borderRadius: 18,
borderColor: 'transparent',
right: -6,
bottom: -6,
},

secondAvatarSubscriptCompact: {
position: 'absolute',
bottom: -1,
right: -1,
borderWidth: 1,
borderRadius: 18,
borderColor: 'transparent',
},

leftSideLargeAvatar: {
Expand Down
2 changes: 1 addition & 1 deletion src/styles/variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export default {
popoverMenuShadow: '0px 4px 12px 0px rgba(0, 0, 0, 0.06)',
optionRowHeight: 64,
optionRowHeightCompact: 52,
optionsListSectionHeaderHeight: getValueUsingPixelRatio(54, 60),
optionsListSectionHeaderHeight: getValueUsingPixelRatio(32, 38),
overlayOpacity: 0.6,
lineHeightSmall: getValueUsingPixelRatio(14, 16),
lineHeightNormal: getValueUsingPixelRatio(16, 21),
Expand Down
1 change: 1 addition & 0 deletions tests/ui/UnreadIndicatorsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ function signInAndGetAppWithUnreadChat() {
lastVisibleActionCreated: reportAction9CreatedDate,
lastMessageText: 'Test',
participants: [USER_B_EMAIL],
type: CONST.REPORT.TYPE.CHAT,
});
const createdReportActionID = NumberUtils.rand64();
Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${REPORT_ID}`, {
Expand Down

0 comments on commit bd6743c

Please sign in to comment.