Gathering detailed insights and metrics for @rn-toolkit/react-native-lottie-splash-screen
Gathering detailed insights and metrics for @rn-toolkit/react-native-lottie-splash-screen
Gathering detailed insights and metrics for @rn-toolkit/react-native-lottie-splash-screen
Gathering detailed insights and metrics for @rn-toolkit/react-native-lottie-splash-screen
⚡ Lottie splash screen for your react native app!
npm install @rn-toolkit/react-native-lottie-splash-screen
Typescript
Module System
Node Version
NPM Version
Java (53.09%)
Objective-C (32.68%)
Swift (6.11%)
Ruby (5.43%)
JavaScript (2.69%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
1 Stars
232 Commits
1 Branches
Updated on Jun 03, 2024
Latest Version
1.1.5
Package Id
@rn-toolkit/react-native-lottie-splash-screen@1.1.5
Unpacked Size
2.10 MB
Size
1.93 MB
File Count
24
NPM Version
8.19.4
Node Version
16.20.1
Published on
Aug 16, 2023
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
2
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:
1cd ios && pod install
For android, the package will be linked automatically on build.
1react-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:1include ':react-native-lottie-splash-screen' 2project(':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:1... 2dependencies { 3 ... 4 implementation project(':react-native-lottie-splash-screen') 5}
react-native-lottie-splash-screen
via the following changes:1// react-native-lottie-splash-screen >= 0.3.1 2import org.devio.rn.splashscreen.SplashScreenReactPackage; 3// react-native-lottie-splash-screen < 0.3.1 4import com.cboy.rn.splashscreen.SplashScreenReactPackage; 5 6public class MainApplication extends Application implements ReactApplication { 7 8 private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { 9 @Override 10 public boolean getUseDeveloperSupport() { 11 return BuildConfig.DEBUG; 12 } 13 14 @Override 15 protected List<ReactPackage> getPackages() { 16 return Arrays.<ReactPackage>asList( 17 new MainReactPackage(), 18 new SplashScreenReactPackage() //here 19 ); 20 } 21 }; 22 23 @Override 24 public ReactNativeHost getReactNativeHost() { 25 return mReactNativeHost; 26 } 27}
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:
1import android.os.Bundle; 2import com.facebook.react.ReactActivity; 3import org.devio.rn.splashscreen.SplashScreen; // here 4import android.os.Bundle; 5 6public class MainActivity extends ReactActivity { 7 @Override 8 protected void onCreate(Bundle savedInstanceState) { 9 SplashScreen.show(this, R.id.lottie); // here 10 SplashScreen.setAnimationFinished(true); // If you want the animation dialog to be forced to close when hide is called, use this code 11 super.onCreate(savedInstanceState); 12 // ...other code 13 } 14}
iOS:
Dynamic.swift
with the following contents:1import UIKit
2import Foundation
3import Lottie
4
5@objc class Dynamic: NSObject {
6
7 @objc func createAnimationView(rootView: UIView, lottieName: String) -> AnimationView {
8 let animationView = AnimationView(name: lottieName)
9 animationView.frame = rootView.frame
10 animationView.center = rootView.center
11 animationView.backgroundColor = UIColor.white;
12 return animationView;
13 }
14
15 @objc func play(animationView: AnimationView) {
16 animationView.play(
17 completion: { (success) in
18 RNSplashScreen.setAnimationFinished(true)
19 }
20 );
21 }
22}
If you use lottie-ios version >= 4.0.1
1import UIKit
2import Foundation
3import Lottie
4
5@objc class Dynamic: NSObject {
6
7 @objc func createAnimationView(rootView: UIView, lottieName: String) -> LottieAnimationView {
8 let animationView = LottieAnimationView(name: lottieName)
9 animationView.frame = rootView.frame
10 animationView.center = rootView.center
11 if #available(iOS 13, *) {
12 animationView.backgroundColor = UIColor.systemBackground;
13 } else {
14 animationView.backgroundColor = UIColor.clear;
15 }
16 return animationView;
17 }
18
19 @objc func play(animationView: LottieAnimationView) {
20 animationView.play(
21 completion: { (success) in
22 RNSplashScreen.setAnimationFinished(true)
23 }
24 );
25 }
26}
[your-project-name]-Bridging-Header.h
with the following contents:1// HyperMoney-Bridging-Header.h 2 3#ifndef HyperMoney_Bridging_Header_h 4#define HyperMoney_Bridging_Header_h 5 6#import "RNSplashScreen.h" // here 7 8#endif /* HyperMoney_Bridging_Header_h */ 9
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)1 2#import "AppDelegate.h" 3 4#import <React/RCTBridge.h> 5#import <React/RCTBundleURLProvider.h> 6#import <React/RCTRootView.h> 7#import "RNSplashScreen.h" // here 8 9#import "HyperMoney-Swift.h" // here, change project name to yours 10 11@implementation AppDelegate 12 13- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 14{ 15 16 // ...other code 17 18 /* here */ 19 UIViewController *rootViewController = [UIViewController new]; 20 21 rootViewController.view = rootView; 22 23 self.window.rootViewController = rootViewController; 24 [self.window makeKeyAndVisible]; 25 26 Dynamic *t = [Dynamic new]; 27 UIView *animationUIView = (UIView *)[t createAnimationViewWithRootView:rootView lottieName:@"loading"]; // change lottieName to your lottie files name 28 animationUIView.backgroundColor = [UIColor whiteColor]; // change backgroundColor 29 30 // register LottieSplashScreen to RNSplashScreen 31 [RNSplashScreen showLottieSplash:animationUIView inRootView:rootView]; 32 33 // casting UIView type to AnimationView type 34 AnimationView *animationView = (AnimationView *) animationUIView; 35 // use lottie-ios >= 4.0.1 36 // LottieAnimationView *animationView = (LottieAnimationView *) animationUIView; 37 38 // play 39 [t playWithAnimationView:animationView]; 40 41 // If you want the animation layout to be forced to remove when hide is called, use this code 42 [RNSplashScreen setAnimationFinished:true]; 43 44 /* here */ 45 46 return YES; 47}
4.1 For React-Native version 0.71, in AppDelegate.mm
rootView is no longer here. We need access to the rootView.
1 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 2{ 3 self.moduleName = @"YOUR_PROJECT_NAME"; 4 // You can add your custom initial props in the dictionary below. 5 // They will be passed down to the ViewController used by React Native. 6 self.initialProps = @{}; 7 // return [super application:application didFinishLaunchingWithOptions:launchOptions]; //This will be assigned as success instead 8 9 BOOL success = [super application:application didFinishLaunchingWithOptions:launchOptions]; 10 11 if (success) { 12 //This is where we will put the logic to get access to rootview 13 UIView *rootView = self.window.rootViewController.view; 14 15 Dynamic *t = [Dynamic new]; 16 UIView *animationUIView = (UIView *)[t createAnimationViewWithRootView:rootView lottieName:@"logo_animated"]; // change lottieName to your lottie files name 17 18 BOOL closeWhenAnimationFinished = true; 19 20 if (@available(iOS 13.0, *)) { 21 closeWhenAnimationFinished = false; 22 } else { 23 closeWhenAnimationFinished = true; 24 } 25 26 // register LottieSplashScreen to RNSplashScreen 27 [RNSplashScreen showLottieSplash:animationUIView inRootView:rootView]; 28 // casting UIView type to AnimationView type 29 AnimationView *animationView = (AnimationView *) animationUIView; 30 // use lottie-ios >= 4.0.1 31 // LottieAnimationView *animationView = (LottieAnimationView *) animationUIView; 32 // play 33 [t playWithAnimationView:animationView]; 34 // If you want the animation layout to be forced to remove when hide is called, use this code 35 [RNSplashScreen setAnimationFinished:closeWhenAnimationFinished]; 36 } 37 38 return success; 39 40}
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:
1<?xml version="1.0" encoding="utf-8"?> 2<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:app="http://schemas.android.com/apk/res-auto" 4 xmlns:tools="http://schemas.android.com/tools" 5 tools:context=".MainActivity" 6 android:orientation="vertical" 7 android:layout_width="match_parent" 8 android:layout_height="match_parent" 9 android:background="@color/white" 10 > 11 <com.airbnb.lottie.LottieAnimationView 12 android:id="@+id/lottie" 13 android:layout_width="match_parent" 14 android:layout_height="match_parent" 15 app:lottie_rawRes="@raw/loading" 16 app:lottie_autoPlay="true" 17 app:lottie_loop="false" 18 /> 19</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 #
1#import "RNSplashScreen.h" // here 2#import "ExpoModulesCore-Swift.h" // here 3#import "ExpoLSSTestApp-Swift.h" // here, change project name to yours
1"build:ios": "react-native bundle --entry-file='index.js' --bundle-output='./ios/main.jsbundle' --dev=false --platform='ios'" 2j
Use like so:
When the app is finished loading, hide the LottieSplashScreen.
The contents of the App.js may be the following:
1import React, { useEffect } from "react"; 2import LottieSplashScreen from "react-native-lottie-splash-screen"; 3import RootNavigator from "@navi/RootNavigator"; 4 5const App = () => { 6 useEffect(() => { 7 LottieSplashScreen.hide(); // here 8 }, []); 9 return <RootNavigator />; 10}; 11 12export 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.
No vulnerabilities found.
No security vulnerabilities found.