globules-io commented on issue #1514: URL: https://github.com/apache/cordova-android/issues/1514#issuecomment-3127196561
I am really annoyed with this glitch so I did a lot of debugging around it and could not find any issue with the code. Here's my updated SplashScreenPlugin.java file to add lots of debug info around the fading and preventing multiple fade calls and tracing the alpha while fading but everything is straight and it is still happening. If someone wants to take it from here... ``` package org.apache.cordova; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.annotation.SuppressLint; import android.os.Handler; import android.util.Log; import android.view.View; import android.view.animation.AccelerateInterpolator; import androidx.annotation.NonNull; import androidx.core.splashscreen.SplashScreen; import androidx.core.splashscreen.SplashScreenViewProvider; import org.json.JSONArray; import org.json.JSONException; @SuppressLint("LongLogTag") public class SplashScreenPlugin extends CordovaPlugin { static final String PLUGIN_NAME = "CordovaSplashScreenPlugin"; // Default config preference values private static final boolean DEFAULT_AUTO_HIDE = true; private static final int DEFAULT_DELAY_TIME = -1; private static final boolean DEFAULT_FADE = true; private static final int DEFAULT_FADE_TIME = 500; // Config preference values /** * Boolean flag to auto hide splash screen (default=true) */ private boolean autoHide; /** * Integer value of how long to delay in milliseconds (default=-1) */ private int delayTime; /** * Boolean flag if to fade to fade out splash screen (default=true) */ private boolean isFadeEnabled; /** * Integer value of the fade duration in milliseconds (default=500) */ private int fadeDuration; // Internal variables /** * Boolean flag to determine if the splash screen remains visible. */ private boolean keepOnScreen = true; @Override protected void pluginInitialize() { // Auto Hide & Delay Settings autoHide = preferences.getBoolean("AutoHideSplashScreen", DEFAULT_AUTO_HIDE); delayTime = preferences.getInteger("SplashScreenDelay", DEFAULT_DELAY_TIME); LOG.d(PLUGIN_NAME, "Auto Hide: " + autoHide); if (delayTime != DEFAULT_DELAY_TIME) { LOG.d(PLUGIN_NAME, "Delay: " + delayTime + "ms"); } // Fade & Fade Duration isFadeEnabled = preferences.getBoolean("FadeSplashScreen", DEFAULT_FADE); fadeDuration = preferences.getInteger("FadeSplashScreenDuration", DEFAULT_FADE_TIME); LOG.d(PLUGIN_NAME, "Fade: " + isFadeEnabled); if (isFadeEnabled) { LOG.d(PLUGIN_NAME, "Fade Duration: " + fadeDuration + "ms"); } } @Override public boolean execute( String action, JSONArray args, CallbackContext callbackContext ) throws JSONException { if (action.equals("hide") && autoHide == false) { /* * The `.hide()` method can only be triggered if the `splashScreenAutoHide` * is set to `false`. */ keepOnScreen = false; Log.d("SplashScreenPlugin", "Hide action triggered"); } else { return false; } callbackContext.success(); return true; } @Override public Object onMessage(String id, Object data) { switch (id) { case "setupSplashScreen": setupSplashScreen((SplashScreen) data); break; case "onPageFinished": attemptCloseOnPageFinished(); break; } return null; } private void setupSplashScreen(SplashScreen splashScreen) { // Setup Splash Screen Delay splashScreen.setKeepOnScreenCondition(() -> { Log.d("SplashScreenPlugin", "KeepOnScreenCondition checked: " + keepOnScreen); return keepOnScreen; }); // Disable back navigation for splash screen to prevent system interference splashScreen.setOnExitAnimationListener(splashScreenViewProvider -> { View splashScreenView = splashScreenViewProvider.getView(); splashScreenView.setOnKeyListener((v, keyCode, event) -> { // Block back key to prevent WindowOnBackDispatcher interference Log.d("SplashScreenPlugin", "Back key blocked during splash screen"); return true; }); }); // Auto hide splash screen when custom delay is defined if (autoHide && delayTime != DEFAULT_DELAY_TIME) { Handler splashScreenDelayHandler = new Handler(cordova.getContext().getMainLooper()); splashScreenDelayHandler.postDelayed(() -> { Log.d("SplashScreenPlugin", "Auto-hide triggered after delay: " + delayTime); keepOnScreen = false; }, delayTime); } // Auto hide with default delay (-1) is controlled by the `onPageFinished` message // If auto hide is disabled (false), hiding is triggered by `navigator.splashscreen.hide()` if (isFadeEnabled) { // Setup the fade with a guard to prevent multiple animations splashScreen.setOnExitAnimationListener(new SplashScreen.OnExitAnimationListener() { private boolean isAnimationRunning = false; // Guard to prevent multiple animations @Override public void onSplashScreenExit(@NonNull SplashScreenViewProvider splashScreenViewProvider) { if (isAnimationRunning) { Log.d("SplashScreenPlugin", "Animation already running, skipping"); return; } isAnimationRunning = true; View splashScreenView = splashScreenViewProvider.getView(); // Prevent view redraws during animation splashScreenView.setLayerType(View.LAYER_TYPE_HARDWARE, null); // Disable view updates to avoid opacity reset splashScreenView.setWillNotDraw(false); splashScreenView.setAlpha(1.0f); // Explicitly set initial opacity Log.d("SplashScreenPlugin", "Starting fade animation with duration: " + fadeDuration); splashScreenView .animate() .alpha(0.0f) .setDuration(fadeDuration) .setStartDelay(0) .setInterpolator(new AccelerateInterpolator()) .setUpdateListener(animation -> Log.d("SplashScreenPlugin", "Animation update, view alpha: " + splashScreenView.getAlpha())) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { Log.d("SplashScreenPlugin", "Fade animation started, view alpha: " + splashScreenView.getAlpha()); } @Override public void onAnimationEnd(Animator animation) { Log.d("SplashScreenPlugin", "Fade animation ended, view alpha: " + splashScreenView.getAlpha()); splashScreenViewProvider.remove(); isAnimationRunning = false; splashScreenView.setLayerType(View.LAYER_TYPE_NONE, null); } @Override public void onAnimationCancel(Animator animation) { Log.d("SplashScreenPlugin", "Fade animation cancelled, view alpha: " + splashScreenView.getAlpha()); isAnimationRunning = false; splashScreenViewProvider.remove(); splashScreenView.setLayerType(View.LAYER_TYPE_NONE, null); } @Override public void onAnimationRepeat(Animator animation) { Log.d("SplashScreenPlugin", "Fade animation repeated unexpectedly, view alpha: " + splashScreenView.getAlpha()); } }) .start(); } }); } } private void attemptCloseOnPageFinished() { if (autoHide && delayTime == DEFAULT_DELAY_TIME) { Log.d("SplashScreenPlugin", "Page finished, triggering auto-hide"); keepOnScreen = false; } } } ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@cordova.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@cordova.apache.org For additional commands, e-mail: issues-h...@cordova.apache.org