From 1ca8ef20344cfe19a802b8dd977b0c3c2316af5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Musia=C5=82?= Date: Wed, 26 Aug 2026 12:41:03 +0200 Subject: [PATCH 1/3] Cleanup for Decompose Avatar component --- src/CONST/index.ts | 7 ++ src/components/Avatar/AvatarFromIcon.tsx | 53 ++++++++++++ src/components/Avatar/UserAvatar.tsx | 6 +- src/components/Avatar/WorkspaceAvatar.tsx | 4 +- src/components/Avatar/index.tsx | 80 ------------------- .../Avatar/layouts/DiagonalAvatars.tsx | 22 +++-- .../Avatar/layouts/HorizontalAvatars.tsx | 11 +-- .../layouts/PressableDiagonalAvatars.tsx | 10 +-- .../layouts/PressableSubscriptAvatar.tsx | 18 ++--- .../Avatar/layouts/SingleAvatar.tsx | 13 +-- .../Avatar/layouts/SubscriptAvatar.tsx | 19 ++--- .../layouts/SubscriptCardFeedAvatar.tsx | 11 +-- .../Avatar/primitives/AvatarIcon.tsx | 4 +- .../Avatar/primitives/AvatarImage.tsx | 4 +- .../Avatar/primitives/AvatarLetter.tsx | 4 +- src/components/Avatar/types.ts | 8 +- src/components/AvatarSelector.tsx | 2 +- .../ImportedFromAccountingSoftware.tsx | 2 +- src/components/MentionSuggestions.tsx | 2 +- src/components/RoomHeaderAvatars.tsx | 18 ++--- .../FilterComponents/ExportedToSelector.tsx | 2 +- .../ListItem/AvatarWithTextCell.tsx | 12 +-- .../SearchList/ListItem/ExportedIconCell.tsx | 2 +- .../ListItem/MultiSelectListItem.tsx | 10 +-- .../SingleSelectWithAvatarListItem.tsx | 10 +-- .../BaseUserDetailsTooltip/index.tsx | 23 +++--- .../BaseOnboardingAccounting.tsx | 4 +- .../Agents/Fields/EditAgentAvatarPage.tsx | 2 +- src/pages/settings/Agents/NewAgentPage.tsx | 2 +- .../workspace/upgrade/UpgradeIntroView.tsx | 2 +- src/styles/utils/index.ts | 9 ++- src/styles/utils/types.ts | 2 + tests/ui/GroupChatNameTests.tsx | 19 ++++- tests/unit/AvatarTest.tsx | 43 ++++------ 34 files changed, 184 insertions(+), 256 deletions(-) create mode 100644 src/components/Avatar/AvatarFromIcon.tsx delete mode 100644 src/components/Avatar/index.tsx diff --git a/src/CONST/index.ts b/src/CONST/index.ts index 701529ddf2e5..fa6e907ba923 100644 --- a/src/CONST/index.ts +++ b/src/CONST/index.ts @@ -4699,6 +4699,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..64bd757e0778 --- /dev/null +++ b/src/components/Avatar/AvatarFromIcon.tsx @@ -0,0 +1,53 @@ +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, imageStyles, iconAdditionalStyles, containerStyles, size, fill, testID}: 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..e59274b618fe 100644 --- a/src/components/Avatar/UserAvatar.tsx +++ b/src/components/Avatar/UserAvatar.tsx @@ -61,7 +61,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 +84,7 @@ function UserAvatar({ - ); - } - - return ( - - ); -} - -export default Avatar; diff --git a/src/components/Avatar/layouts/DiagonalAvatars.tsx b/src/components/Avatar/layouts/DiagonalAvatars.tsx index 2a08edfa4483..e14c0b0f9973 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; @@ -53,12 +57,8 @@ function DiagonalAvatars({size, icons, isInReportAction, secondaryAvatarContaine avatar={primaryIcon} fallbackDisplayName={fallbackDisplayName} > - - - - - - - - - - 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)} /> ) : ( - ); @@ -152,14 +148,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/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..cde30f6b3c30 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, @@ -311,12 +312,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), + borderRadius: shape === CONST.AVATAR_SHAPE.ROUNDED_SQUARE ? avatarBorderSizes[size] : variables.buttonBorderRadius, }; } @@ -2458,4 +2459,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/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( From 968bdc1c0fb090ea4d158e1cc0a9ea26897c6f4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Musia=C5=82?= Date: Thu, 27 Aug 2026 10:33:04 +0200 Subject: [PATCH 2/3] Address review comments --- src/components/Avatar/AvatarFromIcon.tsx | 4 +--- src/components/Avatar/UserAvatar.tsx | 3 +-- src/components/Avatar/WorkspaceAvatar.tsx | 4 ++-- src/components/Avatar/layouts/DiagonalAvatars.tsx | 11 ++++++----- .../Avatar/layouts/HorizontalAvatars.tsx | 5 ++--- .../Avatar/layouts/PressableDiagonalAvatars.tsx | 5 ++--- .../Avatar/layouts/PressableSubscriptAvatar.tsx | 2 -- src/components/Avatar/layouts/SingleAvatar.tsx | 1 - src/components/Avatar/layouts/SubscriptAvatar.tsx | 2 -- .../Avatar/layouts/SubscriptCardFeedAvatar.tsx | 1 - src/components/Avatar/types.ts | 6 ------ .../ReportActionAvatars/useReportActionAvatars.ts | 4 ---- src/components/RoomHeaderAvatars.tsx | 4 +++- .../Search/SearchList/ListItem/AttendeesCell.tsx | 9 +++++++-- src/styles/utils/index.ts | 14 +++++++++++--- src/types/onyx/OnyxCommon.ts | 3 --- 16 files changed, 35 insertions(+), 43 deletions(-) diff --git a/src/components/Avatar/AvatarFromIcon.tsx b/src/components/Avatar/AvatarFromIcon.tsx index 64bd757e0778..cadaa689b342 100644 --- a/src/components/Avatar/AvatarFromIcon.tsx +++ b/src/components/Avatar/AvatarFromIcon.tsx @@ -18,7 +18,7 @@ type AvatarFromIconProps = Omit & { /** 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, imageStyles, iconAdditionalStyles, containerStyles, size, fill, testID}: AvatarFromIconProps) { +function AvatarFromIcon({icon, imageStyles, iconAdditionalStyles, containerStyles, size, testID}: AvatarFromIconProps) { if (icon.type === CONST.ICON_TYPE_WORKSPACE) { return ( ); @@ -44,7 +43,6 @@ function AvatarFromIcon({icon, imageStyles, iconAdditionalStyles, containerStyle iconAdditionalStyles={iconAdditionalStyles} containerStyles={containerStyles} size={size} - fill={fill} testID={testID} /> ); diff --git a/src/components/Avatar/UserAvatar.tsx b/src/components/Avatar/UserAvatar.tsx index e59274b618fe..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, @@ -111,7 +110,7 @@ function UserAvatar({ iconAdditionalStyles={iconAdditionalStyles} fallbackAvatarTestID={fallbackAvatarTestID} iconColors={iconColors} - fill={iconColors?.fill ?? (hasImageError ? theme.offline : fill)} + fill={iconColors?.fill ?? (hasImageError ? theme.offline : undefined)} /> ); diff --git a/src/components/Avatar/WorkspaceAvatar.tsx b/src/components/Avatar/WorkspaceAvatar.tsx index c1bb67b9293c..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(); @@ -70,7 +70,7 @@ function WorkspaceAvatar({source, imageStyles, iconAdditionalStyles, containerSt iconAdditionalStyles={iconAdditionalStyles} fallbackAvatarTestID={fallbackAvatarTestID} iconColors={iconColors} - fill={iconColors?.fill ?? (hasImageError ? theme.offline : fill)} + fill={iconColors?.fill ?? (hasImageError ? theme.offline : undefined)} /> ); diff --git a/src/components/Avatar/layouts/DiagonalAvatars.tsx b/src/components/Avatar/layouts/DiagonalAvatars.tsx index e14c0b0f9973..9610315946c5 100644 --- a/src/components/Avatar/layouts/DiagonalAvatars.tsx +++ b/src/components/Avatar/layouts/DiagonalAvatars.tsx @@ -20,7 +20,7 @@ import type {MultipleAvatarsProps} from './types'; import DiagonalAvatarsFrame from './DiagonalAvatarsFrame'; import getDiagonalAvatarSizing from './getDiagonalAvatarSizing'; -// Rendered when the icons array is unexpectedly short — falls back to the default user avatar. +// 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 & { @@ -50,8 +50,11 @@ 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={ @@ -113,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 ca087db64f91..d0f6c82df13d 100644 --- a/src/components/Avatar/layouts/PressableDiagonalAvatars.tsx +++ b/src/components/Avatar/layouts/PressableDiagonalAvatars.tsx @@ -58,7 +58,6 @@ function PressableDiagonalAvatars({size, primaryAvatar, secondaryAvatar, iconCou > @@ -85,7 +84,6 @@ function PressableSubscriptAvatar({size, primaryAvatar, secondaryAvatar, onAvata diff --git a/src/components/Avatar/layouts/SingleAvatar.tsx b/src/components/Avatar/layouts/SingleAvatar.tsx index a0eccc03c322..31ba2bc101f5 100644 --- a/src/components/Avatar/layouts/SingleAvatar.tsx +++ b/src/components/Avatar/layouts/SingleAvatar.tsx @@ -26,7 +26,6 @@ function SingleAvatar({avatar, size, containerStyles, fallbackDisplayName}: Sing diff --git a/src/components/Avatar/layouts/SubscriptAvatar.tsx b/src/components/Avatar/layouts/SubscriptAvatar.tsx index f07bbe884429..301f56627bd9 100644 --- a/src/components/Avatar/layouts/SubscriptAvatar.tsx +++ b/src/components/Avatar/layouts/SubscriptAvatar.tsx @@ -50,7 +50,6 @@ function SubscriptAvatar({primaryAvatar, secondaryAvatar, size, subscriptAvatarB @@ -65,7 +64,6 @@ function SubscriptAvatar({primaryAvatar, secondaryAvatar, size, subscriptAvatarB diff --git a/src/components/Avatar/layouts/SubscriptCardFeedAvatar.tsx b/src/components/Avatar/layouts/SubscriptCardFeedAvatar.tsx index 10f38f4091dc..06e1afa18949 100644 --- a/src/components/Avatar/layouts/SubscriptCardFeedAvatar.tsx +++ b/src/components/Avatar/layouts/SubscriptCardFeedAvatar.tsx @@ -72,7 +72,6 @@ function SubscriptCardFeedAvatar({ diff --git a/src/components/Avatar/types.ts b/src/components/Avatar/types.ts index 1c9cde04bdbc..a6c45a4ac1e1 100644 --- a/src/components/Avatar/types.ts +++ b/src/components/Avatar/types.ts @@ -22,12 +22,6 @@ type AvatarCommonProps = { /** Set the size of Avatar */ size?: AvatarSizeName; - /** - * The fill color for the icon. Can be hex, rgb, rgba, or valid react-native named color such as 'red' or 'blue' - * For workspace avatars this fill color is ignored — the colors are derived from the avatarID prop instead. - */ - fill?: string; - /** Test ID for the Avatar component */ testID?: string; }; diff --git a/src/components/ReportActionAvatars/useReportActionAvatars.ts b/src/components/ReportActionAvatars/useReportActionAvatars.ts index ed7e3027f81d..e3f00d91dd61 100644 --- a/src/components/ReportActionAvatars/useReportActionAvatars.ts +++ b/src/components/ReportActionAvatars/useReportActionAvatars.ts @@ -260,7 +260,6 @@ function useReportActionAvatars({ name: delegatePersonalDetails.displayName, id: delegatePersonalDetails.accountID, type: CONST.ICON_TYPE_AVATAR, - fill: undefined, fallbackIcon, } : undefined; @@ -271,7 +270,6 @@ function useReportActionAvatars({ id: policy?.id, name: policy?.name, type: CONST.ICON_TYPE_WORKSPACE, - fill: undefined, fallbackIcon, }; @@ -280,7 +278,6 @@ function useReportActionAvatars({ id: accountID, name: defaultDisplayName ?? fallbackDisplayName, type: CONST.ICON_TYPE_AVATAR, - fill: undefined, fallbackIcon, }; @@ -289,7 +286,6 @@ function useReportActionAvatars({ source: '', type: CONST.ICON_TYPE_AVATAR, id: 0, - fill: undefined, fallbackIcon, }; diff --git a/src/components/RoomHeaderAvatars.tsx b/src/components/RoomHeaderAvatars.tsx index e5675eaccf98..f1212c4d2359 100644 --- a/src/components/RoomHeaderAvatars.tsx +++ b/src/components/RoomHeaderAvatars.tsx @@ -131,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 ( 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/styles/utils/index.ts b/src/styles/utils/index.ts index cde30f6b3c30..317c856f79b7 100644 --- a/src/styles/utils/index.ts +++ b/src/styles/utils/index.ts @@ -299,11 +299,18 @@ function getAvatarBorderWidth(size: AvatarSizeName): ViewStyle { }; } +/** + * Map an icon type to the avatar shape it renders with + */ +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 */ -function getAvatarBorderRadius(size: AvatarSizeName, type?: string): ViewStyle { - if (type === CONST.ICON_TYPE_WORKSPACE) { +function getAvatarBorderRadius(size: AvatarSizeName, shape: AvatarShape): ViewStyle { + if (shape === CONST.AVATAR_SHAPE.ROUNDED_SQUARE) { return {borderRadius: avatarBorderSizes[size]}; } @@ -317,7 +324,7 @@ function getAvatarBorderRadius(size: AvatarSizeName, type?: string): ViewStyle { function getAvatarBorderStyle(size: AvatarSizeName, shape: AvatarShape): ViewStyle { return { overflow: 'hidden', - borderRadius: shape === CONST.AVATAR_SHAPE.ROUNDED_SQUARE ? avatarBorderSizes[size] : variables.buttonBorderRadius, + ...getAvatarBorderRadius(size, shape), }; } @@ -1414,6 +1421,7 @@ const staticStyleUtils = { getAvatarSizeWithBorder, getAvatarWidthStyle, getAvatarSubscriptIconContainerStyle, + getShapeFromIconType, getBackgroundAndBorderStyle, getBackgroundColorStyle, getBackgroundColorWithOpacityStyle, 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}; From 66c3446612e44ef8bb1fff9386077acf8f2232af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Musia=C5=82?= Date: Thu, 27 Aug 2026 10:38:07 +0200 Subject: [PATCH 3/3] fix comment --- src/components/Avatar/AvatarFromIcon.tsx | 14 +++----------- src/styles/utils/index.ts | 2 +- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/components/Avatar/AvatarFromIcon.tsx b/src/components/Avatar/AvatarFromIcon.tsx index cadaa689b342..b1cf26d53787 100644 --- a/src/components/Avatar/AvatarFromIcon.tsx +++ b/src/components/Avatar/AvatarFromIcon.tsx @@ -18,18 +18,14 @@ type AvatarFromIconProps = Omit & { /** 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, imageStyles, iconAdditionalStyles, containerStyles, size, testID}: AvatarFromIconProps) { +function AvatarFromIcon({icon, ...rest}: AvatarFromIconProps) { if (icon.type === CONST.ICON_TYPE_WORKSPACE) { return ( ); } @@ -39,11 +35,7 @@ function AvatarFromIcon({icon, imageStyles, iconAdditionalStyles, containerStyle accountID={getAccountIDFromAvatarID(icon.id)} fallbackIcon={icon.fallbackIcon} source={icon.source} - imageStyles={imageStyles} - iconAdditionalStyles={iconAdditionalStyles} - containerStyles={containerStyles} - size={size} - testID={testID} + {...rest} /> ); } diff --git a/src/styles/utils/index.ts b/src/styles/utils/index.ts index 317c856f79b7..c58967669506 100644 --- a/src/styles/utils/index.ts +++ b/src/styles/utils/index.ts @@ -307,7 +307,7 @@ function getShapeFromIconType(type?: string): AvatarShape { } /** - * Return the border radius for an avatar + * 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) {