-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.android.js
107 lines (98 loc) · 2.45 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
//#region Imports
import React, { Component } from "react";
import {
AppRegistry,
StyleSheet,
Text,
TextInput,
View,
BackHandler
} from "react-native";
import firebase from "firebase";
import { Actions } from "react-native-router-flux";
import Toast from "react-native-simple-toast";
import NewBG from "./app/Components/NewBG";
import LoginForm from "./app/Components/LoginForm";
import Bglst from "./app/Components/BgLst";
import Router from "./app/Router";
//#endregion
export default class DiabetesJournal extends Component {
constructor(props) {
super(props);
this.state = {
isLoggedIn: false,
Exitcount: 0
};
}
componentWillMount() {
if (!firebase.apps.length) {
firebase.initializeApp({
apiKey: "AIzaSyBgwVLxWeradAHjqw-5rMvLZ2_2NoZ0nKA",
authDomain: "diabetesjournal-405cf.firebaseapp.com",
databaseURL: "https://diabetesjournal-405cf.firebaseio.com",
projectId: "diabetesjournal-405cf",
storageBucket: "diabetesjournal-405cf.appspot.com",
messagingSenderId: "750281915622"
});
}
firebase.auth().onAuthStateChanged(user => {
if (user) {
this.setState({ isLoggedIn: true });
Actions.BG();
} else {
this.setState({ isLoggedIn: false });
Actions.auth();
}
});
BackHandler.removeEventListener("hardwareBackPress", this.onBackPress);
}
componentDidMount() {
BackHandler.addEventListener(
"hardwareBackPress",
this.onBackPress.bind(this)
);
}
onBackPress() {
if (Actions.state.index === 0) {
return false;
}
if (Actions.currentScene === "_bglst") {
this.setState({ Exitcount: this.state.Exitcount + 1 });
if (this.state.Exitcount <= 1) {
Toast.show("Press One More Time To Exit", Toast.SHORT);
}
if (this.state.Exitcount > 1) {
this.state.Exitcount = 0;
return false;
}
} else {
Actions.pop();
return true;
}
return true
}
CompnentSelector(self) {
if (self.state.isLoggedIn) {
return (
<View>
<Header Headertxt={"BG Journal"} />
<Bglst />
</View>
);
} else {
return (
<View>
<LoginForm />
</View>
);
}
}
render() {
return (
<View style={{ flex: 1 }}>
<Router />
</View>
);
}
}
AppRegistry.registerComponent("DiabetesJournal", () => DiabetesJournal);