
Product
Socket Now Supports pylock.toml Files
Socket now supports pylock.toml, enabling secure, reproducible Python builds with advanced scanning and full alignment with PEP 751's new standard.
@rn-toolkit/react-native-lottie-splash-screen
Advanced tools
A lottie splash screen for react-native, hide when application loaded ,it works on iOS and Android.
Fork of react-native-splash-screen and add implement for animation splash screen using airbnb lottie files.
Works on IOS and Android.
You can run examples in this project
Run yarn add lottie-ios lottie-react-native @rn-toolkit/react-native-lottie-splash-screen
The package is automatically linked when building the app. All you need to do is:
cd ios && pod install
For android, the package will be linked automatically on build.
react-native link react-native-lottie-splash-screen
If you don't want to use the methods above, you can always do Manual installation.
Android:
android/settings.gradle
file, make the following additions:include ':react-native-lottie-splash-screen'
project(':react-native-lottie-splash-screen').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-lottie-splash-screen/android')
:react-native-lottie-splash-screen
project as a compile-time dependency:...
dependencies {
...
implementation project(':react-native-lottie-splash-screen')
}
react-native-lottie-splash-screen
via the following changes:// react-native-lottie-splash-screen >= 0.3.1
import org.devio.rn.splashscreen.SplashScreenReactPackage;
// react-native-lottie-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:
cd ios
run pod install
OR
In XCode, in the project navigator, right click Libraries
β Add Files to [your project's name]
Go to node_modules
β react-native-lottie-splash-screen
and add SplashScreen.xcodeproj
In XCode, in the project navigator, select your project. Add libSplashScreen.a
to your project's Build Phases
β Link Binary With Libraries
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-lottie-splash-screen/ios
Android:
Update the MainActivity.java
to use react-native-lottie-splash-screen
via the following changes:
import android.os.Bundle;
import com.facebook.react.ReactActivity;
import org.devio.rn.splashscreen.SplashScreen; // here
import android.os.Bundle;
public class MainActivity extends ReactActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
SplashScreen.show(this, R.id.lottie); // here
SplashScreen.setAnimationFinished(true); // If you want the animation dialog to be forced to close when hide is called, use this code
super.onCreate(savedInstanceState);
// ...other code
}
}
iOS:
Dynamic.swift
with the following contents:import UIKit
import Foundation
import Lottie
@objc class Dynamic: NSObject {
@objc func createAnimationView(rootView: UIView, lottieName: String) -> AnimationView {
let animationView = AnimationView(name: lottieName)
animationView.frame = rootView.frame
animationView.center = rootView.center
animationView.backgroundColor = UIColor.white;
return animationView;
}
@objc func play(animationView: AnimationView) {
animationView.play(
completion: { (success) in
RNSplashScreen.setAnimationFinished(true)
}
);
}
}
If you use lottie-ios version >= 4.0.1
import UIKit
import Foundation
import Lottie
@objc class Dynamic: NSObject {
@objc func createAnimationView(rootView: UIView, lottieName: String) -> LottieAnimationView {
let animationView = LottieAnimationView(name: lottieName)
animationView.frame = rootView.frame
animationView.center = rootView.center
if #available(iOS 13, *) {
animationView.backgroundColor = UIColor.systemBackground;
} else {
animationView.backgroundColor = UIColor.clear;
}
return animationView;
}
@objc func play(animationView: LottieAnimationView) {
animationView.play(
completion: { (success) in
RNSplashScreen.setAnimationFinished(true)
}
);
}
}
[your-project-name]-Bridging-Header.h
with the following contents:// HyperMoney-Bridging-Header.h
#ifndef HyperMoney_Bridging_Header_h
#define HyperMoney_Bridging_Header_h
#import "RNSplashScreen.h" // here
#endif /* HyperMoney_Bridging_Header_h */
Import Swift code into Objective-C within the same framework:
Under Build Settings, in Packaging, make sure the Defines Module setting for that framework target is set to Yes.
Import the Swift code from that framework target into any Objective-C .m file within that target using this syntax and substituting the appropriate names:
AppDelegate.mm
with the following additions: (for react-native@0.71 proceed to 4.1)
#import "AppDelegate.h"
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import "RNSplashScreen.h" // here
#import "HyperMoney-Swift.h" // here, change project name to yours
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// ...other code
/* here */
UIViewController *rootViewController = [UIViewController new];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
Dynamic *t = [Dynamic new];
UIView *animationUIView = (UIView *)[t createAnimationViewWithRootView:rootView lottieName:@"loading"]; // change lottieName to your lottie files name
animationUIView.backgroundColor = [UIColor whiteColor]; // change backgroundColor
// register LottieSplashScreen to RNSplashScreen
[RNSplashScreen showLottieSplash:animationUIView inRootView:rootView];
// casting UIView type to AnimationView type
AnimationView *animationView = (AnimationView *) animationUIView;
// use lottie-ios >= 4.0.1
// LottieAnimationView *animationView = (LottieAnimationView *) animationUIView;
// play
[t playWithAnimationView:animationView];
// If you want the animation layout to be forced to remove when hide is called, use this code
[RNSplashScreen setAnimationFinished:true];
/* here */
return YES;
}
4.1 For React-Native version 0.71, in AppDelegate.mm
rootView is no longer here. We need access to the rootView.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.moduleName = @"YOUR_PROJECT_NAME";
// You can add your custom initial props in the dictionary below.
// They will be passed down to the ViewController used by React Native.
self.initialProps = @{};
// return [super application:application didFinishLaunchingWithOptions:launchOptions]; //This will be assigned as success instead
BOOL success = [super application:application didFinishLaunchingWithOptions:launchOptions];
if (success) {
//This is where we will put the logic to get access to rootview
UIView *rootView = self.window.rootViewController.view;
Dynamic *t = [Dynamic new];
UIView *animationUIView = (UIView *)[t createAnimationViewWithRootView:rootView lottieName:@"logo_animated"]; // change lottieName to your lottie files name
BOOL closeWhenAnimationFinished = true;
if (@available(iOS 13.0, *)) {
closeWhenAnimationFinished = false;
} else {
closeWhenAnimationFinished = true;
}
// register LottieSplashScreen to RNSplashScreen
[RNSplashScreen showLottieSplash:animationUIView inRootView:rootView];
// casting UIView type to AnimationView type
AnimationView *animationView = (AnimationView *) animationUIView;
// use lottie-ios >= 4.0.1
// LottieAnimationView *animationView = (LottieAnimationView *) animationUIView;
// play
[t playWithAnimationView:animationView];
// If you want the animation layout to be forced to remove when hide is called, use this code
[RNSplashScreen setAnimationFinished:closeWhenAnimationFinished];
}
return success;
}
Import react-native-lottie-splash-screen
in your JS file.
import SplashScreen from 'react-native-lottie-splash-screen'
Create a file called launch_screen.xml
in app/src/main/res/layout
(create the layout
-folder if it doesn't exist). Next, locate your lottie files in app/src/main/res/raw
(loading.json in this example). The contents of the file should be the following:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
>
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/lottie"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:lottie_rawRes="@raw/loading"
app:lottie_autoPlay="true"
app:lottie_loop="false"
/>
</LinearLayout>
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
Drag your lottie files to Xcode Project. Click Finish. That's all.
It's really annoying to resolve issues with expo bare workflow because I do not use this π₯². But a lot of developers want to use this project to expo bare workflow. So, If you managed to this, please star and share this project! That's a really big energy to me! :rocket::rocket::rocket:
"Cannot find 'RNSplashScreen' in scope - Build iOS error" issue in Dynamic.swift #
#import "RNSplashScreen.h" // here
#import "ExpoModulesCore-Swift.h" // here
#import "ExpoLSSTestApp-Swift.h" // here, change project name to yours
"build:ios": "react-native bundle --entry-file='index.js' --bundle-output='./ios/main.jsbundle' --dev=false --platform='ios'"
j
Use like so:
When the app is finished loading, hide the LottieSplashScreen.
The contents of the App.js may be the following:
import React, { useEffect } from "react";
import LottieSplashScreen from "react-native-lottie-splash-screen";
import RootNavigator from "@navi/RootNavigator";
const App = () => {
useEffect(() => {
LottieSplashScreen.hide(); // here
}, []);
return <RootNavigator />;
};
export default App;
Method | Type | Optional | Description |
---|---|---|---|
hide() | function | false | Close lottie splash screen |
I open-source almost everything I can and try to reply to everyone needing help using these projects. Obviously, this takes time. You can use this service for free.
However, if you are using this project and are happy with it or just want to encourage me to continue creating stuff, there are a few ways you can do it:
Thanks! :heart:
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.
FAQs
A lottie splash screen for react-native, hide when application loaded ,it works on iOS and Android.
The npm package @rn-toolkit/react-native-lottie-splash-screen receives a total of 5 weekly downloads. As such, @rn-toolkit/react-native-lottie-splash-screen popularity was classified as not popular.
We found that @rn-toolkit/react-native-lottie-splash-screen demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.Β It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports pylock.toml, enabling secure, reproducible Python builds with advanced scanning and full alignment with PEP 751's new standard.
Security News
Research
Socket uncovered two npm packages that register hidden HTTP endpoints to delete all files on command.
Research
Security News
Malicious Ruby gems typosquat Fastlane plugins to steal Telegram bot tokens, messages, and files, exploiting demand after Vietnamβs Telegram ban.