From 617ad8109055701214a1fdff5423a3742edc9f69 Mon Sep 17 00:00:00 2001 From: Dan Polivy Date: Wed, 24 Feb 2016 17:03:58 -0800 Subject: [PATCH] CB-10692 Don't fade when plugin is forced to close The fading logic exposed a race condition in an edge case when the plugin was repeatedly reinitialized, e.g. when the WebView tries to load a new URL. To address this, we add a flag to removeSplashScreen() that allows the fade logic to be bypassed in certain circumstances -- specifically, when hiding the splashscreen due to onPause or onDestroy events. By hiding it immediately in this scenario, we can avoid any race conditions due to the fade delay. github: close #86 --- src/android/SplashScreen.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/android/SplashScreen.java b/src/android/SplashScreen.java index 6a077c0..d9ac66a 100644 --- a/src/android/SplashScreen.java +++ b/src/android/SplashScreen.java @@ -134,7 +134,7 @@ public class SplashScreen extends CordovaPlugin { return; } // hide the splash screen to avoid leaking a window - this.removeSplashScreen(); + this.removeSplashScreen(true); } @Override @@ -143,7 +143,7 @@ public class SplashScreen extends CordovaPlugin { return; } // hide the splash screen to avoid leaking a window - this.removeSplashScreen(); + this.removeSplashScreen(true); // If we set this to true onDestroy, we lose track when we go from page to page! //firstShow = true; } @@ -177,7 +177,7 @@ public class SplashScreen extends CordovaPlugin { } if ("splashscreen".equals(id)) { if ("hide".equals(data.toString())) { - this.removeSplashScreen(); + this.removeSplashScreen(false); } else { this.showSplashScreen(false); } @@ -206,12 +206,13 @@ public class SplashScreen extends CordovaPlugin { } } - private void removeSplashScreen() { + private void removeSplashScreen(final boolean forceHideImmediately) { cordova.getActivity().runOnUiThread(new Runnable() { public void run() { if (splashDialog != null && splashDialog.isShowing()) { final int fadeSplashScreenDuration = getFadeDuration(); - if (fadeSplashScreenDuration > 0) { + // CB-10692 If the plugin is being paused/destroyed, skip the fading and hide it immediately + if (fadeSplashScreenDuration > 0 && forceHideImmediately == false) { AlphaAnimation fadeOut = new AlphaAnimation(1, 0); fadeOut.setInterpolator(new DecelerateInterpolator()); fadeOut.setDuration(fadeSplashScreenDuration); @@ -319,7 +320,7 @@ public class SplashScreen extends CordovaPlugin { handler.postDelayed(new Runnable() { public void run() { if (lastHideAfterDelay) { - removeSplashScreen(); + removeSplashScreen(false); } } }, effectiveSplashDuration);