All Projects → crazycodeboy → React Native Splash Screen

crazycodeboy / React Native Splash Screen

Licence: mit
A splash screen for react-native, hide when application loaded ,it works on iOS and Android.

Programming Languages

java
68154 projects - #9 most used programming language
objective c
16641 projects - #2 most used programming language
ruby
36898 projects - #4 most used programming language
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Native Splash Screen

SplashScreen
A demo project showcasing different methods to create splash screen in Android and discusses the details in the companion Medium article.
Stars: ✭ 37 (-99.27%)
Mutual labels:  splash-screen, splashscreen
DarkModeSplashScreen
A sample app for iOS and Android written in Xamarin.Forms showing how to implement a Splash Page for Dark Mode
Stars: ✭ 28 (-99.44%)
Mutual labels:  splash-screen, splashscreen
SplashScreenExample
How to implement a Splash Screen in ReactNative
Stars: ✭ 14 (-99.72%)
Mutual labels:  splash-screen, splashscreen
Splashy
Splash screen library for Android
Stars: ✭ 112 (-97.78%)
Mutual labels:  splash-screen, splashscreen
react-native-lottie-splash-screen
⚡ Lottie splash screen for your react native app!
Stars: ✭ 124 (-97.54%)
Mutual labels:  splash-screen, splashscreen
AdaptivePlus-Android
Free forever Marketing SDK with a dashboard for in-app SplashScreen banners with built-in analytics
Stars: ✭ 16 (-99.68%)
Mutual labels:  splash-screen
react-native-boilerplate-starter-app
📱🚀A POWERFUL React Native starter kit to bootstrap the start of your mobile app development
Stars: ✭ 202 (-95.99%)
Mutual labels:  splashscreen
SplashScreen
Splash screen demo that used with Jetpack ‘SplashScreen‘ library and Android 12's Splash Screen API.
Stars: ✭ 46 (-99.09%)
Mutual labels:  splashscreen
ReactNativeStarterKits
Agiletech React Native Starter Kits
Stars: ✭ 21 (-99.58%)
Mutual labels:  splash-screen
Kotlin-Example
An example for who are all going to start learning Kotlin programming language to develop Android application.
Stars: ✭ 54 (-98.93%)
Mutual labels:  splashscreen
emacs-splash
An alternative splash screen for GNU Emacs
Stars: ✭ 59 (-98.83%)
Mutual labels:  splash-screen
splash-screen
Android library for getting a nice and simple SlashScreen into your Android app
Stars: ✭ 107 (-97.88%)
Mutual labels:  splashscreen
vue-splash
splash plugin for vue js
Stars: ✭ 120 (-97.62%)
Mutual labels:  splash-screen
LoginAndRegistrationWithSocialMedia
Created a Project to design login screen, registration screen, login with google ,slider navigation drawer,dashboard screen login with Facebook using Flutter
Stars: ✭ 82 (-98.37%)
Mutual labels:  splashscreen
AnimateViewLibrary
Developing easy to use any animation set for splash screen or any other views in your Android application. Easy to use, so you can animate your whole app just using this library
Stars: ✭ 19 (-99.62%)
Mutual labels:  splash-screen
retropiesplashscreen
Splashscreen Randomizer for Retropie!
Stars: ✭ 19 (-99.62%)
Mutual labels:  splash-screen
magikarp
[Work in Progress] Splash Screens for Android
Stars: ✭ 19 (-99.62%)
Mutual labels:  splash-screen
expo-ticket-app
💎 A React Native ticket app to start learning Expo very quickly with selected libraries 📚
Stars: ✭ 87 (-98.27%)
Mutual labels:  splashscreen
ComposeBird
Flappy Bird game
Stars: ✭ 193 (-96.17%)
Mutual labels:  splashscreen
Pwa Asset Generator
Automates PWA asset generation and image declaration. Automatically generates icon and splash screen images, favicons and mstile images. Updates manifest.json and index.html files with the generated images according to Web App Manifest specs and Apple Human Interface guidelines.
Stars: ✭ 1,787 (-64.53%)
Mutual labels:  splash-screen

react-native-splash-screen

Download PRs Welcome react-native-splash-screen release 语言 中文 License MIT 原理 解析 Flutter

A splash screen API for react-native which can programatically hide and show the splash screen. Works on iOS and Android.

Content

Changes

For React Native >= 0.47.0 use v3.+, for React Native < 0.47.0 use v2.1.0

Examples

react-native-splash-screen-Android react-native-splash-screen-iOS

Installation

First step(Download):

Run npm i react-native-splash-screen --save

Second step(Plugin Installation):

Automatic installation

react-native link react-native-splash-screen or rnpm link react-native-splash-screen

Manual installation

Android:

  1. In your android/settings.gradle file, make the following additions:
include ':react-native-splash-screen'   
project(':react-native-splash-screen').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-splash-screen/android')
  1. In your android/app/build.gradle file, add the :react-native-splash-screen project as a compile-time dependency:
...
dependencies {
    ...
    implementation project(':react-native-splash-screen')
}
  1. Update the MainApplication.java file to use react-native-splash-screen via the following changes:
// react-native-splash-screen >= 0.3.1
import org.devio.rn.splashscreen.SplashScreenReactPackage;
// react-native-splash-screen < 0.3.1
import com.cboy.rn.splashscreen.SplashScreenReactPackage;

public class MainApplication extends Application implements ReactApplication {

    private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
        @Override
        public boolean getUseDeveloperSupport() {
            return BuildConfig.DEBUG;
        }

        @Override
        protected List<ReactPackage> getPackages() {
            return Arrays.<ReactPackage>asList(
                    new MainReactPackage(),
            new SplashScreenReactPackage()  //here
            );
        }
    };

    @Override
    public ReactNativeHost getReactNativeHost() {
        return mReactNativeHost;
    }
}

iOS:

  1. cd ios
  2. run pod install

OR

  1. In XCode, in the project navigator, right click LibrariesAdd Files to [your project's name]

  2. Go to node_modulesreact-native-splash-screen and add SplashScreen.xcodeproj

  3. In XCode, in the project navigator, select your project. Add libSplashScreen.a to your project's Build PhasesLink Binary With Libraries

  4. 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

Third step(Plugin Configuration):

Android:

Update the MainActivity.java to use react-native-splash-screen via the following changes:

import android.os.Bundle; // here
import com.facebook.react.ReactActivity;
// react-native-splash-screen >= 0.3.1
import org.devio.rn.splashscreen.SplashScreen; // here
// react-native-splash-screen < 0.3.1
import com.cboy.rn.splashscreen.SplashScreen; // here

public class MainActivity extends ReactActivity {
   @Override
    protected void onCreate(Bundle savedInstanceState) {
        SplashScreen.show(this);  // here
        super.onCreate(savedInstanceState);
    }
    // ...other code
}

iOS:

Update AppDelegate.m with the following additions:

#import "AppDelegate.h"

#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import "RNSplashScreen.h"  // here

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // ...other code

    [RNSplashScreen show];  // here
    // or
    //[RNSplashScreen showSplash:@"LaunchScreen" inRootView:rootView];
    return YES;
}

@end

Getting started

Import react-native-splash-screen in your JS file.

import SplashScreen from 'react-native-splash-screen'

Android:

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:

<?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>

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:

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <!--设置透明背景-->
        <item name="android:windowIsTranslucent">true</item>
    </style>
</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

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="status_bar_color"><!-- Colour of your status bar here --></color>
</resources>

Create a style definition for this in android/app/src/main/res/values/styles.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="SplashScreenTheme" parent="SplashScreen_SplashTheme">
        <item name="colorPrimaryDark">@color/status_bar_color</item>
    </style>
</resources>

Change your show method to include your custom style:

SplashScreen.show(this, R.style.SplashScreenTheme);

iOS

Customize your splash screen via LaunchScreen.storyboard or LaunchScreen.xib

Learn more to see examples

Usage

Use like so:

import SplashScreen from 'react-native-splash-screen'

export default class WelcomePage extends Component {

    componentDidMount() {
    	// do stuff while splash screen is shown
        // After having done stuff (such as async tasks) hide the splash screen
        SplashScreen.hide();
    }
}

API

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

Testing

Jest

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'); } ),
}

Troubleshooting

Splash screen always appears stretched/distorted

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>

Contribution

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.


MIT Licensed

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].