|
diff --git a/node_modules/@rn-toolkit/react-native-lottie-splash-screen/android/build.gradle b/node_modules/@rn-toolkit/react-native-lottie-splash-screen/android/build.gradle |
|
index ddbf339..c42b5ec 100644 |
|
--- a/node_modules/@rn-toolkit/react-native-lottie-splash-screen/android/build.gradle |
|
+++ b/node_modules/@rn-toolkit/react-native-lottie-splash-screen/android/build.gradle |
|
@@ -31,5 +31,5 @@ dependencies { |
|
testImplementation 'junit:junit:4.12' |
|
implementation "com.android.support:appcompat-v7:$supportLibVersion" |
|
implementation "com.facebook.react:react-native:+" // From node_modules |
|
- implementation 'com.airbnb.android:lottie:3.4.4' |
|
+ implementation 'com.airbnb.android:lottie:6.3.0' |
|
} |
|
diff --git a/node_modules/@rn-toolkit/react-native-lottie-splash-screen/android/src/main/java/org/devio/rn/splashscreen/SplashScreen.java b/node_modules/@rn-toolkit/react-native-lottie-splash-screen/android/src/main/java/org/devio/rn/splashscreen/SplashScreen.java |
|
index c219f9f..5ce4f9d 100644 |
|
--- a/node_modules/@rn-toolkit/react-native-lottie-splash-screen/android/src/main/java/org/devio/rn/splashscreen/SplashScreen.java |
|
+++ b/node_modules/@rn-toolkit/react-native-lottie-splash-screen/android/src/main/java/org/devio/rn/splashscreen/SplashScreen.java |
|
@@ -3,34 +3,28 @@ package org.devio.rn.splashscreen; |
|
import android.animation.Animator; |
|
import android.app.Activity; |
|
import android.app.Dialog; |
|
-import android.os.Build; |
|
+ |
|
+import androidx.annotation.NonNull; |
|
+ |
|
import com.airbnb.lottie.LottieAnimationView; |
|
+ |
|
import java.lang.ref.WeakReference; |
|
+import java.util.concurrent.atomic.AtomicBoolean; |
|
|
|
-/** |
|
- * SplashScreen |
|
- * 启动屏 |
|
- * from:http://www.devio.org |
|
- * Author:CrazyCodeBoy |
|
- * GitHub:https://github.com/crazycodeboy |
|
- * Email:[email protected] |
|
- */ |
|
public class SplashScreen { |
|
private static Dialog mSplashDialog; |
|
private static WeakReference<Activity> mActivity; |
|
- private static Boolean isAnimationFinished = false; |
|
- private static Boolean waiting = false; |
|
+ private static AtomicBoolean isAnimationFinished = new AtomicBoolean(false); |
|
+ private static AtomicBoolean waiting = new AtomicBoolean(false); |
|
|
|
- /** |
|
- * 打开启动屏 |
|
- */ |
|
public static void show(final Activity activity, final int themeResId, final int lottieId) { |
|
- if (activity == null) |
|
+ if (activity == null) { |
|
return; |
|
- mActivity = new WeakReference<Activity>(activity); |
|
- activity.runOnUiThread(new Runnable() { |
|
- @Override |
|
- public void run() { |
|
+ } |
|
+ |
|
+ synchronized (SplashScreen.class) { |
|
+ mActivity = new WeakReference<>(activity); |
|
+ activity.runOnUiThread(() -> { |
|
if (!activity.isFinishing()) { |
|
mSplashDialog = new Dialog(activity, themeResId); |
|
mSplashDialog.setContentView(R.layout.launch_screen); |
|
@@ -39,52 +33,48 @@ public class SplashScreen { |
|
|
|
lottie.addAnimatorListener(new Animator.AnimatorListener() { |
|
@Override |
|
- public void onAnimationStart(Animator animation) { |
|
- System.out.println("asdf"); |
|
- } |
|
+ public void onAnimationStart(@NonNull Animator animation) {} |
|
|
|
@Override |
|
- public void onAnimationEnd(Animator animation) { |
|
- SplashScreen.setAnimationFinished(true); |
|
+ public void onAnimationEnd(@NonNull Animator animation) { |
|
+ SplashScreen.hide(activity); |
|
} |
|
|
|
@Override |
|
- public void onAnimationCancel(Animator animation) {} |
|
+ public void onAnimationCancel(@NonNull Animator animation) {} |
|
|
|
@Override |
|
- public void onAnimationRepeat(Animator animation) {} |
|
+ public void onAnimationRepeat(@NonNull Animator animation) {} |
|
}); |
|
|
|
if (!mSplashDialog.isShowing()) { |
|
mSplashDialog.show(); |
|
} |
|
} |
|
- } |
|
- }); |
|
+ }); |
|
+ } |
|
} |
|
|
|
public static void setAnimationFinished(boolean flag) { |
|
- if (mActivity == null) { |
|
- return; |
|
- } |
|
+ isAnimationFinished.set(flag); |
|
|
|
- isAnimationFinished = flag; |
|
+ if (mActivity == null) return; |
|
|
|
final Activity _activity = mActivity.get(); |
|
|
|
- _activity.runOnUiThread(new Runnable() { |
|
- @Override |
|
- public void run() { |
|
+ if (_activity == null) return; |
|
+ |
|
+ _activity.runOnUiThread(() -> { |
|
+ synchronized (SplashScreen.class) { |
|
if (mSplashDialog != null && mSplashDialog.isShowing()) { |
|
boolean isDestroyed = false; |
|
|
|
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { |
|
- isDestroyed = _activity.isDestroyed(); |
|
- } |
|
+ isDestroyed = _activity.isDestroyed(); |
|
|
|
- if (!_activity.isFinishing() && !isDestroyed && waiting) { |
|
+ if (!_activity.isFinishing() && !isDestroyed && waiting.get()) { |
|
mSplashDialog.dismiss(); |
|
mSplashDialog = null; |
|
+ mActivity.clear(); |
|
} |
|
} |
|
} |
|
@@ -96,37 +86,28 @@ public class SplashScreen { |
|
show(activity, resourceId, lottieId); |
|
} |
|
|
|
- /** |
|
- * 关闭启动屏 |
|
- */ |
|
public static void hide(Activity activity) { |
|
- if (activity == null) { |
|
- if (mActivity == null) { |
|
- return; |
|
- } |
|
+ if (activity == null && mActivity != null) { |
|
activity = mActivity.get(); |
|
} |
|
|
|
- if (activity == null) |
|
- return; |
|
+ if (activity == null) return; |
|
|
|
- waiting = true; |
|
+ waiting.set(true); |
|
|
|
final Activity _activity = activity; |
|
|
|
- _activity.runOnUiThread(new Runnable() { |
|
- @Override |
|
- public void run() { |
|
+ _activity.runOnUiThread(() -> { |
|
+ synchronized (SplashScreen.class) { |
|
if (mSplashDialog != null && mSplashDialog.isShowing()) { |
|
boolean isDestroyed = false; |
|
|
|
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { |
|
- isDestroyed = _activity.isDestroyed(); |
|
- } |
|
+ isDestroyed = _activity.isDestroyed(); |
|
|
|
- if (!_activity.isFinishing() && !isDestroyed && isAnimationFinished) { |
|
+ if (!_activity.isFinishing() && !isDestroyed && isAnimationFinished.get()) { |
|
mSplashDialog.dismiss(); |
|
mSplashDialog = null; |
|
+ mActivity.clear(); |
|
} |
|
} |
|
} |
|
diff --git a/node_modules/@rn-toolkit/react-native-lottie-splash-screen/android/src/main/res/values/attrs.xml b/node_modules/@rn-toolkit/react-native-lottie-splash-screen/android/src/main/res/values/attrs.xml |
|
new file mode 100644 |
|
index 0000000..5433b7a |
|
--- /dev/null |
|
+++ b/node_modules/@rn-toolkit/react-native-lottie-splash-screen/android/src/main/res/values/attrs.xml |
|
@@ -0,0 +1,4 @@ |
|
+<?xml version="1.0" encoding="utf-8"?> |
|
+<resources> |
|
+ <attr name="postBootSplashTheme" format="reference" /> |
|
+</resources> |
|
diff --git a/node_modules/@rn-toolkit/react-native-lottie-splash-screen/android/src/main/res/values/public.xml b/node_modules/@rn-toolkit/react-native-lottie-splash-screen/android/src/main/res/values/public.xml |
|
new file mode 100644 |
|
index 0000000..16a2bf9 |
|
--- /dev/null |
|
+++ b/node_modules/@rn-toolkit/react-native-lottie-splash-screen/android/src/main/res/values/public.xml |
|
@@ -0,0 +1,4 @@ |
|
+<?xml version="1.0" encoding="utf-8"?> |
|
+<resources> |
|
+ <public name="postBootSplashTheme" type="attr" /> |
|
+</resources> |
|
diff --git a/node_modules/@rn-toolkit/react-native-lottie-splash-screen/android/src/main/res/values/styles.xml b/node_modules/@rn-toolkit/react-native-lottie-splash-screen/android/src/main/res/values/styles.xml |
|
index 6db777b..b48a63c 100644 |
|
--- a/node_modules/@rn-toolkit/react-native-lottie-splash-screen/android/src/main/res/values/styles.xml |
|
+++ b/node_modules/@rn-toolkit/react-native-lottie-splash-screen/android/src/main/res/values/styles.xml |
|
@@ -8,5 +8,6 @@ |
|
</style> |
|
<style name="SplashScreen_Fullscreen" parent="SplashScreen_SplashTheme"> |
|
<item name="android:windowFullscreen">true</item> |
|
+ <item name="postBootSplashTheme">?android:attr/theme</item> |
|
</style> |
|
</resources> |
|
diff --git a/node_modules/@rn-toolkit/react-native-lottie-splash-screen/ios/RNSplashScreen.m b/node_modules/@rn-toolkit/react-native-lottie-splash-screen/ios/RNSplashScreen.m |
|
index c74a3c0..c07d96a 100644 |
|
--- a/node_modules/@rn-toolkit/react-native-lottie-splash-screen/ios/RNSplashScreen.m |
|
+++ b/node_modules/@rn-toolkit/react-native-lottie-splash-screen/ios/RNSplashScreen.m |
|
@@ -1,96 +1,118 @@ |
|
-/** |
|
- * SplashScreen |
|
- * 启动屏 |
|
- * from:http://www.devio.org |
|
- * Author:CrazyCodeBoy |
|
- * GitHub:https://github.com/crazycodeboy |
|
- * Email:[email protected] |
|
- */ |
|
- |
|
#import "RNSplashScreen.h" |
|
#import <React/RCTBridge.h> |
|
|
|
static bool waiting = true; |
|
static bool isAnimationFinished = false; |
|
-static bool addedJsLoadErrorObserver = false; |
|
static UIView* loadingView = nil; |
|
|
|
@implementation RNSplashScreen |
|
+ |
|
- (dispatch_queue_t)methodQueue { |
|
return dispatch_get_main_queue(); |
|
} |
|
+ |
|
RCT_EXPORT_MODULE(SplashScreen) |
|
|
|
-+ (void)show { |
|
- if (!addedJsLoadErrorObserver) { |
|
++ (void)initialize { |
|
+ if (self == [RNSplashScreen class]) { |
|
[[NSNotificationCenter defaultCenter] addObserver:self |
|
selector:@selector(jsLoadError:) |
|
name:RCTJavaScriptDidFailToLoadNotification |
|
object:nil]; |
|
- addedJsLoadErrorObserver = true; |
|
- } |
|
- |
|
- while (waiting) { |
|
- NSDate* later = [NSDate dateWithTimeIntervalSinceNow:0.1]; |
|
- [[NSRunLoop mainRunLoop] runUntilDate:later]; |
|
} |
|
} |
|
|
|
-+ (void)showSplash:(NSString*)splashScreen inRootView:(UIView*)rootView { |
|
- if (!loadingView) { |
|
- loadingView = [[[NSBundle mainBundle] loadNibNamed:splashScreen owner:self |
|
- options:nil] objectAtIndex:0]; |
|
- CGRect frame = rootView.frame; |
|
- frame.origin = CGPointMake(0, 0); |
|
- loadingView.frame = frame; |
|
- } |
|
- waiting = false; |
|
++ (void)show { |
|
+ dispatch_async(dispatch_get_main_queue(), ^{ |
|
+ if (loadingView) { |
|
+ loadingView.backgroundColor = [UIColor redColor]; |
|
+ } |
|
+ else { |
|
+ // Initialize loadingView and add to rootView |
|
+ } |
|
+ waiting = false; |
|
+ }); |
|
+} |
|
|
|
- [rootView addSubview:loadingView]; |
|
++ (void)showSplash:(NSString*)splashScreen inRootView:(nonnull UIView*)rootView { |
|
+ dispatch_async(dispatch_get_main_queue(), ^{ |
|
+ if (!loadingView) { |
|
+ NSArray *nibViews = [[NSBundle mainBundle] loadNibNamed:splashScreen owner:self options:nil]; |
|
+ if ([nibViews count] > 0) { |
|
+ loadingView = [nibViews objectAtIndex:0]; |
|
+ CGRect frame = rootView.frame; |
|
+ frame.origin = CGPointMake(0, 0); |
|
+ loadingView.frame = frame; |
|
+ [rootView addSubview:loadingView]; |
|
+ } |
|
+ else { |
|
+ NSLog(@"Error: No views in nib named %@", splashScreen); |
|
+ } |
|
+ } |
|
+ }); |
|
} |
|
|
|
+ (void)showLottieSplash:(UIView*)animationView inRootView:(UIView*)rootView { |
|
- loadingView = animationView; |
|
- waiting = false; |
|
- [rootView addSubview:animationView]; |
|
+ dispatch_async(dispatch_get_main_queue(), ^{ |
|
+ if (!loadingView) { |
|
+ loadingView = animationView; |
|
+ CGRect frame = rootView.frame; |
|
+ frame.origin = CGPointMake(0, 0); |
|
+ loadingView.frame = frame; |
|
+ [rootView addSubview:loadingView]; |
|
+ waiting = false; |
|
+ } |
|
+ }); |
|
} |
|
|
|
+ (void)hide { |
|
- if (waiting) { |
|
- dispatch_async(dispatch_get_main_queue(), ^{ |
|
- waiting = false; |
|
- }); |
|
- } else { |
|
- waiting = true; |
|
- if (isAnimationFinished) { |
|
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), |
|
- dispatch_get_main_queue(), ^{ |
|
- [UIView animateWithDuration:0.2 |
|
- animations:^{loadingView.alpha = 0.0;} |
|
- completion:^(BOOL finished){ [loadingView removeFromSuperview]; }]; |
|
- }); |
|
- } |
|
- } |
|
+ dispatch_async(dispatch_get_main_queue(), ^{ |
|
+ if (loadingView && loadingView.superview) { |
|
+ [UIView animateWithDuration:0.3 animations:^{ |
|
+ loadingView.alpha = 0.0; |
|
+ } completion:^(BOOL finished){ |
|
+ [loadingView removeFromSuperview]; |
|
+ loadingView = nil; |
|
+ }]; |
|
+ } |
|
+ waiting = false; |
|
+ }); |
|
} |
|
|
|
+ (void)setAnimationFinished:(Boolean)flag { |
|
+ dispatch_async(dispatch_get_main_queue(), ^{ |
|
isAnimationFinished = flag; |
|
- if (waiting) { |
|
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), |
|
- dispatch_get_main_queue(), ^{ |
|
- [loadingView removeFromSuperview]; |
|
- }); |
|
+ if (!waiting && isAnimationFinished) { |
|
+ [UIView animateWithDuration:0.3 animations:^{ |
|
+ loadingView.alpha = 0.0; |
|
+ } completion:^(BOOL finished){ |
|
+ [loadingView removeFromSuperview]; |
|
+ loadingView = nil; |
|
+ }]; |
|
} |
|
+ }); |
|
} |
|
|
|
+ (void)jsLoadError:(NSNotification*)notification { |
|
- // If there was an error loading javascript, hide the splash screen so it can be shown. Otherwise |
|
- // the splash screen will remain forever, which is a hassle to debug. |
|
- [RNSplashScreen hide]; |
|
+ dispatch_async(dispatch_get_main_queue(), ^{ |
|
+ [RNSplashScreen hide]; |
|
+ }); |
|
+} |
|
+ |
|
+RCT_EXPORT_METHOD(hide) { |
|
+ dispatch_async(dispatch_get_main_queue(), ^{ |
|
+ [RNSplashScreen hide]; |
|
+ }); |
|
} |
|
|
|
-RCT_EXPORT_METHOD(hide) { [RNSplashScreen hide]; } |
|
+RCT_EXPORT_METHOD(show) { |
|
+ dispatch_async(dispatch_get_main_queue(), ^{ |
|
+ [RNSplashScreen show]; |
|
+ }); |
|
+} |
|
|
|
-RCT_EXPORT_METHOD(show) { [RNSplashScreen show]; } |
|
++ (void)dealloc { |
|
+ [[NSNotificationCenter defaultCenter] removeObserver:self]; |
|
+} |
|
|
|
@end |
if anyone got any questions leave a comment and will try to answer asap