Skip to content

Instantly share code, notes, and snippets.

@FarazPatankar
Last active October 27, 2023 09:26
Show Gist options
  • Save FarazPatankar/a79650627a2cb95195133f5070f925ab to your computer and use it in GitHub Desktop.
Save FarazPatankar/a79650627a2cb95195133f5070f925ab to your computer and use it in GitHub Desktop.
Splash screen configuration for a bare expo app.
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