-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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] Fix: Modal Animation Repeats When Returning from Background #28538
base: main
Are you sure you want to change the base?
Conversation
Hey there @bhavanesh2001! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could include an UITest like
https://github.com/user-attachments/assets/bf28a45f-dcde-4b26-bdb3-1342dc9d4a3c
?
In the test, can use:
App.BackgroundApp();
App.ForegroundApp();
To move the App to background etc.
@jsuarezruiz Would it be possible to include a UI test for this? Since the issue is that the modal animation replays when returning from the background, how can we verify in an automated test that the animation has not been triggered again? |
@@ -322,10 +322,28 @@ public override AView OnCreateView(LayoutInflater inflater, ViewGroup? container | |||
_navigationRootManager.Connect(_modal, modalContext); | |||
|
|||
UpdateBackgroundColor(); | |||
if (IsAnimated && _navigationRootManager is not null && _navigationRootManager.RootView is not null) | |||
{ | |||
_ = new GenericGlobalLayoutListener((listner,view) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it fine to not dispose this GenericGlobalLayoutListener
? would be good to add double check with a memory leak test, if the existing ones don't test for that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pictos I added a commit to explicitly dispose the listener once it's no longer needed. Does this look like the correct approach for cleanup?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the other hand, I don't think it's a good idea to call Dispose() manually, so I reverted the commit. Since we are already removing it from ViewTreeObserver, it should be cleaned up automatically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GenericGlobalLayoutListener has an Invalidate
method you can call which won't dispose of it but still cleans it up
I think we should use that vs the calling Remove on line 329
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PureWeen Thanks for the suggestion
I think GenericGlobalLayoutListener will cause memory leaks |
IMO the animation should start in the
|
@kubaflo I get that |
@kubaflo I’ve added a memory leak test for when a modal is opened with animation, and it passes with the GenericGlobalLayoutListener implementation. device_test.mov@jsuarezruiz could you run pipelines on this? |
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jsuarezruiz fixed failing tests. |
Description of Change
This PR provides a fix for #28492 and is an alternative to #28522. It ensures that modal animations only play once when the modal is first displayed and do not replay when the app returns from the background.
Rather than starting the animation in
OnStart()
,this fix attaches aGlobalLayoutListener
to the view insideOnCreateView()
. When the view's layout is complete for the first time, the listener invokes the animation and then removes itself to prevent any further invocations. Additionally, theOnAnimationEnded
method has been moved out of the lambda for improved readability.After Fix:
fix.mov
Issues Fixed
Fixes #28492
Related PR #28522