useCachedResources.js 1.5 KB

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