useCachedResources.ts 935 B

1234567891011121314151617181920212223242526272829303132
  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. }
  23. }
  24. loadResourcesAndDataAsync();
  25. }, []);
  26. return isLoadingComplete;
  27. }