Skip to content
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
37 changes: 24 additions & 13 deletions src/components/LHNOptionsList/OptionRowLHN.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import CONST from '../../CONST';
import variables from '../../styles/variables';
import themeColors from '../../styles/themes/default';
import SidebarUtils from '../../libs/SidebarUtils';
import TextPill from '../TextPill';
import OfflineWithFeedback from '../OfflineWithFeedback';

const propTypes = {
Expand Down Expand Up @@ -66,11 +67,12 @@ const OptionRowLHN = (props) => {
: styles.sidebarLinkText;
const textUnreadStyle = optionItem.isUnread
? [textStyle, styles.sidebarLinkTextUnread] : [textStyle];
const displayNameStyle = StyleUtils.combineStyles(props.viewMode === CONST.OPTION_MODE.COMPACT
? [styles.optionDisplayName, ...textUnreadStyle, styles.optionDisplayNameCompact, styles.mr2]
: [styles.optionDisplayName, ...textUnreadStyle], props.style);
const displayNameStyle = StyleUtils.combineStyles([styles.optionDisplayName, styles.optionDisplayNameCompact, ...textUnreadStyle], props.style);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah why are we merging styles.optionDisplayName and styles.optionDisplayNameCompact here? Originally we were only appending styles.optionDisplayNameCompact if props.viewMode === CONST.OPTION_MODE.COMPACT

@bernhardoj bernhardoj Oct 22, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

When the viewMode is Compact, we put the latest chat text next to DisplayName and we append the style.optionDisplayNameCompact to make sure DisplayName will take the whole available width. Now, we have TextPill next to DisplayName, that's why I append it no matter what the viewMode is. If we don't do this, the DisplayName will get truncated like @shawnborton previously mentioned here.

For this screenshot here: image

I don't think we want the #announce room to truncate unless it was truly wider than the total available horizontal width of that row. Let me know if that makes sense.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Any update on this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh thanks for the explanation @bernhardoj, sorry for the delay here

const textPillStyle = props.isFocused
? [styles.ml1, StyleUtils.getBackgroundColorWithOpacityStyle(themeColors.icon, 0.5)]
: [styles.ml1];
const alternateTextStyle = StyleUtils.combineStyles(props.viewMode === CONST.OPTION_MODE.COMPACT
? [textStyle, styles.optionAlternateText, styles.textLabelSupporting, styles.optionAlternateTextCompact]
? [textStyle, styles.optionAlternateText, styles.textLabelSupporting, styles.optionAlternateTextCompact, styles.ml2]
: [textStyle, styles.optionAlternateText, styles.textLabelSupporting], props.style);
const contentContainerStyles = props.viewMode === CONST.OPTION_MODE.COMPACT
? [styles.flex1, styles.flexRow, styles.overflowHidden, styles.alignItemsCenter]
Expand Down Expand Up @@ -161,15 +163,24 @@ const OptionRowLHN = (props) => {
)
}
<View style={contentContainerStyles}>
<DisplayNames
accessibilityLabel="Chat user display names"
fullTitle={optionItem.text}
displayNamesWithTooltips={optionItem.displayNamesWithTooltips}
tooltipEnabled
numberOfLines={1}
textStyles={displayNameStyle}
shouldUseFullTitle={optionItem.isChatRoom || optionItem.isPolicyExpenseChat}
/>
<View style={[styles.flexRow, styles.alignItemsCenter, styles.mw100, styles.overflowHidden]}>
<DisplayNames
accessibilityLabel="Chat user display names"
fullTitle={optionItem.text}
displayNamesWithTooltips={optionItem.displayNamesWithTooltips}
tooltipEnabled
numberOfLines={1}
textStyles={displayNameStyle}
shouldUseFullTitle={optionItem.isChatRoom || optionItem.isPolicyExpenseChat}
/>
{optionItem.isChatRoom && (
<TextPill
style={textPillStyle}
accessibilityLabel="Workspace name"
text={optionItem.subtitle}
/>
)}
</View>
{optionItem.alternateText ? (
<Text
style={alternateTextStyle}
Expand Down
30 changes: 30 additions & 0 deletions src/components/TextPill.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react';
import PropTypes from 'prop-types';
import Text from './Text';
import styles from '../styles/styles';
import stylePropTypes from '../styles/stylePropTypes';
import * as StyleUtils from '../styles/StyleUtils';

const propTypes = {
text: PropTypes.string.isRequired,

/** Text additional style */
style: stylePropTypes,
};

const defaultProps = {
style: [],
};

const TextPill = (props) => {
const propsStyle = StyleUtils.parseStyleAsArray(props.style);

// eslint-disable-next-line react/jsx-props-no-spreading
return <Text {...props} style={[styles.textPill, ...propsStyle]} numberOfLines={1}>{props.text}</Text>;
};

TextPill.propTypes = propTypes;
TextPill.defaultProps = defaultProps;
TextPill.displayName = 'TextPill';

export default TextPill;
21 changes: 21 additions & 0 deletions src/styles/StyleUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,26 @@ function getBackgroundColorStyle(backgroundColor) {
};
}

/**
* Returns a background color with opacity style
*
* @param {String} backgroundColor
* @param {number} opacity
* @returns {Object}
*/
function getBackgroundColorWithOpacityStyle(backgroundColor, opacity) {
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(backgroundColor);
if (result !== null) {
const r = parseInt(result[1], 16);
const g = parseInt(result[2], 16);
const b = parseInt(result[3], 16);
return {
backgroundColor: `rgba(${r}, ${g}, ${b}, ${opacity})`,
};
}
return {};
}

/**
* Generate a style for the background color of the Badge
*
Expand Down Expand Up @@ -532,6 +552,7 @@ export {
getAutoGrowTextInputStyle,
getBackgroundAndBorderStyle,
getBackgroundColorStyle,
getBackgroundColorWithOpacityStyle,
getBadgeColorStyle,
getButtonBackgroundColorStyle,
getIconFillColor,
Expand Down
11 changes: 11 additions & 0 deletions src/styles/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -2698,6 +2698,17 @@ const styles = {
maxWidth: 450,
alignSelf: 'center',
},

textPill: {
ellipsizeMode: 'end',
Comment thread
marcochavezf marked this conversation as resolved.
Outdated
backgroundColor: colors.gray2,
borderRadius: 10,
overflow: 'hidden',
paddingVertical: 2,
flexShrink: 1,
fontSize: variables.fontSizeSmall,
...spacing.ph2,
},
};

export default styles;