bamlab / react-native-make

A collection of everyday React Native CLI tools
MIT License
761 stars 87 forks source link

SplashScreen not hiding in Android #29

Open RiseOoi opened 4 years ago

RiseOoi commented 4 years ago

Hi, I haven't complete the iOS one, but I hope my Android case helps you. I will try to update this comment after I complete the iOS one.

For my case (RN 0.61) in Android, it seems like the library messes up my MainActivity.java so I just discard the changes made to it and it worked.

The the library adds:

import android.os.Bundle;
import org.devio.rn.splashscreen.SplashScreen;
...
@Override
    protected void onCreate(Bundle savedInstanceState) {
SplashScreen.show(this, R.style.SplashScreenTheme);        anything_that_exists_here();
        super.onCreate(savedInstanceState);
SplashScreen.show(this, R.style.SplashScreenTheme);    }

to the android/app/src/main/java/com/project_name/MainActivity.java

  1. import android.os.Bundle and import org.devio.rn.splashscreen.SplashScreen are already there for my case, but since they are not the 1st and 2nd imports, the library forcefully adding the imports made it double imports. This is not the reason it didn't work though.

  2. The real culprit is that SplashScreen.show(this, R.style.SplashScreenTheme); is added after the anything_you_had_here(); \n super.onCreate(savedInstanceState);. So yeah, there is a bug in this library that the line adding is messed up.

I don't have the time to do a PR for the moment but I hope this helps @yleflour track down the bug both on the Android and iOS (if present) side and fix it. Good luck guys!

=== For completeness, you just need:

protected void onCreate(Bundle savedInstanceState) {
    SplashScreen.show(this, R.style.SplashScreenTheme);
    super.onCreate(savedInstanceState);
}

Once you do this, then the library will detect SplashScreen.show(this, R.style.SplashScreenTheme); successfully next time so you won't ever have to manually do this again.

adibas03 commented 4 years ago

@Riseley You need to explicitly call SplashScreen.hide() in your code It is fully explained here: https://github.com/bamlab/react-native-make/blob/master/docs/set-splash.md#prerequisites

gruming commented 4 years ago

@adibas03 i already call SplashScreen.hid() but Not hiding in Android

@Override
  protected void onCreate(Bundle savedInstanceState) {
    SplashScreen.show(this, R.style.SplashScreenTheme);    <<<
    SplashScreen.show(this, true);  // here
    super.onCreate(savedInstanceState);
    SplashScreen.show(this, R.style.SplashScreenTheme);    <<<
  }

In the code above, two additional lines are generated.

so i edit

=== For completeness, you just need:

protected void onCreate(Bundle savedInstanceState) {
    SplashScreen.show(this, R.style.SplashScreenTheme);
    super.onCreate(savedInstanceState);
}

Once you do this, then the library will detect SplashScreen.show(this, R.style.SplashScreenTheme); successfully next time so you won't ever have to manually do this again.