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
This commit is contained in:
parent
03ea0a4e80
commit
617ad81090
@ -134,7 +134,7 @@ public class SplashScreen extends CordovaPlugin {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// hide the splash screen to avoid leaking a window
|
// hide the splash screen to avoid leaking a window
|
||||||
this.removeSplashScreen();
|
this.removeSplashScreen(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -143,7 +143,7 @@ public class SplashScreen extends CordovaPlugin {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// hide the splash screen to avoid leaking a window
|
// 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!
|
// If we set this to true onDestroy, we lose track when we go from page to page!
|
||||||
//firstShow = true;
|
//firstShow = true;
|
||||||
}
|
}
|
||||||
@ -177,7 +177,7 @@ public class SplashScreen extends CordovaPlugin {
|
|||||||
}
|
}
|
||||||
if ("splashscreen".equals(id)) {
|
if ("splashscreen".equals(id)) {
|
||||||
if ("hide".equals(data.toString())) {
|
if ("hide".equals(data.toString())) {
|
||||||
this.removeSplashScreen();
|
this.removeSplashScreen(false);
|
||||||
} else {
|
} else {
|
||||||
this.showSplashScreen(false);
|
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() {
|
cordova.getActivity().runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
if (splashDialog != null && splashDialog.isShowing()) {
|
if (splashDialog != null && splashDialog.isShowing()) {
|
||||||
final int fadeSplashScreenDuration = getFadeDuration();
|
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);
|
AlphaAnimation fadeOut = new AlphaAnimation(1, 0);
|
||||||
fadeOut.setInterpolator(new DecelerateInterpolator());
|
fadeOut.setInterpolator(new DecelerateInterpolator());
|
||||||
fadeOut.setDuration(fadeSplashScreenDuration);
|
fadeOut.setDuration(fadeSplashScreenDuration);
|
||||||
@ -319,7 +320,7 @@ public class SplashScreen extends CordovaPlugin {
|
|||||||
handler.postDelayed(new Runnable() {
|
handler.postDelayed(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
if (lastHideAfterDelay) {
|
if (lastHideAfterDelay) {
|
||||||
removeSplashScreen();
|
removeSplashScreen(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, effectiveSplashDuration);
|
}, effectiveSplashDuration);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user