Skip to content

Instantly share code, notes, and snippets.

@eightyfive
Last active January 14, 2021 15:27
Show Gist options
  • Save eightyfive/c7acfd062a46ec450ff88ece90d27dab to your computer and use it in GitHub Desktop.
Save eightyfive/c7acfd062a46ec450ff88ece90d27dab to your computer and use it in GitHub Desktop.
Android react-native-splash-screen setup

Steps

  1. $ yarn add react-native-splash-screen
  2. $ cd ios/ && pod install && cd ..
  3. $ npx yown @eightyfive/react-native-splash-screen
  4. Rename yourapp folder to your project name
  5. Rename package com.yourapp in Java files
  6. Create android/app/src/main/res/drawable-hdpi/logo.png file (1024x1024, transparent background)

Warning

Only compatible with wix/react-native-navigation Android applications.

@@ -15,13 +15,23 @@
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:launchMode="singleTask"
- android:windowSoftInputMode="adjustResize">
+ android:windowSoftInputMode="adjustResize"
+ android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
+ <activity
+ android:name=".SplashActivity"
+ android:theme="@style/SplashTheme"
+ android:label="@string/app_name">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
</application>
</manifest>
package com.yourapp;
+import android.os.Bundle;
+import org.devio.rn.splashscreen.SplashScreen;
+
import com.reactnativenavigation.NavigationActivity;
public class MainActivity extends NavigationActivity {
-
-
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ SplashScreen.show(this);
+ super.onCreate(savedInstanceState);
+ }
}
package com.yourapp;
import android.content.Intent;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
public class SplashActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
}
}
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/primary_dark" />
</shape>
<?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/background"
android:gravity="center">
<ImageView
android:src="@drawable/logo"
android:layout_width="200dp"
android:layout_height="200dp" />
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="primary_dark">#0039cb</color>
</resources>
@@ -6,4 +6,8 @@
<item name="android:textColor">#000000</item>
</style>
+ <style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
+ <item name="android:windowBackground">@drawable/background</item>
+ </style>
+
</resources>
{
"keywords": ["react-native-splash-screen", "react-native", "react-native-navigation"]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment