Я изо всех сил пытался убрать эффект затухания до того, как мой первый реагирующий нативный интерфейс появился на экране, но до сих пор я его не получал.
Я пробовал с этим уроком: https://android.jlelse.eu/right-way-to-create-splash-screen-on-android-e7f1709ba154, но не работает.
Я также пытался добавить SplashActivity, но он не работает.
Это моя основная активность
package com.cv;
import android.os.Bundle;
import com.facebook.react.ReactActivity;
import org.devio.rn.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 "CV";
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SplashScreen.show(this, false); // here
}
}
MainApplication
package com.cv;
import android.app.Application;
import com.facebook.react.ReactApplication;
import org.devio.rn.splashscreen.SplashScreenReactPackage;
import com.oblador.vectoricons.VectorIconsPackage;
import com.horcrux.svg.SvgPackage;
import com.github.wuxudong.rncharts.MPAndroidChartPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;
import java.util.Arrays;
import java.util.List;
public class MainApplication extends Application implements ReactApplication {
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new SplashScreenReactPackage(),
new VectorIconsPackage(),
new SvgPackage(),
new MPAndroidChartPackage()
);
}
@Override
protected String getJSMainModuleName() {
return "index";
}
};
@Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
@Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
}
}
AndroidManifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cv">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<application
android:label="@string/app_name"
android:icon="@drawable/launch_screen"
android:allowBackup="true"
android:theme="@style/AppTheme"
android:supportsRtl="true"
>
<activity
android:name=".SplashActivity"
android:theme="@style/SplashTheme"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.cv.MainActivity" android:screenOrientation="portrait" />
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
</manifest>
И это мое имя пакета SplashActivity
package com.cv;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
public class SplashActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
Intent intent = new Intent(this, com.cv.MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(intent);
overridePendingTransition(0, 0);
finish();
}
}
правильно в build.gradle (внутри приложения), манифесте ифайлы классов.
Я использовал эту команду для запуска приложения:
react-native run-android
и
react-native run-android --appId com.cv --main-activity SplashActivity
Вывод:
BUILD SUCCESSFUL in 37s
108 actionable tasks: 40 executed, 68 up-to-date
Running /Users/xxxxxxx/Library/Android/sdk//platform-tools/adb -s CB5A1Z9N9S reverse tcp:8081 tcp:8081
Starting the app on CB5A1Z9N9S (/Users/xxxxxxx/Library/Android/sdk//platform-tools/adb -s CB5A1Z9N9S shell am start -n com.cv/com.cv.SplashActivity)...
Starting: Intent { cmp=com.cv/.SplashActivity }
Но когда приложение открывается, показывает всплеск и внезапно закрывается, но в Logcat я получил:
08-26 00:17:03.414 27240-27240/? I/art: Late-enabling -Xcheck:jni
08-26 00:17:03.479 27240-27240/com.cv W/ResourceType: Found multiple library tables, ignoring...
08-26 00:17:03.549 27240-27240/com.cv W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
08-26 00:17:03.569 27240-27240/com.cv I/Timeline: Timeline: Activity_launch_request id:com.cv time:38049157
08-26 00:17:03.613 27240-27240/com.cv D/AndroidRuntime: Shutting down VM
08-26 00:17:03.615 27240-27240/com.cv E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.cv, PID: 27240
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.cv/com.cv.MainActivity}: java.lang.ClassCastException: android.app.Application cannot be cast to com.facebook.react.ReactApplication
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2442)
at android.app.ActivityThread.access$800(ActivityThread.java:156)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1351)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:211)
at android.app.ActivityThread.main(ActivityThread.java:5389)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815)
Caused by: java.lang.ClassCastException: android.app.Application cannot be cast to com.facebook.react.ReactApplication
at com.facebook.react.ReactActivityDelegate.getReactNativeHost(ReactActivityDelegate.java:71)
at com.facebook.react.ReactActivityDelegate.loadApp(ReactActivityDelegate.java:91)
at com.facebook.react.ReactActivityDelegate.onCreate(ReactActivityDelegate.java:80)
at com.facebook.react.ReactActivity.onCreate(ReactActivity.java:52)
at com.cv.MainActivity.onCreate(MainActivity.java:20)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2332)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2442)
at android.app.ActivityThread.access$800(ActivityThread.java:156)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1351)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:211)
at android.app.ActivityThread.main(ActivityThread.java:5389)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815)
08-26 00:17:07.542 27240-27240/? I/Process: Sending signal. PID: 27240 SIG: 9
В данный момент я не знаю, что именно делать.Любая идея?.Спасибо.
Зависимости моего приложения:
"native-base": "^2.7.2",
"react": "16.4.1",
"react-native": "0.56.0",
"react-native-animate-number": "^0.1.2",
"react-native-charts-wrapper": "^0.4.3",
"react-native-splash-screen": "^3.1.1",
"react-native-svg": "^6.5.1",
"react-native-timeline-listview": "^0.2.3",
"react-native-timer": "^1.3.4",
"react-native-vector-icons": "^5.0.0",
"victory-native": "^30.1.0"
Узел: 8.11.2 npm: 6.1.0 ОС: Mac OS Sierra Android Studio: 3.1.3