GT2/Ejectable/hooks/useCachedResources.ts

34 lines
969 B
TypeScript
Raw Permalink Normal View History

2021-08-22 04:30:04 +00:00
import { FontAwesome } from '@expo/vector-icons';
2021-08-16 07:50:50 +00:00
import * as Font from 'expo-font';
2021-08-21 13:05:22 +00:00
import * as HomeScreen from 'expo-splash-screen';
2021-08-16 07:50:50 +00:00
import * as React from 'react';
export default function useCachedResources() {
const [isLoadingComplete, setLoadingComplete] = React.useState(false);
// Load any resources or data that we need prior to rendering the app
React.useEffect(() => {
async function loadResourcesAndDataAsync() {
try {
2021-08-21 13:05:22 +00:00
HomeScreen.preventAutoHideAsync();
2021-08-16 07:50:50 +00:00
// Load fonts
await Font.loadAsync({
2021-08-22 04:30:04 +00:00
...FontAwesome.font,
2021-08-16 07:50:50 +00:00
'space-mono': require('../assets/fonts/SpaceMono-Regular.ttf'),
});
} catch (e) {
// We might want to provide this error information to an error reporting service
console.warn(e);
} finally {
setLoadingComplete(true);
2021-08-21 13:05:22 +00:00
HomeScreen.hideAsync();
2021-08-16 07:50:50 +00:00
}
}
loadResourcesAndDataAsync();
}, []);
return isLoadingComplete;
}