-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
102 lines (93 loc) · 3.11 KB
/
App.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import React, {Component} from 'react';
import {createStackNavigator, createAppContainer} from 'react-navigation';
import {AsyncStorage} from 'react-native';
import firebase from 'react-native-firebase';
import HomeScreen from './components/HomeScreen';
import Message from './components/Message';
export default class App extends React.Component {
async componentDidMount() {
const notificationOpen: NotificationOpen = await firebase
.notifications()
.getInitialNotification();
if (notificationOpen) {
const action = notificationOpen.action;
const notification: Notification = notificationOpen.notification;
var seen = [];
alert(
JSON.stringify(notification.data, function(key, val) {
if (val != null && typeof val === 'object') {
if (seen.indexOf(val) >= 0) {
return;
}
seen.push(val);
}
return val;
}),
);
}
this.messageListener = firebase.messaging().onMessage(message => {
debugger;
});
const channel = new firebase.notifications.Android.Channel(
'firebasenotifs',
'Firebase Notifications',
firebase.notifications.Android.Importance.Max,
).setDescription('My apps test channel');
// Create the channel
firebase.notifications().android.createChannel(channel);
this.notificationDisplayedListener = firebase
.notifications()
.onNotificationDisplayed((notification: Notification) => {
});
this.notificationListener = firebase
.notifications()
.onNotification((notification: Notification) => {
// Process your notification as required
notification.android
.setChannelId('firebasenotifs')
.android.setSmallIcon('@drawable/ic_stat_aa')
.android.setBigPicture('@drawable/bigpic');
firebase.notifications().displayNotification(notification);
});
this.notificationOpenedListener = firebase
.notifications()
.onNotificationOpened((notificationOpen: NotificationOpen) => {
// Get the action triggered by the notification being opened
const action = notificationOpen.action;
// Get information about the notification that was opened
const notification: Notification = notificationOpen.notification;
var seen = [];
alert(
JSON.stringify(notification.data, function(key, val) {
if (val != null && typeof val === 'object') {
if (seen.indexOf(val) >= 0) {
return;
}
seen.push(val);
}
return val;
}),
);
firebase
.notifications()
.removeDeliveredNotification(notification.notificationId);
});
}
componentWillUnmount() {
this.notificationDisplayedListener();
this.notificationListener();
this.notificationOpenedListener();
}
render() {
return <AppContainer />;
}
}
const AppNavigator = createStackNavigator({
Home: {
screen: HomeScreen,
},
Topic: {
screen: Message,
},
});
const AppContainer = createAppContainer(AppNavigator);