zoontek / react-native-bootsplash

🚀 Show a splash screen during app startup. Hide it when you are ready.
MIT License
3.64k stars 253 forks source link

Android - init method requires an Activity type #453

Closed saperlipopette45 closed 1 year ago

saperlipopette45 commented 1 year ago

Bug summary

After a fresh install of the package, everything works great on iOS.

However, I am stuck on Android when setting the following code to the MainActivity.java file :

@Override
protected void onCreate(Bundle savedInstanceState) {
  RNBootSplash.init(this);
  super.onCreate(null);
}

Library version

4.7.1

Environment info

System:
    OS: macOS 13.0.1
    CPU: (8) arm64 Apple M1 Pro
    Memory: 110.53 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.18.1 - ~/.nvm/versions/node/v16.18.1/bin/node
    Yarn: 1.22.19 - ~/Desktop/proxi/club-visa-infinite-app/node_modules/.bin/yarn
    npm: 8.19.2 - ~/.nvm/versions/node/v16.18.1/bin/npm
    Watchman: 2023.05.01.00 - /opt/homebrew/bin/watchman
  Managers:
    CocoaPods: 1.11.3 - /opt/homebrew/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 22.1, iOS 16.1, macOS 13.0, tvOS 16.1, watchOS 9.1
    Android SDK: Not Found
  IDEs:
    Android Studio: 2021.3 AI-213.7172.25.2113.9123335
    Xcode: 14.1/14B47b - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.16.1 - /opt/homebrew/opt/openjdk@11/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 18.1.0 => 18.1.0 
    react-native: 0.70.6 => 0.70.6 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Steps to reproduce

  1. Add the library to the project
  2. Add the following dependency to app/build.gradle : implementation("androidx.core:core-splashscreen:1.0.0")
  3. Create the android/app/src/main/res/values/styles.xml as in the docs
  4. Edit the AndroidManifest.xml file as in the docs
  5. Edit the code in MainActivity.java
image

Reproducible sample code

package my.package.app;

import com.facebook.react.ReactActivity;
import com.facebook.react.ReactActivityDelegate;
import com.facebook.react.ReactRootView;
import com.swmansion.reanimated.BuildConfig;

import android.os.Bundle;
import com.zoontek.rnbootsplash.RNBootSplash;

public class MainActivity extends ReactActivity {

  /**
   * Returns the name of the main component registered from JavaScript. This is used to schedule
   * rendering of the component.
   */
  @Override
  protected String getMainComponentName() {
    return "MyApp";
  }

  /**
   * Returns the instance of the {@link ReactActivityDelegate}. There the RootView is created and
   * you can specify the renderer you wish to use - the new renderer (Fabric) or the old renderer
   * (Paper).
   */
  @Override
  protected ReactActivityDelegate createReactActivityDelegate() {
    return new MainActivityDelegate(this, getMainComponentName());
  }

  public static class MainActivityDelegate extends ReactActivityDelegate {
    public MainActivityDelegate(ReactActivity activity, String mainComponentName) {
      super(activity, mainComponentName);
    }

    @Override
    protected ReactRootView createRootView() {
      ReactRootView reactRootView = new ReactRootView(getContext());
      // If you opted-in for the New Architecture, we enable the Fabric Renderer.
      reactRootView.setIsFabric(BuildConfig.IS_NEW_ARCHITECTURE_ENABLED);
      return reactRootView;
    }

    @Override
    protected boolean isConcurrentRootEnabled() {
      // If you opted-in for the New Architecture, we enable Concurrent Root (i.e. React 18).
      // More on this on https://reactjs.org/blog/2022/03/29/react-v18.html
      return BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
      RNBootSplash.init(this);
      super.onCreate(null);
    }
  }
}
zoontek commented 1 year ago

@saperlipopette45 onCreate goes in MainActivity, not in MainActivityDelegate 😄

Move it under getMainComponentName

saperlipopette45 commented 1 year ago

@saperlipopette45 onCreate goes in MainActivity, not in MainActivityDelegate 😄

Move it under getMainComponentName

Thank you so much ! Can't believe I lost 2 hours on this ˆ_ˆ