forked from aryaminus/RN-firechat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
112 lines (103 loc) · 2.41 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
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from "react";
import { Platform, StyleSheet, Text, View, StatusBar } from "react-native";
import Login from "./app/components/Login";
import Boiler from "./app/components/Boiler";
import Friendlist from "./app/components/Friendlist";
import Chat from "./app/components/Chat";
import GloChat from "./app/components/GloChat";
import ForgetPassword from "./app/components/ForgetPassword";
import Register from "./app/components/Register";
import { StackNavigator } from "react-navigation";
import firebase from "react-native-firebase";
class Home extends Component<{}> {
constructor() {
super();
this.state = {
page: "connection",
loading: true,
authenticated: false
};
}
static navigationOptions = {
headerStyle: {
backgroundColor: "#16a085",
elevation: null
},
header: null
};
componentDidMount() {
firebase.auth().onAuthStateChanged(user => {
if (user) {
firebase.messaging().requestPermissions();
firebase.messaging().subscribeToTopic("chat");
this.setState({ loading: false, authenticated: true });
} else {
firebase.messaging().unsubscribeFromTopic("chat");
this.setState({ loading: false, authenticated: false });
}
});
}
render() {
if (this.state.loading) return null; // Render loading/splash screen etc
if (!this.state.authenticated) {
return <Login navigation={this.props.navigation} />;
}
return <Boiler navigation={this.props.navigation} />;
}
}
export default (App = StackNavigator({
Home: {
screen: Home,
navigationOptions: {
title: "Home"
}
},
Login: {
screen: Login,
navigationOptions: {
title: "Login"
}
},
Register: {
screen: Register,
navigationOptions: {
title: "Register"
}
},
ForgetPassword: {
screen: ForgetPassword,
navigationOptions: {
title: "ForgetPassword"
}
},
Boiler: {
screen: Boiler,
navigationOptions: {
title: "Boiler"
}
},
GloChat: {
screen: GloChat,
navigationOptions: {
title: "GloChat"
}
},
Friendlist: {
screen: Friendlist,
navigationOptions: {
title: "Friendlist"
}
},
Chat: {
screen: Chat,
navigationOptions: {
title: "Chat"
}
}
}));
const styles = StyleSheet.create({});