react-native-startup-splash
v0.3.6
Published
A simple and efficient React Native library for showing a splash during application startup
Readme
react-native-startup-splash
A simple and efficient React Native library for showing a splash during application startup
Table of Contents
Tested with the following versions of React-Native
- 0.76.5 ✅
- 0.80.0 ✅
Installation
npm install react-native-startup-splash --saveGetting started
Android
- Define color resources in the
android/app/src/main/res/values/colors.xml
<resources>
<color name="startup_splash_background_color">#001F54</color>
</resources>- Create a theme called
StartupSplashThemein theandroid/app/src/main/res/values/styles.xmlfile
<resources>
...
<style name="StartupSplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">@color/startup_splash_background_color</item>
</style>
</resources>- Add
android:theme="@style/StartupSplashTheme"to theapplicationtag in theAndroidManifest.xml
<application
...
android:theme="@style/StartupSplashTheme"
...>- Add new file
startup_splash.xmlto theandroid/app/src/main/res/layoutfolder. Here's an example of what thestartup_splash.xmlcontent might look like
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/startup_splash_background_color">
<TextView
android:id="@+id/centered_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Hello, react-native-startup-splash!"
android:textColor="#FFFFFF"
android:textSize="18sp" />
</RelativeLayout>- Override the
onCreatefunction in theMainActivity.ktfile
// ...
import android.os.Bundle // <--
import com.dzmitry.klokau.rn.startupsplash.StartupSplashManager // <--
class MainActivity : ReactActivity() {
// ...
override fun onCreate(savedInstanceState: Bundle?) {
setTheme(R.style.AppTheme) // <--
super.onCreate(savedInstanceState)
StartupSplashManager.show(this) // <--
}
}iOS
Customize your storyboard file
ios/<YourProjectName>/LaunchScreen.storyboard. example fileAdd
StartupSplashManager.showStartupSplash()just before the call tofactory.startReactNativein theios/<YourProjectName>/AppDelegate.swift
import StartupSplash // <--
...
class AppDelegate: UIResponder, UIApplicationDelegate {
...
func application(...) -> Bool {
...
StartupSplashManager.showStartupSplash() // <--
factory.startReactNative..
...
}
}If you are using Objective-C++ AppDelegate file (AppDelegate.mm):
- Create StartupSplashBridge.swift (accept the creation of bridging header file)
import Foundation
import StartupSplash
@objc public class StartupSplashBridge: NSObject {
@objc public static func showStartupSplash() {
StartupSplashManager.showStartupSplash()
}
}- In your AppDelegate.mm file
//...
#import "YourProjectName-Swift.h"
//...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// ...
bool didLaunchFinish = [super application:application didFinishLaunchingWithOptions:launchOptions];
NSLog(@"Show startup splash");
[StartupSplashBridge showStartupSplash];
return didLaunchFinish;
}
// ...
Usage
Use like so:
import { useEffect } from 'react';
import StartupSplash from 'react-native-startup-splash'; // <--
// ...
useEffect(() => {
setTimeout(() => {
StartupSplash.hide(); // <--
}, 3000);
}, []);Contributing
License
This project is licensed under the MIT License
