useCachedResources.js 969 B

123456789101112131415161718192021222324252627282930313233
  1. import { Ionicons } from '@expo/vector-icons';
  2. import * as Font from 'expo-font';
  3. import * as SplashScreen from 'expo-splash-screen';
  4. import * as React from 'react';
  5. export default function useCachedResources() {
  6. const [isLoadingComplete, setLoadingComplete] = React.useState(false);
  7. // Load any resources or data that we need prior to rendering the app
  8. React.useEffect(() => {
  9. async function loadResourcesAndDataAsync() {
  10. try {
  11. SplashScreen.preventAutoHideAsync();
  12. // Load fonts
  13. await Font.loadAsync({
  14. ...Ionicons.font,
  15. 'space-mono': require('../assets/fonts/SpaceMono-Regular.ttf'),
  16. });
  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. SplashScreen.hideAsync();
  23. }
  24. }
  25. loadResourcesAndDataAsync();
  26. }, []);
  27. return isLoadingComplete;
  28. }