diff --git a/src/CONST/index.ts b/src/CONST/index.ts index 1fa5f67728bc..e137f2b3a06c 100644 --- a/src/CONST/index.ts +++ b/src/CONST/index.ts @@ -4731,6 +4731,13 @@ const CONST = { XXXX_LARGE: 'xxxx-large', }, + AVATAR_SHAPE: { + // Fully round, used for user avatars + CIRCLE: 'circle', + // Corner radius scaled to the avatar size, used for workspace avatars + ROUNDED_SQUARE: 'rounded-square', + }, + COMPANY_CARD: { // Mostly used for feed details FEED_BANK_NAME: { diff --git a/src/components/Avatar/AvatarFromIcon.tsx b/src/components/Avatar/AvatarFromIcon.tsx new file mode 100644 index 000000000000..b1cf26d53787 --- /dev/null +++ b/src/components/Avatar/AvatarFromIcon.tsx @@ -0,0 +1,43 @@ +import {getAccountIDFromAvatarID} from '@libs/UserAvatarUtils'; + +import CONST from '@src/CONST'; +import type {Icon} from '@src/types/onyx/OnyxCommon'; + +import React from 'react'; + +import type {AvatarCommonProps} from './types'; + +import UserAvatar from './UserAvatar'; +import WorkspaceAvatar from './WorkspaceAvatar'; + +type AvatarFromIconProps = Omit & { + /** Icon entry (typically from item.icons) describing the avatar to render. Forks on `icon.type`. */ + icon: Icon; +}; + +/** Renders a user or workspace avatar from an Onyx `Icon` entry. + * Prefer `UserAvatar` and `WorkspaceAvatar` directly when the avatar kind is known at the call site. + */ +function AvatarFromIcon({icon, ...rest}: AvatarFromIconProps) { + if (icon.type === CONST.ICON_TYPE_WORKSPACE) { + return ( + + ); + } + + return ( + + ); +} + +export default AvatarFromIcon; diff --git a/src/components/Avatar/UserAvatar.tsx b/src/components/Avatar/UserAvatar.tsx index 826b4521b2fa..7d923b3bfd62 100644 --- a/src/components/Avatar/UserAvatar.tsx +++ b/src/components/Avatar/UserAvatar.tsx @@ -35,7 +35,6 @@ function UserAvatar({ iconAdditionalStyles, containerStyles, size = CONST.AVATAR_SIZE.DEFAULT, - fill, fallbackIcon, fallbackIconTestID = '', accountID, @@ -61,7 +60,7 @@ function UserAvatar({ urlColors={letterAvatar.colors} accountID={accountID} size={size} - type={CONST.ICON_TYPE_AVATAR} + shape={CONST.AVATAR_SHAPE.CIRCLE} containerStyles={imageStyles} containerAdditionalStyles={iconAdditionalStyles} /> @@ -84,7 +83,7 @@ function UserAvatar({ ); diff --git a/src/components/Avatar/WorkspaceAvatar.tsx b/src/components/Avatar/WorkspaceAvatar.tsx index 5ee0d20188c3..3f546dda90d6 100644 --- a/src/components/Avatar/WorkspaceAvatar.tsx +++ b/src/components/Avatar/WorkspaceAvatar.tsx @@ -25,7 +25,7 @@ type WorkspaceAvatarProps = AvatarCommonProps & { }; /** Renders a workspace avatar, falling back to a default icon derived from the workspace name. */ -function WorkspaceAvatar({source, imageStyles, iconAdditionalStyles, containerStyles, size = CONST.AVATAR_SIZE.DEFAULT, fill, name, avatarID, testID}: WorkspaceAvatarProps) { +function WorkspaceAvatar({source, imageStyles, iconAdditionalStyles, containerStyles, size = CONST.AVATAR_SIZE.DEFAULT, name, avatarID, testID}: WorkspaceAvatarProps) { const theme = useTheme(); const StyleUtils = useStyleUtils(); const defaultAvatars = useDefaultAvatars(); @@ -46,7 +46,7 @@ function WorkspaceAvatar({source, imageStyles, iconAdditionalStyles, containerSt ); diff --git a/src/components/Avatar/index.tsx b/src/components/Avatar/index.tsx deleted file mode 100644 index 4a5693a0ecef..000000000000 --- a/src/components/Avatar/index.tsx +++ /dev/null @@ -1,80 +0,0 @@ -import type {AvatarSource} from '@libs/UserAvatarUtils'; -import {getAccountIDFromAvatarID} from '@libs/UserAvatarUtils'; - -import CONST from '@src/CONST'; -import type {AvatarType} from '@src/types/onyx/OnyxCommon'; - -import React from 'react'; - -import type {AvatarCommonProps} from './types'; - -import UserAvatar from './UserAvatar'; -import WorkspaceAvatar from './WorkspaceAvatar'; - -type AvatarProps = AvatarCommonProps & { - /** ID of the avatar owner: account ID for user avatars, policy ID for workspace avatars. Falls back to the anonymous default when omitted. */ - avatarID?: number | string; - - /** A fallback avatar icon to display when there is an error on loading avatar from remote URL. Only used for user avatars. */ - fallbackIcon?: AvatarSource; - - /** Used to locate fallback icon in end-to-end tests. Only used for user avatars. */ - fallbackIconTestID?: string; - - /** Workspace name. Only used for workspace avatars — seeds the default workspace avatar. */ - name?: string; - - /** Denotes whether it is an avatar or a workspace avatar */ - type: AvatarType; -}; - -/** Renders a user or workspace avatar depending on the `type` prop. - * Prefer `WorkspaceAvatar` and `UserAvatar` directly when the avatar kind is known at the call site. - */ -function Avatar({ - type, - name = '', - fallbackIcon, - fallbackIconTestID, - source, - imageStyles, - iconAdditionalStyles, - containerStyles, - size, - fill, - testID, - avatarID = CONST.DEFAULT_NUMBER_ID, -}: AvatarProps) { - if (type === CONST.ICON_TYPE_WORKSPACE) { - return ( - - ); - } - - return ( - - ); -} - -export default Avatar; diff --git a/src/components/Avatar/layouts/DiagonalAvatars.tsx b/src/components/Avatar/layouts/DiagonalAvatars.tsx index 2a08edfa4483..9610315946c5 100644 --- a/src/components/Avatar/layouts/DiagonalAvatars.tsx +++ b/src/components/Avatar/layouts/DiagonalAvatars.tsx @@ -1,3 +1,4 @@ +import AvatarFromIcon from '@components/Avatar/AvatarFromIcon'; import AvatarNamesTooltip from '@components/Avatar/tooltips/AvatarNamesTooltip'; import AvatarTooltip from '@components/Avatar/tooltips/AvatarTooltip'; import Text from '@components/Text'; @@ -7,6 +8,7 @@ import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; import CONST from '@src/CONST'; +import type {Icon} from '@src/types/onyx/OnyxCommon'; import type {StyleProp, ViewStyle} from 'react-native'; @@ -15,10 +17,12 @@ import {View} from 'react-native'; import type {MultipleAvatarsProps} from './types'; -import Avatar from '..'; import DiagonalAvatarsFrame from './DiagonalAvatarsFrame'; import getDiagonalAvatarSizing from './getDiagonalAvatarSizing'; +// Rendered when the icons array is unexpectedly short. Falls back to the default user avatar. +const EMPTY_USER_ICON: Icon = {source: '', type: CONST.ICON_TYPE_AVATAR}; + type DiagonalAvatarsProps = MultipleAvatarsProps & { /** Style for the secondary avatar container */ secondaryAvatarContainerStyle?: StyleProp; @@ -46,20 +50,18 @@ function DiagonalAvatars({size, icons, isInReportAction, secondaryAvatarContaine size={size} iconCount={icons.length} containerStyle={StyleUtils.getContainerStyles(size, isInReportAction)} - primaryContainerStyle={primaryIcon?.type === CONST.ICON_TYPE_WORKSPACE && StyleUtils.getAvatarBorderRadius(size, primaryIcon.type)} - secondaryContainerStyle={[secondaryAvatarContainerStyles, secondaryIcon?.type === CONST.ICON_TYPE_WORKSPACE && StyleUtils.getAvatarBorderRadius(size, secondaryIcon.type)]} + primaryContainerStyle={primaryIcon?.type === CONST.ICON_TYPE_WORKSPACE && StyleUtils.getAvatarBorderRadius(size, CONST.AVATAR_SHAPE.ROUNDED_SQUARE)} + secondaryContainerStyle={[ + secondaryAvatarContainerStyles, + secondaryIcon?.type === CONST.ICON_TYPE_WORKSPACE && StyleUtils.getAvatarBorderRadius(size, CONST.AVATAR_SHAPE.ROUNDED_SQUARE), + ]} primary={ - - - @@ -118,7 +112,7 @@ function HorizontalAvatars({ }), StyleUtils.getBackgroundColorWithOpacityStyle(theme.overlay, variables.overlayOpacity), StyleUtils.getHorizontalStackedOverlayAvatarStyle(size), - icons.at(3)?.type === CONST.ICON_TYPE_WORKSPACE && StyleUtils.getAvatarBorderRadius(size, icons.at(3)?.type), + icons.at(3)?.type === CONST.ICON_TYPE_WORKSPACE && StyleUtils.getAvatarBorderRadius(size, CONST.AVATAR_SHAPE.ROUNDED_SQUARE), ]} > diff --git a/src/components/Avatar/layouts/PressableDiagonalAvatars.tsx b/src/components/Avatar/layouts/PressableDiagonalAvatars.tsx index 8826048714cc..d0f6c82df13d 100644 --- a/src/components/Avatar/layouts/PressableDiagonalAvatars.tsx +++ b/src/components/Avatar/layouts/PressableDiagonalAvatars.tsx @@ -1,3 +1,4 @@ +import AvatarFromIcon from '@components/Avatar/AvatarFromIcon'; import AvatarTooltip from '@components/Avatar/tooltips/AvatarTooltip'; import PressableWithoutFocus from '@components/Pressable/PressableWithoutFocus'; @@ -13,7 +14,6 @@ import type {ValueOf} from 'type-fest'; import React from 'react'; -import Avatar from '..'; import DiagonalAvatarsFrame from './DiagonalAvatarsFrame'; import getDiagonalAvatarSizing from './getDiagonalAvatarSizing'; @@ -56,13 +56,8 @@ function PressableDiagonalAvatars({size, primaryAvatar, secondaryAvatar, iconCou accessibilityRole={CONST.ROLE.BUTTON} sentryLabel={sentryLabel} > - - @@ -86,14 +81,9 @@ function PressableSubscriptAvatar({size, primaryAvatar, secondaryAvatar, onAvata accessibilityRole={CONST.ROLE.BUTTON} sentryLabel={sentryLabel} > - diff --git a/src/components/Avatar/layouts/SingleAvatar.tsx b/src/components/Avatar/layouts/SingleAvatar.tsx index b680624abe3e..31ba2bc101f5 100644 --- a/src/components/Avatar/layouts/SingleAvatar.tsx +++ b/src/components/Avatar/layouts/SingleAvatar.tsx @@ -1,16 +1,13 @@ +import AvatarFromIcon from '@components/Avatar/AvatarFromIcon'; import AvatarTooltip from '@components/Avatar/tooltips/AvatarTooltip'; import type {AvatarIcon} from '@components/Avatar/types'; -import CONST from '@src/CONST'; - import type {StyleProp, ViewStyle} from 'react-native'; import React from 'react'; import type {BaseAvatarProps} from './types'; -import Avatar from '..'; - type SingleAvatarProps = BaseAvatarProps & { /** The resolved avatar icon to render */ avatar: AvatarIcon; @@ -26,14 +23,9 @@ function SingleAvatar({avatar, size, containerStyles, fallbackDisplayName}: Sing avatar={avatar} fallbackDisplayName={fallbackDisplayName} > - diff --git a/src/components/Avatar/layouts/SubscriptAvatar.tsx b/src/components/Avatar/layouts/SubscriptAvatar.tsx index b71e53a0b94f..301f56627bd9 100644 --- a/src/components/Avatar/layouts/SubscriptAvatar.tsx +++ b/src/components/Avatar/layouts/SubscriptAvatar.tsx @@ -1,10 +1,10 @@ +import AvatarFromIcon from '@components/Avatar/AvatarFromIcon'; import AvatarTooltip from '@components/Avatar/tooltips/AvatarTooltip'; import useStyleUtils from '@hooks/useStyleUtils'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; -import CONST from '@src/CONST'; import type {Icon as IconType} from '@src/types/onyx/OnyxCommon'; import type {ColorValue, StyleProp, ViewStyle} from 'react-native'; @@ -13,7 +13,6 @@ import React from 'react'; import type {BaseAvatarProps} from './types'; -import Avatar from '..'; import getSubscriptAvatarSizing from './getSubscriptAvatarSizing'; import SubscriptAvatarFrame from './SubscriptAvatarFrame'; @@ -48,14 +47,9 @@ function SubscriptAvatar({primaryAvatar, secondaryAvatar, size, subscriptAvatarB avatar={primaryAvatar} fallbackDisplayName={fallbackDisplayName} > - @@ -67,14 +61,9 @@ function SubscriptAvatar({primaryAvatar, secondaryAvatar, size, subscriptAvatarB avatar={secondaryAvatar} style={styles[containerStyleKey]} > - diff --git a/src/components/Avatar/layouts/SubscriptCardFeedAvatar.tsx b/src/components/Avatar/layouts/SubscriptCardFeedAvatar.tsx index aba77ce3d534..06e1afa18949 100644 --- a/src/components/Avatar/layouts/SubscriptCardFeedAvatar.tsx +++ b/src/components/Avatar/layouts/SubscriptCardFeedAvatar.tsx @@ -1,3 +1,4 @@ +import AvatarFromIcon from '@components/Avatar/AvatarFromIcon'; import AvatarTooltip from '@components/Avatar/tooltips/AvatarTooltip'; import Icon from '@components/Icon'; @@ -11,7 +12,6 @@ import {getCardFeedIcon} from '@libs/CardUtils'; import variables from '@styles/variables'; -import CONST from '@src/CONST'; import type {CardFeed} from '@src/types/onyx/CardFeeds'; import type {Icon as IconType} from '@src/types/onyx/OnyxCommon'; @@ -22,7 +22,6 @@ import {View} from 'react-native'; import type {BaseAvatarProps} from './types'; -import Avatar from '..'; import SubscriptAvatarFrame from './SubscriptAvatarFrame'; type SubscriptCardFeedAvatarProps = BaseAvatarProps & { @@ -70,14 +69,9 @@ function SubscriptCardFeedAvatar({ avatar={primaryAvatar} fallbackDisplayName={fallbackDisplayName} > - diff --git a/src/components/Avatar/primitives/AvatarIcon.tsx b/src/components/Avatar/primitives/AvatarIcon.tsx index 462d43c8e290..2c27a4903edf 100644 --- a/src/components/Avatar/primitives/AvatarIcon.tsx +++ b/src/components/Avatar/primitives/AvatarIcon.tsx @@ -34,12 +34,12 @@ type AvatarIconProps = AvatarPrimitivesCommonProps & { }; /** Renders an avatar as an SVG icon. */ -function AvatarIcon({avatarSource, size, type, iconContainerStyles, iconAdditionalStyles, fallbackAvatarTestID, iconColors, fill}: AvatarIconProps) { +function AvatarIcon({avatarSource, size, shape, iconContainerStyles, iconAdditionalStyles, fallbackAvatarTestID, iconColors, fill}: AvatarIconProps) { const styles = useThemeStyles(); const StyleUtils = useStyleUtils(); const iconSize = StyleUtils.getAvatarSize(size); const containerStyles = iconContainerStyles ? [StyleUtils.getAvatarStyle(size), styles.bgTransparent, iconContainerStyles] : undefined; - const additionalStyles = [StyleUtils.getAvatarBorderStyle(size, type), iconColors, iconAdditionalStyles]; + const additionalStyles = [StyleUtils.getAvatarBorderStyle(size, shape), iconColors, iconAdditionalStyles]; return ( diff --git a/src/components/Avatar/primitives/AvatarImage.tsx b/src/components/Avatar/primitives/AvatarImage.tsx index 5f4b2aea7dc4..ce8e1f8415d3 100644 --- a/src/components/Avatar/primitives/AvatarImage.tsx +++ b/src/components/Avatar/primitives/AvatarImage.tsx @@ -24,14 +24,14 @@ type AvatarImageProps = AvatarPrimitivesCommonProps & { }; /** Renders an avatar as a remote image. */ -function AvatarImage({avatarSource, size, type, imageStyles, imageContainerAdditionalStyles, onImageError}: AvatarImageProps) { +function AvatarImage({avatarSource, size, shape, imageStyles, imageContainerAdditionalStyles, onImageError}: AvatarImageProps) { const styles = useThemeStyles(); const StyleUtils = useStyleUtils(); const imageStyle = [StyleUtils.getAvatarStyle(size), imageStyles, styles.noBorderRadius]; const imageContainerStyle = imageStyles ? [StyleUtils.getAvatarStyle(size), styles.bgTransparent, imageStyles] : undefined; return ( - + {/* eslint-disable-next-line react-native-a11y/has-valid-accessibility-ignores-invert-colors -- Custom Image wrapper does not support this prop. */} ; }; -function AvatarLetter({initials, urlColors, accountID, size, type, containerStyles, containerAdditionalStyles: initialsAdditionalStyles}: AvatarLetterProps) { +function AvatarLetter({initials, urlColors, accountID, size, shape, containerStyles, containerAdditionalStyles: initialsAdditionalStyles}: AvatarLetterProps) { const styles = useThemeStyles(); const StyleUtils = useStyleUtils(); const avatarSize = StyleUtils.getAvatarSize(size); @@ -46,7 +46,7 @@ function AvatarLetter({initials, urlColors, accountID, size, type, containerStyl const colors = pickedColorKey && isLetterAvatarSchemeKey(pickedColorKey) ? LETTER_AVATAR_SCHEMES[pickedColorKey] : urlColors; return ( - + diff --git a/src/components/ImportedFromAccountingSoftware.tsx b/src/components/ImportedFromAccountingSoftware.tsx index 9d2c7f919630..bf6edd87a179 100644 --- a/src/components/ImportedFromAccountingSoftware.tsx +++ b/src/components/ImportedFromAccountingSoftware.tsx @@ -83,7 +83,7 @@ function ImportedFromAccountingSoftware({policyID, currentConnectionName, transl src={icon} height={variables.iconSizeMedium} width={variables.iconSizeMedium} - additionalStyles={[StyleUtils.getAvatarBorderStyle(CONST.AVATAR_SIZE.X_SMALL, ''), styles.appBG]} + additionalStyles={[StyleUtils.getAvatarBorderStyle(CONST.AVATAR_SIZE.X_SMALL, CONST.AVATAR_SHAPE.CIRCLE), styles.appBG]} /> ) : undefined } diff --git a/src/components/MentionSuggestions.tsx b/src/components/MentionSuggestions.tsx index 39ad2180f993..4d880aa84fd4 100644 --- a/src/components/MentionSuggestions.tsx +++ b/src/components/MentionSuggestions.tsx @@ -105,7 +105,7 @@ function MentionSuggestions({ width={StyleUtils.getAvatarSize(CONST.AVATAR_SIZE.XXX_SMALL)} height={StyleUtils.getAvatarSize(CONST.AVATAR_SIZE.XXX_SMALL)} fill={theme.success} - additionalStyles={StyleUtils.getAvatarBorderStyle(CONST.AVATAR_SIZE.XXX_SMALL, CONST.ICON_TYPE_AVATAR)} + additionalStyles={StyleUtils.getAvatarBorderStyle(CONST.AVATAR_SIZE.XXX_SMALL, CONST.AVATAR_SHAPE.CIRCLE)} /> ) : ( - ); @@ -135,7 +131,9 @@ function RoomHeaderAvatars({icons, report, policy, participants, currentUserAcco // Bordered workspace avatars here are 88px (avatar + border), so they keep the larger rounded radius instead of the 16px radius mapped to a plain xxx-large avatar. const getRoomHeaderAvatarBorderRadius = (type?: string) => - type === CONST.ICON_TYPE_WORKSPACE ? {borderRadius: variables.componentBorderRadiusRounded} : StyleUtils.getAvatarBorderRadius(CONST.AVATAR_SIZE.XXX_LARGE, type); + type === CONST.ICON_TYPE_WORKSPACE + ? {borderRadius: variables.componentBorderRadiusRounded} + : StyleUtils.getAvatarBorderRadius(CONST.AVATAR_SIZE.XXX_LARGE, StyleUtils.getShapeFromIconType(type)); return ( @@ -152,14 +150,10 @@ function RoomHeaderAvatars({icons, report, policy, participants, currentUserAcco accessibilityLabel={icon.name ?? ''} disabled={icon.source === expensifyIcons.FallbackAvatar} > - {index === CONST.REPORT.MAX_PREVIEW_AVATARS - 1 && icons.length - CONST.REPORT.MAX_PREVIEW_AVATARS !== 0 && ( diff --git a/src/components/Search/FilterComponents/ExportedToSelector.tsx b/src/components/Search/FilterComponents/ExportedToSelector.tsx index 8612ef67e2a2..fb85971cfb5b 100644 --- a/src/components/Search/FilterComponents/ExportedToSelector.tsx +++ b/src/components/Search/FilterComponents/ExportedToSelector.tsx @@ -85,7 +85,7 @@ function ExportedToSelector({value = [], policyID, selectionListTextInputStyle, src={icon} width={variables.iconSizeXLarge} height={variables.iconSizeXLarge} - additionalStyles={[StyleUtils.getAvatarBorderStyle(CONST.AVATAR_SIZE.DEFAULT, CONST.ICON_TYPE_AVATAR)]} + additionalStyles={[StyleUtils.getAvatarBorderStyle(CONST.AVATAR_SIZE.DEFAULT, CONST.AVATAR_SHAPE.CIRCLE)]} /> ) : ( diff --git a/src/components/Search/SearchList/ListItem/AttendeesCell.tsx b/src/components/Search/SearchList/ListItem/AttendeesCell.tsx index 65b28e3c8407..667e7b20b94d 100644 --- a/src/components/Search/SearchList/ListItem/AttendeesCell.tsx +++ b/src/components/Search/SearchList/ListItem/AttendeesCell.tsx @@ -77,7 +77,12 @@ function AttendeesCell({attendees, isHovered, isPressed}: AttendeesCellProps) { }} shouldRender > - + diff --git a/src/components/Search/SearchList/ListItem/AvatarWithTextCell.tsx b/src/components/Search/SearchList/ListItem/AvatarWithTextCell.tsx index 27a88314169b..027256179a0f 100644 --- a/src/components/Search/SearchList/ListItem/AvatarWithTextCell.tsx +++ b/src/components/Search/SearchList/ListItem/AvatarWithTextCell.tsx @@ -1,4 +1,4 @@ -import Avatar from '@components/Avatar'; +import AvatarFromIcon from '@components/Avatar/AvatarFromIcon'; import Text from '@components/Text'; import useThemeStyles from '@hooks/useThemeStyles'; @@ -28,14 +28,10 @@ function AvatarWithTextCell({reportName, icon, isLargeScreenWidth, textStyle}: A return ( {!!icon && ( - )} diff --git a/src/components/Search/SearchList/ListItem/ExportedIconCell.tsx b/src/components/Search/SearchList/ListItem/ExportedIconCell.tsx index 3d6f70bcdcbf..6c435ad223d2 100644 --- a/src/components/Search/SearchList/ListItem/ExportedIconCell.tsx +++ b/src/components/Search/SearchList/ListItem/ExportedIconCell.tsx @@ -120,7 +120,7 @@ function ExportedIconCell({reportActions}: ExportedIconCellProps) { key={name} src={src} size={CONST.ICON_SIZE.SMALL} - additionalStyles={[StyleUtils.getAvatarBorderStyle(CONST.AVATAR_SIZE.XXX_SMALL, CONST.ICON_TYPE_AVATAR)]} + additionalStyles={[StyleUtils.getAvatarBorderStyle(CONST.AVATAR_SIZE.XXX_SMALL, CONST.AVATAR_SHAPE.CIRCLE)]} /> ))} diff --git a/src/components/SelectionList/ListItem/MultiSelectListItem.tsx b/src/components/SelectionList/ListItem/MultiSelectListItem.tsx index c8ef2fbb5650..bc34bb5c697b 100644 --- a/src/components/SelectionList/ListItem/MultiSelectListItem.tsx +++ b/src/components/SelectionList/ListItem/MultiSelectListItem.tsx @@ -1,4 +1,4 @@ -import Avatar from '@components/Avatar'; +import AvatarFromIcon from '@components/Avatar/AvatarFromIcon'; import useThemeStyles from '@hooks/useThemeStyles'; @@ -75,13 +75,9 @@ function AvatarLeftElement({icon}: {icon: Icon}) { return ( - ); diff --git a/src/components/SelectionList/ListItem/SingleSelectWithAvatarListItem.tsx b/src/components/SelectionList/ListItem/SingleSelectWithAvatarListItem.tsx index d27a904cf47d..36615d874e10 100644 --- a/src/components/SelectionList/ListItem/SingleSelectWithAvatarListItem.tsx +++ b/src/components/SelectionList/ListItem/SingleSelectWithAvatarListItem.tsx @@ -1,4 +1,4 @@ -import Avatar from '@components/Avatar'; +import AvatarFromIcon from '@components/Avatar/AvatarFromIcon'; import useThemeStyles from '@hooks/useThemeStyles'; @@ -31,13 +31,9 @@ function SingleSelectWithAvatarListItem({item, wrapperSt const avatarElement = ( - diff --git a/src/components/UserDetailsTooltip/BaseUserDetailsTooltip/index.tsx b/src/components/UserDetailsTooltip/BaseUserDetailsTooltip/index.tsx index 35b55e4f85e3..1145772034e1 100644 --- a/src/components/UserDetailsTooltip/BaseUserDetailsTooltip/index.tsx +++ b/src/components/UserDetailsTooltip/BaseUserDetailsTooltip/index.tsx @@ -1,4 +1,5 @@ -import Avatar from '@components/Avatar'; +import AvatarFromIcon from '@components/Avatar/AvatarFromIcon'; +import UserAvatar from '@components/Avatar/UserAvatar'; import {usePersonalDetails} from '@components/OnyxListItemProvider'; import Text from '@components/Text'; import Tooltip from '@components/Tooltip'; @@ -59,14 +60,18 @@ function BaseUserDetailsTooltip({accountID, fallbackUserDetails, icon, delegateA () => ( - + {icon ? ( + + ) : ( + + )} {title} {subtitle} diff --git a/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx b/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx index 1d7ecbe9d0dd..d1e45b4ddb5c 100644 --- a/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx +++ b/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx @@ -168,7 +168,7 @@ function BaseOnboardingAccounting({shouldUseNativeStyles}: BaseOnboardingAccount src={icon} width={variables.iconSizeExtraLarge} height={variables.iconSizeExtraLarge} - additionalStyles={[StyleUtils.getAvatarBorderStyle(CONST.AVATAR_SIZE.DEFAULT, CONST.ICON_TYPE_AVATAR), styles.mr3]} + additionalStyles={[StyleUtils.getAvatarBorderStyle(CONST.AVATAR_SIZE.DEFAULT, CONST.AVATAR_SHAPE.CIRCLE), styles.mr3]} /> ), isSelected: selectedIntegration === integration.key, @@ -184,7 +184,7 @@ function BaseOnboardingAccounting({shouldUseNativeStyles}: BaseOnboardingAccount width={variables.iconSizeNormal} height={variables.iconSizeNormal} fill={theme.icon} - additionalStyles={[StyleUtils.getAvatarBorderStyle(CONST.AVATAR_SIZE.DEFAULT, CONST.ICON_TYPE_AVATAR), styles.mr3, styles.onboardingSmallIcon]} + additionalStyles={[StyleUtils.getAvatarBorderStyle(CONST.AVATAR_SIZE.DEFAULT, CONST.AVATAR_SHAPE.CIRCLE), styles.mr3, styles.onboardingSmallIcon]} /> ), isSelected: isOtherSelected, diff --git a/src/pages/settings/Agents/Fields/EditAgentAvatarPage.tsx b/src/pages/settings/Agents/Fields/EditAgentAvatarPage.tsx index 2500de21e96f..5389dd9b2ec9 100644 --- a/src/pages/settings/Agents/Fields/EditAgentAvatarPage.tsx +++ b/src/pages/settings/Agents/Fields/EditAgentAvatarPage.tsx @@ -211,7 +211,7 @@ function EditAgentAvatarContent({accountID, fallbackRoute, onSave, initialPreset src={local} width={presetAvatarSize} height={presetAvatarSize} - additionalStyles={StyleUtils.getAvatarBorderStyle(CONST.AVATAR_SIZE.X_LARGE, CONST.ICON_TYPE_AVATAR)} + additionalStyles={StyleUtils.getAvatarBorderStyle(CONST.AVATAR_SIZE.X_LARGE, CONST.AVATAR_SHAPE.CIRCLE)} /> diff --git a/src/pages/settings/Agents/NewAgentPage.tsx b/src/pages/settings/Agents/NewAgentPage.tsx index 60d9cefe5e36..b6f3e5280bfc 100644 --- a/src/pages/settings/Agents/NewAgentPage.tsx +++ b/src/pages/settings/Agents/NewAgentPage.tsx @@ -55,7 +55,7 @@ function AgentTemplateCard({template, avatarID, onAdd}: AgentTemplateCardProps) src={avatar} width={avatarSize} height={avatarSize} - additionalStyles={StyleUtils.getAvatarBorderStyle(CONST.AVATAR_SIZE.DEFAULT, CONST.ICON_TYPE_AVATAR)} + additionalStyles={StyleUtils.getAvatarBorderStyle(CONST.AVATAR_SIZE.DEFAULT, CONST.AVATAR_SHAPE.CIRCLE)} /> {template.name} diff --git a/src/pages/workspace/upgrade/UpgradeIntroView.tsx b/src/pages/workspace/upgrade/UpgradeIntroView.tsx index 79e4bda95b4a..7afc56a2f47c 100644 --- a/src/pages/workspace/upgrade/UpgradeIntroView.tsx +++ b/src/pages/workspace/upgrade/UpgradeIntroView.tsx @@ -87,7 +87,7 @@ function UpgradeIntroView({ const subscriptionLink = subscriptionPlan ? `${environmentURL}/${ROUTES.SETTINGS_SUBSCRIPTION.getRoute(Navigation.getActiveRoute())}` : CONST.PLAN_TYPES_AND_PRICING_HELP_URL; const iconSize = StyleUtils.getAvatarSize(isIllustration ? CONST.AVATAR_SIZE.LARGE : CONST.AVATAR_SIZE.DEFAULT); - const iconStyles = isIllustration ? iconAdditionalStyles : StyleUtils.getAvatarBorderStyle(CONST.AVATAR_SIZE.DEFAULT, CONST.ICON_TYPE_AVATAR); + const iconStyles = isIllustration ? iconAdditionalStyles : StyleUtils.getAvatarBorderStyle(CONST.AVATAR_SIZE.DEFAULT, CONST.AVATAR_SHAPE.CIRCLE); return ( diff --git a/src/styles/utils/index.ts b/src/styles/utils/index.ts index d26e7e8c4708..c58967669506 100644 --- a/src/styles/utils/index.ts +++ b/src/styles/utils/index.ts @@ -25,6 +25,7 @@ import {PixelRatio, Dimensions as RNDimensions, StyleSheet} from 'react-native'; import type {ThemeStyles} from '..'; import type { AllStyles, + AvatarShape, AvatarSizeName, AvatarStyle, ButtonSizeValue, @@ -299,10 +300,17 @@ function getAvatarBorderWidth(size: AvatarSizeName): ViewStyle { } /** - * Return the border radius for an avatar + * Map an icon type to the avatar shape it renders with */ -function getAvatarBorderRadius(size: AvatarSizeName, type?: string): ViewStyle { - if (type === CONST.ICON_TYPE_WORKSPACE) { +function getShapeFromIconType(type?: string): AvatarShape { + return type === CONST.ICON_TYPE_WORKSPACE ? CONST.AVATAR_SHAPE.ROUNDED_SQUARE : CONST.AVATAR_SHAPE.CIRCLE; +} + +/** + * Return the border radius for an avatar of the given shape + */ +function getAvatarBorderRadius(size: AvatarSizeName, shape: AvatarShape): ViewStyle { + if (shape === CONST.AVATAR_SHAPE.ROUNDED_SQUARE) { return {borderRadius: avatarBorderSizes[size]}; } @@ -311,12 +319,12 @@ function getAvatarBorderRadius(size: AvatarSizeName, type?: string): ViewStyle { } /** - * Return the border style for an avatar + * Return the border style for an avatar of the given shape */ -function getAvatarBorderStyle(size: AvatarSizeName, type: string): ViewStyle { +function getAvatarBorderStyle(size: AvatarSizeName, shape: AvatarShape): ViewStyle { return { overflow: 'hidden', - ...getAvatarBorderRadius(size, type), + ...getAvatarBorderRadius(size, shape), }; } @@ -1413,6 +1421,7 @@ const staticStyleUtils = { getAvatarSizeWithBorder, getAvatarWidthStyle, getAvatarSubscriptIconContainerStyle, + getShapeFromIconType, getBackgroundAndBorderStyle, getBackgroundColorStyle, getBackgroundColorWithOpacityStyle, @@ -2458,4 +2467,4 @@ const createStyleUtils = (theme: ThemeColors, styles: ThemeStyles) => ({ type StyleUtilsType = ReturnType; export default createStyleUtils; -export type {StyleUtilsType, AvatarSizeName}; +export type {StyleUtilsType, AvatarShape, AvatarSizeName}; diff --git a/src/styles/utils/types.ts b/src/styles/utils/types.ts index 1095c6dc59a4..44b962f5781f 100644 --- a/src/styles/utils/types.ts +++ b/src/styles/utils/types.ts @@ -11,6 +11,7 @@ type ParsableStyle = StyleProp | ((state: PressableStateCallbackType) type ColorValue = ValueOf; type AvatarSizeName = ValueOf; +type AvatarShape = ValueOf; type EReceiptColorName = ValueOf; type AvatarStyle = Dimensions & { @@ -38,6 +39,7 @@ export type { AllStyles, ParsableStyle, ColorValue, + AvatarShape, AvatarSizeName, EReceiptColorName, AvatarStyle, diff --git a/src/types/onyx/OnyxCommon.ts b/src/types/onyx/OnyxCommon.ts index b3d63748e873..963f81e4b396 100644 --- a/src/types/onyx/OnyxCommon.ts +++ b/src/types/onyx/OnyxCommon.ts @@ -70,9 +70,6 @@ type Icon = { /** A fallback avatar icon to display when there is an error on loading avatar from remote URL. */ fallbackIcon?: AvatarSource; - - /** Fill color of the icon */ - fill?: string; }; export type {Icon, PendingAction, PendingFields, ErrorFields, Errors, AvatarType, OnyxValueWithOfflineFeedback, TranslationKeyError, TranslationKeyErrors}; diff --git a/tests/ui/GroupChatNameTests.tsx b/tests/ui/GroupChatNameTests.tsx index 5c06c8ad37cc..086a19d2f3fc 100644 --- a/tests/ui/GroupChatNameTests.tsx +++ b/tests/ui/GroupChatNameTests.tsx @@ -39,8 +39,23 @@ jest.mock('react-native/Libraries/LogBox/LogBox', () => ({ jest.mock('@react-navigation/native'); -// Mock Avatar component to prevent act() warnings from state updates during render -jest.mock('@src/components/Avatar', () => { +// Mock avatar components to prevent act() warnings from state updates during render +jest.mock('@src/components/Avatar/UserAvatar', () => { + const {View} = require('react-native'); + return ({source, accountID, testID = 'Avatar'}: {source?: unknown; accountID?: number; testID?: string}) => { + return ( + + ); + }; +}); +jest.mock('@src/components/Avatar/WorkspaceAvatar', () => { const {View} = require('react-native'); return ({source, name, avatarID, testID = 'Avatar'}: {source?: unknown; name?: string; avatarID?: string; testID?: string}) => { return ( diff --git a/tests/unit/AvatarTest.tsx b/tests/unit/AvatarTest.tsx index b7be45230c11..9dc3dfc086e6 100644 --- a/tests/unit/AvatarTest.tsx +++ b/tests/unit/AvatarTest.tsx @@ -1,6 +1,6 @@ import {render, screen} from '@testing-library/react-native'; -import Avatar from '@components/Avatar'; +import AvatarFromIcon from '@components/Avatar/AvatarFromIcon'; import UserAvatar from '@components/Avatar/UserAvatar'; import WorkspaceAvatar from '@components/Avatar/WorkspaceAvatar'; import ComposeProviders from '@components/ComposeProviders'; @@ -92,10 +92,10 @@ function queryHiddenTestId(testID: string) { return screen.queryByTestId(testID, hiddenElementOptions); } -function renderAvatar(props: React.ComponentProps) { +function renderAvatarFromIcon(props: React.ComponentProps) { return render( - + , ); } @@ -236,11 +236,8 @@ describe('Avatar', () => { describe('workspace avatar', () => { it('renders the Image branch for a letter-avatar URL because initials are user-avatar-only', async () => { - renderAvatar({ - type: CONST.ICON_TYPE_WORKSPACE, - source: LETTER_AVATAR_URL, - name: WORKSPACE_NAME, - avatarID: 'policy_123', + renderAvatarFromIcon({ + icon: {type: CONST.ICON_TYPE_WORKSPACE, source: LETTER_AVATAR_URL, name: WORKSPACE_NAME, id: 'policy_123'}, }); await waitForBatchedUpdates(); @@ -250,11 +247,8 @@ describe('Avatar', () => { }); it('renders the Image branch for an uploaded workspace logo URL', async () => { - renderAvatar({ - type: CONST.ICON_TYPE_WORKSPACE, - source: UPLOADED_AVATAR_URL, - name: WORKSPACE_NAME, - avatarID: 'policy_123', + renderAvatarFromIcon({ + icon: {type: CONST.ICON_TYPE_WORKSPACE, source: UPLOADED_AVATAR_URL, name: WORKSPACE_NAME, id: 'policy_123'}, }); await waitForBatchedUpdates(); @@ -267,10 +261,8 @@ describe('Avatar', () => { it('renders the default workspace Icon when no source is provided', async () => { const workspaceFallbackTestID = getDefaultWorkspaceAvatarTestID(WORKSPACE_NAME); - renderAvatar({ - type: CONST.ICON_TYPE_WORKSPACE, - name: WORKSPACE_NAME, - avatarID: 'policy_123', + renderAvatarFromIcon({ + icon: {type: CONST.ICON_TYPE_WORKSPACE, source: '', name: WORKSPACE_NAME, id: 'policy_123'}, }); await waitForBatchedUpdates(); @@ -282,11 +274,8 @@ describe('Avatar', () => { it('switches from the Image branch to the default workspace Icon when the uploaded logo fails to load', async () => { const workspaceFallbackTestID = getDefaultWorkspaceAvatarTestID(WORKSPACE_NAME); - renderAvatar({ - type: CONST.ICON_TYPE_WORKSPACE, - source: UPLOADED_AVATAR_URL, - name: WORKSPACE_NAME, - avatarID: 'policy_123', + renderAvatarFromIcon({ + icon: {type: CONST.ICON_TYPE_WORKSPACE, source: UPLOADED_AVATAR_URL, name: WORKSPACE_NAME, id: 'policy_123'}, }); await waitForBatchedUpdates(); @@ -304,11 +293,9 @@ describe('Avatar', () => { }); describe('UserAvatar and WorkspaceAvatar', () => { - it('the back-compat facade renders the user branch the same as UserAvatar', async () => { - renderAvatar({ - type: CONST.ICON_TYPE_AVATAR, - source: UPLOADED_AVATAR_URL, - avatarID: 1, + it('AvatarFromIcon renders the user branch the same as UserAvatar', async () => { + renderAvatarFromIcon({ + icon: {type: CONST.ICON_TYPE_AVATAR, source: UPLOADED_AVATAR_URL, id: 1}, }); await waitForBatchedUpdates(); @@ -317,7 +304,7 @@ describe('Avatar', () => { expect(screen.getByTestId(AVATAR_IMAGE_TEST_ID)).toBeTruthy(); }); - it('WorkspaceAvatar renders the same as the back-compat default for workspace avatars', async () => { + it('WorkspaceAvatar renders the default workspace icon when no source is provided', async () => { const workspaceFallbackTestID = getDefaultWorkspaceAvatarTestID(WORKSPACE_NAME); render(