Skip to content

[WIP][iOS] Horizontal CollectionView jumps to beginning - #37307

Draft
SubhikshaSf4851 wants to merge 3 commits into
dotnet:mainfrom
SubhikshaSf4851:Fix-36546
Draft

[WIP][iOS] Horizontal CollectionView jumps to beginning#37307
SubhikshaSf4851 wants to merge 3 commits into
dotnet:mainfrom
SubhikshaSf4851:Fix-36546

Conversation

@SubhikshaSf4851

@SubhikshaSf4851 SubhikshaSf4851 commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

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 whether this change resolves your issue. Thank you!

This pull request resolves a build-breaking duplicate-method conflict between two independent CustomUICollectionViewCompositionalLayout fixes on iOS, while preserving the rotation-invalidation behavior that #32664 introduced for #32435.

Issue Details

PR #36546's fix added a ShouldInvalidateLayoutForBoundsChange(CGRect newBounds) override (with _currentSize tracking via PrepareLayout()) to CustomUICollectionViewCompositionalLayout in LayoutFactory2.cs, to stop unrelated ancestor/sibling layout passes from resetting the CollectionView's scroll position.

PR #32664 had already added a second override of the exact same method (ShouldInvalidateLayoutForBoundsChange) in the same class, to fix #32435 — text disappearing in a horizontal CollectionView after rotating the simulator, because the compositional layout's default ShouldInvalidateLayoutForBoundsChange returns false and never re-measures cells after a bounds change.

Having two overrides of the same method in the same class does not compile (CS0111: Type already defines a member with the same parameter types).

Description of Change

Removed the duplicate override:

  • Removed the second ShouldInvalidateLayoutForBoundsChange(CGRect newBounds) override from CustomUICollectionViewCompositionalLayout in LayoutFactory2.cs. The _currentSize/PrepareLayout()-based override from iOS Horizontal CollectionView jumps to beginning #36546 is kept, since it already covers the "ignore same-size bounds changes" case for both scenarios.

Restored rotation invalidation via the view controller instead of the layout:

  • The rotation handling was moved up to ItemsViewController2:
    • Added _isRotating and _orientationObserver fields.
    • Subscribed to UIDevice.OrientationDidChangeNotification in ViewDidLoad(), setting _isRotating = true in the DeviceOrientationChanged handler.
    • Unsubscribed the observer in Dispose(bool) to avoid leaks.
    • In ViewWillLayoutSubviews(), when _isRotating is set, explicitly call CollectionView.CollectionViewLayout.InvalidateLayout() to force cells to re-measure/re-render after the rotation completes, then reset _isRotating.

This keeps the #36546 scroll-jump fix intact (layout still returns false for same-size bounds changes) while independently guaranteeing a genuine invalidation happens after a real device rotation, without needing two competing overrides of the same UIKit method.

Why tests not added

The scroll-reset scenario from #36546 is intermittent and doesn't reproduce reliably at the same item/position, so it isn't suited to an automated test. The rotation fix for #32435 already has manual UI test coverage from #32664 (Issue32435.cs in TestCases.HostApp/TestCases.Shared.Tests), which continues to apply here.

Issues Fixed

Fixes #36546

Tested the behavior in the following platforms

  • Windows
  • Android
  • iOS
  • Mac
Before Issue Fix After Issue Fix
BeforeFix36546.mov
AfterFix36546.mov

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

Or

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

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service dotnet-policy-service Bot added the community ✨ Community Contribution label Aug 11, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Hey there @@SubhikshaSf4851! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@vishnumenon2684

Copy link
Copy Markdown
Contributor

/azp run maui-pr-uitests , maui-pr-devicetests

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).

@vishnumenon2684

Copy link
Copy Markdown
Contributor

/azp run maui-pr-uitests , maui-pr-devicetests

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).

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 collectionview-cv2 community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration platform/ios

Projects

None yet

3 participants