Giter Site home page Giter Site logo

react-native-splashscreen's Introduction

React Native SplashScreen (remobile)

A splashscreen for react-native, hide when application loaded

Installation

npm install @remobile/react-native-splashscreen --save

Installation (iOS)

  • Drag RCTSplashScreen.xcodeproj to your project on Xcode.

  • Click on your main project file (the one that represents the .xcodeproj) select Build Phases and drag libRCTSplashScreen.a from the Products folder inside the RCTSplashScreen.xcodeproj.

  • In AppDelegate.m

...
#import "RCTSplashScreen.h" //<--- import
...
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                      moduleName:@"KitchenSink"
                                               initialProperties:nil
                                                   launchOptions:launchOptions];
  [RCTSplashScreen show:rootView]; //<--- add show SplashScreen

  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  UIViewController *rootViewController = [[UIViewController alloc] init];
  rootViewController.view = rootView;
  self.window.rootViewController = rootViewController;
  [self.window makeKeyAndVisible];
  return YES;

Installation (Android)

...
include ':react-native-splashscreen'
project(':react-native-splashscreen').projectDir = new File(settingsDir, '../node_modules/@remobile/react-native-splashscreen/android')
  • In android/app/build.gradle
...
dependencies {
    ...
    compile project(':react-native-splashscreen')
}
  • register module (in MainApplication.java)
......
import com.remobile.splashscreen.RCTSplashScreenPackage;  // <--- import

......

@Override
protected List<ReactPackage> getPackages() {
   ......
   new RCTSplashScreenPackage(MainActivity.activity, true),            // <------ add here [the seconde params is translucent]
   ......
}
  • register module (in MainActivity.java)
public class MainActivity extends ReactActivity {
    public static Activity activity;           // <------ add here
    ......
    @Override
    protected String getMainComponentName() {
        activity = this;           // <------ add here
        ......
    }
}

Screencasts

gif

Usage

Example

'use strict';
var React = require('react');
var ReactNative = require('react-native');
var {
    AppRegistry,
    View,
    Text,
} = ReactNative;
var SplashScreen = require('@remobile/react-native-splashscreen');

var KitchenSink = React.createClass({
    componentDidMount: function() {
        SplashScreen.hide();
    },
    render() {
        return(
            <View>
                <Text>
                    fangyunjiang is a good developer!
                </Text>
            </View>
        );
    }
});

AppRegistry.registerComponent('KitchenSink', () => KitchenSink);

constants

  • translucent is translucent enable

methods

  • hide() hide SplashScreen

genarate splash with ffmpeg

  • you must install ffmpeg first
#!/bin/bash

src="${1-./img/splash.png}"

ffmpeg -i ${src} -s 640x1136 ../ios/CardC/splash/Default-568h@2x~iphone.png -y
ffmpeg -i ${src} -s 750x1334 ../ios/CardC/splash/Default-667h.png -y
ffmpeg -i ${src} -s 1242x2208 ../ios/CardC/splash/Default-736h.png -y
ffmpeg -i ${src} -s 640x960 ../ios/CardC/splash/Default@2x~iphone.png -y
ffmpeg -i ${src} -s 320x480 ../ios/CardC/splash/Default~iphone.png -y
ffmpeg -i ${src} -s 320x568 ../ios/CardC/splash/splash.png -y
mkdir -p ../android/app/src/main/res/drawable
cp ../ios/CardC/splash/splash.png ../android/app/src/main/res/drawable/splash.png

see detail use

the best way use SplashScreen in splash.js in example

react-native-splashscreen's People

Contributors

jrichardlai avatar sky42550564 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-splashscreen's Issues

It will cause crash on Android release version

It works fine on debug version with emulator/device, but the release version will crash on device with following log

Activity com.diary.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{42bda540 V.E..... R.....ID 0,0-720,1280} that was originally added here
                                                  android.view.WindowLeaked: Activity com.diary.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{42bda540 V.E..... R.....ID 0,0-720,1280} that was originally added here
                                                      at android.view.ViewRootImpl.<init>(ViewRootImpl.java:454)
                                                      at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:258)
                                                      at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:73)
                                                      at android.app.Dialog.show(Dialog.java:287)
                                                      at com.remobile.splashscreen.RCTSplashScreen$3.run(RCTSplashScreen.java:129)
                                                      at android.os.Handler.handleCallback(Handler.java:730)
                                                      at android.os.Handler.dispatchMessage(Handler.java:92)
                                                      at android.os.Looper.loop(Looper.java:137)
                                                      at android.app.ActivityThread.main(ActivityThread.java:5493)
                                                      at java.lang.reflect.Method.invokeNative(Native Method)
                                                      at java.lang.reflect.Method.invoke(Method.java:525)
                                                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1209)
                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1025)
                                                      at dalvik.system.NativeStart.main(Native Method)

Environment: Windows + Android. RN 0.17

can not understand with Installation (Android)

where should I put

include ':react-native-splashscreen'
project(':react-native-splashscreen').projectDir = new File(rootProject.projectDir, '../node_modules/@remobile/react-native-splashscreen/android')

in android/app/build.gradle?

react-native start

EPERM: operation not permitted, lstat '..\node_modules@remobile\react-native-splashscreen\android\build\intermediates\packaged_res\debug\drawable'

Android crash on load splash screen

Hi
I get this error on android (RN version 0.30.0)
screenshot 2016-10-29 23 44 38

This happens because I invoke the call to

new RCTSplashScreenPackage(MainActivity.activity)

before calling

    @Override
    protected String getMainComponentName() {
        activity = this;
        return "app";
    }

so MainActivity.activity is null.

Anyone experiencing this as well?

Projects after converting to RN v0.29 don't compile any more

After implementing app migration steps with MainApplication.java and all that (as indicated in breaking changes for release 0.29) I now get compile error when running react-native build-android:

/MainApplication.java:35: error: incompatible types: cannot be converted to Activity
new RCTSplashScreenPackage(this),
^
My MainApplication.java after performing the migration looks like this:

package com.myreddoor;

import android.app.Application;
import android.util.Log;

import com.facebook.react.ReactApplication;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;

import com.BV.LinearGradient.LinearGradientPackage;
import com.remobile.splashscreen.*;
import android.app.Activity;
import com.facebook.react.ReactActivity;
import io.mezon.rnslider.RNSliderPackage;
import com.eguma.barcodescanner.BarcodeScannerPackage;

import java.util.Arrays;
import java.util.List;

public class MainApplication extends Application implements ReactApplication {

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

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
          new LinearGradientPackage(),
          new RCTSplashScreenPackage(this),
          new RNSliderPackage(),
          new BarcodeScannerPackage()
      );
    }
  };

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

Obviously RCTSplashScreenPackage excepts an instance of Activity type, hence the error.
What should the package instantiation be after upgrading to RN v0.29?
It would also be nice to update the implementation steps. They are very old.

[Android] change image -> npm install -> changes gone

Hi,
on Android, how would I put my splash image into my React Native project itself? The problem with the current solution is that it's stored in the node_modules folder which means that every time I call rm -rf node_modules && npm install, I have to change splash.png again.
Thanks!

Android: Delay between native splash screen and the artificial splash screen

I noticed on Android there is a sub-second time delay between the native splash screen image and the time it takes to load the react-native-splashscreen's splash image. So for instance the default app background color is white so there will be a white screen shown in between the launching process of the app until SplashScreen.hide() is called. Is there a way to fix this?

Multiple resolutions images

As I saw, that use only one image for all resolutions. The android way - there is many images for all resolutions. Does that plugin can make that or not? Does auto detect resolution and set image for it?

SplashScreen.hide(); Not Recognized

My simulator is saying that it doesn't know what SplashScreen.hide(); is, and is saying SplashScreen = Undefined (can perform .hide() of undefined). I followed your installation instructions as well - would love assistance if possible! Also, the instructions weren't very clear on replacing the splash.png. Where exactly is it? Do I rename the replacement file the same thing?

Problem publishing app to App Store

When trying to publish the app to App Store, I find the following error:

iTunes Store operation failed.
Your binary is not optimized for iPhone 5 - New iPhone apps and app updates submitted must support the 4-inch display on iPhone 5 and must include a launch image referenced in the Info.plist under UILaunchImages with a UILaunchImageSize value set to {320, 568}. Launch images must be PNG files and located at the top-level of your bundle, or provided within each .lproj folder if you localize your launch images. Learn more about iPhone 5 support and app launch images by reviewing the 'iOS Human Interface Guidelines' at https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/IconsImages/IconsImages.html#//apple_ref/doc/uid/TP40006556-CH14-SW5 and the 'iOS App Programming Guide' at https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/App-RelatedResources/App-RelatedResources.html#//apple_ref/doc/uid/TP40007072-CH6-SW12.

It seems to me that is related to the way the library is installed in our project. Even though when I test on iPhone 5 everything works as usual, the problem occurs. When I remove the library and build Launch Images the standard way, the build works.

If this is a problem that occurs only with our setup, please close this issue.

How to get a landscape view of splash screen

Hi,
I am Using you module in my application.
I need a landscape view of the splash screen
Is it possible to convert to landscape using your module if yes please help me how to do this.

Not working on iOS

Hi,
The splash screen works great on Android, but on iOS I can still see the old React Native splash.

I did everything as documented.

给你提个需求

能否增加两个需求:
1、 启动界面异步动态加载新图片,首次显示默认图片
2、 加载的图片本地可以缓存,下载代替默认图片

很少写死了,又不想频繁更新app

In Crashlytics, I am seeing "NullPointerException" issue

StackTrace from Crashlytics is as follows :

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.view.ContextThemeWrapper.getResources()' on a null object reference
at com.remobile.splashscreen.RCTSplashScreen.getSplashId(RCTSplashScreen.java:95)
at com.remobile.splashscreen.RCTSplashScreen.showSplashScreen(RCTSplashScreen.java:103)
at com.remobile.splashscreen.RCTSplashScreen.(RCTSplashScreen.java:39)
at com.remobile.splashscreen.RCTSplashScreenPackage.createNativeModules(RCTSplashScreenPackage.java:28)
at com.facebook.react.NativeModuleRegistryBuilder.processPackage(NativeModuleRegistryBuilder.java:106)
at com.facebook.react.ReactInstanceManager.processPackage(ReactInstanceManager.java:1050)
at com.facebook.react.ReactInstanceManager.processPackages(ReactInstanceManager.java:1021)
at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:959)
at com.facebook.react.ReactInstanceManager.access$600(ReactInstanceManager.java:109)
at com.facebook.react.ReactInstanceManager$4.run(ReactInstanceManager.java:802)
at java.lang.Thread.run(Thread.java:760)

snip20181025_1

'RCTSplashScreen.h' file not found

Installed and linked as per the comments given in readme file but still getting this issue in iOS. Can anyone help me out???

React Native: 0.59.5
react-native-splashscreen: 1.0.8
OS: iOS
Versions: Mojave

splashsceen not work

I fllow you step to config the splashscreen ,but it not work, it has ios version limit?

Android compilation problem

Hello,
i'm having issues with Android - the compilation fails with this error:

A problem occurred evaluating project ':react-native-splashscreen'.
> Project with path ':react-native-cordova' could not be found in project ':react-native-splashscreen'.

If i remove compile project(':react-native-cordova') from the module's own build.gradle everything works.

Android configuration

in the readme in the android installation part i can see this. where do i add these lines

...
include ':react-native-splashscreen'
project(':react-native-splashscreen').projectDir = new File(settingsDir, '../node_modules/@remobile/react-native-splashscreen/android')

please clarify.

RCT namespace is reserved.

The convention on iOS is to use two or three-letter prefixes as global namespaces to prevent collisions between projects.

React Native uses the RCT prefix for all its classes so that we won't conflict with classes in other libraries or plugins.

If we were to ever introduce an RCTSplashScreen class of our own, it would break your plugin. Perhaps it would be better to call your class RNSplashScreen, or something else?

安卓build失败

Hi, 亲:
我在安卓下的报错信息如下:
/Users/ruanjiawei/workingspace/aurora-react-native/android/app/src/main/java/com/aurorarn/MainActivity.java:6: 错误: 找不到符号
public static Activity activity;
^
符号: 类 Activity
位置: 类 MainActivity
1 个错误
:app:compileDebugJavaWithJavac FAILED

FAILURE: Build failed with an exception.

请问这怎么修改?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.