Skip to content

Commit af092b8

Browse files
refactor: Notification card refactor and ui fix for empty window
1 parent 3b5521e commit af092b8

File tree

3 files changed

+23
-18
lines changed

3 files changed

+23
-18
lines changed

example/ios/Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ prepare_react_native_project!
1717
# dependencies: {
1818
# ...(process.env.NO_FLIPPER ? { 'react-native-flipper': { platforms: { ios: null } } } : {}),
1919
# ```
20-
flipper_config = ENV['NO_FLIPPER'] == "1" ? FlipperConfiguration.disabled : FlipperConfiguration.enabled
20+
flipper_config = FlipperConfiguration.disabled
2121

2222
linkage = ENV['USE_FRAMEWORKS']
2323
if linkage != nil

src/components/card.tsx

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import React, { useState, type ReactElement } from 'react';
1+
import React, { useState, type ReactElement, useMemo, useEffect } from 'react';
22
import { 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';
75
import { CommonUtils } from '../utils';
86
import CloseIcon from './closeIcon';
97
import TimerIcon from './timerIcon';
@@ -43,32 +41,39 @@ import TimerIcon from './timerIcon';
4341

4442
const 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]}>

src/components/emptyWindow.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ const style = StyleSheet.create({
5151
},
5252
emptyText: {
5353
fontSize: 14,
54-
fontWeight: '400',
54+
fontWeight: '600',
5555
paddingBottom: 5,
5656
textAlign: 'center',
5757
paddingTop: 20
5858
},
5959
emptyDescription: {
6060
fontSize: 12,
61-
fontWeight: '600',
61+
fontWeight: '400',
6262
textAlign: 'center',
6363
opacity: 0.8
6464
},

0 commit comments

Comments
 (0)