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

Group chat stacked avatars are different in Search list and LHN #36403

Merged
Show file tree
Hide file tree
Changes from 2 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
140 changes: 74 additions & 66 deletions src/components/SelectionList/BaseListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function BaseListItem<TItem extends User | RadioItem>({
onDismissError = () => {},
rightHandSideComponent,
keyForList,
shouldUseOnySubscriptAvatar = true,
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo

Suggested change
shouldUseOnySubscriptAvatar = true,
shouldUseOnlySubscriptAvatar = true,

Could you give the case for this specific prop? I see that we pass false on the search page.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just so as not to change the display logic on other places where we use UserListItem
I added this parameter so that we display SubscriptAvatar or MultipleAvatars only on the Search screen

}: BaseListItemProps<TItem>) {
const theme = useTheme();
const styles = useThemeStyles();
Expand Down Expand Up @@ -63,77 +64,84 @@ function BaseListItem<TItem extends User | RadioItem>({
onMouseDown={shouldPreventDefaultFocusOnSelectRow ? (e) => e.preventDefault() : undefined}
nativeID={keyForList}
>
<View
style={[
styles.flex1,
styles.justifyContentBetween,
styles.sidebarLinkInner,
styles.userSelectNone,
isUserItem ? styles.peopleRow : styles.optionRow,
isFocused && styles.sidebarLinkActive,
]}
>
{canSelectMultiple && (
{({hovered}) => (
<>
<View
role={CONST.ACCESSIBILITY_ROLE.BUTTON}
style={StyleUtils.getCheckboxPressableStyle()}
style={[
styles.flex1,
styles.justifyContentBetween,
styles.sidebarLinkInner,
styles.userSelectNone,
isUserItem ? styles.peopleRow : styles.optionRow,
isFocused && styles.sidebarLinkActive,
]}
>
<View
style={[
StyleUtils.getCheckboxContainerStyle(20),
styles.mr3,
item.isSelected && styles.checkedContainer,
item.isSelected && styles.borderColorFocus,
item.isDisabled && styles.cursorDisabled,
item.isDisabled && styles.buttonOpacityDisabled,
]}
>
{item.isSelected && (
<Icon
src={Expensicons.Checkmark}
fill={theme.textLight}
height={14}
width={14}
/>
)}
</View>
</View>
)}
{canSelectMultiple && (
<View
role={CONST.ACCESSIBILITY_ROLE.BUTTON}
style={StyleUtils.getCheckboxPressableStyle()}
>
<View
style={[
StyleUtils.getCheckboxContainerStyle(20),
styles.mr3,
item.isSelected && styles.checkedContainer,
item.isSelected && styles.borderColorFocus,
item.isDisabled && styles.cursorDisabled,
item.isDisabled && styles.buttonOpacityDisabled,
]}
>
{item.isSelected && (
<Icon
src={Expensicons.Checkmark}
fill={theme.textLight}
height={14}
width={14}
/>
)}
</View>
</View>
)}

<ListItem
item={item}
textStyles={[
styles.optionDisplayName,
isFocused ? styles.sidebarLinkActiveText : styles.sidebarLinkText,
styles.sidebarLinkTextBold,
styles.pre,
item.alternateText ? styles.mb1 : null,
]}
alternateTextStyles={[styles.textLabelSupporting, styles.lh16, styles.pre]}
isDisabled={isDisabled}
onSelectRow={() => onSelectRow(item)}
showTooltip={showTooltip}
/>
<ListItem
item={item}
textStyles={[
styles.optionDisplayName,
isFocused ? styles.sidebarLinkActiveText : styles.sidebarLinkText,
styles.sidebarLinkTextBold,
styles.pre,
item.alternateText ? styles.mb1 : null,
]}
alternateTextStyles={[styles.textLabelSupporting, styles.lh16, styles.pre]}
isDisabled={isDisabled}
onSelectRow={() => onSelectRow(item)}
showTooltip={showTooltip}
isFocused={isFocused}
isHovered={hovered}
shouldUseOnySubscriptAvatar={shouldUseOnySubscriptAvatar}
/>

{!canSelectMultiple && item.isSelected && !rightHandSideComponent && (
<View
style={[styles.flexRow, styles.alignItemsCenter, styles.ml3]}
accessible={false}
>
<View>
<Icon
src={Expensicons.Checkmark}
fill={theme.success}
/>
</View>
{!canSelectMultiple && item.isSelected && !rightHandSideComponent && (
<View
style={[styles.flexRow, styles.alignItemsCenter, styles.ml3]}
accessible={false}
>
<View>
<Icon
src={Expensicons.Checkmark}
fill={theme.success}
/>
</View>
</View>
)}
{rightHandSideComponentRender()}
</View>
)}
{rightHandSideComponentRender()}
</View>
{isUserItem && item.invitedSecondaryLogin && (
<Text style={[styles.ml9, styles.ph5, styles.pb3, styles.textLabelSupporting]}>
{translate('workspace.people.invitedBySecondaryLogin', {secondaryLogin: item.invitedSecondaryLogin})}
</Text>
{isUserItem && item.invitedSecondaryLogin && (
<Text style={[styles.ml9, styles.ph5, styles.pb3, styles.textLabelSupporting]}>
{translate('workspace.people.invitedBySecondaryLogin', {secondaryLogin: item.invitedSecondaryLogin})}
</Text>
)}
</>
)}
</PressableWithFeedback>
</OfflineWithFeedback>
Expand Down
2 changes: 2 additions & 0 deletions src/components/SelectionList/BaseSelectionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ function BaseSelectionList<TItem extends User | RadioItem>(
rightHandSideComponent,
isLoadingNewOptions = false,
onLayout,
shouldUseOnySubscriptAvatar = true,
}: BaseSelectionListProps<TItem>,
inputRef: ForwardedRef<RNTextInput>,
) {
Expand Down Expand Up @@ -300,6 +301,7 @@ function BaseSelectionList<TItem extends User | RadioItem>(
shouldPreventDefaultFocusOnSelectRow={shouldPreventDefaultFocusOnSelectRow}
rightHandSideComponent={rightHandSideComponent}
keyForList={item.keyForList}
shouldUseOnySubscriptAvatar={shouldUseOnySubscriptAvatar}
/>
);
};
Expand Down
37 changes: 31 additions & 6 deletions src/components/SelectionList/UserListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,45 @@
import React from 'react';
import {View} from 'react-native';
import MultipleAvatars from '@components/MultipleAvatars';
import SubscriptAvatar from '@components/SubscriptAvatar';
import TextWithTooltip from '@components/TextWithTooltip';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import type {UserListItemProps} from './types';

function UserListItem({item, textStyles, alternateTextStyles, showTooltip, style}: UserListItemProps) {
function UserListItem({item, textStyles, alternateTextStyles, showTooltip, style, isFocused, isHovered, shouldUseOnySubscriptAvatar = true}: UserListItemProps) {
const styles = useThemeStyles();
const theme = useTheme();
const StyleUtils = useStyleUtils();

const focusedBackgroundColor = styles.sidebarLinkActive.backgroundColor;
const subscriptAvatarBorderColor = isFocused ? focusedBackgroundColor : theme.sidebar;
const hoveredBackgroundColor = !!styles.sidebarLinkHover && 'backgroundColor' in styles.sidebarLinkHover ? styles.sidebarLinkHover.backgroundColor : theme.sidebar;

return (
<>
{!!item.icons && (
<SubscriptAvatar
mainAvatar={item.icons[0]}
secondaryAvatar={item.icons[1]}
showTooltip={showTooltip}
/>
<>
{item.shouldShowSubscript ?? shouldUseOnySubscriptAvatar ? (
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you explain more about this condition and give the example for the case?

Copy link
Contributor Author

@ZhenjaHorbach ZhenjaHorbach Feb 13, 2024

Choose a reason for hiding this comment

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

Oh )
Sorry )
It should be like this
shouldUseOnySubscriptAvatar || item.shouldShowSubscript
By default shouldUseOnySubscriptAvatar is true this means that we will display only SubscriptAvatar as before
But for Search this value is false, so depending on item.shouldShowSubscript we will show SubscriptAvatar or MultipleAvatars as on LHN or Header chat

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we not using shouldUseOnySubscriptAvatar? I don't see any scenario for the props to exist.

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 think we can)
I'm just afraid
So that this does not cause regression)

Copy link
Contributor

Choose a reason for hiding this comment

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

I understand that. Let's see how it goes, and I'll help test it thoroughly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem )
Give me few minutes )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, I found only one place where we use UserListItem except Search
When we create request money and select participants
And everything looks good )

<SubscriptAvatar
mainAvatar={item.icons[0]}
secondaryAvatar={item.icons[1]}
showTooltip={showTooltip}
backgroundColor={isHovered && !isFocused ? hoveredBackgroundColor : subscriptAvatarBorderColor}
/>
) : (
<MultipleAvatars
icons={item.icons ?? []}
shouldShowTooltip={showTooltip}
secondAvatarStyle={[
StyleUtils.getBackgroundAndBorderStyle(theme.sidebar),
isFocused ? StyleUtils.getBackgroundAndBorderStyle(focusedBackgroundColor) : undefined,
isHovered && !isFocused ? StyleUtils.getBackgroundAndBorderStyle(hoveredBackgroundColor) : undefined,
]}
/>
)}
</>
)}
<View style={[styles.flex1, styles.flexColumn, styles.justifyContentCenter, styles.alignItemsStretch, styles.optionRow]}>
<TextWithTooltip
Expand Down
13 changes: 13 additions & 0 deletions src/components/SelectionList/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ type User = {

/** Represents the index of the option within the section it came from */
index?: number;

/** Whether this option should show subscript */
shouldShowSubscript?: boolean;
};

type UserListItemProps = CommonListItemProps<User> & {
Expand All @@ -81,6 +84,12 @@ type UserListItemProps = CommonListItemProps<User> & {

/** Additional styles to apply to text */
style?: StyleProp<TextStyle>;

/** Is item hovered */
isHovered?: boolean;

/** Whether this item should use only the subscript avatar */
shouldUseOnySubscriptAvatar?: boolean;
};

type RadioItem = {
Expand Down Expand Up @@ -115,6 +124,7 @@ type BaseListItemProps<TItem extends User | RadioItem> = CommonListItemProps<TIt
item: TItem;
shouldPreventDefaultFocusOnSelectRow?: boolean;
keyForList?: string;
shouldUseOnySubscriptAvatar?: boolean;
};

type Section<TItem extends User | RadioItem> = {
Expand Down Expand Up @@ -239,6 +249,9 @@ type BaseSelectionListProps<TItem extends User | RadioItem> = Partial<ChildrenPr

/** Fired when the list is displayed with the items */
onLayout?: (event: LayoutChangeEvent) => void;

/** Whether this item should use only the subscript avatar */
shouldUseOnySubscriptAvatar?: boolean;
};

type ItemLayout = {
Expand Down
1 change: 1 addition & 0 deletions src/pages/SearchPage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ function SearchPage({betas, reports, isSearchingForReports}) {
showLoadingPlaceholder={!didScreenTransitionEnd || !isOptionsDataReady}
footerContent={SearchPageFooterInstance}
isLoadingNewOptions={isSearchingForReports}
shouldUseOnySubscriptAvatar={false}
/>
</View>
</>
Expand Down
Loading