Skip to content

Commit 0d4974d

Browse files
Merge pull request #62 from KeyValueSoftwareSystems/fix/release-110-fixes
Fix: custom delete icon issue and refactor
2 parents f424331 + 6259697 commit 0d4974d

File tree

6 files changed

+18
-12
lines changed

6 files changed

+18
-12
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ theme | Object for custom themes | Theme | {} |
112112
customStyles | Object for custom styling | CustomStyleProps | {} |
113113
darkMode | Toggle to enable dark mode| boolean | false |
114114
itemsPerFetch | Number of notifications fetch per api request (have a max cap of 50) | number | 20 |
115-
cardProps | Props for customizing the card | CardProps | { hideAvatar: false, disableAutoMarkAsRead: false, hideDelete: false, deleteIcon: JSX.Element, onAvatarClick: ()=> null } |
115+
cardProps | Props for customizing the card | CardProps | { hideAvatar: false, disableAutoMarkAsRead: false, hideDelete: false, deleteIcon: JSX.Element, onAvatarClick: ()=> null, hideMediaThumbnailL: false, onMediaThumbnailClick: ()=> null} |
116116
customCard | Function for rendering custom card | (notification)=> JSX Element | null |
117117
onCardClick | Custom click handler for card | (notification)=> void | ()=>null |
118118
listEmptyComponent | Custom component for empty list | JSX Element | null |

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"@react-navigation/bottom-tabs": "^6.5.14",
1414
"@react-navigation/native": "^6.1.12",
1515
"@react-navigation/native-stack": "^6.9.20",
16-
"@sirenapp/react-native-inbox": "^1.0.0",
16+
"@sirenapp/react-native-inbox": "^1.1.0",
1717
"react": "18.2.0",
1818
"react-native": "0.73.4",
1919
"react-native-modal": "^13.0.1",

src/components/card.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,14 @@ const Card = (props: NotificationCardProps): ReactElement => {
173173
<Text numberOfLines={2} style={[styles.cardTitle, style.cardTitle]}>
174174
{notification.message?.header}
175175
</Text>
176-
{!hideDelete &&
177-
(deleteIcon || (
178-
<CloseIcon onDelete={onDeleteItem} notification={notification} styles={styles} />
179-
))}
176+
{!hideDelete && (
177+
<CloseIcon
178+
onDelete={onDeleteItem}
179+
customIcon={deleteIcon}
180+
notification={notification}
181+
styles={styles}
182+
/>
183+
)}
180184
</View>
181185
{Boolean(notification.message?.subHeader) && (
182186
<Text numberOfLines={2} style={[style.cardSubTitle, styles.cardSubTitle]}>

src/components/closeIcon.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ import type { StyleProps } from '../types';
88
const CloseIcon = ({
99
notification,
1010
styles,
11+
customIcon,
1112
onDelete
1213
}: {
1314
notification: NotificationDataType;
1415
styles: Partial<StyleProps>;
16+
customIcon?: ReactElement | null;
1517
onDelete: (id: string) => void;
1618
}): ReactElement => {
1719
const icon: JSX.Element[] = [];
@@ -36,7 +38,7 @@ const CloseIcon = ({
3638
testID='delete-button'
3739
accessibilityLabel={`siren-notification-delete${notification.id}`}
3840
>
39-
<>{icon}</>
41+
<>{customIcon || icon}</>
4042
</TouchableOpacity>
4143
);
4244
};

src/components/sirenProvider.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type {
1111
} from '@sirenapp/js-sdk/dist/esm/types';
1212

1313
import type { SirenProviderConfigProps } from '../types';
14-
import { isNonEmptyArray, logger } from '../utils/commonUtils';
14+
import { generateUniqueId, isNonEmptyArray, logger } from '../utils/commonUtils';
1515
import {
1616
events,
1717
eventTypes,
@@ -76,10 +76,6 @@ export const useSirenContext = (): SirenContextProp => useContext(SirenContext);
7676
const SirenProvider: React.FC<SirenProvider> = ({ config, children }) => {
7777
let retryCount = 0;
7878

79-
const generateUniqueId = (): string => {
80-
return Math.random().toString(36).substring(2, 15);
81-
};
82-
8379
const { markAllAsViewed } = useSiren();
8480

8581
const [id] = useState(generateUniqueId());

src/utils/commonUtils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import { DefaultTheme } from './index';
88
export const isNonEmptyArray = (arr?: unknown[] | null) =>
99
Boolean(arr && typeof arr === 'object' && arr instanceof Array && arr.length > 0);
1010

11+
export const generateUniqueId = (): string => {
12+
return Math.random().toString(36).substring(2, 15);
13+
};
14+
1115
export const updateNotifications = (
1216
eventData: {
1317
id?: string;

0 commit comments

Comments
 (0)