Last active
October 27, 2023 09:26
-
-
Save FarazPatankar/a79650627a2cb95195133f5070f925ab to your computer and use it in GitHub Desktop.
Splash screen configuration for a bare expo app.
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 React, { useState, useEffect } from 'react'; | |
import { useFonts } from '@use-expo/font'; | |
import * as SplashScreen from 'expo-splash-screen'; | |
const App = () => { | |
const [isReady, setIsReady] = useState(false) | |
const [isLoaded] = useFonts({ | |
'Poppins-Regular': require('./assets/fonts/Poppins-Regular.ttf'), | |
'Poppins-Medium': require('./assets/fonts/Poppins-Medium.ttf'), | |
'Poppins-SemiBold': require('./assets/fonts/Poppins-SemiBold.ttf'), | |
}); | |
useEffect(() => { | |
// Stop the Splash Screen from being hidden. | |
const showSplashScreen = async () => { | |
await SplashScreen.preventAutoHideAsync(); | |
} | |
showSplashScreen(); | |
// You can do additional data fetching here. | |
// I have a function that fetches my user from Firebase | |
// but I have left it out because it is kind of irrelevant | |
// in this demo. | |
}, []); | |
useEffect(() => { | |
// Once our data is ready, hide the Splash Screen | |
const hideSplashScreen = async () => { | |
await SplashScreen.hideAsync(); | |
} | |
if (isLoaded && isReady) hideSplashScreen(); | |
}, [isReady]) | |
if (!isReady) return null; | |
return ( | |
<RootComponent /> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment