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] CollectionView logical children grows with Header/Footer #17012

Merged
merged 2 commits into from
Aug 28, 2023

Conversation

jonathanpeppers
Copy link
Member

@jonathanpeppers jonathanpeppers commented Aug 25, 2023

Fixes #16961

Debugging the ItemsSourceDoesNotLeak() test with a new Header and Footer on Android, there was some very odd behavior...

At the end of the test, _logicalChildren contained 9 items!

Header
Footer
Header
Footer
Header
null
null
null
Footer

Where I would expect it to contain 5?!?

It appears the problem is:

  • CollectionView.ItemsSource changes

  • We notify Android's RecyclerView to refresh

  • RecyclerView calls OnCreateViewHolder() for the header, footer, and all rows.

  • CreateHeaderFooterViewHolder() is called again for the header & footer.

  • Duplicate viewHolder.View items are added as logical children.

To fix this, an idea:

  • Create a new internal ContainsLogicalChild() method

  • Call this before adding the same View in CreateHeaderFooterViewHolder()

This isn't the best, because it will iterate over the _logicalChildren to decide if the list contains the view. But this is better than what strange behavior might result from this?

Fixes: dotnet#16961

Debugging the `ItemsSourceDoesNotLeak()` test with a new `Header` and
`Footer` on Android, there was some very odd behavior...

At the end of the test, `_logicalChildren` contained 9 items!

    Header
    Footer
    Header
    Footer
    Header
    null
    null
    null
    Footer

Where I would expect it to contain 5?!?

It appears the problem is:

* `CollectionView.ItemsSource` changes

* We notify Android's `RecyclerView` to refresh

* `RecyclerView` calls `OnCreateViewHolder()` for the header, footer,
  and all rows.

* `CreateHeaderFooterViewHolder()` is called again for the header &
  footer.

* Duplicate `viewHolder.View` items are added as logical children.

To fix this, an idea:

* Create a new `internal ContainsLogicalChild()` method

* Call this before adding the same `View` in
  `CreateHeaderFooterViewHolder()`

This isn't the *best*, because it will iterate over the
`_logicalChildren` to decide if the list contains the view. But this is
better than what strange behavior might result from this?
@samhouts samhouts added this to the .NET 8 GA milestone Aug 28, 2023
@jonathanpeppers jonathanpeppers marked this pull request as ready for review August 28, 2023 19:46
@jonathanpeppers jonathanpeppers requested a review from a team as a code owner August 28, 2023 19:46
@PureWeen PureWeen merged commit df1fb2d into dotnet:main Aug 28, 2023
38 checks passed
@jonathanpeppers jonathanpeppers deleted the AndroidItemsSourceIsWeird branch August 28, 2023 22:01
@github-actions github-actions bot locked and limited conversation to collaborators Dec 5, 2023
@samhouts samhouts added the fixed-in-8.0.0-rc.1.9171 Look for this fix in 8.0.0-rc.1.9171 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.0-rc.1.9171 Look for this fix in 8.0.0-rc.1.9171 platform/android 🤖
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Android CollectionView leaks if given a header or footer
3 participants