forked from berty/berty
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNotificationProvider.tsx
41 lines (34 loc) · 1.07 KB
/
NotificationProvider.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import React from 'react'
import { InAppNotificationProvider, withInAppNotification } from 'react-native-in-app-notification'
import { useMsgrContext } from '@berty-tech/store/hooks'
import NotificationBody from './NotificationBody'
const NotificationBridge: React.FC = withInAppNotification(({ showNotification }: any) => {
const { addNotificationListener, removeNotificationListener } = useMsgrContext()
React.useEffect(() => {
const listener = (evt: any) => {
showNotification({
title: evt.payload.title,
message: evt.payload.body,
additionalProps: evt,
})
}
addNotificationListener(listener)
return () => {
removeNotificationListener(listener)
}
}, [showNotification, addNotificationListener, removeNotificationListener])
return null
})
const NotificationProvider: React.FC = ({ children }) => (
<InAppNotificationProvider
notificationBodyComponent={NotificationBody}
backgroundColour='transparent'
closeInterval={5000}
>
<>
<NotificationBridge />
{children}
</>
</InAppNotificationProvider>
)
export default NotificationProvider