useCachedResources.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /* eslint-disable global-require */
  2. import { Ionicons } from '@expo/vector-icons';
  3. import * as Font from 'expo-font';
  4. import * as SplashScreen from 'expo-splash-screen';
  5. import * as React from 'react';
  6. export default function useCachedResources() {
  7. const [isLoadingComplete, setLoadingComplete] = React.useState(false);
  8. // Load any resources or data that we need prior to rendering the app
  9. React.useEffect(() => {
  10. async function loadResourcesAndDataAsync() {
  11. try {
  12. SplashScreen.preventAutoHideAsync();
  13. // Load fonts
  14. await Font.loadAsync({
  15. ...Ionicons.font,
  16. 'space-mono': require('../assets/fonts/SpaceMono-Regular.ttf'),
  17. antoutline: require('@ant-design/icons-react-native/fonts/antoutline.ttf'),
  18. antfill: require('@ant-design/icons-react-native/fonts/antfill.ttf'),
  19. Roboto: require('native-base/Fonts/Roboto.ttf'),
  20. Roboto_medium: require('native-base/Fonts/Roboto_medium.ttf'),
  21. });
  22. } catch (e) {
  23. // We might want to provide this error information to an error reporting service
  24. // eslint-disable-next-line no-console
  25. // console.warn(e);
  26. } finally {
  27. setLoadingComplete(true);
  28. SplashScreen.hideAsync();
  29. }
  30. }
  31. loadResourcesAndDataAsync();
  32. }, []);
  33. return isLoadingComplete;
  34. }