-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
188 lines (139 loc) · 4.92 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
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow
* @lint-ignore-every XPLATJSCOPYRIGHT1
*/
import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View,AsyncStorage} from 'react-native';
import {Router,Scene,Stack,Drawer,Lightbox} from 'react-native-router-flux';
import {LandingComponent} from './src/LandingComponent';
import SideBar from './src/components/DrawerContent';
import Gallery from './src/components/Gallery';
import OfficeBearers from './src/components/OfficeBearers';
import EventDetail from './src/components/EventDetail';
import HomeComponent from './src/HomeComponent';
import Profile from './src/components/Profile';
import {Icon} from 'native-base';
import NewsLetter from './src/components/NewsLetter';
import PdfViewer from './src/components/Pdf';
import firebase from 'react-native-firebase';
import Message from './src/components/Message';
import Login from './src/components/login';
import SignUp from './src/components/signup';
import TimelineView from './src/components/Timeline';
export default class App extends Component{
async createChannel(){
const channel = new firebase.notifications.Android.Channel('test-channel', 'Test Channel', firebase.notifications.Android.Importance.Max)
.setDescription('My apps test channel');
try{
await firebase.notifications().android.createChannel(channel);
}
catch(error){
alert(error.message)
}
}
async showNotif(data){
const notification = new firebase.notifications.Notification()
.setNotificationId('notificationId')
.setTitle(data.title)
.setBody(data.body)
.setData({
key1: 'value1',
key2: 'value2',
});
notification.android.setBigPicture('https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcT_iU8Yzjy2pQ4R-7uBQBJtxVfqG5F91V7jqXpbgcdmztDB92oEaQ')
notification.android.setPriority(firebase.notifications.Android.Priority.High) /// set to High
notification.android.setChannelId("test-channel") ///for android 8.0 and above
try{
await firebase.notifications().displayNotification(notification)
alert('notification')
}
catch(error){
console.log({error})
alert(error.message)
}
}
async getToken(){
const fcmToken = await firebase.messaging().getToken();
if (fcmToken) {
console.log({fcmToken})
firebase.messaging().subscribeToTopic('common');
return fcmToken;
} else {
alert('No token')
}
}
componentDidMount() {
this.getToken()
this.createChannel()
this.messageListener = firebase.messaging().onMessage((message) => {
alert('Received a message')
this.showNotif(message)
});
firebase.messaging().hasPermission()
.then(enabled => {
if (enabled) {
} else {
// user doesn't have permission
firebase.messaging().requestPermission()
.then(() => {
})
.catch(error => {
alert('Please allow notifications.')
});
}
});
}
render() {
return (
<Router navigationBarStyle={{ backgroundColor: "#1e3c64"}}
titleStyle={{color:'white'}}
>
<Drawer
hideNavBar
key="drawer"
drawerIcon={<Icon name='md-menu' type='Ionicons'
style={{color:'white'}}/>}
contentComponent={SideBar}
drawerWidth={300}
>
<Stack key="root">
<Scene key="home" component={HomeComponent} title='Home' initial/>
<Scene key='events' component={LandingComponent} title="Events"/>
<Scene key='gallery' component={Gallery} title="Gallery"/>
<Scene key='office_bearers' component={OfficeBearers} title='Office Bearers'/>
<Scene key='event_detail' component={EventDetail} title='Details'/>
<Scene key='profile' component={Profile} title='Profile'/>
<Scene key='newsletter' component={NewsLetter} title='NewsLetter'/>
<Scene key='pdf' component={PdfViewer} title='NewsLetter'/>
<Scene key='message' component={Message} title='Messages'/>
<Scene key="login" component={Login} />
<Scene key="signup" component={SignUp}/>
<Scene key="timeline" component={TimelineView} />
</Stack>
</Drawer>
</Router>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});