Skip to content

[iOS] Fixed issue where group Header/Footer template was set to all items when IsGrouped was true for an ObservableCollection#29144

Merged
kubaflo merged 8 commits intodotnet:inflight/currentfrom
Tamilarasan-Paranthaman:fix-29141
Mar 5, 2026
Merged

[iOS] Fixed issue where group Header/Footer template was set to all items when IsGrouped was true for an ObservableCollection#29144
kubaflo merged 8 commits intodotnet:inflight/currentfrom
Tamilarasan-Paranthaman:fix-29141

Conversation

@Tamilarasan-Paranthaman
Copy link
Member

@Tamilarasan-Paranthaman Tamilarasan-Paranthaman commented Apr 23, 2025

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 GroupFooterTemplateProperty and GroupHeaderTemplateProperty in GroupableItemsViewHandler was 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__ || TIZEN preprocessor guard from GroupableItemsViewHandler.cs, making the GroupFooterTemplateProperty and GroupHeaderTemplateProperty mappers active on all platforms including iOS. Both mappers call MapIsGrouped, which triggers UpdateItemsSource() 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), the GroupsCount() method iterated over all items in _groupSource and counted every item, regardless of whether it was an IEnumerable (i.e., an actual group). When IsGrouped = true but the source was a flat ObservableCollection<T> (non-grouped), each non-grouped item was counted as a section, causing NumberOfSections to 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 implement IEnumerable. Non-IEnumerable items are no longer counted as sections. As a result, NumberOfSections now 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 a CollectionView bound to a flat ObservableCollection, with radio buttons to toggle IsGrouped, GroupHeaderTemplate, and GroupFooterTemplate at 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.

Note: The test is currently excluded from Windows (unrelated NullReferenceException — see #28824) and Android (separate fix in PR #28886). It runs on iOS and MacCatalyst.

Platforms Tested

  • iOS
  • Android
  • Mac
  • Windows

@dotnet-policy-service dotnet-policy-service bot added community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration labels Apr 23, 2025
@jsuarezruiz jsuarezruiz added platform/ios area-controls-collectionview CollectionView, CarouselView, IndicatorView labels Apr 23, 2025
@Tamilarasan-Paranthaman Tamilarasan-Paranthaman marked this pull request as ready for review April 25, 2025 12:22
Copilot AI review requested due to automatic review settings April 25, 2025 12:22
@Tamilarasan-Paranthaman Tamilarasan-Paranthaman requested a review from a team as a code owner April 25, 2025 12:22
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

@jsuarezruiz
Copy link
Contributor

/azp run MAUI-UITests-public

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Contributor

@jsuarezruiz jsuarezruiz left a comment

Choose a reason for hiding this comment

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

There are some related tests failing on iOS and Mac:
image
Could you review if are related with the changes?

@Tamilarasan-Paranthaman
Copy link
Member Author

There are some related tests failing on iOS and Mac: image Could you review if are related with the changes?

@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?

@jsuarezruiz
Copy link
Contributor

/azp run MAUI-UITests-public

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@PureWeen PureWeen added this to the .NET 9 SR9 milestone Jun 10, 2025
@PureWeen PureWeen added the p/1 Work that is important, and has been scheduled for release in this or an upcoming sprint label Jun 10, 2025
@PureWeen PureWeen moved this from Todo to Approved in MAUI SDK Ongoing Jun 10, 2025
@PureWeen PureWeen moved this from Approved to Ready To Review in MAUI SDK Ongoing Jun 10, 2025
@PureWeen PureWeen modified the milestones: .NET 9 SR9, .NET 9 SR10 Jul 3, 2025
@PureWeen PureWeen modified the milestones: .NET 9 SR10, .NET 9 SR11 Aug 4, 2025
@PureWeen PureWeen modified the milestones: .NET 9 SR11, .NET 10 SR1 Sep 10, 2025
@PureWeen PureWeen modified the milestones: .NET 10 SR1, .NET 10.0 SR2 Nov 4, 2025
@Tamilarasan-Paranthaman
Copy link
Member Author

@Tamilarasan-Paranthaman I see :) Alright, could you please add a Ui Test, or even cherry pick the one from Android?

@kubaflo, The UI test has been added.

@kubaflo kubaflo added the s/agent-suggestions-implemented Maintainer applies when PR author adopts agent's recommendation label Feb 17, 2026
@kubaflo kubaflo added s/agent-changes-requested AI agent recommends changes - found a better alternative or issues s/agent-gate-passed AI verified tests catch the bug (fail without fix, pass with fix) and removed s/agent-gate-failed AI could not verify tests catch the bug s/agent-review-incomplete AI agent could not complete all phases (blocker, timeout, error) labels Feb 25, 2026
@PureWeen PureWeen modified the milestones: .NET 10 SR5, .NET 10 SR6 Mar 3, 2026
Copy link
Contributor

@kubaflo kubaflo left a comment

Choose a reason for hiding this comment

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

Could you please verify #29144 (comment)

PureWeen and others added 7 commits March 4, 2026 08:56
…#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>
@Vignesh-SF3580
Copy link
Contributor

Could you please verify #29144 (comment)

@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.

@kubaflo kubaflo added s/agent-fix-implemented PR author implemented the agent suggested fix s/agent-fix-win AI found a better alternative fix than the PR s/agent-approved AI agent recommends approval - PR fix is correct and optimal s/agent-fix-pr-picked AI could not beat the PR fix - PR is the best among all candidates and removed s/agent-changes-requested AI agent recommends changes - found a better alternative or issues s/agent-fix-win AI found a better alternative fix than the PR labels Mar 4, 2026
@github-project-automation github-project-automation bot moved this from Changes Requested to Approved in MAUI SDK Ongoing Mar 5, 2026
@kubaflo kubaflo changed the base branch from main to inflight/current March 5, 2026 12:53
@kubaflo kubaflo merged commit f67ab7f into dotnet:inflight/current Mar 5, 2026
29 checks passed
@github-project-automation github-project-automation bot moved this from Approved to Done in MAUI SDK Ongoing Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-controls-collectionview CollectionView, CarouselView, IndicatorView community ✨ Community Contribution p/1 Work that is important, and has been scheduled for release in this or an upcoming sprint partner/syncfusion Issues / PR's with Syncfusion collaboration platform/ios s/agent-approved AI agent recommends approval - PR fix is correct and optimal s/agent-fix-implemented PR author implemented the agent suggested fix s/agent-fix-pr-picked AI could not beat the PR fix - PR is the best among all candidates s/agent-gate-passed AI verified tests catch the bug (fail without fix, pass with fix) s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review) s/agent-suggestions-implemented Maintainer applies when PR author adopts agent's recommendation

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[iOS] Group Header/Footer Repeated for All Items When IsGrouped is True for ObservableCollection in CollectionView

7 participants