-
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
CollectionView Header/Footer/EmptyView issues when adding/removing items. #24830
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…ing/removing items
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. |
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
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
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
PureWeen
requested changes
Oct 2, 2024
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.
Tests failing
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
Azure Pipelines successfully started running 3 pipeline(s). |
1 similar comment
Azure Pipelines successfully started running 3 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
4 tasks
rmarinho
approved these changes
Oct 10, 2024
rmarinho
added a commit
that referenced
this pull request
Oct 10, 2024
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 <[email protected]>
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
community ✨
Community Contribution
fixed-in-net8.0-nightly
This may be available in a nightly release!
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Screenshots
Android:
iOS: