-
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
Add/Remove CarouselView Layout Listener when view is add/removed from window #18771
Conversation
protected override void OnAttachedToWindow() | ||
{ | ||
base.OnAttachedToWindow(); | ||
AddLayoutListener(); |
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.
I do wonder if we want this to be a layout listener. Global Layout Listeners fire for everything, so any changes to the layout anywhere causes the code inside the CV to execute. Maybe that's the intent? It does seem a little excessive.
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.
Can you test the changes here in this app?
If it works and you see |
Description of Change
#18584 modified the
CarouselViewOnGlobalLayoutListener
so that it only retains a weak reference to the recycler view. Because this layout listener no longer participates in keeping theCarouselView
from being collected there's a chance that it could still get triggered from android.We also need to tie the lifetime of the
CarouselViewOnGlobalLayoutListener
to something otherwise it will continue to fire even beyond the lifetime of theCarouselView.
BecauseGlobalLayoutListeners
are added to theViewTreeObserver
they are essentially being added to a resilient static container. This PR makes it so theGlobalLayoutListener
is only added when theCarouselView
is part of the Visual Tree.Issues Fixed
Fixes #18733