Github: github.com/crazycodebo…

Installation instructions

Step 1 (Download):

Open the terminal in the project root directory and run NPM I react-native-splash-screen –save

Step 2 (Installation):

Automatic installation

Terminal run: react-native link react-native splash-screen or RNPM link react-native splash-screen

Manual Installation (Android)

  1. Add the following code to your Android /settings.gradle file:
include ':react-native-splash-screen'   
project(':react-native-splash-screen').projectDir = new File(rootProject.projectDir, '.. /node_modules/react-native-splash-screen/android')
Copy the code
  1. Add the following to your Android /app/build.gradle file :react-native splash-screen:
dependencies {
    ...
    implementation project(':react-native-splash-screen')}Copy the code
  1. Update your mainApplication. Java file as follows: line 11 is introduced
import com.facebook.react.shell.MainReactPackage;
import java.util.Arrays;
Copy the code
public class MainApplication extends Application implements ReactApplication {

    private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
        @Override
        protected boolean getUseDeveloperSupport() {
            return BuildConfig.DEBUG;
        }
        @Override
        protected List<ReactPackage> getPackages() {
            return<ReactPackage>asList(new MainReactPackage(), new SplashScreenReactPackage()); }}; @Override public ReactNativeHostgetReactNativeHost() {
        returnmReactNativeHost; }}Copy the code

Step 3 (Configuration):

Update your mainactivity. Java file as follows: third line introduced

import android.os.Bundle;
import org.devio.rn.splashscreen.SplashScreen;
Copy the code
public class MainActivity extends ReactActivity { @Override protected void onCreate(Bundle savedInstanceState) { SplashScreen.show(this); // Add the sentence super.onCreate(savedInstanceState); } / /... other code }Copy the code

Directions for use

  1. Import react-native-splash-screen into your JS file.import SplashScreen from 'react-native-splash-screen'
  2. Create a new Android \app\ SRC \main\res\layout file and create a new launch_screen.xml file in the folder as follows:
<? xml version="1.0" encoding="utf-8"? > <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/launch_screen">
</LinearLayout>
Copy the code
  1. newandroid\app\src\main\res\drawable-hdpiFolder, put the launch page image in it and name itlaunch_screen.png
  2. If you only do the above steps, your application will flash and exit, so you need to add it to the Android \app\ SRC \main\res\values\colors<color name="primary_dark">#660B0B0B</color>Do the above steps and the Android startup screen is complete

In addition:

You can also enable the app Theme transparency option to resolve the temporary blank screen caused by the theme during app startup. The steps are as follows: Open the android/app/SRC/main/res/values/styles. The XML file, add the item name = “android: windowIsTranslucent” > true < / item >, as follows:

<resources> <! -- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <! -- Customize your theme here. --> <! --> + <item name="android:windowIsTranslucent">true</item>
    </style>
</resources>
Copy the code

API

methods type optional describe
show() function false Open the startup screen (native method)
hide() function false Turn off the startup screen