-
-
Save mauriciord/0a28c42ff2ec43818c7caac02c6a3e1d to your computer and use it in GitHub Desktop.
React hook to abstract loading resources from expo and showing splash screen until completion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect, useState } from 'react'; | |
import * as Font from 'expo-font'; | |
import { SplashScreen } from 'expo'; | |
/** | |
* Load and use resources that need to be loaded async by Expo SDK | |
*/ | |
const useExpoResources = () => { | |
const [isLoading, setIsLoading] = useState(true); | |
/** | |
* Load resources and prevents SplashScreen from hiding until completed | |
*/ | |
useEffect(() => { | |
SplashScreen.preventAutoHide(); | |
const loadFonts = async () => { | |
try { | |
await Font.loadAsync({ | |
SomeFont: require('../../assets/fonts/SomeFont.ttf'), | |
}); | |
setIsLoading(false); | |
SplashScreen.hide(); | |
} catch (error) { | |
// handle error | |
} | |
}; | |
loadFonts(); | |
}, []); | |
return isLoading; | |
}; | |
export default useExpoResources; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment