简体   繁体   中英

React Native Android Programming: Extending from two libraries in MainActivity.java

I was following the configuration guide for react-native-splash-screen and eventually came across the following instruction :

import android.os.Bundle;
import com.facebook.react.ReactActivity;
import org.devio.rn.splashscreen.SplashScreen;

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

My problem is our current source code already extends from react-native-navigation 's SplashActivity . I'm aware that I can't extend a class from two or more superclasses. How do I reconcile this need? I come from primarily a Javascript programming background.

import com.reactnativenavigation.controllers.SplashActivity;

public class MainActivity extends SplashActivity {...}

There are other resources about this, but I'm looking for an answer from someone who can answer from a standpoint of a react-native programming experience since I have minimal exposure to Java or native Android development.

Looking at the Source Code of React's SplashActivity , there isn't much going on. Could you not simply let MainActivity extend ReactActivity and manually mix in the code for React's SplashActivity ?

I am aware that this is not an ideal solution, especially in case the implementation of React's SplashActivity may change, however, this seems to be the only option available at the moment.

You could create an issue on ReactNative's Github asking that the SplashActivity code be plugin-able.

The main goal of react-native-navigation SplashActivity is to provide an easy way to show a splash screen (by implementing createSplashLayout() or getSplashLayout() , See https://wix.github.io/react-native-navigation/#/android-specific-use-cases?id=splash-screen ). If you don't specifically need a feature in react-native-splash-screen I would recommend using the SplashActivity as I don't see any way to make them work together for now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM