Fix CollectionView Header/Footer Toggle Issues on Windows and Android #32178
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.
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Description
Fixes header and footer toggle issues in
CollectionViewon Windows and Android platforms where:Changes Made
Windows (
StructuredItemsViewHandler.Windows.cs)Clear template when removing header/footer: Added explicit clearing of
HeaderTemplate/FooterTemplatewhen header/footer is set to null. This ensures the native control properly releases the previous template reference.Prevent duplicate logical child additions: Added a check to only add the view as a logical child if it's not already a child of the element. This prevents issues when the same View instance is toggled multiple times.
Android (
StructuredItemsViewAdapter.cs)Replaced the generic
NotifyDataSetChanged()with specific item notifications for better RecyclerView management:NotifyItemRemoved(0)- Properly animates and removes the header itemNotifyItemInserted(0)- Properly animates and inserts the header itemTesting
Added comprehensive UI test
CollectionViewHeaderFooterTogglethat validates:Platforms Affected
Related Issues
Fixes issue reported in: [Windows/Android] Header/Footer re-add and removal issues in CollectionView
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
scanning-api.github.com/home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
This section details on the original issue you should resolve
<issue_title>[Windows/Android] Header/Footer re-add and removal issues in CollectionView</issue_title>
<issue_description>### Description
When the header/footer are added in CollectionView, the following issues were observed on Windows and Android platforms:
Windows: When toggling the Header/Footer button to the null state and then enabling it again, the header or footer content is not added back
Android: The header and footer are not removed at runtime when set to null.
Actual Behavior:
Windows - the header or footer content is not added back.
Android retains the old header/footer even after setting them to null.
Expected Behavior:
On Windows: Header/Footer should be re-added.
On Android: Header/Footer should be removed properly when set to null.
Steps to Reproduce