-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
171 lines (123 loc) · 4.89 KB
/
App.js
File metadata and controls
171 lines (123 loc) · 4.89 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import React from 'react';
import { StyleSheet, Platform, Image, Text, View, ScrollView, TouchableOpacity, AsyncStorage } from 'react-native';
import firebase from 'react-native-firebase';
import navigation, { createSwitchNavigator, NavigationActions, createStackNavigator } from 'react-navigation'
import splash from './src/splash'
import verify from './src/verify'
import webview from './src/webview'
const Navigator = createSwitchNavigator({
splash: {
screen: splash,
},
verify: {
screen: verify,
},
webview: {
screen: webview,
},
},
{
}
)
const InAppNavigator = createSwitchNavigator({
webview: {
screen: webview,
},
})
export default class App extends React.Component {
constructor() {
super();
this.state = {
// firebase things?
link: null,
};
}
/* goWebView = (link) => {
navigation.navigate('webview', {webViewLink: link})
AsyncStorage.setItem("webViewLink", "")
}*/
async componentDidMount() {
const notificationOpen: NotificationOpen = await firebase.notifications().getInitialNotification();
if (notificationOpen) {
console.log("İnitialize ")
// App was opened by a notification
// 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;
console.log(notification.data.link)
this.setState({ link: notification.data.link })
}/*
firebase.notifications().getInitialNotification()
.then((notificationOpen: NotificationOpen) => {
if (notificationOpen) {
console.log("İnitialize ")
// App was opened by a notification
// 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;
console.log(notification.data.link)
this.setState({ link: notification.data.link })
//firebase.notifications().removeAllDeliveredNotifications()
}
})
*/
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;
console.log("notifopen")
if (notification.data.link) {
console.log(notification.data.link)
this.setState({ link: notification.data.link })
}
});
const channel = new firebase.notifications.Android.Channel(
'channelId',
'Channel Name',
firebase.notifications.Android.Importance.Max
).setDescription('A natural description of the channel');
firebase.notifications().android.createChannel(channel);
// the listener returns a function you can use to unsubscribe
this.unsubscribeFromNotificationListener = firebase.notifications().onNotification((notification) => {
if (Platform.OS === 'android') {
const localNotification = new firebase.notifications.Notification({
sound: 'default',
show_in_foreground: true,
})
.setNotificationId(notification.notificationId)
.setTitle(notification.title)
.setSubtitle(notification.subtitle)
.setBody(notification.body)
.setData(notification.data)
.android.setChannelId('channelId') // e.g. the id you chose above
.android.setColor('#000000') // you can set a color here
.android.setPriority(firebase.notifications.Android.Priority.High);
firebase.notifications()
.displayNotification(localNotification)
.catch(err => console.error(err));
} else if (Platform.OS === 'ios') {
const localNotification = new firebase.notifications.Notification()
.setNotificationId(notification.notificationId)
.setTitle(notification.title)
.setSubtitle(notification.subtitle)
.setBody(notification.body)
.setData(notification.data)
.ios.setBadge(notification.ios.badge);
firebase.notifications()
.displayNotification(localNotification)
.catch(err => console.error(err));
}
});
}
componentWillUnmount() {
// this is where you unsubscribe
this.unsubscribeFromNotificationListener();
this.notificationOpenedListener();
}
render() {
return <Navigator screenProps={{ webViewLink: this.state.link }} />;
}
}