@@ -4,6 +4,7 @@ import type {ColorValue, TextStyle} from 'react-native';
44import type { OnyxEntry } from 'react-native-onyx' ;
55import type { ValueOf } from 'type-fest' ;
66import useOnyx from '@hooks/useOnyx' ;
7+ import type { ReportAvatarDetails } from '@hooks/useReportAvatarDetails' ;
78import useReportIsArchived from '@hooks/useReportIsArchived' ;
89import useStyleUtils from '@hooks/useStyleUtils' ;
910import useTheme from '@hooks/useTheme' ;
@@ -39,6 +40,7 @@ import {FallbackAvatar} from './Icon/Expensicons';
3940import MultipleAvatars from './MultipleAvatars' ;
4041import ParentNavigationSubtitle from './ParentNavigationSubtitle' ;
4142import PressableWithoutFeedback from './Pressable/PressableWithoutFeedback' ;
43+ import SingleReportAvatar from './ReportActionItem/SingleReportAvatar' ;
4244import type { TransactionListItemType } from './SelectionList/types' ;
4345import SubscriptAvatar from './SubscriptAvatar' ;
4446import Text from './Text' ;
@@ -73,6 +75,9 @@ type AvatarWithDisplayNameProps = {
7375
7476 /** Color of the secondary avatar border, usually should match the container background */
7577 avatarBorderColor ?: ColorValue ;
78+
79+ /** If we want to override the default avatar behavior and set a single avatar, we should pass this prop. */
80+ singleAvatarDetails ?: ReportAvatarDetails ;
7681} ;
7782
7883const fallbackIcon : Icon = {
@@ -167,6 +172,7 @@ function AvatarWithDisplayName({
167172 shouldEnableAvatarNavigation = true ,
168173 shouldUseCustomSearchTitleName = false ,
169174 transactions = [ ] ,
175+ singleAvatarDetails,
170176 openParentReportInCurrentTab = false ,
171177 avatarBorderColor : avatarBorderColorProp ,
172178} : AvatarWithDisplayNameProps ) {
@@ -236,40 +242,74 @@ function AvatarWithDisplayName({
236242 Navigation . navigate ( ROUTES . REPORT_WITH_ID_DETAILS . getRoute ( report . reportID ) ) ;
237243 }
238244 } , [ report , shouldEnableDetailPageNavigation , goToDetailsPage ] ) ;
245+
239246 const shouldUseFullTitle = isMoneyRequestOrReport || isAnonymous ;
240- const avatar = (
241- < View accessibilityLabel = { title } >
242- { shouldShowSubscriptAvatar ? (
243- < SubscriptAvatar
244- backgroundColor = { avatarBorderColor }
245- mainAvatar = { icons . at ( 0 ) ?? fallbackIcon }
246- secondaryAvatar = { icons . at ( 1 ) }
247- size = { size }
248- />
249- ) : (
250- < MultipleAvatars
251- icons = { icons }
252- size = { size }
253- secondAvatarStyle = { [ StyleUtils . getBackgroundAndBorderStyle ( avatarBorderColor ) ] }
247+
248+ const getAvatar = useCallback (
249+ ( accountID : number ) => {
250+ if ( shouldShowSubscriptAvatar ) {
251+ return (
252+ < SubscriptAvatar
253+ backgroundColor = { avatarBorderColor }
254+ mainAvatar = { icons . at ( 0 ) ?? fallbackIcon }
255+ secondaryAvatar = { icons . at ( 1 ) }
256+ size = { size }
257+ />
258+ ) ;
259+ }
260+
261+ if ( ! singleAvatarDetails || singleAvatarDetails . shouldDisplayAllActors || ! singleAvatarDetails . reportPreviewSenderID ) {
262+ return (
263+ < MultipleAvatars
264+ icons = { icons }
265+ size = { size }
266+ secondAvatarStyle = { [ StyleUtils . getBackgroundAndBorderStyle ( avatarBorderColor ) ] }
267+ />
268+ ) ;
269+ }
270+
271+ return (
272+ < SingleReportAvatar
273+ reportPreviewDetails = { singleAvatarDetails }
274+ personalDetails = { personalDetails }
275+ containerStyles = { [ styles . actionAvatar , styles . mr3 ] }
276+ actorAccountID = { accountID }
254277 />
255- ) }
256- </ View >
278+ ) ;
279+ } ,
280+ [ StyleUtils , avatarBorderColor , icons , personalDetails , shouldShowSubscriptAvatar , singleAvatarDetails , size , styles ] ,
257281 ) ;
282+
283+ const getWrappedAvatar = useCallback (
284+ ( accountID : number ) => {
285+ const avatar = getAvatar ( accountID ) ;
286+
287+ if ( ! shouldEnableAvatarNavigation ) {
288+ return < View accessibilityLabel = { title } > { avatar } </ View > ;
289+ }
290+
291+ return (
292+ < View accessibilityLabel = { title } >
293+ < PressableWithoutFeedback
294+ onPress = { showActorDetails }
295+ accessibilityLabel = { title }
296+ role = { getButtonRole ( true ) }
297+ >
298+ { avatar }
299+ </ PressableWithoutFeedback >
300+ </ View >
301+ ) ;
302+ } ,
303+ [ getAvatar , shouldEnableAvatarNavigation , showActorDetails , title ] ,
304+ ) ;
305+
306+ const WrappedAvatar = getWrappedAvatar ( actorAccountID ?. current ?? CONST . DEFAULT_NUMBER_ID ) ;
307+
258308 const headerView = (
259309 < View style = { [ styles . appContentHeaderTitle , styles . flex1 ] } >
260310 { ! ! report && ! ! title && (
261311 < View style = { [ styles . flex1 , styles . flexRow , styles . alignItemsCenter , styles . justifyContentBetween ] } >
262- { shouldEnableAvatarNavigation ? (
263- < PressableWithoutFeedback
264- onPress = { showActorDetails }
265- accessibilityLabel = { title }
266- role = { getButtonRole ( true ) }
267- >
268- { avatar }
269- </ PressableWithoutFeedback >
270- ) : (
271- avatar
272- ) }
312+ { WrappedAvatar }
273313 < View style = { [ styles . flex1 , styles . flexColumn ] } >
274314 { getCustomDisplayName (
275315 shouldUseCustomSearchTitleName ,
0 commit comments