Coder Social home page Coder Social logo

crazycodeboy / react-native-splash-screen Goto Github PK

View Code? Open in Web Editor NEW
5.6K 61.0 1.1K 3.82 MB

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

License: MIT License

JavaScript 3.26% Java 62.73% Objective-C 27.49% Ruby 6.52%
react-native splash-screen android splashscreen ios react-native-splashscreen launchimage

react-native-splash-screen's Introduction

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

react-native-splash-screen's People

Contributors

ahadc avatar askell avatar christianchown avatar christophermark avatar crazycodeboy avatar danieloprado avatar deadcoder0904 avatar dependabot[bot] avatar dluksza avatar donni106 avatar esco avatar f111fei avatar fenderrex avatar filipposarzana avatar gamingumar avatar haikyuu avatar ishigamii avatar kesha-antonov avatar puti94 avatar radko93 avatar rodolfosilva avatar shhzdmrz avatar stevepotter avatar sudharakap avatar taranda avatar vitorreis avatar wcandillon avatar xchunzhao avatar xiongcaichang avatar yuhj86 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  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

react-native-splash-screen's Issues

specified for property 'assetsDir' does not exist.

Well, I did every step from the readme and ain't working.
What can I do to solve it?

Best Regars

:react-native-splash-screen:processReleaseResources FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    A problem was found with the configuration of task ':react-native-splash-screen:processReleaseResources'.

Directory 'F:\Development\Projeto\Sala-one\example\node_modules\react-native-splash-screen\android\build\intermediates\bundles\release\assets' specified for property 'assetsDir' does not exist.

Add code after `super` usually

Is this necessary?

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

It is normally

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

MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView

Hello.

When I start my app compiled in release mode I've got this error :

Activity com.myapp.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{415ceea8 V.E..... R.....I. 0,0-1024,552} that was originally added here
E/WindowManager(25826): android.view.WindowLeaked: Activity com.myapp.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{415ceea8 V.E..... R.....I. 0,0-1024,552} that was originally added here
E/WindowManager(25826): 	at android.view.ViewRootImpl.<init>(ViewRootImpl.java:409)
E/WindowManager(25826): 	at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:218)
E/WindowManager(25826): 	at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
E/WindowManager(25826): 	at android.app.Dialog.show(Dialog.java:281)
E/WindowManager(25826): 	at com.cboy.rn.splashscreen.SplashScreen$1.run(SplashScreen.java:32)
E/WindowManager(25826): 	at android.app.Activity.runOnUiThread(Activity.java:4662)
E/WindowManager(25826): 	at com.cboy.rn.splashscreen.SplashScreen.show(SplashScreen.java:22)
E/WindowManager(25826): 	at com.cboy.rn.splashscreen.SplashScreen.show(SplashScreen.java:42)
E/WindowManager(25826): 	at com.myapp.MainActivity.onCreate(MainActivity.java:11)
E/WindowManager(25826): 	at android.app.Activity.performCreate(Activity.java:5122)
E/WindowManager(25826): 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
E/WindowManager(25826): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)
E/WindowManager(25826): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358)
E/WindowManager(25826): 	at android.app.ActivityThread.access$600(ActivityThread.java:156)
E/WindowManager(25826): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1340)
E/WindowManager(25826): 	at android.os.Handler.dispatchMessage(Handler.java:99)
E/WindowManager(25826): 	at android.os.Looper.loop(Looper.java:153)
E/WindowManager(25826): 	at android.app.ActivityThread.main(ActivityThread.java:5299)
E/WindowManager(25826): 	at java.lang.reflect.Method.invokeNative(Native Method)
E/WindowManager(25826): 	at java.lang.reflect.Method.invoke(Method.java:511)
E/WindowManager(25826): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
E/WindowManager(25826): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
E/WindowManager(25826): 	at dalvik.system.NativeStart.main(Native Method)

I fix it with the following code in the MainActivity.java :

    @Override
    protected void onCreate(Bundle savedInstanceState) {
      SplashScreen.show(this);
      super.onCreate(savedInstanceState);
    }

    // my new code here
    @Override
    protected void onPause() {
      SplashScreen.hide(this);
      super.onPause();
    }

I can't confirm that it's the best solution but it works !

Splash Screen doesn't go away on Android

Hello.

I am just starting my Android application and I was testing this plugin. I follow every single step that it is in the instructions and it works but the splash screen doesn't go away, stay fixed.

Can you give me some help in order to make it done?

Update README.md for Android

Please, add to README.md information about required splash screen pictures in directories ./android/app/src/main/res/drawable-*/launch_screen.png. I didn't know about it and I spent a lot of time to find it.

Need to Update README.MD Installation

3.Update the MainApplication.java file to use react-native-splash-screen via the following changes:

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 SplashScreenReactPackage()  //here
            );
        }
    };

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

Need to import the package.

import com.cboy.rn.splashscreen.SplashScreenReactPackage;
Android:

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

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

Also, need to import the package.

import com.cboy.rn.splashscreen.SplashScreen;

背景图稍微大一点,Android就crash

楼主,背景图稍微大一点就crash了,我用的图片是191KB(算不上大图),然后就crash了,然后我把background换成颜色,然后就成功运行了,然后我把背景色换成一个小图,100KB,也是可以正常运行的,我在android studio看到的日志,见附件
2017-04-10 05 14 26 pm

iOS SplashScreen.h file not found

Hi,

Thank you for the awesome library. With react-native 0.40, after running react-native link react-native-splash-screen and adding #import "SplashScreen.h" to AppDelegate.m for iOS, I get the error SplashScreen.h file is not found when trying to build the project.

Is anybody else experiencing the same issue or know what's wrong?

does not work

version 2.0.0
this linking and updating the search path doesnt work in iOS IDE.
I kept having error SplashScreen.h file not found AppDelegate.m
Please guide me.

Improve Readme

hi @crazycodeboy thanks for this useful code, but I got some problem during the setup.

would be great if u cool add the java imports of each file in the Readme file, because u just added the code. I had to review ur examples code to notice that:

in mainApplication.java I must include:

import com.cboy.rn.splashscreen.SplashScreenReactPackage;

and in mainActivity.java

import android.os.Bundle; import com.cboy.rn.splashscreen.SplashScreen;

Also u mention adding

Go to node_modules ➜ react-native-launch-image and add SplashScreen.xcodeproj

I suspect that u had renamed ur component from react-native-launch-image to react-native-splash-screen and u forgot update this line right?

Last thing, is that I was not able to render the splash screen in IOS, where should I put the image to be rendered by IOS, should I add some xml file like we did for android? in the Readme getting started u only mention Adroid :(

Splash Screen displayed, does not go away (iOS && Android)

I have the Splash Screen displaying on both iOS and Android (simulators), but it does not go away after the app loads. (messages are appearing in console as if the app is working normally, but all I see is the splash screen)

I'm on RN 0.35.0

edit- I just noticed this appearing in Terminal (constantly scrolling non-stop):

[10/25/2016, 1:26:44 PM] <END>   Symbolicating (313ms)
[10/25/2016, 1:26:44 PM] <START> Symbolicating
[10/25/2016, 1:26:44 PM] <END>   Symbolicating (322ms)
[Hot Module Replacement] Sending HMR update to client (13:26:44:629)
[Hot Module Replacement] Sending HMR update to client (13:26:44:629)
[Hot Module Replacement] Sending HMR update to client (13:26:44:631)
[Hot Module Replacement] Sending HMR update to client (13:26:44:631)
[10/25/2016, 1:26:44 PM] <START> Symbolicating
[10/25/2016, 1:26:44 PM] <END>   Symbolicating (307ms)
[Hot Module Replacement] Sending HMR update to client (13:26:44:940)
[Hot Module Replacement] Sending HMR update to client (13:26:44:940)
[10/25/2016, 1:26:44 PM] <START> Symbolicating
[10/25/2016, 1:26:45 PM] <END>   Symbolicating (291ms)
[10/25/2016, 1:26:45 PM] <START> Symbolicating
[10/25/2016, 1:26:45 PM] <END>   Symbolicating (312ms)
[10/25/2016, 1:26:45 PM] <START> Symbolicating
[10/25/2016, 1:26:45 PM] <END>   Symbolicating (301ms)
[10/25/2016, 1:26:45 PM] <START> Symbolicating
[10/25/2016, 1:26:46 PM] <END>   Symbolicating (300ms)
[10/25/2016, 1:26:46 PM] <START> Symbolicating
[10/25/2016, 1:26:46 PM] <END>   Symbolicating (291ms)
[Hot Module Replacement] Sending HMR update to client (13:26:46:440)
[Hot Module Replacement] Sending HMR update to client (13:26:46:440)
[10/25/2016, 1:26:46 PM] <START> Symbolicating
[10/25/2016, 1:26:46 PM] <END>   Symbolicating (311ms)
[Hot Module Replacement] Sending HMR update to client (13:26:46:752)
[Hot Module Replacement] Sending HMR update to client (13:26:46:752)
[Hot Module Replacement] Sending HMR update to client (13:26:46:754)
[Hot Module Replacement] Sending HMR update to client (13:26:46:754)
[Hot Module Replacement] Sending HMR update to client (13:26:46:755)
[Hot Module Replacement] Sending HMR update to client (13:26:46:755)
[10/25/2016, 1:26:46 PM] <START> Symbolicating
[10/25/2016, 1:26:47 PM] <END>   Symbolicating (328ms)
[10/25/2016, 1:26:47 PM] <START> Symbolicating
[10/25/2016, 1:26:47 PM] <END>   Symbolicating (299ms)
[Hot Module Replacement] Sending HMR update to client (13:26:47:385)
[Hot Module Replacement] Sending HMR update to client (13:26:47:385)
[10/25/2016, 1:26:47 PM] <START> Symbolicating
[10/25/2016, 1:26:47 PM] <END>   Symbolicating (302ms)
[Hot Module Replacement] Sending HMR update to client (13:26:47:688)
[Hot Module Replacement] Sending HMR update to client (13:26:47:688)
[Hot Module Replacement] Sending HMR update to client (13:26:47:689)
[Hot Module Replacement] Sending HMR update to client (13:26:47:689)
[10/25/2016, 1:26:47 PM] <START> Symbolicating
[10/25/2016, 1:26:47 PM] <END>   Symbolicating (289ms)
[10/25/2016, 1:26:47 PM] <START

Android crash

Could not get BatchedBridge, make sure your bundle is packaged correctly

Android 5.5.1,
react-native-splash-screen v2.0.0
react-native v0.43.2

Dependency error while running "npm i react-native-splash-screen --save"

This is when my package.json file has
{
"name": "Project",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "react-native start"
},
"dependencies": {
"react": "^15.4.0",
"react-native": "^0.40.0",
"react-native-splash-screen": "^2.0.0"
}
}

Output:
$ npm i react-native-splash-screen --save
[email protected] /Users/splashScreen
├── UNMET PEER DEPENDENCY [email protected]
└── [email protected]

npm WARN [email protected] requires a peer of react@~15.4.0-rc.4 but none was installed.

When I change my package.json file's react version to 15.4.0 the output I get is

$ npm i react-native-splash-screen --save
[email protected] /splashScreen
├── UNMET PEER DEPENDENCY [email protected]
└── [email protected]

npm WARN [email protected] requires a peer of react@~15.4.0-rc.4 but none was installed.

Can any one help me for above problem ?

White splash screen

i did exactly the same thing. everything seems alright till i get a totally blank splash screen.
can anyone explains why?

WeakReference NullPointerException

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.lang.ref.WeakReference.get()' on a null object reference
	at com.cboy.rn.splashscreen.SplashScreen.hide(SplashScreen.java:51)
	at com.cboy.rn.splashscreen.SplashScreenModule.hide(SplashScreenModule.java:38)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.facebook.react.bridge.BaseJavaModule$JavaMethod.invoke(BaseJavaModule.java:345)
	at com.facebook.react.cxxbridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:136)
	at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
	at android.os.Handler.handleCallback(Handler.java:815)
	at android.os.Handler.dispatchMessage(Handler.java:104)
	at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31)
	at android.os.Looper.loop(Looper.java:207)
	at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:196)
	at java.lang.Thread.run(Thread.java:818)

android 闪退问题

配置好了之后 项目是可以跑成功的 但是打开app出现闪退 ios没问题

Error on Android

i got this message after build and i got message that "Unforturnately, App has stopped"

03-03 12:01:27.800 3084-3084/com.thesis E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.thesis, PID: 3084
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.thesis/com.thesis.MainActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f04002a type #0x1 is not valid
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f04002a type #0x1 is not valid
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2779)
at android.content.res.Resources.getLayout(Resources.java:1165)
at android.view.LayoutInflater.inflate(LayoutInflater.java:421)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393)
at android.app.Dialog.setContentView(Dialog.java:512)
at com.cboy.rn.splashscreen.SplashScreen$1.run(SplashScreen.java:30)
at android.app.Activity.runOnUiThread(Activity.java:5511)
at com.cboy.rn.splashscreen.SplashScreen.show(SplashScreen.java:24)
at com.thesis.MainActivity.onCreate(MainActivity.java:19)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

Unfortunately has stopped on Android

I have this problem on android

here is my MainApplication

`package com.splash;

import android.app.Application;

import com.facebook.react.ReactApplication;
import com.cboy.rn.splashscreen.SplashScreenReactPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;

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

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;
}

@OverRide
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
}
}
My MainActivityimport android.os.Bundle;
import com.facebook.react.ReactActivity;
import com.cboy.rn.splashscreen.SplashScreen;

public class MainActivity extends ReactActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    SplashScreen.show(this);  // here
    super.onCreate(savedInstanceState);
}
@Override
protected String getMainComponentName() {
   
    return "Splash";
}

}
`

If i comment SplashScreen.show(this) my app started correctly

couldn't I call SplashScreen show again?

hi, thanks for your smart project,

I want to implement that show SplashScreen again when app switch to background, I try to call the method in applicationDidEnterBackground but failed.

what should I do?

thanks for your time.

regards.

ipad splashscreeen

First of all, thanks for this time saving script. Great job! 👍

I've encountered this issue:

Currently your script is leaving out the "minimum-system-version" in Contents.json for iPad portrait mode. This seem to have the effect that landscape iPad splashscreen will have precedence even if your iPad is in portrait mode.

it is not working over anrdroid

my Mainactivity
package com.moa_prod;

import android.os.Bundle;
import com.facebook.react.ReactActivity;
import com.cboy.rn.splashscreen.SplashScreen;

public class MainActivity extends ReactActivity {

/**
 * Returns the name of the main component registered from JavaScript.
 * This is used to schedule rendering of the component.
 */

@Override
protected String getMainComponentName() {
    SplashScreen.show(this);
    return "moa_prod";
}

}

its keep crushing app not working and when i commit the
SplashScreen.show(this);
then nothing happens splash-screen not working .

i did all what readme me say any help please !
here is my MainApplication

package com.moa_prod;

import android.app.Application;

import com.facebook.react.ReactApplication;
import com.cboy.rn.splashscreen.SplashScreenReactPackage;
import com.oblador.vectoricons.VectorIconsPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;

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

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(),
        new VectorIconsPackage()
  );
}

};

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

@OverRide
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
}
}

java.lang.IllegalArgumentException

日志捕获在SplashScreen.java:58行报错
java.lang.IllegalArgumentException: View=com.android.internal.policy.impl.PhoneWindow$DecorView{3edec30a V.E..... R....... 0,0-1080,1920} not attached to window manager
at android.view.WindowManagerGlobal.findViewLocked(WindowManagerGlobal.java:399)
at android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:325)
at android.view.WindowManagerImpl.removeViewImmediate(WindowManagerImpl.java:84)
at android.app.Dialog.dismissDialog(Dialog.java:341)
at android.app.Dialog.dismiss(Dialog.java:324)
at com.cboy.rn.splashscreen.SplashScreen$2.run(SplashScreen.java:58)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5556)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:967)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)

node_modules/react-native-splash-screen/ios/SplashScreen.h:9:9: fatal error: 'React/RCTBridgeModule.h' file not found

In file included from /Users/hejunbin/workspace-js/ReactNative/openproject/GitHubPopular-master/node_modules/react-native-splash-screen/ios/SplashScreen.m:10:
/Users/hejunbin/workspace-js/ReactNative/openproject/GitHubPopular-master/node_modules/react-native-splash-screen/ios/SplashScreen.h:9:9: fatal error:
'React/RCTBridgeModule.h' file not found
#import <React/RCTBridgeModule.h>
^
1 error generated.

** BUILD FAILED **

The following build commands failed:
CompileC /Users/hejunbin/workspace-js/ReactNative/openproject/GitHubPopular-master/ios/build/Build/Intermediates/SplashScreen.build/Debug-iphonesimulator/SplashScreen.build/Objects-normal/x86_64/SplashScreen.o SplashScreen.m normal x86_64 objective-c com.apple.compilers.llvm.clang.1_0.compiler
(1 failure)
Installing build/Build/Products/Debug-iphonesimulator/GitHubPopular.app
An error was encountered processing the command (domain=NSPOSIXErrorDomain, code=2):
Failed to install the requested application
An application bundle was not found at the provided path.
Provide a valid path to the desired application bundle.
Print: Entry, ":CFBundleIdentifier", Does Not Exist

Command failed: /usr/libexec/PlistBuddy -c Print:CFBundleIdentifier build/Build/Products/Debug-iphonesimulator/GitHubPopular.app/Info.plist
Print: Entry, ":CFBundleIdentifier", Does Not Exist

Problem with changing iOS splash screen from default

If I install the current library to my react native app then I see the basic react-native splash screen on iOS (from file ./ios/ProjectName/Base.lproj/LaunchScreen.xib). And if I want to change it to my picture I need to do the following changes:

  1. Add to file ./ios/ProjectName.xcodeproj/project.pbxproj the following strings:
...
	buildSettings = {
		ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
		ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;    /* here */
		CURRENT_PROJECT_VERSION = 1;
		DEAD_CODE_STRIPPING = NO;
		HEADER_SEARCH_PATHS = "$(SRCROOT)/../node_modules/react-native-splash-screen/ios";   /* and here */
...
	buildSettings = {
		ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
		ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;    /* here */
		CURRENT_PROJECT_VERSION = 1;
		DEAD_CODE_STRIPPING = NO;
		HEADER_SEARCH_PATHS = "$(SRCROOT)/../node_modules/react-native-splash-screen/ios";   /* and here */
...
  1. Remove from file ./ios/ProjectName.xcodeproj/project.pbxproj the following strings:
...
	<key>UILaunchStoryboardName</key>
	<string>LaunchScreen</string>
...

If I do it then I see my splash screen from the directory ./ios/ProjectName/Images.xcassets/LaunchImage.launchimage like in example.

Please, add it to README.md or fix it.

P.S. Your example doesn't work for me. I see the following error when app starts:

Application examples has not been registered. This is either due to a require() error during initialization or failure to call AppRegistry.registerComponent.

'SplashScreen.h' file not found

I followed the installation instruction. The library was successfully linked with react-native link
The SplashScreen is now added to the Libraries folder in Xcode.

If I try to import the library with:
#import "SplashScreen.h"
or
#import <SplashScreen.h>

I get this error:
xxx/AppDelegate.m:14:9: 'SplashScreen.h' file not found

Did I forgot something?

Where to put image files?

Hello,

I am a little bit confused, but where exactly do I have to store my splash screen images for ios and android? And do they have to have a specific naming or anything like that? Thanks!

Oncreate not used anymore

I am not sure how to use this in new versions of react as I do not think they use onCreate anymore. Any suggestions?

android启动页还差一点就完美了

经反复测试
android点击桌面应用图标的时候会有短暂的停顿,
大概0.5秒左右才能启动程序,
其实点击应用图标的时候程序是已经启动了
只不过android:windowIsTranslucent这句设置为透明后0.5秒啥也看不到,
这就导致感觉有卡顿似的
去掉这句后android:windowIsTranslucent没有卡顿了 但有白屏了
能否解决这个问题了?

就差这最后一步达到完美了

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.