@@ -2,9 +2,9 @@ import React, {memo, useMemo} from 'react';
2
2
import { StyleProp , View , ViewStyle } from 'react-native' ;
3
3
import { ValueOf } from 'type-fest' ;
4
4
import { AvatarSource } from '@libs/UserUtils' ;
5
- import styles from '@styles/styles' ;
6
5
import * as StyleUtils from '@styles/StyleUtils' ;
7
- import themeColors from '@styles/themes/default' ;
6
+ import useTheme from '@styles/themes/useTheme' ;
7
+ import useThemeStyles from '@styles/useThemeStyles' ;
8
8
import variables from '@styles/variables' ;
9
9
import CONST from '@src/CONST' ;
10
10
import type { Icon } from '@src/types/onyx/OnyxCommon' ;
@@ -63,26 +63,11 @@ type AvatarSizeToStyles = typeof CONST.AVATAR_SIZE.SMALL | typeof CONST.AVATAR_S
63
63
64
64
type AvatarSizeToStylesMap = Record < AvatarSizeToStyles , AvatarStyles > ;
65
65
66
- const avatarSizeToStylesMap : AvatarSizeToStylesMap = {
67
- [ CONST . AVATAR_SIZE . SMALL ] : {
68
- singleAvatarStyle : styles . singleAvatarSmall ,
69
- secondAvatarStyles : styles . secondAvatarSmall ,
70
- } ,
71
- [ CONST . AVATAR_SIZE . LARGE ] : {
72
- singleAvatarStyle : styles . singleAvatarMedium ,
73
- secondAvatarStyles : styles . secondAvatarMedium ,
74
- } ,
75
- [ CONST . AVATAR_SIZE . DEFAULT ] : {
76
- singleAvatarStyle : styles . singleAvatar ,
77
- secondAvatarStyles : styles . secondAvatar ,
78
- } ,
79
- } ;
80
-
81
66
function MultipleAvatars ( {
82
67
fallbackIcon,
83
68
icons = [ ] ,
84
69
size = CONST . AVATAR_SIZE . DEFAULT ,
85
- secondAvatarStyle = [ StyleUtils . getBackgroundAndBorderStyle ( themeColors . componentBG ) ] ,
70
+ secondAvatarStyle : secondAvatarStyleProp ,
86
71
shouldStackHorizontally = false ,
87
72
shouldDisplayAvatarsInRows = false ,
88
73
isHovered = false ,
@@ -93,8 +78,31 @@ function MultipleAvatars({
93
78
shouldUseCardBackground = false ,
94
79
maxAvatarsInRow = CONST . AVATAR_ROW_SIZE . DEFAULT ,
95
80
} : MultipleAvatarsProps ) {
81
+ const theme = useTheme ( ) ;
82
+ const styles = useThemeStyles ( ) ;
83
+
84
+ const avatarSizeToStylesMap : AvatarSizeToStylesMap = useMemo (
85
+ ( ) => ( {
86
+ [ CONST . AVATAR_SIZE . SMALL ] : {
87
+ singleAvatarStyle : styles . singleAvatarSmall ,
88
+ secondAvatarStyles : styles . secondAvatarSmall ,
89
+ } ,
90
+ [ CONST . AVATAR_SIZE . LARGE ] : {
91
+ singleAvatarStyle : styles . singleAvatarMedium ,
92
+ secondAvatarStyles : styles . secondAvatarMedium ,
93
+ } ,
94
+ [ CONST . AVATAR_SIZE . DEFAULT ] : {
95
+ singleAvatarStyle : styles . singleAvatar ,
96
+ secondAvatarStyles : styles . secondAvatar ,
97
+ } ,
98
+ } ) ,
99
+ [ styles ] ,
100
+ ) ;
101
+
102
+ const secondAvatarStyle = secondAvatarStyleProp ?? [ StyleUtils . getBackgroundAndBorderStyle ( theme . componentBG ) ] ;
103
+
96
104
let avatarContainerStyles = StyleUtils . getContainerStyles ( size , isInReportAction ) ;
97
- const { singleAvatarStyle, secondAvatarStyles} = useMemo ( ( ) => avatarSizeToStylesMap [ size as AvatarSizeToStyles ] ?? avatarSizeToStylesMap . default , [ size ] ) ;
105
+ const { singleAvatarStyle, secondAvatarStyles} = useMemo ( ( ) => avatarSizeToStylesMap [ size as AvatarSizeToStyles ] ?? avatarSizeToStylesMap . default , [ size , avatarSizeToStylesMap ] ) ;
98
106
99
107
const tooltipTexts = useMemo ( ( ) => ( shouldShowTooltip ? icons . map ( ( icon ) => icon . name ) : [ '' ] ) , [ shouldShowTooltip , icons ] ) ;
100
108
const avatarSize = useMemo ( ( ) => {
@@ -143,7 +151,7 @@ function MultipleAvatars({
143
151
< Avatar
144
152
source = { icons [ 0 ] . source }
145
153
size = { size }
146
- fill = { themeColors . iconSuccessFill }
154
+ fill = { theme . iconSuccessFill }
147
155
name = { icons [ 0 ] . name }
148
156
type = { icons [ 0 ] . type }
149
157
fallbackIcon = { icons [ 0 ] . fallbackIcon }
@@ -193,7 +201,7 @@ function MultipleAvatars({
193
201
StyleUtils . getAvatarBorderWidth ( size ) ,
194
202
] }
195
203
source = { icon . source ?? fallbackIcon }
196
- fill = { themeColors . iconSuccessFill }
204
+ fill = { theme . iconSuccessFill }
197
205
size = { size }
198
206
name = { icon . name }
199
207
type = { icon . type }
@@ -219,7 +227,7 @@ function MultipleAvatars({
219
227
} ) ,
220
228
221
229
// Set overlay background color with RGBA value so that the text will not inherit opacity
222
- StyleUtils . getBackgroundColorWithOpacityStyle ( themeColors . overlay , variables . overlayOpacity ) ,
230
+ StyleUtils . getBackgroundColorWithOpacityStyle ( theme . overlay , variables . overlayOpacity ) ,
223
231
StyleUtils . getHorizontalStackedOverlayAvatarStyle ( oneAvatarSize , oneAvatarBorderWidth ) ,
224
232
icons [ 3 ] . type === CONST . ICON_TYPE_WORKSPACE ? StyleUtils . getAvatarBorderRadius ( size , icons [ 3 ] . type ) : { } ,
225
233
] }
@@ -256,7 +264,7 @@ function MultipleAvatars({
256
264
< View >
257
265
< Avatar
258
266
source = { icons [ 0 ] . source ?? fallbackIcon }
259
- fill = { themeColors . iconSuccessFill }
267
+ fill = { theme . iconSuccessFill }
260
268
size = { avatarSize }
261
269
imageStyles = { [ singleAvatarStyle ] }
262
270
name = { icons [ 0 ] . name }
@@ -277,7 +285,7 @@ function MultipleAvatars({
277
285
< View >
278
286
< Avatar
279
287
source = { icons [ 1 ] . source ?? fallbackIcon }
280
- fill = { themeColors . iconSuccessFill }
288
+ fill = { theme . iconSuccessFill }
281
289
size = { avatarSize }
282
290
imageStyles = { [ singleAvatarStyle ] }
283
291
name = { icons [ 1 ] . name }
0 commit comments