Skip to content

Commit ddcba2d

Browse files
Feat/card avatar click (#43)
* feat: Add avatar click functionality to notification card * fix: send back notification data as param in onAvatarClick function
1 parent 7bb4be2 commit ddcba2d

File tree

5 files changed

+21
-7
lines changed

5 files changed

+21
-7
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ Here are the custom style options for the notification inbox:
217217
```js
218218
type CardProps = {
219219
hideAvatar?: boolean;
220+
onAvatarClick?: (notification: NotificationDataType) => void;
220221
disableAutoMarkAsRead?: boolean;
221222
hideDelete?: boolean;
222223
};

example/screens/notifications.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,15 @@ function Notifications(): React.JSX.Element {
163163
/>
164164
<View style={styles.contentContainer}>
165165
<SirenInbox
166-
title='Siren Notifications'
167166
inboxHeaderProps={{
168167
hideHeader: hideHeader,
169168
customHeader: showCustomHeader ? renderCustomHeader() : undefined,
170169
showBackButton: true,
171170
onBackPress: () => navigation.goBack(),
171+
title: 'Siren Inbox',
172172
}}
173173
darkMode={sdkDarkModeEnabled}
174-
cardProps={{ hideAvatar: hideAvatar, disableAutoMarkAsRead: false }}
174+
cardProps={{ hideAvatar: hideAvatar, disableAutoMarkAsRead: false, onAvatarClick: (notification: NotificationDataType) => console.log('avatar click', notification) }}
175175
theme={windowThemes[windowThemeIndex]}
176176
customFooter={showCustomFooter ? renderCustomFooter() : undefined}
177177
listEmptyComponent={showCustomEmptyComponent ? renderListEmpty() : undefined}

src/components/card.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import TimerIcon from './timerIcon';
4242

4343
const Card = (props: NotificationCardProps): ReactElement => {
4444
const { onCardClick, notification, cardProps = {}, styles, onDelete, darkMode } = props;
45-
const { hideAvatar, disableAutoMarkAsRead, hideDelete = false } = cardProps;
45+
const { hideAvatar, disableAutoMarkAsRead, hideDelete = false, onAvatarClick } = cardProps;
4646
const { markAsRead } = useSiren();
4747

4848
const opacity = useRef(new Animated.Value(1)).current;
@@ -74,20 +74,28 @@ const Card = (props: NotificationCardProps): ReactElement => {
7474
setImageSource(emptyState());
7575
};
7676

77+
const avatarClick = () => {
78+
if (onAvatarClick) onAvatarClick(notification);
79+
};
80+
7781
const renderAvatar = useMemo((): JSX.Element => {
7882
return (
7983
<View style={style.cardIconContainer}>
80-
<View style={[style.cardIconRound, styles.cardIconRound]}>
84+
<TouchableOpacity
85+
disabled={Boolean(!onAvatarClick)}
86+
onPress={avatarClick}
87+
style={[style.cardIconRound, styles.cardIconRound]}
88+
>
8189
<Image
8290
source={imageSource}
8391
resizeMode='cover'
8492
style={style.cardAvatarStyle}
8593
onError={onError}
8694
/>
87-
</View>
95+
</TouchableOpacity>
8896
</View>
8997
);
90-
}, [styles, darkMode, imageSource]);
98+
}, [styles, darkMode, imageSource, onAvatarClick]);
9199

92100
const onDeleteItem = async (): Promise<void> => {
93101

src/components/sirenInbox.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ const SirenInbox = (props: SirenInboxProps): ReactElement => {
7272
theme = { dark: {}, light: {} },
7373
customStyles = {},
7474
darkMode = false,
75-
cardProps = { hideAvatar: false, disableAutoMarkAsRead: false, hideDelete: false },
75+
cardProps = {
76+
hideAvatar: false,
77+
disableAutoMarkAsRead: false,
78+
hideDelete: false
79+
},
7680
listEmptyComponent = null,
7781
inboxHeaderProps = {},
7882
customFooter = null,

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export type SirenProviderConfigProps = {
8181
*/
8282
type CardProps = {
8383
hideAvatar?: boolean;
84+
onAvatarClick?: (notification: NotificationDataType) => void;
8485
disableAutoMarkAsRead?: boolean;
8586
hideDelete?: boolean;
8687
};

0 commit comments

Comments
 (0)