-
Notifications
You must be signed in to change notification settings - Fork 25
/
App.js
74 lines (61 loc) · 1.61 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
import * as React from 'react';
import { Appearance, StatusBar } from 'react-native';
import { ScreenOrientation } from 'expo';
import AppLoading from 'expo-app-loading';
import { device, func } from './src/constants';
// main navigation stack
import RootStack from './src/navigation/RootStack';
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
isLoading: true,
theme: 'light'
};
// is iPad?
if (device.isPad) {
ScreenOrientation.allowAsync(
ScreenOrientation.Orientation.ALL_BUT_UPSIDE_DOWN
);
}
this.updateTheme = this.updateTheme.bind(this);
}
componentDidMount() {
// get system preference
const colorScheme = Appearance.getColorScheme();
console.log('react-native::Appearance', colorScheme);
// if light or dark
if (colorScheme !== 'no-preference') {
this.setState({
theme: colorScheme
});
}
}
updateTheme(themeType) {
this.setState({
theme: themeType
});
}
render() {
const { isLoading, theme } = this.state;
const iOSStatusType = theme === 'light' ? 'dark-content' : 'light-content';
if (isLoading) {
return (
<AppLoading
onError={() => {
// console.warn
}}
onFinish={() => this.setState({ isLoading: false })}
startAsync={func.loadAssetsAsync}
/>
);
}
return (
<React.Fragment>
<StatusBar barStyle={device.iOS ? iOSStatusType : 'light-content'} />
<RootStack theme={theme} />
</React.Fragment>
);
}
}
export default App;