-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
App.tsx
91 lines (80 loc) · 2.39 KB
/
App.tsx
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
import * as React from 'react';
import { AppLoading } from 'expo';
import * as Font from 'expo-font';
import { Asset } from 'expo-asset';
import { Entypo, Ionicons, MaterialIcons } from '@expo/vector-icons';
import { Platform, StatusBar, StyleSheet, View } from 'react-native';
import { Assets as StackAssets } from 'react-navigation-stack';
import { enableScreens } from 'react-native-screens';
import { AppearanceProvider, useColorScheme, ColorSchemeName } from 'react-native-appearance';
import Icons from './src/constants/Icons';
import RootNavigation from './src/navigation/RootNavigation';
if (Platform.OS === 'android') {
enableScreens(true);
}
const initialState = {
appIsReady: false,
};
type Props = { colorScheme: ColorSchemeName };
type State = typeof initialState;
export default function AppContainer() {
let colorScheme = useColorScheme();
return (
<AppearanceProvider>
<App colorScheme={colorScheme} />
</AppearanceProvider>
);
}
class App extends React.Component<Props, State> {
readonly state: State = initialState;
componentDidMount() {
this._loadAssetsAsync();
}
async _loadAssetsAsync() {
try {
const iconRequires = Object.keys(Icons).map(key => Icons[key]);
const assetPromises: Promise<any>[] = [
Asset.loadAsync(iconRequires),
Asset.loadAsync(StackAssets),
// @ts-ignore
Font.loadAsync(Ionicons.font),
// @ts-ignore
Font.loadAsync(Entypo.font),
// @ts-ignore
Font.loadAsync(MaterialIcons.font),
Font.loadAsync({
'space-mono': require('./assets/fonts/SpaceMono-Regular.ttf'),
}),
];
if (Platform.OS !== 'web')
assetPromises.push(
Font.loadAsync({
Roboto: 'https://github.com/google/fonts/raw/master/apache/roboto/Roboto-Regular.ttf',
})
);
await Promise.all(assetPromises);
} catch (e) {
console.log({ e });
} finally {
this.setState({ appIsReady: true });
}
}
render() {
if (this.state.appIsReady) {
return (
<View style={styles.container} testID="native_component_list">
<RootNavigation />
{Platform.OS === 'ios' && <StatusBar barStyle="dark-content" />}
</View>
);
} else {
return <AppLoading />;
}
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
},
});