File tree Expand file tree Collapse file tree 2 files changed +27
-4
lines changed
android/src/main/java/com/splashview Expand file tree Collapse file tree 2 files changed +27
-4
lines changed Original file line number Diff line number Diff line change @@ -11,12 +11,13 @@ import android.view.WindowManager
1111
1212object SplashView {
1313 private var splashDialog: Dialog ? = null
14-
14+ private var activityRef : java.lang.ref. WeakReference < Any > ? = null
1515 fun showSplashView (activity : Activity ) {
1616 if (activity.isFinishing || activity.isDestroyed) {
1717 println (" Skipping showSplash: Activity is not ready." )
1818 return
1919 }
20+ activityRef = java.lang.ref.WeakReference (activity)
2021
2122 activity.runOnUiThread {
2223 if (splashDialog?.isShowing == true ) return @runOnUiThread
@@ -57,7 +58,29 @@ object SplashView {
5758
5859
5960 fun hideSplashView () {
60- splashDialog?.takeIf { it.isShowing }?.dismiss()
61- splashDialog = null
61+ val activity = activityRef?.get() as ? Activity
62+
63+ if (activity == null ) {
64+ splashDialog = null
65+ activityRef = null
66+ return
67+ }
68+
69+ activity.runOnUiThread {
70+ try {
71+ splashDialog?.let { dialog ->
72+ val decorView = dialog.window?.decorView
73+
74+ if (dialog.isShowing && decorView?.isAttachedToWindow == true ) {
75+ dialog.dismiss()
76+ }
77+ }
78+ } catch (e: Exception ) {
79+ // Safe guard — prevent crash in rare edge cases
80+ } finally {
81+ splashDialog = null
82+ activityRef = null
83+ }
84+ }
6285 }
6386}
Original file line number Diff line number Diff line change 11{
22 "name" : " react-native-splash-view" ,
3- "version" : " 0.0.19 " ,
3+ "version" : " 0.0.21 " ,
44 "description" : " A lightweight splash screen library for React Native." ,
55 "source" : " ./src/index.tsx" ,
66 "main" : " ./lib/commonjs/index.js" ,
You can’t perform that action at this time.
0 commit comments