This repository has been archived by the owner on Jun 14, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
App.js
executable file
·105 lines (90 loc) · 2.42 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
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow
*/
import React, { Component } from "react";
import { AsyncStorage, AppState, View } from "react-native";
import { createRootNavigator } from "./src/app/router/router";
import { createAppContainer } from "react-navigation";
export default class App extends Component {
navigator = null;
constructor(props) {
super(props);
this.state = {
signedIn: true,
loadingPage: "OnBoarding",
appState: AppState.currentState
};
console.disableYellowBox = true;
}
//TODO: App Life Cycle
componentWillMount() {
this.retrieveData();
}
// componentDidMount() {
// AppState.addEventListener('change', this._handleAppStateChange);
//loaderHandler.showLoader("Loading");
// }
// componentWillUnmount() {
// AppState.removeEventListener('change', this._handleAppStateChange);
// }
//TODO: Fun RetriveData
retrieveData = async () => {
try {
var value = await AsyncStorage.getItem("@loadingPage:key");
if (value == "Password") {
this.setState({
signedIn: false
});
} else if (value == "TabbarBottom") {
this.setState({
loadingPage: "TabbarBottom"
});
} else {
this.setState({
loadingPage: "OnBoarding"
});
}
} catch (error) {
console.log(error);
}
};
//TODO: App Check forgound,backgound,active
_handleAppStateChange = async nextAppState => {
if (
this.state.appState.match(/inactive|background/) &&
nextAppState === "active"
) {
try {
var value = await AsyncStorage.getItem("@loadingPage:key");
console.log("forgount value =" + value);
if (value == "Home") {
this.setState({
signedIn: false
});
AsyncStorage.setItem("@signedPage:key", "Home");
}
AsyncStorage.setItem("@loadingPage:key", "Password");
} catch (error) {
// Error saving data
}
}
this.setState({ appState: nextAppState });
};
render() {
const { signedIn } = this.state;
const Layout = createRootNavigator(signedIn, this.state.loadingPage);
const AppContainer = createAppContainer(Layout);
// <BusyIndicator />
return (
<AppContainer
ref={nav => {
this.navigator = nav;
}}
/>
);
}
}