如何使用react-native-navigation v2添加反应本机启动画面

时间:2018-11-03 14:01:54

标签: android-studio react-native splash-screen react-native-navigation react-native-navigation-v2

当我遵循react-native-navigation v2的初始设置的步骤6时,我在项目中使用react-native-navigation v2

然后由我在 MainActivity.java

中进行以下更改
-import com.facebook.react.ReactActivity;
+import com.reactnativenavigation.NavigationActivity;

-public class MainActivity extends ReactActivity { 
+public class MainActivity extends NavigationActivity {
-    @Override
-    protected String getMainComponentName() {
-        return "yourproject";
-    }
}

当我按照react-native-splash-screen中的初始设置步骤进行操作

 import android.os.Bundle; // here 
import com.facebook.react.ReactActivity;
// react-native-splash-screen >= 0.3.1 
import org.devio.rn.splashscreen.SplashScreen; // here 
// react-native-splash-screen < 0.3.1 
import com.cboy.rn.splashscreen.SplashScreen; // here 

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

然后发生冲突,因为 MainActivity 现在已扩展 NavigationActivity ,而不是 ReactActivity ,并且要遵循我需要覆盖 ReactActivity 的react-native-splash-screen的初始设置,现在我应该怎么做,以添加带有react-native-splash-screen的react-native-splash-screen导航v2?

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,并像这样解决了它:

import com.reactnativenavigation.NavigationActivity;
import org.devio.rn.splashscreen.SplashScreen;
import android.os.Bundle;

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