Skip to content

[iOS/Mac] CollectionView: Fix incorrect ItemsViewScrolledEventArgs indices with grouped items#34240

Merged
kubaflo merged 2 commits intodotnet:inflight/currentfrom
SyedAbdulAzeemSF4852:fix-17664_ios
Mar 14, 2026
Merged

[iOS/Mac] CollectionView: Fix incorrect ItemsViewScrolledEventArgs indices with grouped items#34240
kubaflo merged 2 commits intodotnet:inflight/currentfrom
SyedAbdulAzeemSF4852:fix-17664_ios

Conversation

@SyedAbdulAzeemSF4852
Copy link
Copy Markdown
Contributor

@SyedAbdulAzeemSF4852 SyedAbdulAzeemSF4852 commented Feb 25, 2026

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 Details

  • When a CollectionView's IsGrouped property is set to true, the values of FirstVisibleItemIndex, CenterItemIndex, and LastVisibleItemIndex in the ItemsViewScrolledEventArgs passed to the Scrolled event handler are incorrect.

Root Cause

  • Visible items were sorted only by Row, which produced incorrect ordering when items from multiple sections were visible simultaneously.

Description of Change

iOS (ItemsViewDelegator.cs and ItemsViewDelegator2.cs)

  • Changed the sort from .OrderBy(x => x.Row) to .OrderBy(x => x.Section).ThenBy(x => x.Row) so that IndexPathsForVisibleItems is ordered correctly across section boundaries. The fix is applied to both the legacy handler (Items/) and the current handler (Items2/).

Issues Fixed

Fixes #17664

Validated the behaviour in the following platforms

  • Windows
  • Android
  • iOS
  • Mac

Android fix PR: #31437

Output

Before After
iOS_Before.mov
iOS_After.mov

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Feb 25, 2026
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Hey there @@SyedAbdulAzeemSF4852! 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 partner/syncfusion Issues / PR's with Syncfusion collaboration label Feb 25, 2026
@sheiksyedm sheiksyedm added area-controls-collectionview CollectionView, CarouselView, IndicatorView platform/ios labels Feb 26, 2026
@sheiksyedm sheiksyedm marked this pull request as ready for review February 26, 2026 12:44
Copilot AI review requested due to automatic review settings February 26, 2026 12:44
@sheiksyedm
Copy link
Copy Markdown
Contributor

/azp run maui-pr-uitests

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Copy Markdown
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

Fixes incorrect ItemsViewScrolledEventArgs visible-item indices for grouped CollectionView on iOS/Mac by ensuring visible NSIndexPaths are ordered consistently across section boundaries, and adds a HostApp repro page + Appium UI test for issue #17664.

Changes:

  • iOS (legacy Items/) and iOS/MacCatalyst (current Items2/) delegators now sort visible NSIndexPaths by Section then Row.
  • Added HostApp issue page (Issue17664) that displays the “last visible item” text while scrolling grouped content.
  • Added an Appium UI test (Issue17664) validating the label updates after a programmatic scroll.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

File Description
src/Controls/src/Core/Handlers/Items2/iOS/ItemsViewDelegator2.cs Updates visible index-path ordering for grouped sources (Items2 iOS/MacCatalyst handler).
src/Controls/src/Core/Handlers/Items/iOS/ItemsViewDelegator.cs Updates visible index-path ordering for grouped sources (legacy iOS handler).
src/Controls/tests/TestCases.HostApp/Issues/Issue17664.cs Adds repro page using grouped CollectionView + Scrolled handler output.
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue17664.cs Adds Appium UI regression test for the issue.


namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 17664, "Incorrect ItemsViewScrolledEventArgs in CollectionView when IsGrouped is set to true", PlatformAffected.iOS | PlatformAffected.Android)]
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

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

The IssueAttribute marks this as affecting iOS/Android only, but this PR targets iOS + Mac as well. Consider adding PlatformAffected.macOS (and any other affected platforms) so the metadata matches where this scenario is expected to reproduce/be validated.

Suggested change
[Issue(IssueTracker.Github, 17664, "Incorrect ItemsViewScrolledEventArgs in CollectionView when IsGrouped is set to true", PlatformAffected.iOS | PlatformAffected.Android)]
[Issue(IssueTracker.Github, 17664, "Incorrect ItemsViewScrolledEventArgs in CollectionView when IsGrouped is set to true", PlatformAffected.iOS | PlatformAffected.Android | PlatformAffected.macOS)]

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
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.

Hi, could you please apply suggestions from the AI Summary

@github-actions
Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 34240

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 34240"

@SyedAbdulAzeemSF4852
Copy link
Copy Markdown
Contributor Author

Hi, could you please apply suggestions from the AI Summary

@kubaflo, I have reviewed the AI summary and applied all the valid suggestions.

@kubaflo kubaflo added s/agent-fix-implemented PR author implemented the agent suggested fix s/agent-approved AI agent recommends approval - PR fix is correct and optimal labels Mar 10, 2026
@kubaflo kubaflo added s/ai-reproduction-failed s/ai-reproduction-confirmed and removed s/agent-changes-requested AI agent recommends changes - found a better alternative or issues s/ai-reproduction-failed labels Mar 10, 2026
@kubaflo
Copy link
Copy Markdown
Contributor

kubaflo commented Mar 14, 2026

🤖 AI Summary

📊 Expand Full Reviewf2a0ee3 · Remove PlatformAffected.Android and restrict test in Windows
🔍 Pre-Flight — Context & Validation

Issue: #17664 - [iOS/Mac/Windows] CollectionView ItemsViewScrolledEventArgs are incorrect when IsGrouped = true
PR: #34240 - [iOS & Mac] Fix for Incorrect ItemsViewScrolledEventArgs Values in CollectionView with Grouped Items
Platforms Affected: iOS, MacCatalyst (fix); Android fix is separate (PR #31437)
Files Changed: 2 implementation, 2 test

Key Findings

  • Root Cause: GetVisibleItemsIndexPath() called IndexPathsForVisibleItems.OrderBy(x => x.Row) — this sorted visible items by row index only. When a CollectionView is grouped (multiple sections), items from section 0 row 5 sorted before items from section 1 row 0, producing wrong First/Center/Last indices.
  • Fix: Sort by Section first, then Row: .OrderBy(x => x.Section).ThenBy(x => x.Row) — applied to both legacy Items/iOS/ItemsViewDelegator.cs and current Items2/iOS/ItemsViewDelegator2.cs.
  • Remaining concern (Copilot review): GetCenteredIndexPath still sorts only by .Row, so the null-fallback path (centerIndexPath ?? firstVisibleItemIndex) could return an incorrect index when the center point lands between cells and there are multiple sections. PR author dismissed this as "invalid."
  • Tests: UI test added (Issue17664.cs) — taps "Scroll to Category C, Item Update README.md #2" button, then waits for Issue17664DescriptionLabel to show "Category C item Update README.md #2". Test is wrapped with #if TEST_FAILS_ON_ANDROID && TEST_FAILS_ON_WINDOWS, so it only runs on iOS/MacCatalyst.
  • Inline Copilot comment also noted PlatformAffected.iOS is missing macOS — PR author didn't update this.
  • Labels indicate this PR was previously agent-reviewed: s/agent-reviewed, s/agent-approved, s/agent-gate-passed, s/agent-fix-implemented, s/agent-fix-pr-picked.

Fix Candidates

# Source Approach Test Result Files Changed Notes
PR PR #34240 Sort IndexPathsForVisibleItems by Section then Row ⏳ PENDING (Gate) ItemsViewDelegator.cs, ItemsViewDelegator2.cs Original PR; simple 1-line change per file

Prior Agent Review

Previous review found: Gate passed, fix was implemented, PR fix was selected as best candidate. Labels: s/agent-approved, s/agent-gate-passed, s/agent-fix-pr-picked. Proceeding with fresh review.


🚦 Gate — Test Verification

Gate Verification Report — PR #34240

PR: #34240 — [iOS & Mac] Fix for Incorrect ItemsViewScrolledEventArgs Values in CollectionView with Grouped Items
Date: 2026-03-14
Platform: iOS (iPhone 16 Pro, iOS 18.6 Simulator)
Test Filter: Issue17664
Mode: Full Verification (RequireFullVerification)


Result Summary

Check Expected Actual Result
Tests WITHOUT fix FAIL FAIL ❌ ✅ Correct
Tests WITH fix PASS PASS ✅ ✅ Correct

✅ VERIFICATION PASSED


Test Details

Fix Files Verified

  • src/Controls/src/Core/Handlers/Items/iOS/ItemsViewDelegator.cs
  • src/Controls/src/Core/Handlers/Items2/iOS/ItemsViewDelegator2.cs

Merge Base

3f5d0c524882f226fe3e36fc72b39750c77da3d4 (branched from main)


Step 1: Reverted fix files → Step 2: Tests WITHOUT fix

Build: ✅ Succeeded
Test executed: VerifyGroupedCollectionViewVisibleItemIndices
Result: ❌ FAILED (as expected)

Failed VerifyGroupedCollectionViewVisibleItemIndices [1 s]
Assert.That(resultItem, Is.EqualTo("Category C item #2"))
Expected: "Category C item #2"

The test correctly detected the bug: the scroll event args reported wrong item indices for grouped CollectionView, so the label text did not match "Category C item #2".


Step 3: Restored fix files → Step 4: Tests WITH fix

Build: ✅ Succeeded
Test executed: VerifyGroupedCollectionViewVisibleItemIndices
Result: ✅ PASSED

Passed VerifyGroupedCollectionViewVisibleItemIndices [903 ms]
Test Run Successful.
Passed: 1

The fix correctly resolves the grouped scroll event index calculation on iOS.


Labels Updated on PR


Build Environment Note

A pre-existing environment issue was encountered and resolved before verification:
The pre-built Microsoft.Maui.Controls.SourceGen.dll in artifacts referenced a BindingSourceGen.EnumIndex type (added in a later main commit, ad30170c), but the PR branch's BindingSourceGen source predates that commit and lacks EnumIndex. Rebuilding Controls.SourceGen from the PR branch's source resolved the MAUIG1001 build errors. This is a build environment version-skew issue unrelated to the PR itself.


Verdict

🟢 GATE: PASSED


🔧 Fix — Analysis & Comparison

Fix Candidates

# Source Approach Test Result Files Changed Notes
PR PR #34240 Sort by then in PASSED (Gate) ItemsViewDelegator.cs, ItemsViewDelegator2.cs (1 line each) Minimal, surgical, simple
1 try-fix (sonnet-4.6) In : compute flat indices for ALL visible IndexPaths via , use Min/Max PASSED ItemsViewDelegator.cs, ItemsViewDelegator2.cs (+19/-8 each) Sidesteps sort; fixes at index computation layer
2 try-fix (opus-4.6) Sort by Frame.Y/X, map back via ; also fixed fallback PASSED ItemsViewDelegator.cs, ItemsViewDelegator2.cs (+26/-19 each) Geometry-based; also addresses the GetCenteredIndexPath fallback bug

Cross-Pollination

Model Round New Ideas? Details
claude-sonnet-4.6 2 NO NEW IDEAS Confirmed 3 approaches cover the solution space
claude-opus-4.6 2 NO NEW IDEAS Confirmed: index hierarchy, logical position, physical position are the 3 strategies

Exhausted: Yes (both models, 1 round)

Best Fix Selection

Criterion PR Fix Attempt 1 (Min/Max) Attempt 2 (Geometric)
Test passes
Lines changed ~1 per file ~27 per file ~45 per file
Files changed 2 2 2
Simplicity More Most complex complex Simplest
Codebase style LINQ ordering consistent with Different pattern rest
Addresses fallback
Risk of regression Very low Low Higher (more code)

Selected Fix: PR # Reason: All 3 candidates pass tests. The PR fix is the simplest possible change (1 meaningful line per file), directly addresses the root cause at the right layer (GetVisibleItemsIndexPath), and is consistent with the existing LINQ ordering style in the codebase. Attempt-2 has merit in also fixing the GetCenteredIndexPath fallback (a secondary issue the PR author dismissed), but that can be addressed as a follow-up. Attempt-1 is conceptually sound but unnecessarily increases code complexity.34240


📋 Report — Final Recommendation

PR Review Report — #34240

PR: #34240 — [iOS & Mac] Fix for Incorrect ItemsViewScrolledEventArgs Values in CollectionView with Grouped Items
Issue: #17664 — CollectionView ItemsViewScrolledEventArgs are incorrect when IsGrouped = true
Date: 2026-03-14
Platform Tested: iOS (iPhone 16 Pro, iOS 18.6 Simulator)


Phase Summary

Phase Status Notes
Pre-Flight ✅ COMPLETE Context gathered, files classified
Gate ✅ PASSED Tests FAIL without fix, PASS with fix
Try-Fix (2 models) ✅ COMPLETE Both models produced passing alternatives; PR fix selected as best
Report ✅ COMPLETE See below

Fix Summary

Root Cause: In GetVisibleItemsIndexPath(), IndexPathsForVisibleItems was sorted only by .Row. On grouped CollectionViews (multiple UICollectionView sections), items from section 0 row 5 sorted before items from section 1 row 0, producing wrong first/last visible item indices.

PR Fix: Changed sort from .OrderBy(x => x.Row) to .OrderBy(x => x.Section).ThenBy(x => x.Row) in GetVisibleItemsIndexPath(). Applied identically in both:

  • src/Controls/src/Core/Handlers/Items/iOS/ItemsViewDelegator.cs (legacy handler)
  • src/Controls/src/Core/Handlers/Items2/iOS/ItemsViewDelegator2.cs (current handler)

Result: Fix is correct, minimal, and directly addresses the root cause.


Gate Results

Check Expected Actual Result
Tests WITHOUT fix FAIL FAIL
Tests WITH fix PASS PASS

Test: VerifyGroupedCollectionViewVisibleItemIndices in Issue17664.cs

  • Without fix: label showed wrong text (incorrect scroll event indices)
  • With fix: label showed "Category C item Update README.md #2" ✅

Try-Fix Results

# Source Approach Test Result Complexity
PR PR #34240 Sort IndexPaths by .Section then .Row ✅ PASSED 1 line per file
1 try-fix (sonnet-4.6) GetVisibleItemsIndex() Min/Max of all flat indices ✅ PASSED ~27 lines per file
2 try-fix (opus-4.6) Sort VisibleCells by Frame.Y/X + fix GetCenteredIndexPath fallback ✅ PASSED ~45 lines per file

Cross-pollination: Both models said NO NEW IDEAS after reviewing all 3 approaches. Exhausted.

Selected Fix: PR #34240 — the simplest, most surgical, and stylistically consistent solution.


Code Quality Notes

✅ What the PR does well

  • Minimal change (1 meaningful line per file) that directly addresses the root cause
  • Applied consistently to both the legacy (Items/) and current (Items2/) handlers
  • Good comment added explaining the sort rationale
  • Test reproduces the bug accurately and verifies the fix
  • >= 0 guard added for LastVisibleItemIndex (addresses Copilot feedback)

⚠️ Minor Issues (non-blocking)

  1. GetCenteredIndexPath() fallback still uses .OrderBy(x => x.Row) only:
    Both files have a private GetCenteredIndexPath() method that also calls .OrderBy(x => x.Row) as a fallback when IndexPathForItemAtPoint returns null. The PR author dismissed the Copilot review comment as "invalid," but this is a real edge case: if the center point lands on a section header/footer (returning null), the fallback uses the wrong "first" index path from the incorrectly sorted list.

    In practice this path is rarely hit (headers/footers are typically thin), and the existing test does not exercise it. This is a pre-existing pattern and not introduced by this PR, but it is a missed opportunity.

  2. PlatformAffected.iOS should include macOS:
    The [Issue] attribute on the HostApp page specifies PlatformAffected.iOS only, but the PR fixes both iOS and MacCatalyst handlers and the PR description validates on Mac. Non-blocking metadata issue.

  3. #if TEST_FAILS_ON_ANDROID guard:
    The test wraps with #if TEST_FAILS_ON_ANDROID && TEST_FAILS_ON_WINDOWS, meaning it only runs on iOS/MacCatalyst. The Android fix (PR [Android] Fix for Incorrect ItemsViewScrolledEventArgs Values in CollectionView with Grouped Items #31437) has already landed. If Android's TEST_FAILS_ON_ANDROID constant has been removed in main, the guard could now be simplified. This is a minor cleanup item.


Recommendation

✅ APPROVE

The PR fix is correct, minimal, well-tested, and validated by both Gate and independent try-fix exploration. No alternative approach outperforms it on simplicity. The minor issues noted above (GetCenteredIndexPath fallback, PlatformAffected metadata) are non-blocking and can be addressed in a follow-up.

Suggested follow-up (optional): Apply the same Section/Row sort to the GetCenteredIndexPath() fallback path in both files for completeness, since it has the same root problem for edge cases involving null IndexPathForItemAtPoint results.


Result: ✅ APPROVED — PR Fix is Correct and Optimal


📋 Expand PR Finalization Review

PR #34240 Finalization Review

PR: [iOS & Mac] Fix for Incorrect ItemsViewScrolledEventArgs Values in CollectionView with Grouped Items
Author: @SyedAbdulAzeemSF4852
Base branch: main
Files changed: 4 (+154 / -2)


Phase 1: Title & Description

🟡 Title: Minor Improvement Suggested

Current: [iOS & Mac] Fix for Incorrect ItemsViewScrolledEventArgs Values in CollectionView with Grouped Items

Assessment:

  • The content is accurate and searchable ✅
  • & Mac is informal; MAUI convention uses MacCatalyst (or [iOS/Mac] slash form)
  • Fix for prefix is slightly verbose — omitting it is standard

Recommended:

[iOS/Mac] CollectionView: Fix incorrect ItemsViewScrolledEventArgs indices with grouped items

✅ Description: Good — Minor Cleanup Needed

Quality assessment:

Dimension Rating Notes
Structure Clear labeled sections
NOTE block Present at top
Root cause Clearly states sort-by-Row-only bug
Description of change File-by-file breakdown mentioning both Items/ and Items2/
Issues fixed Fixes #17664 present
Platforms tested All four checked
Android cross-reference Links to PR #31437
Output/Before-After Table rows contain empty image markdown — no actual screenshots attached

Only change needed:

  • Remove the empty Before/After table or replace with actual screenshots / GIF. Currently the table cells are empty (| | |), which adds noise without value.

Recommended action: Delete or fill the Output section. Everything else is accurate and complete — do not rewrite the description.


Phase 2: Code Review

✅ Core Fix — Items/iOS/ItemsViewDelegator.cs & Items2/iOS/ItemsViewDelegator2.cs

The fix is minimal, correct, and well-explained.

// Before
var indexPathsForVisibleItems = collectionView.IndexPathsForVisibleItems.OrderBy(x => x.Row).ToList();

// After (both files)
// Sort visible item index paths by section and then by row for consistent order in both grouped and ungrouped sources
var indexPathsForVisibleItems = collectionView.IndexPathsForVisibleItems.OrderBy(x => x.Section).ThenBy(x => x.Row).ToList();

Analysis:

  • UICollectionView.IndexPathsForVisibleItems returns index paths in unspecified order. Sorting by Row alone produces wrong results when items from multiple sections are visible simultaneously because Row resets to 0 per section.
  • Adding .OrderBy(x => x.Section).ThenBy(x => x.Row) gives a globally consistent, ascending order across section boundaries — exactly what's needed for computing FirstVisibleItemIndex, CenterItemIndex, and LastVisibleItemIndex.
  • The comment added on each changed line explains the intent clearly ✅
  • The fix is applied to both the legacy handler (Items/) and the current handler (Items2/) — correct per the MAUI repo convention that Items/ serves Android/Windows/legacy-iOS and Items2/ serves current iOS/MacCatalyst ✅
  • No breaking change for ungrouped sources: single-section sources always have Section == 0, so the secondary ThenBy(Row) produces the same result as the old single-key sort ✅

🟡 Minor Issues

1. PlatformAffected.iOS does not include MacCatalyst

File: src/Controls/tests/TestCases.HostApp/Issues/Issue17664.cs, line 5

[Issue(IssueTracker.Github, 17664, "...", PlatformAffected.iOS)]

The fix in Items2/ applies to both iOS and MacCatalyst. The [Issue] attribute should reflect this:

[Issue(IssueTracker.Github, 17664, "...", PlatformAffected.iOS | PlatformAffected.MacCatalyst)]

This is a non-breaking annotation issue and does not affect test execution, but it does affect discoverability and accuracy.

2. Empty Before/After table in PR description

Location: PR description ### Output section

The Before/After table rows contain no content. This should either be populated with actual screenshots/recordings or removed to avoid confusing reviewers.


✅ Looks Good

src/Controls/tests/TestCases.HostApp/Issues/Issue17664.cs

  • Uses C# only (no XAML) — preferred pattern ✅
  • All interactive elements have AutomationId set ✅
  • Clear CollectionView with grouped ObservableCollection setup that directly reproduces the issue scenario ✅
  • Scrolled event handler safely guards the index: e.LastVisibleItemIndex >= 0 && < flatItems.Count
  • No obsolete APIs used ✅

src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue17664.cs

  • #if TEST_FAILS_ON_ANDROID && TEST_FAILS_ON_WINDOWS correctly gates the test to run only on iOS and MacCatalyst ✅
  • Comment explains why Windows and Android are excluded, not just that they are ✅
  • Inherits from _IssuesUITest
  • Single [Category(UITestCategories.CollectionView)] attribute ✅
  • No inline #if directives inside the test method body ✅
  • Test is simple and deterministic: scroll to known item → assert label text ✅

Summary

Area Status Action Required
Title 🟡 Minor Optional: adopt [iOS/Mac] and drop Fix for prefix
NOTE block ✅ Good None
Description accuracy ✅ Good Remove empty Before/After table
Core fix (logic) ✅ Correct None
Both handlers fixed ✅ Complete None
HostApp test page 🟡 Minor Change PlatformAffected.iOSPlatformAffected.iOS | PlatformAffected.MacCatalyst
UI test ✅ Good None
Platform gating ✅ Correct None

Overall verdict: The implementation is correct and the PR is in good shape. Two minor clean-ups recommended before merge:

  1. Update PlatformAffected to include MacCatalyst.
  2. Remove or populate the empty Before/After screenshot table from the description.

@kubaflo kubaflo added s/agent-review-incomplete AI agent could not complete all phases (blocker, timeout, error) and removed s/agent-approved AI agent recommends approval - PR fix is correct and optimal labels Mar 14, 2026
@kubaflo kubaflo changed the title [iOS & Mac] Fix for Incorrect ItemsViewScrolledEventArgs Values in CollectionView with Grouped Items [iOS/Mac] CollectionView: Fix incorrect ItemsViewScrolledEventArgs indices with grouped items Mar 14, 2026
@kubaflo kubaflo changed the base branch from main to inflight/current March 14, 2026 15:46
@kubaflo kubaflo merged commit 78cf0bb into dotnet:inflight/current Mar 14, 2026
35 of 36 checks passed
PureWeen pushed a commit that referenced this pull request Mar 19, 2026
…dices with grouped items (#34240)

> [!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!

### Issue Details

- When a CollectionView's IsGrouped property is set to true, the values
of FirstVisibleItemIndex, CenterItemIndex, and LastVisibleItemIndex in
the ItemsViewScrolledEventArgs passed to the Scrolled event handler are
incorrect.

### Root Cause

- Visible items were sorted only by Row, which produced incorrect
ordering when items from multiple sections were visible simultaneously.

### Description of Change

**iOS (ItemsViewDelegator.cs and ItemsViewDelegator2.cs)**

- Changed the sort from .OrderBy(x => x.Row) to .OrderBy(x =>
x.Section).ThenBy(x => x.Row) so that IndexPathsForVisibleItems is
ordered correctly across section boundaries. The fix is applied to both
the legacy handler (Items/) and the current handler (Items2/).

### Issues Fixed
Fixes #17664 


### Validated the behaviour in the following platforms

- [x] Windows
- [x] Android
- [x] iOS
- [x] Mac

Android fix PR: #31437

### Output
| Before | After |
|----------|----------|
| <video
src="https://github.com/user-attachments/assets/3612815d-3a43-4dd5-8d2c-3832e3d4a077">
| <video
src="https://github.com/user-attachments/assets/f6cd63b8-1ed9-465a-99d9-11e38b004dac">
|
PureWeen pushed a commit that referenced this pull request Mar 24, 2026
…dices with grouped items (#34240)

> [!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!

### Issue Details

- When a CollectionView's IsGrouped property is set to true, the values
of FirstVisibleItemIndex, CenterItemIndex, and LastVisibleItemIndex in
the ItemsViewScrolledEventArgs passed to the Scrolled event handler are
incorrect.

### Root Cause

- Visible items were sorted only by Row, which produced incorrect
ordering when items from multiple sections were visible simultaneously.

### Description of Change

**iOS (ItemsViewDelegator.cs and ItemsViewDelegator2.cs)**

- Changed the sort from .OrderBy(x => x.Row) to .OrderBy(x =>
x.Section).ThenBy(x => x.Row) so that IndexPathsForVisibleItems is
ordered correctly across section boundaries. The fix is applied to both
the legacy handler (Items/) and the current handler (Items2/).

### Issues Fixed
Fixes #17664 


### Validated the behaviour in the following platforms

- [x] Windows
- [x] Android
- [x] iOS
- [x] Mac

Android fix PR: #31437

### Output
| Before | After |
|----------|----------|
| <video
src="https://github.com/user-attachments/assets/3612815d-3a43-4dd5-8d2c-3832e3d4a077">
| <video
src="https://github.com/user-attachments/assets/f6cd63b8-1ed9-465a-99d9-11e38b004dac">
|
KarthikRajaKalaimani pushed a commit to KarthikRajaKalaimani/maui that referenced this pull request Mar 30, 2026
…dices with grouped items (dotnet#34240)

> [!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!

### Issue Details

- When a CollectionView's IsGrouped property is set to true, the values
of FirstVisibleItemIndex, CenterItemIndex, and LastVisibleItemIndex in
the ItemsViewScrolledEventArgs passed to the Scrolled event handler are
incorrect.

### Root Cause

- Visible items were sorted only by Row, which produced incorrect
ordering when items from multiple sections were visible simultaneously.

### Description of Change

**iOS (ItemsViewDelegator.cs and ItemsViewDelegator2.cs)**

- Changed the sort from .OrderBy(x => x.Row) to .OrderBy(x =>
x.Section).ThenBy(x => x.Row) so that IndexPathsForVisibleItems is
ordered correctly across section boundaries. The fix is applied to both
the legacy handler (Items/) and the current handler (Items2/).

### Issues Fixed
Fixes dotnet#17664 


### Validated the behaviour in the following platforms

- [x] Windows
- [x] Android
- [x] iOS
- [x] Mac

Android fix PR: dotnet#31437

### Output
| Before | After |
|----------|----------|
| <video
src="https://github.com/user-attachments/assets/3612815d-3a43-4dd5-8d2c-3832e3d4a077">
| <video
src="https://github.com/user-attachments/assets/f6cd63b8-1ed9-465a-99d9-11e38b004dac">
|
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 partner/syncfusion Issues / PR's with Syncfusion collaboration platform/ios 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-review-incomplete AI agent could not complete all phases (blocker, timeout, error) s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review) s/ai-reproduction-confirmed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[iOS/Mac/Windows] CollectionView ItemsViewScrolledEventArgs are incorrect when IsGrouped = true

5 participants