简体   繁体   English

React Native Android编程:从MainActivity.java中的两个库扩展

[英]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 : 我遵循了react-native-splash-screen的配置指南,最终遇到了以下说明

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 . 我的问题是我们当前的源代码已经从react-native-navigationSplashActivity 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. 我主要来自Javascript编程背景。

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. 还有其他资源,但是我正在寻找可以从react-native编程经验的角度回答的人的答案,因为我很少接触Java或本机Android开发。

Looking at the Source Code of React's SplashActivity , there isn't much going on. 查看React的SplashActivity的源代码,没有太多事情发生。 Could you not simply let MainActivity extend ReactActivity and manually mix in the code for React's SplashActivity ? 您是否可以简单地让MainActivity扩展ReactActivity并手动混合React的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. 我知道这不是一个理想的解决方案,尤其是在React的SplashActivity的实现可能更改的情况下,但是,这似乎是目前唯一可用的选项。

You could create an issue on ReactNative's Github asking that the SplashActivity code be plugin-able. 您可以在ReactNative's Github上创建一个问题,要求SplashActivity代码可插入。

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 ). react-native-navigation SplashActivity的主要目标是提供一种显示初始屏幕的简单方法(通过实现createSplashLayout()getSplashLayout() ,请参见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. 如果您在react-native-splash-screen不需要特别的功能,我建议您使用SplashActivity ,因为目前还没有任何方法可以使它们一起工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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