xref: /expo/apps/native-component-list/App.tsx (revision eb768dc5)
1import * as SplashScreen from 'expo-splash-screen';
2import * as React from 'react';
3import { Platform, StatusBar } from 'react-native';
4
5import RootNavigation from './src/navigation/RootNavigation';
6import loadAssetsAsync from './src/utilities/loadAssetsAsync';
7
8function useSplashScreen(loadingFunction: () => void) {
9  const [isLoadingCompleted, setLoadingComplete] = React.useState(false);
10
11  // Load any resources or data that we need prior to rendering the app
12  React.useEffect(() => {
13    async function loadAsync() {
14      try {
15        await SplashScreen.preventAutoHideAsync();
16        await loadingFunction();
17      } catch (e) {
18        // We might want to provide this error information to an error reporting service
19        console.warn(e);
20      } finally {
21        setLoadingComplete(true);
22        await SplashScreen.hideAsync();
23      }
24    }
25
26    loadAsync();
27  }, []);
28
29  return isLoadingCompleted;
30}
31
32const App = () => {
33  const isLoadingCompleted = useSplashScreen(async () => {
34    if (Platform.OS === 'ios') {
35      StatusBar.setBarStyle('dark-content', false);
36    }
37    await loadAssetsAsync();
38  });
39
40  return isLoadingCompleted ? <RootNavigation /> : null;
41};
42
43export default App;
44