Skip to content

Commit 3a84a84

Browse files
Merge pull request #44 from KeyValueSoftwareSystems/dev
Refactor : Update props, Improve scroll performance and updated readme
2 parents 2e9d0a6 + dc9c94c commit 3a84a84

File tree

14 files changed

+276
-114
lines changed

14 files changed

+276
-114
lines changed

README.md

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ The `@sirenapp/react-native-inbox` sdk is a comprehensive and customizable React
99
You can install the react sdk from npm
1010

1111
```bash
12-
npm @sirenapp/react-native-inbox
12+
npm install @sirenapp/react-native-inbox
1313
```
1414
or from yarn
1515

1616
```bash
17-
yarn @sirenapp/react-native-inbox
17+
yarn add @sirenapp/react-native-inbox
1818
```
1919

2020
## 2. Configuration
@@ -110,16 +110,13 @@ Prop | Description | Type | Default value |
110110
--- | --- | --- | --- |
111111
theme | Object for custom themes | Theme | {} |
112112
customStyles | Object for custom styling | StyleProps | {} |
113-
title | Title of the notification inbox | string | "Notifications" |
114-
hideHeader | Toggle to hide or show the header section | boolean | false |
115-
hideClearAll | Toggle to hide or show the clear all button | boolean | false |
116113
darkMode | Toggle to enable dark mode| boolean | false |
117114
itemsPerFetch | Number of notifications fetch per api request (have a max cap of 50) | number | 20 |
118-
cardProps | Props for customizing the notification cards | { hideAvatar: boolean } | { hideAvatar: false } |
115+
cardProps | Props for customizing the notification cards | CardProps | { hideAvatar: false, disableAutoMarkAsRead: false, hideDelete: false } |
119116
customNotificationCard | Function for rendering custom notification cards | (notification)=> JSX Element | null |
120117
onNotificationCardClick | Custom click handler for notification cards | (notification)=> void | ()=>null |
121118
listEmptyComponent | Custom component for empty notification list | JSX Element | null |
122-
customHeader | Custom header component | JSX Element | null |
119+
inboxHeaderProps | Props for customizing the header | InboxHeaderProps | { title: "Notifications", hideHeader: false, hideClearAll: false, customHeader: null, showBackButton:false, backButton: null, onBackPress: ()=> null } |
123120
customFooter | Custom footer component | JSX Element | null |
124121
customLoader | Custom component to display the initial loading state| JSX Element | null |
125122
customErrorWindow | Custom error window | JSX Element | null |
@@ -174,7 +171,7 @@ Here are the available theme options:
174171
Here are the custom style options for the notification inbox:
175172

176173
```js
177-
export type StyleProps = {
174+
type StyleProps = {
178175
notificationIcon?: {
179176
size?: number;
180177
};
@@ -216,6 +213,27 @@ Here are the custom style options for the notification inbox:
216213
};
217214
};
218215
```
216+
#### CardProps
217+
```js
218+
type CardProps = {
219+
hideAvatar?: boolean;
220+
disableAutoMarkAsRead?: boolean;
221+
hideDelete?: boolean;
222+
};
223+
```
224+
225+
#### InboxHeaderProps
226+
```js
227+
type InboxHeaderProps = {
228+
title?: string;
229+
hideHeader?: boolean;
230+
hideClearAll?: boolean;
231+
customHeader?: JSX.Element | null;
232+
showBackButton?: boolean;
233+
backButton?: JSX.Element;
234+
onBackPress?: () => void;
235+
};
236+
```
219237

220238
## 3. Hooks
221239

@@ -297,7 +315,7 @@ function MyContainer(): React.JSX.Element {
297315
title="Notifications"
298316
hideHeader={false}
299317
darkMode={false}
300-
cardProps={{hideAvatar: false}}
318+
cardProps={{hideAvatar: false, disableAutoMarkAsRead: false}}
301319
/>
302320
</View>
303321
);

example/App.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ const Stack = createNativeStackNavigator();
1111
function MyStack() {
1212
return (
1313
<Stack.Navigator>
14-
<Stack.Screen name='Home' component={Home} />
14+
<Stack.Screen
15+
name='Home'
16+
options={{
17+
headerShown: false
18+
}}
19+
component={Home}
20+
/>
1521
<Stack.Screen
1622
name='Notifications'
1723
options={{
@@ -31,11 +37,7 @@ function App(): React.JSX.Element {
3137

3238
return (
3339
<NavigationContainer>
34-
<SirenProvider
35-
config={config}
36-
>
37-
{MyStack()}
38-
</SirenProvider>
40+
<SirenProvider config={config}>{MyStack()}</SirenProvider>
3941
</NavigationContainer>
4042
);
4143
}

example/screens/home.tsx

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,24 @@ const badgeThemes = [
1919
{
2020
light: {
2121
badgeStyle: {
22-
color: 'black',
23-
},
22+
color: 'black'
23+
}
2424
},
2525
dark: {
2626
badgeStyle: {
27-
color: 'green',
27+
color: 'green'
2828
}
2929
}
3030
},
3131
{
3232
light: {
3333
badgeStyle: {
34-
color: 'blue',
34+
color: 'blue'
3535
}
3636
},
3737
dark: {
3838
badgeStyle: {
39-
color: 'pink',
39+
color: 'pink'
4040
}
4141
}
4242
}
@@ -48,7 +48,7 @@ function Home(): React.JSX.Element {
4848
const [showTestingWindow, setShowTestingWindow] = useState(false);
4949
const [showCustomNotification, setShowCustomNotification] = useState(false);
5050
const [badgeThemeIndex, setBadgeThemeIndex] = useState(0);
51-
const [showNetwork, setShowNetwork] = useState(true);
51+
const [showNetwork, setShowNetwork] = useState(false);
5252

5353
const backgroundStyle = {
5454
backgroundColor: isDarkMode ? '#000' : '#FFF'
@@ -79,12 +79,9 @@ function Home(): React.JSX.Element {
7979
</View>
8080
{showTestingWindow && (
8181
<View style={styles.testingWindowInnerContainer}>
82-
{renderButton(
83-
`${showNetwork ? 'Hide' : 'Show'} network`,
84-
() => {
85-
setShowNetwork((showNetwork) => !showNetwork);
86-
}
87-
)}
82+
{renderButton(`${showNetwork ? 'Hide' : 'Show'} network`, () => {
83+
setShowNetwork((showNetwork) => !showNetwork);
84+
})}
8885
{renderButton(`${showCustomNotification ? 'Default' : 'Custom'}-N-Icon`, () =>
8986
setShowCustomNotification((showCustomNotification) => !showCustomNotification)
9087
)}
@@ -120,20 +117,24 @@ function Home(): React.JSX.Element {
120117
backgroundColor={backgroundStyle.backgroundColor}
121118
/>
122119
<View style={styles.contentContainer}>
123-
<SirenInboxIcon
124-
theme={badgeThemes[badgeThemeIndex]}
125-
customStyles={{
126-
notificationIcon: {
127-
size: 60
128-
}
129-
}}
130-
notificationIcon={showCustomNotification ? renderNotificationIcon() : undefined}
131-
onPress={() => navigation.navigate('Notifications')}
132-
/>
133-
<Text>Siren Notification Icon Theme Testing</Text>
134-
{showNetwork && <NetworkLogDebugModal />}
120+
<View style={styles.iconContainer}>
121+
<SirenInboxIcon
122+
theme={badgeThemes[badgeThemeIndex]}
123+
customStyles={{
124+
notificationIcon: {
125+
size: 30
126+
}
127+
}}
128+
notificationIcon={showCustomNotification ? renderNotificationIcon() : undefined}
129+
onPress={() => navigation.navigate('Notifications')}
130+
/>
131+
</View>
132+
<View style={styles.contentContainer}>
133+
<Text>Home screen</Text>
134+
{showNetwork && <NetworkLogDebugModal />}
135+
</View>
136+
{testingWindow()}
135137
</View>
136-
{testingWindow()}
137138
</SafeAreaView>
138139
);
139140
}
@@ -171,7 +172,7 @@ const styles = StyleSheet.create({
171172
},
172173
testingWindowInnerContainer: {
173174
flexWrap: 'wrap',
174-
flexDirection: 'row',
175+
flexDirection: 'row'
175176
},
176177
whiteLabel: {
177178
color: '#fff',
@@ -187,6 +188,12 @@ const styles = StyleSheet.create({
187188
margin: 6,
188189
borderRadius: 4,
189190
height: 30
191+
},
192+
iconContainer: {
193+
position: 'absolute',
194+
top: 0,
195+
right: 10,
196+
zIndex:2,
190197
}
191198
});
192199

example/screens/notifications.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ function Notifications(): React.JSX.Element {
4040
const [showTestingWindow, setShowTestingWindow] = useState(false);
4141
const [sdkDarkModeEnabled, setSdkDarkModeEnabled] = useState(false);
4242
const [showCustomHeader, setShowCustomHeader] = useState(false);
43-
const [showCustomFooter, setShowCustomFooter] = useState(true);
43+
const [showCustomFooter, setShowCustomFooter] = useState(false);
4444
const [hideHeader, setHideHeader] = useState(false);
4545
const [hideAvatar, setHideAvatar] = useState(false);
46-
const [showNetwork, setShowNetwork] = useState(true);
46+
const [showNetwork, setShowNetwork] = useState(false);
4747
const [windowThemeIndex, setWindowThemeIndex] = useState(0);
4848
const [showCustomEmptyComponent, setShowCustomEmptyComponent] = useState(false);
4949
const [showCustomNotificationCard, setShowCustomNotificationCard] = useState(false);
@@ -52,7 +52,7 @@ function Notifications(): React.JSX.Element {
5252
backgroundColor: isDarkMode ? '#000' : '#FFF'
5353
};
5454

55-
const { markNotificationsAsReadByDate, markAsRead } = useSiren();
55+
const { markNotificationsAsReadByDate } = useSiren();
5656

5757
const renderListEmpty = () => {
5858
return (
@@ -164,13 +164,17 @@ function Notifications(): React.JSX.Element {
164164
<View style={styles.contentContainer}>
165165
<SirenInbox
166166
title='Siren Notifications'
167-
hideHeader={hideHeader}
167+
inboxHeaderProps={{
168+
hideHeader: hideHeader,
169+
customHeader: showCustomHeader ? renderCustomHeader() : undefined,
170+
showBackButton: true,
171+
onBackPress: () => navigation.goBack(),
172+
}}
168173
darkMode={sdkDarkModeEnabled}
169-
cardProps={{ hideAvatar: hideAvatar, showMedia: true }}
174+
cardProps={{ hideAvatar: hideAvatar, disableAutoMarkAsRead: false }}
170175
theme={windowThemes[windowThemeIndex]}
171176
customFooter={showCustomFooter ? renderCustomFooter() : undefined}
172177
listEmptyComponent={showCustomEmptyComponent ? renderListEmpty() : undefined}
173-
customHeader={showCustomHeader ? renderCustomHeader() : undefined}
174178
customStyles={{
175179
notificationCard: {
176180
avatarSize: 30,
@@ -183,7 +187,6 @@ function Notifications(): React.JSX.Element {
183187
}
184188
onNotificationCardClick={(notification: NotificationDataType) => {
185189
console.log('click on notification');
186-
markAsRead(notification.id);
187190
}}
188191
onError={(error: SirenErrorType) => {
189192
console.log(`error: ${error}`);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"lint": "eslint src",
3030
"lint:fix": "npm run lint -- --fix",
3131
"build": "bob build",
32-
"test-build": "npm run build && npm pack && mv siren-react-native-inbox-1.0.0.tgz example/siren-sdk01.tgz && cd example && npm install",
32+
"test-build": "npm run build && npm pack && mv sirenapp-react-native-inbox-0.0.1.tgz example/siren-sdk01.tgz && cd example && npm install",
3333
"test": "npx jest",
3434
"coverage": "npm run test -- --coverage"
3535
},

src/components/backIcon.tsx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import React, { type ReactElement } from 'react';
2+
import { StyleSheet, View } from 'react-native';
3+
4+
import type { SirenStyleProps } from '../types';
5+
6+
const BackIcon = ({ styles }: { styles: Partial<SirenStyleProps> }): ReactElement => {
7+
return (
8+
<View style={style.backIconContainer}>
9+
<View style={[style.backIconLine1, styles.backIcon]} />
10+
<View style={[style.backIconLine2, styles.backIcon]} />
11+
</View>
12+
);
13+
};
14+
15+
const style = StyleSheet.create({
16+
backIconContainer: {
17+
justifyContent: 'center',
18+
alignItems: 'flex-start',
19+
height: 30,
20+
width: 20,
21+
},
22+
backIconLine1: {
23+
width: 12,
24+
height: 2,
25+
backgroundColor: 'red',
26+
transform: [{
27+
rotate: '130deg'
28+
}]
29+
},
30+
backIconLine2: {
31+
marginTop: 6,
32+
width: 12,
33+
height: 2,
34+
backgroundColor: 'red',
35+
transform: [{
36+
rotate: '230deg'
37+
}]
38+
}
39+
});
40+
41+
export default BackIcon;

0 commit comments

Comments
 (0)