Skip to content
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

[Android] [Shell] Ensure AnimationFinished is called when app backgrounds mid-animation #27534

Conversation

albyrock87
Copy link
Contributor

@albyrock87 albyrock87 commented Feb 3, 2025

Issue

Consider this shell stack: ShellContent > InnerPage.

The user presses a button to pop the page programmatically:

await Shell.Current.GoToAsync("..")
DoSomethingElse();

DoSomethingElse is never being called if the user presses the android back button quickly while the animation is still in progress.

This is caused because IAnimationListener.onAnimationEnd is never being invoked by android as the animation was canceled.

Description of Change

Trigger the animation complete even upon fragment Destroy so that if the navigation is still waiting, it can complete.

Issues Fixed

Relates to #26617 (#27364)

…rounds mid-animation
@albyrock87 albyrock87 requested a review from a team as a code owner February 3, 2025 12:32
@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Feb 3, 2025
albyrock87 added a commit to nalu-development/maui-custom that referenced this pull request Feb 3, 2025
Copy link
Contributor

Hey there @albyrock87! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@jsuarezruiz jsuarezruiz added area-animation Animation, Transitions, Transforms platform/android 🤖 labels Feb 3, 2025
@PureWeen
Copy link
Member

PureWeen commented Feb 3, 2025

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

// the app enters background state in the middle of the animation causing the fragment to be destroyed without completing the animation.
// That'll cause `IAnimationListener.onAnimationEnd` to not be called, so we need to call it manually if something is still subscribed to the event
// to avoid the navigation `TaskCompletionSource` to be stuck forever.
AnimationFinished?.Invoke(this, EventArgs.Empty);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just wondering: Should this method be called only if _isAnimating == true?

Copy link
Contributor Author

@albyrock87 albyrock87 Feb 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question! _isAnimating = true happens after AnimationFinished += subscription, so it's better to trust the event to avoid race conditions.

@PureWeen PureWeen added this to the .NET 9 SR5 milestone Feb 5, 2025
@PureWeen PureWeen self-assigned this Feb 10, 2025
@PureWeen PureWeen merged commit 682849b into dotnet:main Mar 4, 2025
128 checks passed
bhavanesh2001 pushed a commit to bhavanesh2001/maui that referenced this pull request Mar 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-animation Animation, Transitions, Transforms community ✨ Community Contribution platform/android 🤖
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

4 participants