[iOS] Fixed issue where group Header/Footer template was set to all items when IsGrouped was true for an ObservableCollection#29144
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR fixes the issue where group header and footer templates were incorrectly applied and not updating as expected when the ObservableCollection’s IsGrouped property was true.
- Adds group header/footer template mappings for iOS in CollectionViewHandler2.iOS.cs.
- Updates ObservableGroupedSource.cs to only add groups that implement IEnumerable.
- Removes platform-specific mapping conditions in GroupableItemsViewHandler.cs.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/Controls/src/Core/Handlers/Items2/CollectionViewHandler2.iOS.cs | Adds new mapping for group header/footer templates to support dynamic updates on iOS. |
| src/Controls/src/Core/Handlers/Items/iOS/ObservableGroupedSource.cs | Adjusts group source creation with a type-check to include only IEnumerable groups. |
| src/Controls/src/Core/Handlers/Items/GroupableItemsViewHandler.cs | Removes conditional mapping for group header/footer templates on certain platforms. |
src/Controls/src/Core/Handlers/Items/iOS/ObservableGroupedSource.cs
Outdated
Show resolved
Hide resolved
|
/azp run MAUI-UITests-public |
|
Azure Pipelines successfully started running 1 pipeline(s). |
@jsuarezruiz , yes, the failures were caused by these changes. I have updated the fix and committed the changes. Could you please review them and let me know if you have any concerns? |
|
/azp run MAUI-UITests-public |
|
Azure Pipelines successfully started running 1 pipeline(s). |
@kubaflo, The UI test has been added. |
kubaflo
left a comment
There was a problem hiding this comment.
Could you please verify #29144 (comment)
…#34317) <!-- Please let the below note in for people that find this PR --> > [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! ### Description of Change Add `darc-*` to the `trigger: branches: include:` section in `ci-uitests.yml` and `ci-device-tests.yml` so that `maui-pr-uitests` and `maui-pr-devicetests` automatically run when dotnet-maestro pushes dependency updates to `darc-*` branches. Previously, these pipelines required manual `/azp run` comments on every maestro PR. ### Issues Fixed N/A - CI improvement ### Files Changed - `eng/pipelines/ci-uitests.yml` - Added `darc-*` to CI trigger branch filter - `eng/pipelines/ci-device-tests.yml` - Added `darc-*` to CI trigger branch filter Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
095b58a to
2650d18
Compare
@kubaflo Based on the AI summary, I implemented the recommended improvements using a try-fix approach. Also, I added test cases to cover the suggested edge cases and applied these improvements to Android as well. |


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!
Issue 1: Group header and footer templates not updating correctly at runtime on iOS.
Root Cause
The mapper for
GroupFooterTemplatePropertyandGroupHeaderTemplatePropertyinGroupableItemsViewHandlerwas conditionally compiled with#if WINDOWS || __ANDROID__ || TIZEN, meaning it was excluded from iOS builds. As a result, changing the template at runtime on iOS had no effect and templates were never displayed.Description of Change
Removed the
#if WINDOWS || __ANDROID__ || TIZENpreprocessor guard fromGroupableItemsViewHandler.cs, making theGroupFooterTemplatePropertyandGroupHeaderTemplatePropertymappers active on all platforms including iOS. Both mappers callMapIsGrouped, which triggersUpdateItemsSource()and refreshes the grouping state.Issue 2: Group header/footer templates incorrectly applied to all items in a flat ObservableCollection when
IsGrouped = true.Root Cause
In
ObservableGroupedSource.cs(iOS), theGroupsCount()method iterated over all items in_groupSourceand counted every item, regardless of whether it was anIEnumerable(i.e., an actual group). WhenIsGrouped = truebut the source was a flatObservableCollection<T>(non-grouped), each non-grouped item was counted as a section, causingNumberOfSectionsto be inflated. This led to header and footer templates being incorrectly applied to every item.Description of Change
Modified
GroupsCount()to only increment the count for items that implementIEnumerable. Non-IEnumerableitems are no longer counted as sections. As a result,NumberOfSectionsnow correctly reflects the number of actual groups, preventing header/footer templates from appearing for non-grouped items.Issues Fixed
Fixes #29141
Test Case
Tests for this fix are included in this PR:
src/Controls/tests/TestCases.HostApp/Issues/Issue29141.cs— HostApp page with aCollectionViewbound to a flatObservableCollection, with radio buttons to toggleIsGrouped,GroupHeaderTemplate, andGroupFooterTemplateat runtime.src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29141.cs— NUnit UI test verifying that group header/footer template views are NOT shown when the source collection is not grouped.Platforms Tested