11import { useWebHover } from '@/src/common/lib/useWebHover' ;
22import { useTheme , withHexOpacity } from '@/src/common/theme' ;
3+ import { Image , type ImageProps } from 'expo-image' ;
34import {
4- Image ,
5- ImageProps ,
6- ImageSourcePropType ,
75 Pressable ,
86 PressableProps ,
97 StyleSheet ,
108 View ,
119 type ViewProps ,
1210} from 'react-native' ;
13- import { opacity } from 'react-native-reanimated/lib/typescript/Colors' ;
1411
1512export type AvatarSizePreset = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'massive' ;
1613
@@ -28,14 +25,30 @@ export function resolveAvatarSize(size: AvatarSizePreset | number): number {
2825}
2926
3027interface AvatarProps extends Omit < ImageProps , 'source' > {
31- source ?: ImageSourcePropType ;
28+ source ?: ImageProps [ 'source' ] ;
29+ /**
30+ * Forces the image to clear + reload when it changes — set this when an
31+ * Avatar lives in a recycled list row (FlashList) so a reused cell never
32+ * flashes the previous identity's avatar. Defaults to the source URI.
33+ */
34+ recyclingKey ?: string ;
3235 size ?: AvatarSizePreset | number ;
3336 containerProps ?: ViewProps ;
3437 onPress ?: ( ) => void ;
3538}
3639
40+ /** Pull a stable string URI out of an Image source for recycling. */
41+ function sourceUri ( source : ImageProps [ 'source' ] ) : string | undefined {
42+ if ( typeof source === 'string' ) return source ;
43+ if ( source && typeof source === 'object' && 'uri' in source ) {
44+ return typeof source . uri === 'string' ? source . uri : undefined ;
45+ }
46+ return undefined ;
47+ }
48+
3749export function Avatar ( {
3850 source,
51+ recyclingKey,
3952 size : sizeProp = 'md' ,
4053 containerProps,
4154 onPress,
@@ -77,7 +90,8 @@ export function Avatar({
7790 < Image
7891 { ...restImageProps }
7992 source = { source }
80- resizeMode = { 'cover' }
93+ recyclingKey = { recyclingKey ?? sourceUri ( source ) }
94+ contentFit = "cover"
8195 style = { [ styles . image , imageStyle ] }
8296 />
8397 < HoverOverlay visible = { showHoverDim } borderRadius = { size / 2 } />
0 commit comments