mehcode / rn-splash-screen

A JavaScript-controlled splash-screen for React Native designed to be run directly after the native splash-screen.
MIT License
350 stars 95 forks source link

Problem on adding on MainActivity (Android) #18

Closed Okipa closed 7 years ago

Okipa commented 7 years ago

Hi there, I have no problem to use your package on iOS but on Android, I managed to show a native splash screen on the app load. But on the final step of your documentation, when I try to plug your package in the MainActivity.java file, in order to get control of the splash screen display duration, I have the following error :

error: cannot find symbol
      protected void onCreate(Bundle savedInstanceState) {

Here is my MainActivity.java file :

package com.reactnativetest;

import com.facebook.react.ReactActivity;
import com.mehcode.reactnative.splashscreen.SplashScreen;

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 "reactNativeTest";
    }

    @Override
      protected void onCreate(Bundle savedInstanceState) {
          // Show the js-controlled splash screen
          SplashScreen.show(this);

          // After react is initialized; set our background color (override splash screen theme)
          getReactNativeHost().getReactInstanceManager().addReactInstanceEventListener(new ReactInstanceManager.ReactInstanceEventListener() {
              @Override
              public void onReactContextInitialized(ReactContext context) {
                  // Hide the native splash screen
                  getWindow().getDecorView().setBackgroundColor(Color.WHITE);
              }
          });

          super.onCreate(savedInstanceState);
      }

}

What am I doing wrong here ?

ashwoodman commented 7 years ago

I think you just need to import Bundle, using:

import android.os.Bundle;

See the example here:

https://github.com/mehcode/rn-splash-screen/blob/master/example/android/app/src/main/java/com/mehcode/reactnative/splashscreen/example/MainActivity.java

Okipa commented 7 years ago

Nice, thanx for your help, I'm not very at ease yet with android.