1- import React , { useState , type ReactElement } from 'react' ;
1+ import React , { useState , type ReactElement , useMemo , useEffect } from 'react' ;
22import { Image , StyleSheet , Text , TouchableOpacity , View } from 'react-native' ;
33
4- import type { NotificationDataType } from 'test_notification/dist/esm/types' ;
5-
6- import type { NotificationCardProps , SirenStyleProps } from '../types' ;
4+ import type { NotificationCardProps } from '../types' ;
75import { CommonUtils } from '../utils' ;
86import CloseIcon from './closeIcon' ;
97import TimerIcon from './timerIcon' ;
@@ -43,32 +41,39 @@ import TimerIcon from './timerIcon';
4341
4442const Card = ( props : NotificationCardProps ) : ReactElement => {
4543 const { onCardClick, notification, cardProps, styles, onDelete, darkMode } = props ;
46- const emptyState = darkMode
47- ? require ( '../assets/emptyDark.png' )
48- : require ( '../assets/emptyLight.png' ) ;
44+
45+ const emptyState = ( ) => {
46+ return darkMode ? require ( '../assets/emptyDark.png' ) : require ( '../assets/emptyLight.png' ) ;
47+ } ;
48+
4949 const [ imageSource , setImageSource ] = useState (
5050 notification ?. message ?. avatar ?. imageUrl ?. length > 0
5151 ? { uri : notification . message ?. avatar ?. imageUrl }
52- : emptyState
52+ : emptyState ( )
5353 ) ;
5454
55- const renderAvatar = (
56- notification : NotificationDataType ,
57- styles : Partial < SirenStyleProps >
58- ) : JSX . Element => {
55+ useEffect ( ( ) => {
56+ setImageSource (
57+ notification ?. message ?. avatar ?. imageUrl ?. length > 0
58+ ? { uri : notification . message ?. avatar ?. imageUrl }
59+ : emptyState ( )
60+ ) ;
61+ } , [ notification , darkMode ] ) ;
62+
63+ const renderAvatar = useMemo ( ( ) : JSX . Element => {
5964 return (
6065 < View style = { style . cardIconContainer } >
6166 < View style = { [ style . cardIconRound , styles . cardIconRound ] } >
6267 < Image
6368 source = { imageSource }
6469 resizeMode = 'cover'
6570 style = { style . cardAvatarStyle }
66- onError = { ( ) => setImageSource ( emptyState ) }
71+ onError = { ( ) => setImageSource ( emptyState ( ) ) }
6772 />
6873 </ View >
6974 </ View >
7075 ) ;
71- } ;
76+ } , [ styles , darkMode , imageSource ] ) ;
7277
7378 return (
7479 < TouchableOpacity
@@ -85,7 +90,7 @@ const Card = (props: NotificationCardProps): ReactElement => {
8590 ] }
8691 />
8792 < View style = { [ style . cardContainer , styles . cardContainer ] } >
88- { ! cardProps ?. hideAvatar && renderAvatar ( notification , styles ) }
93+ { ! cardProps ?. hideAvatar && renderAvatar }
8994 < View style = { style . cardContentContainer } >
9095 < View style = { style . cardFooterRow } >
9196 < Text numberOfLines = { 2 } style = { [ styles . cardTitle , style . cardTitle ] } >
0 commit comments