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

CollectionView Header/Footer/EmptyView issues when adding/removing items. #24830

Merged
merged 9 commits into from
Oct 10, 2024

Conversation

Vignesh-SF3580
Copy link
Contributor

@Vignesh-SF3580 Vignesh-SF3580 commented Sep 19, 2024

Android:

Sub-Issue1: The footer is not always shown, it appears only for one in two added items

Root Cause

In the AdapterNotifier class, the NotifyItemRangeChanged calls in the NotifyItemInserted and NotifyItemRemoved methods incorrectly used the total _adapter.ItemCount, which included the footer element. This caused the footer to be treated as part of the updated range, leading to the footer being hidden when an odd number of items were added to the CollectionView. When an even number of items were added, the footer reappeared due to the adjusted range calculation.

Description of Change

The fix involved removing unnecessary NotifyItemRangeChanged function calls from the NotifyItemInserted, NotifyItemRemoved, NotifyItemMoved, and NotifyItemRangeInserted methods, as they caused incorrect updates to the footer visibility. These changes were made based on the reference from the Xamarin source code (https://github.com/xamarin/Xamarin.Forms/pull/15236/files#diff-45f23f6731e03254ee2692d1f9d79a864fc85fa802e7fc90eb64656a02156c12), ensuring that the CollectionView properly handles the visibility of the footer during item insertions and removals without the need for redundant range updates.

Fix done at AdapterNotifier.cs

Sub-Issue2: When the last item is removed from the source, the header becomes blank. Subsequently, adding or removing items prevents the footer from appearing until the items list is completely empty again.

Root Cause

In the MauiRecyclerView class, when dynamically switching between an empty view and item view, or vice versa, the adapter's recycled view pool was not cleared. This caused view type mismatches in the recycled view pool, leading to the incorrect rendering of header and footer views. When transitioning from an empty view to an item view, or vice versa, the header and footer views were missing due to the recycled view holders not being correctly updated for the new adapter.

Description of Change

The fix involved clearing the RecyclerView's recycled view pool before swapping adapters using GetRecycledViewPool().Clear(). This ensures that when switching between an empty view and item view, the recycled views (header and footer) are properly recreated with the correct view holders. This change resolved the issue of header and footer views not rendering correctly when transitioning between an empty and item view dynamically.

Fix done at MauiRecyclerView.cs

iOS and MAC : Empty, header, and footer template views not properly shown due to view disposal.

Root Cause:

On iOS, during the update of views (such as header, footer, or empty views), the system incorrectly treated views as empty templates as if they should be disposed. This caused the UIView and VisualElement for these views to be disposed when the view was null, which led to the header, footer, or empty template views not rendering properly in the CollectionView.

Description of Change:

A conditional check was added to ensure that viewTemplate are validated before deciding whether to dispose the UIView and VisualElement. The updated logic prevents disposing of these views unless both the view and its corresponding template are confirmed to be null. This ensures that empty, header, and footer template views are retained and correctly displayed.

Fix done at Items/iOS/ItemsviewController.cs

Issues Fixed

Fixes #11896

Tested the behaviour in the following platforms

  • Android
  • Windows
  • iOS
  • Mac

Screenshots

Android:

Before Issue Fix After Issue Fix

iOS:

Before Issue Fix After Issue Fix

Copy link
Contributor

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

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Sep 19, 2024
@rmarinho
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@rmarinho
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@Vignesh-SF3580 Vignesh-SF3580 changed the title [Android] CollectionView Header/Footer/EmptyView issues when adding/removing items. CollectionView Header/Footer/EmptyView issues when adding/removing items. Sep 27, 2024
@rmarinho
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@Vignesh-SF3580 Vignesh-SF3580 marked this pull request as ready for review September 30, 2024 10:36
@Vignesh-SF3580 Vignesh-SF3580 requested a review from a team as a code owner September 30, 2024 10:36
Copy link
Member

@PureWeen PureWeen left a comment

Choose a reason for hiding this comment

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

Tests failing

@rmarinho
Copy link
Member

rmarinho commented Oct 3, 2024

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

1 similar comment
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@jsuarezruiz
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@rmarinho rmarinho merged commit fb711d4 into dotnet:main Oct 10, 2024
97 checks passed
rmarinho added a commit that referenced this pull request Oct 10, 2024
@samhouts samhouts added the fixed-in-net8.0-nightly This may be available in a nightly release! label Oct 14, 2024
rmarinho added a commit that referenced this pull request Oct 18, 2024
rmarinho added a commit that referenced this pull request Oct 21, 2024
rmarinho added a commit that referenced this pull request Oct 22, 2024
* [tests] Add CV header/footer tests

* Update more tests

* Fixes

* [iOS] Make sure to distinguish between group header and global header on CV2

* [iOS] Porting fix #24830

* [tests] Add test for issue 20443

* [testing] run these tests on iOS for now

Fix build

Add missing usings

* Fix #12429

* Update StructuredItemsViewController.cs

* [iOS] CV2 fix footer

* [iOS] Make sure to handle also the header or footer template

* Fix images

* [tests] This is a bug on CV2

---------

Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
@github-actions github-actions bot locked and limited conversation to collaborators Nov 16, 2024
@sheiksyedm sheiksyedm added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Dec 6, 2024
@samhouts samhouts added fixed-in-9.0.10 fixed-in-net8.0-nightly This may be available in a nightly release! and removed fixed-in-net8.0-nightly This may be available in a nightly release! labels Dec 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
community ✨ Community Contribution fixed-in-9.0.10 fixed-in-net8.0-nightly This may be available in a nightly release! partner/syncfusion Issues / PR's with Syncfusion collaboration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CollectionView Header/Footer/EmptyView issues when adding/removing items
6 participants