Gathering detailed insights and metrics for react-native-splash-screen
Gathering detailed insights and metrics for react-native-splash-screen
Gathering detailed insights and metrics for react-native-splash-screen
Gathering detailed insights and metrics for react-native-splash-screen
A splash screen for react-native, hide when application loaded ,it works on iOS and Android.
npm install react-native-splash-screen
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
5,615 Stars
166 Commits
1,096 Forks
63 Watching
12 Branches
44 Contributors
Updated on 22 Nov 2024
Minified
Minified + Gzipped
Java (62.73%)
Objective-C (27.49%)
Ruby (6.52%)
JavaScript (3.26%)
Cumulative downloads
Total Downloads
Last day
-4.9%
23,192
Compared to previous day
Last week
-2.5%
120,377
Compared to previous week
Last month
3%
530,179
Compared to previous month
Last year
-1.4%
6,267,155
Compared to previous year
1
A splash screen API for react-native which can programatically hide and show the splash screen. Works on iOS and Android.
For React Native >= 0.47.0 use v3.+, for React Native < 0.47.0 use v2.1.0
Run npm i react-native-splash-screen --save
react-native link react-native-splash-screen
or rnpm link react-native-splash-screen
Android:
android/settings.gradle
file, make the following additions:1include ':react-native-splash-screen' 2project(':react-native-splash-screen').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-splash-screen/android')
:react-native-splash-screen
project as a compile-time dependency:1... 2dependencies { 3 ... 4 implementation project(':react-native-splash-screen') 5}
react-native-splash-screen
via the following changes:1// react-native-splash-screen >= 0.3.1 2import org.devio.rn.splashscreen.SplashScreenReactPackage; 3// react-native-splash-screen < 0.3.1 4import com.cboy.rn.splashscreen.SplashScreenReactPackage; 5 6public class MainApplication extends Application implements ReactApplication { 7 8 private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { 9 @Override 10 public boolean getUseDeveloperSupport() { 11 return BuildConfig.DEBUG; 12 } 13 14 @Override 15 protected List<ReactPackage> getPackages() { 16 return Arrays.<ReactPackage>asList( 17 new MainReactPackage(), 18 new SplashScreenReactPackage() //here 19 ); 20 } 21 }; 22 23 @Override 24 public ReactNativeHost getReactNativeHost() { 25 return mReactNativeHost; 26 } 27}
iOS:
cd ios
run pod install
OR
In XCode, in the project navigator, right click Libraries
➜ Add Files to [your project's name]
Go to node_modules
➜ react-native-splash-screen
and add SplashScreen.xcodeproj
In XCode, in the project navigator, select your project. Add libSplashScreen.a
to your project's Build Phases
➜ Link Binary With Libraries
To fix 'RNSplashScreen.h' file not found
, you have to select your project → Build Settings → Search Paths → Header Search Paths to add:
$(SRCROOT)/../node_modules/react-native-splash-screen/ios
Android:
Update the MainActivity.java
to use react-native-splash-screen
via the following changes:
1import android.os.Bundle; // here 2import com.facebook.react.ReactActivity; 3// react-native-splash-screen >= 0.3.1 4import org.devio.rn.splashscreen.SplashScreen; // here 5// react-native-splash-screen < 0.3.1 6import com.cboy.rn.splashscreen.SplashScreen; // here 7 8public class MainActivity extends ReactActivity { 9 @Override 10 protected void onCreate(Bundle savedInstanceState) { 11 SplashScreen.show(this); // here 12 super.onCreate(savedInstanceState); 13 } 14 // ...other code 15}
iOS:
Update AppDelegate.m
with the following additions:
1#import "AppDelegate.h" 2 3#import <React/RCTBundleURLProvider.h> 4#import <React/RCTRootView.h> 5#import "RNSplashScreen.h" // here 6 7@implementation AppDelegate 8 9- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 10{ 11 // ...other code 12 13 [RNSplashScreen show]; // here 14 // or 15 //[RNSplashScreen showSplash:@"LaunchScreen" inRootView:rootView]; 16 return YES; 17} 18 19@end 20
Import react-native-splash-screen
in your JS file.
import SplashScreen from 'react-native-splash-screen'
Create a file called launch_screen.xml
in app/src/main/res/layout
(create the layout
-folder if it doesn't exist). The contents of the file should be the following:
1<?xml version="1.0" encoding="utf-8"?> 2<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:orientation="vertical" android:layout_width="match_parent" 4 android:layout_height="match_parent"> 5 <ImageView android:layout_width="match_parent" android:layout_height="match_parent" android:src="@drawable/launch_screen" android:scaleType="centerCrop" /> 6</RelativeLayout>
Customize your launch screen by creating a launch_screen.png
-file and placing it in an appropriate drawable
-folder. Android automatically scales drawable, so you do not necessarily need to provide images for all phone densities.
You can create splash screens in the following folders:
drawable-ldpi
drawable-mdpi
drawable-hdpi
drawable-xhdpi
drawable-xxhdpi
drawable-xxxhdpi
Add a color called primary_dark
in app/src/main/res/values/colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="primary_dark">#000000</color>
</resources>
Optional steps:
If you want the splash screen to be transparent, follow these steps.
Open android/app/src/main/res/values/styles.xml
and add <item name="android:windowIsTranslucent">true</item>
to the file. It should look like this:
1<resources> 2 <!-- Base application theme. --> 3 <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 4 <!-- Customize your theme here. --> 5 <!--设置透明背景--> 6 <item name="android:windowIsTranslucent">true</item> 7 </style> 8</resources>
To learn more see examples
If you want to customize the color of the status bar when the splash screen is displayed:
Create android/app/src/main/res/values/colors.xml
and add
1<?xml version="1.0" encoding="utf-8"?> 2<resources> 3 <color name="status_bar_color"><!-- Colour of your status bar here --></color> 4</resources>
Create a style definition for this in android/app/src/main/res/values/styles.xml
:
1<?xml version="1.0" encoding="utf-8"?> 2<resources> 3 <style name="SplashScreenTheme" parent="SplashScreen_SplashTheme"> 4 <item name="colorPrimaryDark">@color/status_bar_color</item> 5 </style> 6</resources>
Change your show
method to include your custom style:
1SplashScreen.show(this, R.style.SplashScreenTheme);
Customize your splash screen via LaunchScreen.storyboard
or LaunchScreen.xib
。
Learn more to see examples
Use like so:
1import SplashScreen from 'react-native-splash-screen' 2 3export default class WelcomePage extends Component { 4 5 componentDidMount() { 6 // do stuff while splash screen is shown 7 // After having done stuff (such as async tasks) hide the splash screen 8 SplashScreen.hide(); 9 } 10}
Method | Type | Optional | Description |
---|---|---|---|
show() | function | false | Open splash screen (Native Method ) |
show(final Activity activity, final boolean fullScreen) | function | false | Open splash screen (Native Method ) |
hide() | function | false | Close splash screen |
For Jest to work you will need to mock this component. Here is an example:
// __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'); } ),
}
Add the ImageView with a scaleType in the launch_screen.xml
, e.g.:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<ImageView
android:src="@drawable/launch_screen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
>
</ImageView>
</FrameLayout>
Issues are welcome. Please add a screenshot of you bug and a code snippet. Quickest way to solve issue is to reproduce it in one of the examples.
Pull requests are welcome. If you want to change the API or do something big it is best to create an issue and discuss it first.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 10/21 approved changesets -- score normalized to 4
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
52 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn Morereact-native-pure-splash-screen
react native splash screen
expo-splash-screen
Provides a module to allow keeping the native Splash Screen visible until you choose to hide it.
@exodus/react-native-splash-screen
A splash screen for react-native, hide when application loaded ,it works on iOS and Android.
react-native-app-splash
React Native splash screen library: programmatically show/hide for Android & iOS.