-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathindex.js
55 lines (46 loc) · 1.91 KB
/
index.js
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
* @format
* @lint-ignore-every XPLATJSCOPYRIGHT1
*/
import './polyfills'
import 'react-native-gesture-handler'
import { AppRegistry, Platform } from 'react-native'
import messaging from '@react-native-firebase/messaging'
import notifee, { EventType } from '@notifee/react-native'
import './global'
import App from './App'
import { name as appName } from './app.json'
import PushNotification from 'react-native-push-notification'
import MarketingEvent from '@app/services/Marketing/MarketingEvent'
import AppNotificationPopup from '@app/services/AppNotification/AppNotificationPopup'
import Log from '@app/services/Log/Log'
MarketingEvent.initMarketing(false, true)
PushNotification.configure({
// (required) Called when a remote is received or opened, or local notification is opened
onNotification: async function(notification) {
const initNotification = await messaging().getInitialNotification()
Log.log('PushNotification.configure.onNotification ' + JSON.stringify(notification))
if (Platform.OS === 'android' && !notification?.data?.title && !!initNotification) {
AppNotificationPopup.onOpened(notification)
}
}
})
messaging().setBackgroundMessageHandler(async (message) => {
await Log.log('index.js messaging.setBackgroundMessageHandler ' + JSON.stringify(message))
if (Platform.OS === 'ios') {
await AppNotificationPopup.displayPush(message)
}
})
notifee.onBackgroundEvent(async (message) => {
await Log.log('PushNotificationsActions.onBackgroundEvent message ' + JSON.stringify(message))
switch (message.type) {
case EventType.DISMISSED:
break
case EventType.PRESS:
if (Platform.OS === 'ios' || message?.detail?.notification?.data?.title) {
AppNotificationPopup.onOpened(message?.detail?.notification)
}
break
}
})
AppRegistry.registerComponent(appName, () => App)