Skip to content
Advertisement

Customize Default Splash Screen of react-native

Is there any way to remove the default Splash screen of react-native. Or Coustomize the Default Splash Screen. Like I want to a add a loading bar and fade effects in splash screen. And I want to create 2 splash screens for company & app. Is it possible to change the loading time?

Advertisement

Answer

If you want to set just an image as splash, you can modify your app.json like this,

If you want to do an animated splash, you can use the 'expo-splash-screen'. I use this code one time. the most important part is the preventAutoHideAsync().catch(console.warn); that show the animation as the first component in the app, and in hideAsync().catch(console.warn); you continue the execution of your app.

import 'react-native-gesture-handler';
import { createDrawerNavigator } from '@react-navigation/drawer';
import { NavigationContainer } from '@react-navigation/native';
import Home from '_screens/Home';
import Splash from '_screens/Splash';
import { preventAutoHideAsync, hideAsync } from 'expo-splash-screen';
import React, { useState, useEffect } from 'react';

/* expo-splash-screen works fine but raise an exception because the managed expo workflow
 * use the old version of this library, however a fix was merged and probably in the next version of
 * expo this will be fixed, about this error https://github.com/expo/expo/issues/8067
 */
preventAutoHideAsync().catch(console.warn);

export type RootStackParamList = {
  Home: undefined;
};

export default function App(): JSX.Element {
  const [isLoadingSplash, setIsLoadingSplash] = useState(true);
  const Drawer = createDrawerNavigator();
  const init = (): void => {
    setTimeout(async () => {
      hideAsync().catch(console.warn);
      setIsLoadingSplash(false);
    }, 5000);
  };

  useEffect(() => {
    init();
  }, []);

  return (
    <>
      {isLoadingSplash && <Splash />}
      {!isLoadingSplash && (
        <NavigationContainer>
          <Drawer.Navigator initialRouteName="Home">
            <Drawer.Screen name="Login" component={Login} />
            <Drawer.Screen name="Home" component={Home} />
          </Drawer.Navigator>
        </NavigationContainer>
      )}
    </>
  );
}
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement