项目作者: lumi-software

项目描述 :
Splash screen for ios and android
高级语言: Java
项目地址: git://github.com/lumi-software/react-native-splash-screen.git
创建时间: 2020-06-12T02:37:41Z
项目社区:https://github.com/lumi-software/react-native-splash-screen

开源协议:MIT License

下载


@nghinv/react-native-splash-screen

@nghinv/react-native-splash-screen"">npm
npm

A smart splash screen for React Native apps, written in JS, oc and java for cross-platform support.
It works on iOS and Android.

Preview

react-native-splash-screen-ios
react-native-splash-screen-android

Installation

  • Use yarn
  1. yarn add @nghinv/react-native-splash-screen
  • Use npm
  1. npm install @nghinv/react-native-splash-screen --save

Installation (iOS)

  • With RN >= 0.60 run cd ios && pod install

  • With RN < 0.60 run react-native link @nghinv/react-native-splash-screen

  • delete your project’s LaunchScreen.xib

  • Drag SplashScreenResource folder to your project if you want change image, replace splash.png or add a image with your custom name

  • In AppDelegate.m

  1. ...
  2. #import "RCTSplashScreen.h" //import interface
  3. ...
  4. RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation moduleName:@"ReactNativeComponents" initialProperties:nil launchOptions:launchOptions];
  5. [RCTSplashScreen open:rootView withImageNamed:@"splash"]; // activate splashscreen, imagename from LaunchScreen.xib
  6. rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
  7. self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  8. UIViewController *rootViewController = [UIViewController new];
  9. rootViewController.view = rootView;
  10. self.window.rootViewController = rootViewController;
  11. [self.window makeKeyAndVisible];
  12. return YES;

Installation (Android)

  • Auto link with RN >= 0.60

  • Run react-native link @nghinv/react-native-splash-screen with RN <0.60

  • Add your own drawable/splash.png to android/app/src/main/res/, it is recommended to add drawable-?dpi folders that you need.

    • drawable-hdpi
    • drawable-mdpi
    • drawable-xhdpi
    • drawable-xxhdpi
    • drawable-xxxhdpi
  • in MainActivity.java

  1. ...
  2. import android.os.Bundle;
  3. import com.reactnativecomponent.splashscreen.RCTSplashScreen; //import RCTSplashScreen
  4. ...
  5. @Override
  6. protected void onCreate(Bundle savedInstanceState) {
  7. RCTSplashScreen.openSplashScreen(this); //open splashscreen
  8. super.onCreate(savedInstanceState);
  9. }
  • In android/app/**/styles.xml
  1. ...
  2. <!-- Base application theme. -->
  3. <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
  4. <!-- Customize your theme here. -->
  5. <item name="android:windowIsTranslucent">true</item>
  6. </style>
  7. ...

Usage

  1. ...
  2. import SplashScreen from '@nghinv/react-native-splash-screen';
  3. ...
  4. componentDidMount () {
  5. SplashScreen.close({
  6. animationType: SplashScreen.animationType.scale,
  7. duration: 850,
  8. delay: 500,
  9. })
  10. }
  11. ...

Method

  • close(animationType, duration, delay) close splash screen with custom animation

    • animationType: determine the type of animation. enum(animationType.none, animationType.fade, animationType.scale)
    • duration: determine the duration of animation
    • delay: determine the delay of animation