Splash screen in Create-React-App

Atul Khanduri

I'm using create-react-app to design a PWA. The default Splash screen provided by the App is an icon (in middle of the screen) and a name of the app below that icon. Icon & name must be provided in the manifest file.

Question: Is there any way to customize the Splash Screen instead of using the default one?

Following is the possible solution but searching for a better way to do that.

Possible Solution:

  1. Add a component for Splash Screen.
  2. On the main component, render SplashScreen component untill the API response is returned from the server. I am using renderSplashscreen state for rendering the SplashScreen component.

    // Component for Splash Screen
    class SplashScreen extends React.Component {
      render() {
        const style = {top: 0,
          bottom: 0,
          right: 0,
          left: 0,
          position: 'fixed'};
    
        return (
          <img src={'IMAGE-URL'} style={style}/>
        );
      }
    }
    
    class MainComponent extends React.Component {
      constructor(props) {
        this.state = {
          renderSplashscreen: true
        };
      }
    
      apiCallback(data) {
        // After getting the API response from server
        this.setState({renderSplashscreen: false});
      }
    
      render() {
        let view;
    
        if(this.state.renderSplashscreen)
          return <SplashScreen/>;
        else
          return <OtherComponent/>
      }
    }
    
Atul Khanduri

Here's my own possible solution added in the question, as for now, this is the only solution that works well.

  1. Add a component for Splash Screen.
  2. On the main component, render SplashScreen component untill the API response is returned from the server. I am using renderSplashscreen state for rendering the SplashScreen component.

    // Component for Splash Screen
    class SplashScreen extends React.Component {
      render() {
        const style = {top: 0,
          bottom: 0,
          right: 0,
          left: 0,
          position: 'fixed'};
    
        return (
          <img src={'IMAGE-URL'} style={style}/>
        );
      }
    }
    
    class MainComponent extends React.Component {
      constructor(props) {
        this.state = {
          renderSplashscreen: true
        };
      }
    
      apiCallback(data) {
        // After getting the API response from server
        this.setState({renderSplashscreen: false});
      }
    
      render() {
        let view;
    
        if(this.state.renderSplashscreen)
          return <SplashScreen/>;
        else
          return <OtherComponent/>
      }
    }
    

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

React native app stuck on splash screen on device but works in simulator

React Native Android Splash Screen

How to create some kind of Splash screen/Launching screen, which disappears after App loaded? (React Native)

ionic app splash screen are not shown

How to create a splash screen on Qt?

Splash screen when starting the app

Ionic - app hangs on splash screen

splash screen react native

White screen after splash screen in IONIC app

react navigation splash screen to login screen

React Native Splash Screen: Unfortunately <APP> has stopped after SplashScreen.show()

React Nativ iOS APP is loading black screen instead of main React Native Splash which I designed

How can I display a launch/splash screen in a react-native app without using a package? (iOS specifcally)

React Native app stuck on splash screen after a package update

How to refactor AppDelegate.m to only load app once when using react-native-splash-screen?

App crashes after splash screen

How to create a second splash screen (after default splash screen in ios)?

Automate app icon / splash screen linking in react-native (possibly with rnpm)?

Is iOS app Launch Screen (splash screen) a must?

App stops at Splash screen

Is there any splash screen module like react-native-splash-screen?

My React native app is going back to splash screen whenever i press a button with navigation function

Splash screen using react navigation

White screen before splash screen react native

Xamarin 5.0 Create Splash Screen

React Native splash screen on ios

why is there no picture on the app splash screen

splash screen with react.js

Andoid app (React Native) works perfectly fine running locally, but stuck on splash screen in production