Skip to content

[Android] Fix: Modal Animation Repeats When Returning from Background 2 #29557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 21, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Handle animation while poping
  • Loading branch information
bhavanesh2001 committed May 19, 2025
commit 5771076ec479a97c38a67b0e2eb113a1f32bb4f5
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,35 @@ Task<Page> PopModalPlatformAsync(bool animated)
Page modal = CurrentPlatformModalPage;
_platformModalPages.Remove(modal);

TaskCompletionSource<Page> tcs = new();

var fragmentManager = WindowMauiContext.GetFragmentManager();

var dialogFragmentId = _modals.Pop();
var dialogFragment = (ModalFragment?)fragmentManager.FindFragmentByTag(dialogFragmentId);

if (dialogFragment is null)
{
tcs.TrySetResult(modal);
return tcs.Task;
}

dialogFragment?.Dismiss();

return Task.FromResult(modal);

if (animated)
{
dialogFragment.Dialog?.Window?.SetWindowAnimations(Resource.Style.dialog_exit_animation);
modal.Dispatcher.Dispatch(() =>
{
dialogFragment.Dismiss();
tcs.TrySetResult(modal);
});
}
else
{
dialogFragment.Dismiss();
tcs.TrySetResult(modal);
}

return tcs.Task;
}

// The CurrentPage doesn't represent the root of the platform hierarchy.
Expand Down Expand Up @@ -195,7 +215,7 @@ public ModalFragment(IMauiContext mauiContext, Page modal)

if (IsAnimated)
{
dialog.Window?.SetWindowAnimations(Resource.Style.dialog_animation);
dialog.Window?.SetWindowAnimations(Resource.Style.dialog_enter_animation);
}

return dialog;
Expand Down
4 changes: 3 additions & 1 deletion src/Core/src/Platform/Android/Resources/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,10 @@
<item name="scrollViewStyle">@style/scrollViewScrollBars</item>
</style>

<style name="dialog_animation" >
<style name="dialog_enter_animation" >
<item name="android:windowEnterAnimation">@anim/nav_modal_default_enter_anim</item>
</style>
<style name="dialog_exit_animation" >
<item name="android:windowExitAnimation">@anim/nav_modal_default_exit_anim</item>
</style>
</resources>
Loading