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

Ensure correct background is present for horizontalStackedAvatar style #13351

Merged
merged 5 commits into from
Dec 7, 2022
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
1 change: 1 addition & 0 deletions src/components/LHNOptionsList/OptionRowLHN.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ const OptionRowLHN = (props) => {
&& (
optionItem.shouldShowSubscript ? (
<SubscriptAvatar
backgroundColor={props.isFocused ? themeColors.activeComponentBG : themeColors.sidebar}
mainAvatar={optionItem.icons[0]}
secondaryAvatar={optionItem.icons[1]}
mainTooltip={optionItem.ownerEmail}
Expand Down
2 changes: 2 additions & 0 deletions src/components/MenuItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ const MenuItem = (props) => {
{!_.isEmpty(props.floatRightAvatars) && (
<View style={[styles.justifyContentCenter, (props.brickRoadIndicator ? styles.mr4 : styles.mr3)]}>
<MultipleAvatars
isHovered={hovered}
isPressed={pressed}
icons={props.floatRightAvatars}
size={props.viewMode === CONST.OPTION_MODE.COMPACT ? CONST.AVATAR_SIZE.SMALL : CONST.AVATAR_SIZE.DEFAULT}
fallbackIcon={Expensicons.Workspace}
Expand Down
19 changes: 17 additions & 2 deletions src/components/MultipleAvatars.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ const propTypes = {

/** Prop to identify if we should load avatars vertically instead of diagonally */
shouldStackHorizontally: PropTypes.bool,

/** Whether the avatars are hovered */
isHovered: PropTypes.bool,

/** Whether the avatars are in an element being pressed */
isPressed: PropTypes.bool,
};

const defaultProps = {
Expand All @@ -38,6 +44,8 @@ const defaultProps = {
avatarTooltips: [],
fallbackIcon: undefined,
shouldStackHorizontally: false,
isHovered: false,
isPressed: false,
};

const MultipleAvatars = (props) => {
Expand Down Expand Up @@ -75,7 +83,7 @@ const MultipleAvatars = (props) => {
_.map([...props.icons].splice(0, 4).reverse(), (icon, index) => (
<View
key={`stackedAvatars-${index}`}
style={[styles.horizontalStackedAvatar, styles.alignItemsCenter, horizontalStyles[index]]}
style={[styles.horizontalStackedAvatar, StyleUtils.getHorizontalStackedAvatarBorderStyle(props.isHovered, props.isPressed), horizontalStyles[index]]}
>
<Avatar
source={icon || props.fallbackIcon}
Expand All @@ -86,7 +94,14 @@ const MultipleAvatars = (props) => {
))
}
{props.icons.length > 4 && (
<View style={[styles.alignItemsCenter, styles.justifyContentCenter, styles.horizontalStackedAvatar4Overlay]}>
<View
style={[
styles.alignItemsCenter,
styles.justifyContentCenter,
StyleUtils.getHorizontalStackedAvatarBorderStyle(props.isHovered, props.isPressed),
styles.horizontalStackedAvatar4Overlay,
]}
>
<Text style={styles.avatarInnerTextSmall}>
{`+${props.icons.length - 4}`}
</Text>
Expand Down
6 changes: 5 additions & 1 deletion src/components/SubscriptAvatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@ const propTypes = {

/** Set the size of avatars */
size: PropTypes.oneOf(_.values(CONST.AVATAR_SIZE)),

/** Background color used for subscript avatar border */
backgroundColor: PropTypes.string,
};

const defaultProps = {
mainTooltip: '',
secondaryTooltip: '',
size: CONST.AVATAR_SIZE.DEFAULT,
backgroundColor: themeColors.componentBG,
};

const SubscriptAvatar = props => (
Expand All @@ -42,7 +46,7 @@ const SubscriptAvatar = props => (
</Tooltip>
<View style={[
props.size === CONST.AVATAR_SIZE.SMALL ? styles.secondAvatarSubscriptCompact : styles.secondAvatarSubscript,
StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)]}
StyleUtils.getBackgroundAndBorderStyle(props.backgroundColor)]}
>
<Tooltip text={props.secondaryTooltip}>
<Avatar
Expand Down
23 changes: 23 additions & 0 deletions src/styles/StyleUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,28 @@ function getKeyboardShortcutsModalWidth(isSmallScreenWidth) {
return {maxWidth: 600};
}

/**
* @param {Boolean} isHovered
* @param {Boolean} isPressed
* @returns {Object}
*/
function getHorizontalStackedAvatarBorderStyle(isHovered, isPressed) {
let backgroundColor = themeColors.appBG;

if (isHovered) {
backgroundColor = themeColors.buttonHoveredBG;
}

if (isPressed) {
backgroundColor = themeColors.buttonPressedBG;
}

return {
backgroundColor,
borderColor: backgroundColor,
};
}

export {
getAvatarSize,
getAvatarStyle,
Expand Down Expand Up @@ -572,4 +594,5 @@ export {
hasSafeAreas,
getHeight,
fade,
getHorizontalStackedAvatarBorderStyle,
};
2 changes: 1 addition & 1 deletion src/styles/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -1569,6 +1569,7 @@ const styles = {
backgroundColor: themeColors.appBG,
borderRadius: 33,
paddingTop: 2,
alignItems: 'center',
},

singleSubscript: {
Expand Down Expand Up @@ -1732,7 +1733,6 @@ const styles = {
width: 28,
borderWidth: 2,
borderStyle: 'solid',
borderColor: themeColors.appBG,
backgroundColor: themeColors.opaqueAvatar,
borderRadius: 24,
zIndex: 6,
Expand Down