react-native-carrot-splash-screen
v1.0.8
Published
Solve the problem of launching a white screen in a React Native project
Downloads
1
Readme
react-native-carrot-splash-screen
Solve the problem of launching a white screen in a React Native project
Getting started
$ npm install react-native-carrot-splash-screen --save
Mostly automatic installation
$ react-native link react-native-carrot-splash-screen
Manual installation
iOS
- In XCode, in the project navigator, right click
Libraries
➜Add Files to [your project's name]
- Go to
node_modules
➜react-native-carrot-splash-screen
and addRNCarrotSplashScreen.xcodeproj
- In XCode, in the project navigator, select your project. Add
libRNCarrotSplashScreen.a
to your project'sBuild Phases
➜Link Binary With Libraries
- Run your project (
Cmd+R
)<
Android
- Open up
android/app/src/main/java/[...]/MainActivity.java
- Add
import com.carrot.splashScreen.RNCarrotSplashScreenPackage;
to the imports at the top of the file - Add
new RNCarrotSplashScreenPackage()
to the list returned by thegetPackages()
method
- Append the following lines to
android/settings.gradle
:include ':react-native-carrot-splash-screen' project(':react-native-carrot-splash-screen').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-carrot-splash-screen/android')
- Insert the following lines inside the dependencies block in
android/app/build.gradle
:compile project(':react-native-carrot-splash-screen')
Methods
| Method | Params | Description | | :------------ |:---------------:| :---------------:| | show | - |Called in native, When you want to keep the splash screen | | hide | - | Call in js when you want to close the splash screen |
Usage
javascript
import RNCarrotSplashScreen from 'react-native-carrot-splash-screen';
iOS
AppDelegate.m
#import "AppDelegate.h"
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import "RNCarrotSplashScreen.h"
#import <React/RCTRootView.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
[self.window makeKeyAndVisible];
[RNCarrotSplashScreen show];//Please be sure to write in the last line
return YES;
}
javascript
export default class App extends Component<Props> {
render() {
...
componentDidMount(){
//Hide the splash screen
CarrotSplashScreen.hide();
}
...
}
Android
- Create a layout file under ./res/layout, named launch_screen.
- Call the CarrotSplashScreen.show() method in the onCreate lifecycle of MainActivity.
import android.os.Bundle;
import com.awesomeproject.splash.SplashScreen;
import com.facebook.react.ReactActivity;
public class MainActivity extends ReactActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
SplashScreen.show(this);
super.onCreate(savedInstanceState);
}
...
}