diff --git a/src/Controls/src/Core/Platform/ModalNavigationManager/ModalNavigationManager.Android.cs b/src/Controls/src/Core/Platform/ModalNavigationManager/ModalNavigationManager.Android.cs index d278d4996140..37454c08f895 100644 --- a/src/Controls/src/Core/Platform/ModalNavigationManager/ModalNavigationManager.Android.cs +++ b/src/Controls/src/Core/Platform/ModalNavigationManager/ModalNavigationManager.Android.cs @@ -230,6 +230,7 @@ internal class ModalFragment : DialogFragment IMauiContext _mauiWindowContext; NavigationRootManager? _navigationRootManager; static readonly ColorDrawable TransparentColorDrawable = new(AColor.Transparent); + bool _pendingAnimation = true; public event EventHandler? AnimationEnded; @@ -301,7 +302,7 @@ void OnAnimationEnded(object? sender, AAnimation.AnimationEndEventArgs e) } animation.AnimationEnd -= OnAnimationEnded; - AnimationEnded?.Invoke(this, EventArgs.Empty); + FireAnimationEnded(); } } @@ -320,6 +321,23 @@ public override void OnDismiss(IDialogInterface dialog) base.OnDismiss(dialog); } + public override void OnDestroy() + { + base.OnDestroy(); + FireAnimationEnded(); + } + + void FireAnimationEnded() + { + if (!_pendingAnimation) + { + return; + } + + _pendingAnimation = false; + AnimationEnded?.Invoke(this, EventArgs.Empty); + } + sealed class CustomComponentDialog : ComponentDialog {