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

Add/Remove CarouselView Layout Listener when view is add/removed from window #18771

Merged
merged 5 commits into from
Nov 16, 2023

Conversation

PureWeen
Copy link
Member

@PureWeen PureWeen commented Nov 15, 2023

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 the CarouselView 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 the CarouselView. Because GlobalLayoutListeners are added to the ViewTreeObserver they are essentially being added to a resilient static container. This PR makes it so the GlobalLayoutListener is only added when the CarouselView is part of the Visual Tree.

Issues Fixed

Fixes #18733

@PureWeen PureWeen marked this pull request as ready for review November 15, 2023 22:12
@PureWeen PureWeen requested a review from a team as a code owner November 15, 2023 22:12
@PureWeen PureWeen requested review from StephaneDelcroix and hartez and removed request for StephaneDelcroix November 15, 2023 22:12
@PureWeen PureWeen changed the title Don't fire layout if CV is disposed Don't fire layout if CV is disposed and connect Layout Listener to platform events Nov 15, 2023
@PureWeen PureWeen changed the title Don't fire layout if CV is disposed and connect Layout Listener to platform events Add/Remove CarouselView Layout Listener when view is add/removed from window Nov 15, 2023
protected override void OnAttachedToWindow()
{
base.OnAttachedToWindow();
AddLayoutListener();
Copy link
Member Author

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

@jonathanpeppers
Copy link
Member

jonathanpeppers commented Nov 15, 2023

Can you test the changes here in this app?

If it works and you see ~CarouselView Page, then these changes should be fine. 👍

@PureWeen
Copy link
Member Author

CarouselView

image

@PureWeen PureWeen requested a review from mattleibow November 16, 2023 04:02
@PureWeen PureWeen enabled auto-merge (squash) November 16, 2023 04:02
@PureWeen PureWeen merged commit 573dfb9 into main Nov 16, 2023
@PureWeen PureWeen deleted the fix_dispose_exception branch November 16, 2023 13:48
@github-actions github-actions bot locked and limited conversation to collaborators Dec 17, 2023
@samhouts samhouts added the fixed-in-8.0.6 Look for this fix in 8.0.6 SR1! label Aug 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
fixed-in-8.0.6 Look for this fix in 8.0.6 SR1!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Testing] MauiCarouselRecyclerView occasionally fails when running Controls Device Tests
5 participants