Skip to content

Fix CollectionView not scrolling to top on iOS status bar tap#34687

Open
jfversluis wants to merge 1 commit intomainfrom
fix/collectionview-scrollstotop-19866
Open

Fix CollectionView not scrolling to top on iOS status bar tap#34687
jfversluis wants to merge 1 commit intomainfrom
fix/collectionview-scrollstotop-19866

Conversation

@jfversluis
Copy link
Copy Markdown
Member

Description

Fixes #19866

On iOS, tapping the status bar should scroll the topmost UIScrollView to the top. This was not working for CollectionView, particularly when hosted inside a Shell.

Root Cause

iOS disables its scroll-to-top behavior when multiple UIScrollView instances in the view hierarchy have scrollsToTop = true. The Shell flyout's internal AccessibilityNeutralTableView (a UITableView subclass) defaults scrollsToTop to true, conflicting with the CollectionView's UICollectionView.

Fix

Two changes:

  1. ItemsViewController2.ViewDidLoad() — Explicitly set CollectionView.ScrollsToTop = true to opt in to scroll-to-top behavior
  2. ShellTableViewController.AccessibilityNeutralTableView — Set ScrollsToTop = false on Shell's flyout table view to prevent the multi-scroll-view conflict

This follows the existing codebase pattern where ScrollsToTop is explicitly managed (e.g., ShellSectionRootHeader and ContextActionCell both set it to false).

Validation

Verified with a Sandbox app using a grouped CollectionView inside a Shell with TabBar:

  • Without fix: Diagnostic dump shows two scroll views with scrollsToTop=True → status bar tap does nothing
  • With fix: Only MauiCollectionView has scrollsToTop=True → status bar tap scrolls to top correctly

On iOS, tapping the status bar should scroll the topmost UIScrollView to
the top. This was not working for CollectionView, particularly inside Shell.

Root cause: iOS disables scroll-to-top when multiple UIScrollViews in the
view hierarchy have scrollsToTop=true. The Shell flyout's internal
AccessibilityNeutralTableView (UITableView) defaults scrollsToTop to true,
conflicting with the CollectionView's UICollectionView.

Fix:
- Set CollectionView.ScrollsToTop = true in ItemsViewController2.ViewDidLoad()
  to explicitly opt in to scroll-to-top behavior
- Set ScrollsToTop = false on Shell's AccessibilityNeutralTableView to
  prevent the multi-scroll-view conflict

Fixes #19866

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jfversluis jfversluis requested review from PureWeen and Copilot and removed request for Copilot March 26, 2026 20:16
@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 -- 34687

Or

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

@jfversluis
Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 3 pipeline(s).

@MauiBot
Copy link
Copy Markdown
Collaborator

MauiBot commented Mar 27, 2026

🚦 Gate — Test Verification

📊 Expand Full Gate5639e24 · Fix CollectionView not scrolling to top on iOS status bar tap

Gate Result: ❌ FAILED

Platform: ios


@MauiBot
Copy link
Copy Markdown
Collaborator

MauiBot commented Mar 27, 2026

🤖 AI Summary

📊 Expand Full Review5639e24 · Fix CollectionView not scrolling to top on iOS status bar tap
🔍 Pre-Flight — Context & Validation

Issue: #19866 - [iOS] UICollectionView ScrollToTop does not work
PR: #34687 - Fix CollectionView not scrolling to top on iOS status bar tap
Platforms Affected: iOS (macCatalyst may also benefit)
Files Changed: 2 implementation, 0 test

Key Findings

  • iOS disables scroll-to-top-on-status-bar-tap when multiple UIScrollView instances in the same window have scrollsToTop = true simultaneously
  • Shell flyout's AccessibilityNeutralTableView (a UITableView subclass) defaults scrollsToTop to true, conflicting with CollectionView's UICollectionView
  • PR's fix is in Items2/iOS/ — the current, non-deprecated handler path for iOS/MacCatalyst (not deprecated Items/)
  • Established codebase pattern already exists: ShellSectionRootHeader and ContextActionCell both set ScrollsToTop = false for the same reason
  • PR has NO test files — Gate ❌ FAILED because no tests were provided to verify the fix
  • Issue reporter tried workaround via CollectionViewHandler.Mapper.AppendToMapping(...) but used deprecated Items/ handler path, not Items2/
  • Diff is minimal: 3 lines added across 2 files (ItemsViewController2.cs + ShellTableViewController.cs)
  • Prior agent review completed (same Gate failure, 5 try-fix attempts all passed regression tests)
  • CollectionView.ScrollsToTop = true in ItemsViewController2.ViewDidLoad() is technically redundant (UICollectionView defaults to true) but makes intent explicit

Fix Candidates

# Source Approach Test Result Files Changed Notes
PR PR #34687 Set CollectionView.ScrollsToTop = true in ItemsViewController2.ViewDidLoad() + Set ScrollsToTop = false in AccessibilityNeutralTableView() constructor ❌ Gate FAILED (no tests) ItemsViewController2.cs, ShellTableViewController.cs 3 lines total; class-level fix; follows codebase pattern

@MauiBot MauiBot added s/agent-changes-requested AI agent recommends changes - found a better alternative or issues s/agent-fix-pr-picked AI could not beat the PR fix - PR is the best among all candidates s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review) s/agent-review-incomplete AI agent could not complete all phases (blocker, timeout, error) and removed s/agent-changes-requested AI agent recommends changes - found a better alternative or issues labels Mar 27, 2026
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.

FIx looks good, but maybe some tests are possible ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

s/agent-fix-pr-picked AI could not beat the PR fix - PR is the best among all candidates 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)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[iOS] UICollectionView ScrollToTop does not work

3 participants