Customize iOS Splash Screen
masterLaunchScreen.storyboard or LaunchScreen.xib within your Xcode project.repository·master·Indexed 26 days ago
https://github.com/crazycodeboy/react-native-splash-screenA React Native library (v3.3.0) that provides a programmatic API to show and hide splash screens on iOS and Android. It allows for a smoother transition from the native launch screen to the application, featuring a JavaScript API with show() and hide() methods, and detailed configuration guides for Android layout XMLs and iOS LaunchScreen storyboards.
LaunchScreen.storyboard or LaunchScreen.xib within your Xcode project.To enable the splash screen on Android, update MainActivity.java:
public class MainActivity extends ReactActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
SplashScreen.show(this); // Add this line
super.onCreate(savedInstanceState);
}
// ...other code
}Customizing the Layout:
Create a file named launch_screen.xml in your Android resources to define the splash screen layout:
<?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>Preventing White Flash (Translucent Theme):
To avoid a brief white screen during app startup, add android:windowIsTranslucent to your theme in android/app/src/main/res/values/styles.xml:
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowIsTranslucent">true</item>
</style>
</resources>SplashScreen.show(this);Follow these steps to manually link and configure the plugin for Android:
In android/settings.gradle:
include ':react-native-splash-screen'
project(':react-native-splash-screen').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-splash-screen/android')In android/app/build.gradle:
dependencies {
implementation project(':react-native-splash-screen')
}Update MainApplication.java to include SplashScreenReactPackage in your getPackages() list:
// react-native-splash-screen >= 0.3.1
import org.devio.rn.splashscreen.SplashScreenReactPackage;
// Inside getPackages()
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new SplashScreenReactPackage()
);Update MainActivity.java to show the splash screen when the activity is created:
import android.os.Bundle;
// react-native-splash-screen >= 0.3.1
import org.devio.rn.splashscreen.SplashScreen;
public class MainActivity extends ReactActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
SplashScreen.show(this);
super.onCreate(savedInstanceState);
}
}To enable the splash screen on iOS, update AppDelegate.m:
#import "AppDelegate.h"
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import "RNSplashScreen.h" // Add this line
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// ...other code
[RNSplashScreen show]; // Add this line at the very end
return YES;
}
@endCustomizing the Splash Screen:
Use LaunchScreen.storyboard or LaunchScreen.xib in Xcode to customize the visual appearance.
[RNSplashScreen show];Follow these steps for manual iOS installation:
Libraries ➜ Add Files to [your project's name].SplashScreen.xcodeproj located at node_modules/react-native-splash-screen/SplashScreen.xcodeproj.Build Phases ➜ Link Binary With Libraries and add libSplashScreen.a.'SplashScreen.h' file not found:
If you encounter this error, add the following to your Header Search Paths in Build Settings:
$(SRCROOT)/../node_modules/react-native-splash-screen/iosOnce the storyboard and image set are created, link them together:
LaunchScreen.storyboard in Xcode.ImageView to the view hierarchy.ImageView as needed.ImageView to the LaunchScreen image set you created.You can link the library automatically using the React Native CLI:
react-native link react-native-splash-screenOr using rnpm:
rnpm link react-native-splash-screencd ios
run pod installAlternatively, via Xcode:
Libraries ➜ Add Files to [your project's name] and add node_modules/react-native-splash-screen/ios/SplashScreen.xcodeproj.libSplashScreen.a to your project's Build Phases ➜ Link Binary With Libraries.'RNSplashScreen.h' file not found, add $(SRCROOT)/../node_modules/react-native-splash-screen/ios to your project's Build Settings ➜ Search Paths ➜ Header Search Paths.Update AppDelegate.m:
#import "RNSplashScreen.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// ... other code
[RNSplashScreen show];
return YES;
}
@endSince React Native projects do not include a LaunchScreen.storyboard by default, you must create one manually in Xcode to support splash screens on iOS.
LaunchScreen.storyboard).To provide images for your splash screen, you need to create a dedicated Image Set in your assets catalog:
Images.xcassets in Xcode.LaunchScreen.To ensure iOS uses your new storyboard as the app launch screen, you must register it in your project settings:
LaunchScreen (or your specific storyboard filename) from the dropdown.Create app/src/main/res/layout/launch_screen.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView android:layout_width="match_parent" android:layout_height="match_parent" android:src="@drawable/launch_screen" android:scaleType="centerCrop" />
</RelativeLayout>Place your splash image (e.g., launch_screen.png) in the appropriate drawable folders (e.g., drawable-hdpi, drawable-xhdpi, etc.).
In android/app/src/main/res/values/styles.xml, add:
<item name="android:windowIsTranslucent">true</item>Add a color to app/src/main/res/values/colors.xml:
<resources>
<color name="status_bar_color">#YOUR_COLOR_HERE</color>
</resources>And define a style in styles.xml:
<style name="SplashScreenTheme" parent="SplashScreen_SplashTheme">
<item name="colorPrimaryDark">@color/status_bar_color</item>
</style>Then call SplashScreen.show(this, R.style.SplashScreenTheme); in MainActivity.java.