-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.js
81 lines (71 loc) · 1.75 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
// Differentiate between setup and layout components
import React from 'react';
import { Text, View, StatusBar } from 'react-native';
import Layout from './layouts/app';
import Setup from './layouts/setup';
import Setting from './layouts/setting';
import API from './api';
export default class App extends React.Component {
constructor(props){
super(props);
this.state = {
setup: false,
setting: false
}
}
componentWillMount(){
API.getData("setup").then(setupStatus => {
if(setupStatus == "start"){
this.setState({setup: "start"});
}else{
this.setState({setup: "done"});
}
});
}
componentDidMount(){
API.event.addListener("setting", (setting) => {
//this.setState({setting});
this.setState({setup: "start"});
});
this.checkTimeout();
}
checkTimeout(){
setTimeout(() => {
if(!this.state.setup){
API.getData("setup").then(setupStatus => {
if(setupStatus == "start"){
this.setState({setup: "start"});
}else{
this.setState({setup: "done"});
}
});
this.checkTimeout();
}
}, 300);
}
setupFinished(){
this.setState({setup: "done"});
API.setData("setup", "done");
}
renderMainComponent(){
if(this.state.setup == "start"){
return(<Setup finished={this.setupFinished.bind(this)}/>);
}else if(this.state.setup == "done"){
if(this.state.setting){
return(<Setting/>);
}else{
return(<Layout language={this.state.currentLang}/>);
}
}else{
return null;
}
}
render() {
return (
<View style={{flex: 1}}>
<StatusBar hidden={true}/>
{this.renderMainComponent()}
</View>
);
}
}