-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.android.js
107 lines (95 loc) · 2.78 KB
/
index.android.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
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
AppRegistry,
ActivityIndicator,
Navigator,
StyleSheet,
} from 'react-native';
import Home from './App/Components/Home';
import Login from './App/Components/Login';
import SignUp from './App/Components/SignUp';
import Messenger from './App/Components/Messenger';
import { User } from './App/Models';
import {Scene, Router} from 'react-native-router-flux';
import FCM from 'react-native-fcm';
export default class CheckIn extends Component {
constructor(props) {
super(props);
this.state = {
authenticated: false,
loading: true,
};
}
componentWillMount() {
User.isUserSignedIn({
onSuccess: function(data) {
this.setState({
loading: false,
authenticated: data.authenticated
})
}.bind(this)
})
}
componentWillUnmount() {
this.notificationListener.remove();
this.refreshTokenListener.remove();
}
componentDidMount() {
FCM.requestPermissions(); // for iOS
FCM.getFCMToken().then(token => {
console.log(token)
// store fcm token in your server
});
this.notificationListener = FCM.on('notification', (notif) => {
// there are two parts of notif. notif.notification contains the notification payload, notif.data contains data payload
if(notif.local_notification){
//this is a local notification
}
if(notif.opened_from_tray){
//app is open/resumed because user clicked banner
}
});
this.refreshTokenListener = FCM.on('refreshToken', (token) => {
console.log(token)
// fcm token may not be available on first load, catch it here
});
FCM.subscribeToTopic('messages');
}
render() {
var component;
if (this.state.loading) {
return (
<ActivityIndicator
animating={this.state.loading}
style={[styles.centering, {height: 80}]}
size="large"
/>
);
}
else {
return (
<Router>
<Scene key="root">
<Scene key="Home" component={Home} initial={this.state.authenticated} title="Home" hideNavBar={true}/>
<Scene key="Login" component={Login} initial={!this.state.authenticated} title="Login" hideNavBar={true}/>
<Scene key="SignUp" component={SignUp} title="Sign Up" hideNavBar={true}/>
<Scene key="Messenger" component={Messenger} hideNavBar={false} title="Messenger"/>
</Scene>
</Router>
);
}
}
}
const styles = StyleSheet.create({
centering: {
alignItems: 'center',
justifyContent: 'center',
padding: 8,
},
});
AppRegistry.registerComponent('CheckIn', () => CheckIn);