1
1
import React , { useCallback , useEffect , useRef } from 'react' ;
2
2
import { View } from 'react-native' ;
3
+ import type { TextStyle } from 'react-native' ;
3
4
import type { OnyxEntry } from 'react-native-onyx' ;
4
5
import type { ValueOf } from 'type-fest' ;
5
6
import useOnyx from '@hooks/useOnyx' ;
@@ -8,6 +9,7 @@ import useTheme from '@hooks/useTheme';
8
9
import useThemeStyles from '@hooks/useThemeStyles' ;
9
10
import Navigation from '@libs/Navigation/Navigation' ;
10
11
import { getPersonalDetailsForAccountIDs } from '@libs/OptionsListUtils' ;
12
+ import type { DisplayNameWithTooltips } from '@libs/ReportUtils' ;
11
13
import {
12
14
getChatRoomSubtitle ,
13
15
getDisplayNamesWithTooltips ,
@@ -31,10 +33,12 @@ import type {Policy, Report} from '@src/types/onyx';
31
33
import type { Icon } from '@src/types/onyx/OnyxCommon' ;
32
34
import { getButtonRole } from './Button/utils' ;
33
35
import DisplayNames from './DisplayNames' ;
36
+ import type DisplayNamesProps from './DisplayNames/types' ;
34
37
import { FallbackAvatar } from './Icon/Expensicons' ;
35
38
import MultipleAvatars from './MultipleAvatars' ;
36
39
import ParentNavigationSubtitle from './ParentNavigationSubtitle' ;
37
40
import PressableWithoutFeedback from './Pressable/PressableWithoutFeedback' ;
41
+ import type { TransactionListItemType } from './SelectionList/types' ;
38
42
import SubscriptAvatar from './SubscriptAvatar' ;
39
43
import Text from './Text' ;
40
44
@@ -53,6 +57,12 @@ type AvatarWithDisplayNameProps = {
53
57
54
58
/** Whether we should enable detail page navigation */
55
59
shouldEnableDetailPageNavigation ?: boolean ;
60
+
61
+ /** Whether we should enable custom title logic designed for search lis */
62
+ shouldUseCustomSearchTitleName ?: boolean ;
63
+
64
+ /** Transactions inside report */
65
+ transactions ?: TransactionListItemType [ ] ;
56
66
} ;
57
67
58
68
const fallbackIcon : Icon = {
@@ -62,10 +72,93 @@ const fallbackIcon: Icon = {
62
72
id : - 1 ,
63
73
} ;
64
74
65
- function AvatarWithDisplayName ( { policy, report, isAnonymous = false , size = CONST . AVATAR_SIZE . DEFAULT , shouldEnableDetailPageNavigation = false } : AvatarWithDisplayNameProps ) {
75
+ function getCustomDisplayName (
76
+ shouldUseCustomSearchTitleName : boolean ,
77
+ report : OnyxEntry < Report > ,
78
+ title : string ,
79
+ displayNamesWithTooltips : DisplayNameWithTooltips ,
80
+ transactions : TransactionListItemType [ ] ,
81
+ shouldUseFullTitle : boolean ,
82
+ customSearchDisplayStyle : TextStyle [ ] ,
83
+ regularStyle : TextStyle [ ] ,
84
+ isAnonymous : boolean ,
85
+ isMoneyRequestOrReport : boolean ,
86
+ ) : React . ReactNode {
87
+ const reportName = report ?. reportName ?? CONST . REPORT . DEFAULT_REPORT_NAME ;
88
+ const isIOUOrInvoice = report ?. type === CONST . REPORT . TYPE . IOU || report ?. type === CONST . REPORT . TYPE . INVOICE ;
89
+ const hasTransactions = transactions . length > 0 ;
90
+
91
+ function getDisplayProps ( ) : DisplayNamesProps {
92
+ const baseProps = {
93
+ displayNamesWithTooltips,
94
+ tooltipEnabled : true ,
95
+ numberOfLines : 1 ,
96
+ } ;
97
+
98
+ if ( shouldUseCustomSearchTitleName ) {
99
+ const styleProps = {
100
+ textStyles : customSearchDisplayStyle ,
101
+ } ;
102
+
103
+ if ( ! hasTransactions ) {
104
+ return {
105
+ fullTitle : reportName ,
106
+ shouldUseFullTitle,
107
+ ...baseProps ,
108
+ ...styleProps ,
109
+ } ;
110
+ }
111
+
112
+ if ( isIOUOrInvoice ) {
113
+ return {
114
+ fullTitle : title ,
115
+ shouldUseFullTitle : true ,
116
+ ...baseProps ,
117
+ ...styleProps ,
118
+ } ;
119
+ }
120
+
121
+ return {
122
+ fullTitle : reportName ,
123
+ shouldUseFullTitle,
124
+ ...baseProps ,
125
+ ...styleProps ,
126
+ } ;
127
+ }
128
+
129
+ return {
130
+ fullTitle : title ,
131
+ textStyles : regularStyle ,
132
+ shouldUseFullTitle : isMoneyRequestOrReport || isAnonymous ,
133
+ ...baseProps ,
134
+ } ;
135
+ }
136
+
137
+ const { fullTitle, textStyles, displayNamesWithTooltips : displayNamesWithTooltipsProp , tooltipEnabled, numberOfLines, shouldUseFullTitle : shouldUseFullTitleProp } = getDisplayProps ( ) ;
138
+
139
+ return (
140
+ < DisplayNames
141
+ fullTitle = { fullTitle }
142
+ displayNamesWithTooltips = { displayNamesWithTooltipsProp }
143
+ tooltipEnabled = { tooltipEnabled }
144
+ numberOfLines = { numberOfLines }
145
+ textStyles = { textStyles }
146
+ shouldUseFullTitle = { shouldUseFullTitleProp }
147
+ />
148
+ ) ;
149
+ }
150
+
151
+ function AvatarWithDisplayName ( {
152
+ policy,
153
+ report,
154
+ isAnonymous = false ,
155
+ size = CONST . AVATAR_SIZE . DEFAULT ,
156
+ shouldEnableDetailPageNavigation = false ,
157
+ shouldUseCustomSearchTitleName = false ,
158
+ transactions = [ ] ,
159
+ } : AvatarWithDisplayNameProps ) {
66
160
const [ parentReportActions ] = useOnyx ( `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ report ?. parentReportID } ` , { canEvict : false , canBeMissing : false } ) ;
67
161
const [ personalDetails ] = useOnyx ( ONYXKEYS . PERSONAL_DETAILS_LIST , { canBeMissing : false } ) ?? CONST . EMPTY_OBJECT ;
68
-
69
162
const theme = useTheme ( ) ;
70
163
const styles = useThemeStyles ( ) ;
71
164
const StyleUtils = useStyleUtils ( ) ;
@@ -128,7 +221,7 @@ function AvatarWithDisplayName({policy, report, isAnonymous = false, size = CONS
128
221
Navigation . navigate ( ROUTES . REPORT_WITH_ID_DETAILS . getRoute ( report . reportID ) ) ;
129
222
}
130
223
} , [ report , shouldEnableDetailPageNavigation , goToDetailsPage ] ) ;
131
-
224
+ const shouldUseFullTitle = isMoneyRequestOrReport || isAnonymous ;
132
225
const headerView = (
133
226
< View style = { [ styles . appContentHeaderTitle , styles . flex1 ] } >
134
227
{ ! ! report && ! ! title && (
@@ -156,14 +249,18 @@ function AvatarWithDisplayName({policy, report, isAnonymous = false, size = CONS
156
249
</ View >
157
250
</ PressableWithoutFeedback >
158
251
< View style = { [ styles . flex1 , styles . flexColumn ] } >
159
- < DisplayNames
160
- fullTitle = { title }
161
- displayNamesWithTooltips = { displayNamesWithTooltips }
162
- tooltipEnabled
163
- numberOfLines = { 1 }
164
- textStyles = { [ isAnonymous ? styles . headerAnonymousFooter : styles . headerText , styles . pre ] }
165
- shouldUseFullTitle = { isMoneyRequestOrReport || isAnonymous }
166
- />
252
+ { getCustomDisplayName (
253
+ shouldUseCustomSearchTitleName ,
254
+ report ,
255
+ title ,
256
+ displayNamesWithTooltips ,
257
+ transactions ,
258
+ shouldUseFullTitle ,
259
+ [ styles . headerText , styles . pre ] ,
260
+ [ isAnonymous ? styles . headerAnonymousFooter : styles . headerText , styles . pre ] ,
261
+ isAnonymous ,
262
+ isMoneyRequestOrReport ,
263
+ ) }
167
264
{ Object . keys ( parentNavigationSubtitleData ) . length > 0 && (
168
265
< ParentNavigationSubtitle
169
266
parentNavigationSubtitleData = { parentNavigationSubtitleData }
0 commit comments