A splash screen API for React Native that provides programmatic control over splash screen visibility on iOS and Android platforms.
npx @tessl/cli install tessl/npm-react-native-splash-screen@3.3.0React Native Splash Screen provides programmatic control over native splash screens on iOS and Android platforms. It allows developers to show and hide splash screens dynamically during app initialization and loading processes.
npm install react-native-splash-screenimport SplashScreen from 'react-native-splash-screen';CommonJS:
const SplashScreen = require('react-native-splash-screen');import React, { Component } from 'react';
import SplashScreen from 'react-native-splash-screen';
export default class App extends Component {
componentDidMount() {
// Hide splash screen when app has loaded
// This is the most common usage pattern
SplashScreen.hide();
}
showSplashAgain = () => {
// Show splash screen programmatically
SplashScreen.show();
// Hide it after some time
setTimeout(() => {
SplashScreen.hide();
}, 2000);
};
render() {
return (
// Your app content
);
}
}Displays the native splash screen programmatically.
/**
* Shows the splash screen
* Displays native splash screen with platform-specific configuration
*/
SplashScreen.show(): void;Usage:
import SplashScreen from 'react-native-splash-screen';
// Show splash screen during async operations
const performAsyncOperation = async () => {
SplashScreen.show();
try {
await someAsyncTask();
} finally {
SplashScreen.hide();
}
};Hides/dismisses the currently displayed splash screen.
/**
* Hides the splash screen
* Dismisses the currently displayed splash screen
*/
SplashScreen.hide(): void;Shows a custom splash screen with specific configuration for iOS platform.
/**
* Shows a custom splash screen from a specific storyboard or XIB file
* iOS-specific method for advanced splash screen control
* @param splashScreen - Name of the splash screen file (LaunchScreen, etc.)
* @param rootView - Root view to display the splash screen in
*/
SplashScreen.showSplash(splashScreen: string, rootView: any): void;Usage:
import SplashScreen from 'react-native-splash-screen';
// Typical usage in componentDidMount or useEffect
componentDidMount() {
// Perform app initialization
this.initializeApp().then(() => {
// Hide splash screen when ready
SplashScreen.hide();
});
}Usage (iOS showSplash):
import SplashScreen from 'react-native-splash-screen';
import { View } from 'react-native';
// iOS-specific custom splash screen
class App extends Component {
componentDidMount() {
// Show custom splash screen with specific storyboard
SplashScreen.showSplash("LaunchScreen", this.rootView);
// Later hide it
setTimeout(() => {
SplashScreen.hide();
}, 2000);
}
render() {
return (
<View ref={ref => this.rootView = ref}>
{/* App content */}
</View>
);
}
}declare module "react-native-splash-screen" {
export default class SplashScreen {
/**
* Shows the splash screen
*/
static show(): void;
/**
* Hides the splash screen
*/
static hide(): void;
/**
* Shows a custom splash screen (iOS only)
* @param splashScreen - Name of the splash screen file
* @param rootView - Root view to display the splash screen in
*/
static showSplash(splashScreen: string, rootView: any): void;
}
}The library includes built-in error handling:
Beyond npm installation, platform-specific setup is required:
Android Setup:
android/settings.gradleandroid/app/build.gradle dependenciesMainApplication.java to include SplashScreenReactPackageMainActivity.java to call SplashScreen.show(this) in onCreatelaunch_screen.xml layout file in app/src/main/res/layoutiOS Setup:
pod install) or manual Xcode integrationAppDelegate.m to import RNSplashScreen.h and call [RNSplashScreen show]showSplash:inRootView: methodFor Jest testing, mock the module:
// __mocks__/react-native-splash-screen.js
export default {
show: jest.fn().mockImplementation(() => {
console.log('show splash screen');
}),
hide: jest.fn().mockImplementation(() => {
console.log('hide splash screen');
}),
};