react-native-splash-screen icon indicating copy to clipboard operation
react-native-splash-screen copied to clipboard

MainActivity different from documentation

Open diegoiglesias opened this issue 3 years ago • 7 comments

  • React Native version 0.70.6
  • Latest "react-native-splash-screen" version
  • Android

The code of my MainActivity.java file is different from the one in the docs:

Docs:

@Override
protected List<ReactPackage> getPackages() {
    return Arrays.<ReactPackage>asList(
            new MainReactPackage(),
    new SplashScreenReactPackage()  //here
    );
}

Mine:

@Override
protected List<ReactPackage> getPackages() {
  @SuppressWarnings("UnnecessaryLocalVariable")
  List<ReactPackage> packages = new PackageList(this).getPackages();
  // Packages that cannot be autolinked yet can be added manually here, for example:
  // packages.add(new MyReactNativePackage());
  return packages;
}

What should I do to add the SplashScreenReactPackage code?

diegoiglesias avatar Dec 31 '22 17:12 diegoiglesias

You should add below code:

@Override protected List<ReactPackage> getPackages() { @SuppressWarnings("UnnecessaryLocalVariable") List<ReactPackage> packages = new PackageList(this).getPackages(); packages.add(new SplashScreenReactPackage()); return packages; }

thanhtung0212 avatar Jan 03 '23 14:01 thanhtung0212

The solution above did not work for me, it threw an error when I run the project for android.

I'm using "react-native": "0.70.6", and "react-native-splash-screen": "^3.3.0" I only had to edit next files:

  1. settings.gradle
  2. build.gradle inside app
  3. MainActivity.java

No edits inside MainApplication.java were needed for 0.70.6

Milutin-P avatar Jan 08 '23 16:01 Milutin-P

@Milutin-P How did you change MainActivity.java? because from the version of "react-native": "0.70.6" is different from the documentation

ferrero1987 avatar Jan 18 '23 09:01 ferrero1987

@Milutin-P How did you change MainActivity.java? because from the version of "react-native": "0.70.6" is different from the documentation

In the MainActivity.java i just included import org.devio.rn.splashscreen.SplashScreen; then with the following

  @Override
  protected void onCreate(Bundle savedInstanceState){
    SplashScreen.show(this);
    super.onCreate(savedInstanceState);
  }

and it works just fine for me in "react-native": "0.71.0",

samuelhenshaw2020 avatar Jan 18 '23 10:01 samuelhenshaw2020

@ferrero1987 what @samuelhenshaw2020 wrote. I am using "react-native": "0.70.6"

...
import org.devio.rn.splashscreen.SplashScreen;

public class MainActivity extends ReactActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        SplashScreen.show(this);
        super.onCreate(savedInstanceState);
    }
...

Milutin-P avatar Jan 19 '23 10:01 Milutin-P

for me "react-native": "0.71.6", "react-native-splash-screen": "^3.3.0",

in MainActivity.java i added

import android.os.Bundle; import org.devio.rn.splashscreen.SplashScreen;

@Override protected ReactActivityDelegate createReactActivityDelegate() { SplashScreen.show(this); //here return new DefaultReactActivityDelegate( this, getMainComponentName(), // If you opted-in for the New Architecture, we enable the Fabric Renderer. DefaultNewArchitectureEntryPoint.getFabricEnabled(), // fabricEnabled // If you opted-in for the New Architecture, we enable Concurrent React (i.e. React 18). DefaultNewArchitectureEntryPoint.getConcurrentReactEnabled() // concurrentRootEnabled ); } }

walidmaouche avatar Apr 15 '23 23:04 walidmaouche

for me "react-native": "0.71.6", "react-native-splash-screen": "^3.3.0",

in MainActivity.java i added

import android.os.Bundle; import org.devio.rn.splashscreen.SplashScreen;

@Override protected ReactActivityDelegate createReactActivityDelegate() { SplashScreen.show(this); //here return new DefaultReactActivityDelegate( this, getMainComponentName(), // If you opted-in for the New Architecture, we enable the Fabric Renderer. DefaultNewArchitectureEntryPoint.getFabricEnabled(), // fabricEnabled // If you opted-in for the New Architecture, we enable Concurrent React (i.e. React 18). DefaultNewArchitectureEntryPoint.getConcurrentReactEnabled() // concurrentRootEnabled ); } }

walidmaouche avatar Apr 15 '23 23:04 walidmaouche