Repository navigation
ReportActionAvatars -> UserAvatar for multi avatars migration + leftovers #97983
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
Merged
roryabraham
merged 12 commits into
Expensify:main
from
software-mansion-labs:chore/account-avatars-for-multi-avatar-usages
Aug 18, 2026
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f9b4ad2
Remainig Account avatars cases
jmusial 36b2aea
Merge branch 'main' into chore/account-avatars-for-multi-avatar-usages
jmusial 4e324b8
fix knip
jmusial 71cb19a
fix case when no accounts are passed to AccountAvatars
jmusial 03307ff
fix consistencty
jmusial 2b78b61
Merge branch 'main' into chore/account-avatars-for-multi-avatar-usages
jmusial a489166
update per review comments
jmusial fa67726
ger rid of usePersonalDetails double subscription
jmusial eedbd1e
fix tests
jmusial 1768f7b
fix tests v2 & update atendees cell
jmusial 10010cc
https://github.com/Expensify/App/pull/93581
jmusial 97f7b5c
Merge branch 'main' into chore/account-avatars-for-multi-avatar-usages
jmusial File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/components/Avatar/connected/AccountAvatarWithCardFeed.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import SubscriptCardFeedAvatar from '@components/Avatar/layouts/SubscriptCardFeedAvatar'; | ||
|
|
||
| import CONST from '@src/CONST'; | ||
| import type {CardFeed} from '@src/types/onyx/CardFeeds'; | ||
|
|
||
| import type {ColorValue, StyleProp, ViewStyle} from 'react-native'; | ||
| import type {ValueOf} from 'type-fest'; | ||
|
|
||
| import React from 'react'; | ||
|
|
||
| import useAccountIcons from './useAccountIcons'; | ||
|
|
||
| type AccountAvatarWithCardFeedProps = { | ||
| /** Account ID of the cardholder. `CONST.DEFAULT_NUMBER_ID` renders a placeholder avatar, so the card icon keeps its slot when the cardholder is unknown. */ | ||
| accountID: number; | ||
|
|
||
| /** Card feed to display as the subscript */ | ||
| cardFeed: CardFeed; | ||
|
|
||
| /** Size of the subscript card feed icon */ | ||
| cardFeedIconSize?: {width: number; height: number}; | ||
|
|
||
| /** Border color for the subscript card feed icon container */ | ||
| borderColor?: ColorValue; | ||
|
|
||
| /** Size of the avatar */ | ||
| size?: ValueOf<typeof CONST.AVATAR_SIZE>; | ||
|
|
||
| /** Display name used as a fallback for the avatar tooltip */ | ||
| fallbackDisplayName?: string; | ||
|
|
||
| /** Container styles for the avatar */ | ||
| containerStyle?: StyleProp<ViewStyle>; | ||
| }; | ||
|
|
||
| /** | ||
| * Renders one account's avatar with a card feed icon as its subscript, resolving the icon from the personal-details | ||
| * context (zero Onyx subscriptions). Use for cardholder rows; reach for `AccountAvatar` when there is no card feed. | ||
| */ | ||
| function AccountAvatarWithCardFeed({ | ||
| accountID, | ||
| cardFeed, | ||
| cardFeedIconSize, | ||
| borderColor, | ||
| size = CONST.AVATAR_SIZE.DEFAULT, | ||
| fallbackDisplayName, | ||
| containerStyle, | ||
| }: AccountAvatarWithCardFeedProps) { | ||
| const [icon] = useAccountIcons([accountID]); | ||
|
|
||
| return ( | ||
| <SubscriptCardFeedAvatar | ||
| primaryAvatar={icon} | ||
| cardFeed={cardFeed} | ||
| cardFeedIconSize={cardFeedIconSize} | ||
| size={size} | ||
| containerStyle={containerStyle} | ||
| subscriptAvatarBorderColor={borderColor} | ||
| fallbackDisplayName={fallbackDisplayName} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| export default AccountAvatarWithCardFeed; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| import HorizontalAvatars from '@components/Avatar/layouts/HorizontalAvatars'; | ||
| import type {HorizontalStackingOptions} from '@components/Avatar/layouts/HorizontalAvatars'; | ||
| import SingleAvatar from '@components/Avatar/layouts/SingleAvatar'; | ||
|
|
||
| import useLocalize from '@hooks/useLocalize'; | ||
|
|
||
| import {sortIconsByName} from '@libs/ReportUtils'; | ||
|
|
||
| import CONST from '@src/CONST'; | ||
| import type {InvitedEmailsToAccountIDs} from '@src/types/onyx'; | ||
| import type {Icon} from '@src/types/onyx/OnyxCommon'; | ||
|
|
||
| import type {ValueOf} from 'type-fest'; | ||
|
|
||
| import lodashSortBy from 'lodash/sortBy'; | ||
| import React from 'react'; | ||
|
|
||
| import useAccountIcons from './useAccountIcons'; | ||
|
|
||
| type SortByValue = ValueOf<typeof CONST.REPORT_ACTION_AVATARS.SORT_BY>; | ||
|
|
||
| type SortBy = | ||
| | readonly [typeof CONST.REPORT_ACTION_AVATARS.SORT_BY.NAME] | ||
| | readonly [typeof CONST.REPORT_ACTION_AVATARS.SORT_BY.ID] | ||
| | readonly [typeof CONST.REPORT_ACTION_AVATARS.SORT_BY.REVERSE] | ||
| | readonly [typeof CONST.REPORT_ACTION_AVATARS.SORT_BY.NAME, typeof CONST.REPORT_ACTION_AVATARS.SORT_BY.REVERSE] | ||
| | readonly [typeof CONST.REPORT_ACTION_AVATARS.SORT_BY.ID, typeof CONST.REPORT_ACTION_AVATARS.SORT_BY.REVERSE]; | ||
|
|
||
| type MultiAccountAvatarProps = { | ||
| /** Account IDs to display avatars for. Entries equal to `CONST.DEFAULT_NUMBER_ID` are dropped; when none remain, a single placeholder avatar renders so the slot keeps its size. */ | ||
| accountIDs: number[]; | ||
|
|
||
| /** Options for the horizontal stack */ | ||
| horizontalOptions?: HorizontalStackingOptions; | ||
|
|
||
| /** How to order the avatars before rendering them. Every avatar sits in an equivalent slot, so any order is renderable. Omit to leave them in the order `accountIDs` was passed */ | ||
| sortBy?: SortBy; | ||
|
|
||
| /** Emails of invited, not-yet-registered accounts. Also seeds a deterministic fallback avatar for each invited account */ | ||
| invitedEmailsToAccountIDs?: InvitedEmailsToAccountIDs; | ||
|
|
||
| /** Set the size of avatars */ | ||
| size?: ValueOf<typeof CONST.AVATAR_SIZE>; | ||
|
|
||
| /** Display name used as a fallback for the avatar tooltip */ | ||
| fallbackDisplayName?: string; | ||
|
|
||
| /** Whether the avatars are displayed within a report action */ | ||
| isInReportAction?: boolean; | ||
| }; | ||
|
|
||
| /** Applies the requested ordering. `undefined` leaves the icons in the order the account IDs were passed. */ | ||
| function sortIcons(icons: Icon[], sortBy: SortBy | undefined, localeCompare: ReturnType<typeof useLocalize>['localeCompare']) { | ||
| if (!sortBy) { | ||
| return icons; | ||
| } | ||
|
|
||
| const sortKeys: readonly SortByValue[] = sortBy; | ||
|
|
||
| let sortedIcons = icons; | ||
| if (sortKeys.includes(CONST.REPORT_ACTION_AVATARS.SORT_BY.NAME)) { | ||
| // Icons built by `useAccountIcons` carry their own `displayName`, so no personal-details lookup is needed here | ||
| sortedIcons = sortIconsByName(icons, undefined, localeCompare); | ||
| } else if (sortKeys.includes(CONST.REPORT_ACTION_AVATARS.SORT_BY.ID)) { | ||
| sortedIcons = lodashSortBy(icons, (icon) => icon.id); | ||
| } | ||
|
|
||
| return sortKeys.includes(CONST.REPORT_ACTION_AVATARS.SORT_BY.REVERSE) ? [...sortedIcons].reverse() : sortedIcons; | ||
| } | ||
|
|
||
| /** | ||
| * Renders several known accounts as an overlapping row of avatars, resolving the icons from the personal-details context | ||
| * (zero Onyx subscriptions). Use `AccountAvatar` when there is exactly one account, and `ReportActionAvatars` when the | ||
| * actors still have to be resolved from a report, a report action or a policy. | ||
| */ | ||
| function MultiAccountAvatar({ | ||
| accountIDs, | ||
| horizontalOptions, | ||
| sortBy, | ||
| invitedEmailsToAccountIDs, | ||
| size = CONST.AVATAR_SIZE.DEFAULT, | ||
| fallbackDisplayName, | ||
| isInReportAction = false, | ||
| }: MultiAccountAvatarProps) { | ||
| const {localeCompare} = useLocalize(); | ||
|
|
||
| const filteredAccountIDs = accountIDs.filter((accountID) => accountID !== CONST.DEFAULT_NUMBER_ID); | ||
| const hasAccountsToRender = filteredAccountIDs.length > 0; | ||
| // When no account resolves, render one placeholder avatar instead of collapsing the slot, | ||
| // matching the fallback ReportActionAvatars renders for an empty account list. | ||
| const icons = useAccountIcons(hasAccountsToRender ? filteredAccountIDs : [CONST.DEFAULT_NUMBER_ID], invitedEmailsToAccountIDs); | ||
|
roryabraham marked this conversation as resolved.
Resolved
|
||
| const placeholderIcon = icons.at(0); | ||
|
|
||
| if (!hasAccountsToRender && placeholderIcon) { | ||
| return ( | ||
| <SingleAvatar | ||
| avatar={placeholderIcon} | ||
| size={size} | ||
| containerStyles={[]} | ||
| fallbackDisplayName={fallbackDisplayName} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <HorizontalAvatars | ||
| {...horizontalOptions} | ||
| size={size} | ||
| icons={sortIcons(icons, sortBy, localeCompare)} | ||
| isInReportAction={isInReportAction} | ||
| fallbackDisplayName={fallbackDisplayName} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| export default MultiAccountAvatar; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import {usePersonalDetails} from '@components/OnyxListItemProvider'; | ||
|
|
||
| import useDefaultAvatars from '@hooks/useDefaultAvatars'; | ||
|
|
||
| import {buildUserIcon} from '@libs/UserAvatarUtils'; | ||
|
|
||
| import type {InvitedEmailsToAccountIDs} from '@src/types/onyx'; | ||
| import type {Icon} from '@src/types/onyx/OnyxCommon'; | ||
|
|
||
| /** | ||
| * Resolves account IDs into avatar {@link Icon}s from the personal-details context and the default-avatar set. | ||
| * | ||
| * @param invitedEmailsToAccountIDs Emails of invited, not-yet-registered accounts. An account listed here gets a | ||
| * deterministic fallback avatar seeded from its email, so it looks the same before and after it registers. | ||
| */ | ||
| function useAccountIcons(accountIDs: number[], invitedEmailsToAccountIDs?: InvitedEmailsToAccountIDs): Icon[] { | ||
| const personalDetails = usePersonalDetails(); | ||
| const defaultAvatars = useDefaultAvatars(); | ||
|
|
||
| return accountIDs.map((accountID) => | ||
| buildUserIcon({ | ||
| accountID, | ||
| personalDetails, | ||
| defaultAvatars, | ||
| invitedEmail: invitedEmailsToAccountIDs ? Object.keys(invitedEmailsToAccountIDs).find((email) => invitedEmailsToAccountIDs[email] === accountID) : undefined, | ||
| }), | ||
| ); | ||
| } | ||
|
|
||
| export default useAccountIcons; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.