forked from btk/aac-native
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
64 lines (57 loc) · 1.5 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
import React from 'react';
import { StyleSheet, Text, View, StatusBar } from 'react-native';
import Layout from './layouts/app';
import Settings from './js/settings';
const LANGUAGE_FLUSH = false;
// LANGUAGE_FLUSH is a constant variable for development tests
// It flushes the localstorage saved language and locale data
// if any exists
export default class App extends React.Component {
constructor(props){
super(props);
this.state = {
currentLang: ""
}
if(LANGUAGE_FLUSH && !(this.state.currentLang)){
Settings.setOption("language", "").then((flushed) => {
console.log("Timeout start");
setTimeout(() => {
console.log("Timeout end");
this.setLanguageAsState();
}, 10000);
});
}else{
this.setLanguageAsState();
}
}
setLanguageAsState(){
Settings.getOption("language").then(lang => {
if(lang){
console.log("App is loading in language: ", lang);
this.setState({currentLang: lang});
}else{
console.log("Language not yet set, will try in 1s");
setTimeout(() => {
this.setLanguageAsState();
}, 1000);
}
});
}
render() {
if(this.state.currentLang){
return (
<View style={styles.generalContainer}>
<StatusBar hidden={true}/>
<Layout language={this.state.currentLang}/>
</View>
);
} else {
return null;
}
}
}
const styles = StyleSheet.create({
generalContainer: {
flex: 1
},
});