-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
64 lines (53 loc) · 1.92 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-native-gesture-handler';
import * as Font from 'expo-font';
import * as SplashScreen from 'expo-splash-screen';
import AudioPlayer from './shared/AudioPlayer.js';
import ColorMode from './shared/ColorMode';
import Drawer from './components/Drawer';
import React, { useCallback, useEffect, useState } from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import { StatusBar } from 'expo-status-bar';
export default function App() {
ColorMode.init();
const [appIsReady, setAppIsReady] = useState(false);
const [colorMode, setColorMode] = useState(ColorMode.value());
ColorMode.addListener(value => setColorMode(value));
useEffect(() => {
async function prepare() {
try {
// Keep the splash screen visible while we fetch resources
await SplashScreen.preventAutoHideAsync();
const sounds = AudioPlayer.load({
'dice': require('./assets/sounds/dice.mp3'),
'dice7': require('./assets/sounds/dice7.mp3'),
});
await Promise.all([sounds]);
await Font.loadAsync({
'CrimsonText_400Regular': require('@expo-google-fonts/crimson-text/CrimsonText_400Regular.ttf'),
'CrimsonText_700Bold': require('@expo-google-fonts/crimson-text/CrimsonText_700Bold.ttf'),
'VnBook-Antiqua': require('./assets/fonts/VnBook-Antiqua.otf'),
});
} catch (e) {
console.warn(e);
} finally {
// Tell the application to render
setAppIsReady(true);
// TODO move to onLayoutRootView instead?
await SplashScreen.hideAsync();
}
}
prepare();
}, []);
if (!appIsReady) {
return null;
}
return (
<SafeAreaProvider>
<NavigationContainer>
<Drawer />
</NavigationContainer>
<StatusBar style={colorMode ? 'light' : 'dark'} hidden={false} />
</SafeAreaProvider>
);
}