Skip to content

[iOS] Horizontal CollectionView jumps to beginning - #37307

Merged
kubaflo merged 4 commits into
dotnet:inflight/currentfrom
SubhikshaSf4851:Fix-36546
Aug 31, 2026
Merged

kubaflo merged 4 commits into
dotnet:inflight/currentfrom
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).

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

@SubhikshaSf4851 SubhikshaSf4851 changed the title [WIP][iOS] Horizontal CollectionView jumps to beginning [iOS] Horizontal CollectionView jumps to beginning Aug 18, 2026
@SubhikshaSf4851
SubhikshaSf4851 marked this pull request as ready for review August 27, 2026 11:27
Copilot AI lite review requested due to automatic review settings August 27, 2026 11:27
@MauiBot MauiBot removed the s/agent-review-in-progress AI review is currently running for this PR label Aug 28, 2026

@kubaflo kubaflo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you please check the ai's suggestions?

Copilot AI review requested due to automatic review settings August 31, 2026 09:37
@SubhikshaSf4851

Copy link
Copy Markdown
Contributor Author

Could you please check the ai's suggestions?

@kubaflo I have checked the AI's suggestions and addressed the valid changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

Review details

Suppressed comments (2)

src/Controls/src/Core/Handlers/Items2/iOS/LayoutFactory2.cs:583

  • The inline comment has accidental formatting issues (tab after //, missing spaces around parentheses, missing space after the period), which makes it harder to read and looks unintentional.
				// 	The CollectionView's own size hasn't actually changed, so there's no need to
				// invalidate(and potentially reset scroll position / content offset).This is what
				// prevents an unrelated sibling resize from jumping this CollectionView's scroll
				// back to the start.

src/Controls/src/Core/Handlers/Items2/iOS/ItemsViewController2.cs:200

  • A couple of new comments have trailing whitespace and are missing ending punctuation, which reads like an accidental formatting artifact.
			// Rotation doesn't invalidate a UICollectionViewCompositionalLayout by default (its
			// ShouldInvalidateLayoutForBoundsChange override returns false), so cells that were
			// already measured before the rotation can end up with stale/empty content 
			var weakController = new WeakReference<ItemsViewController2<TItemsView>>(this);
			UIDevice.CurrentDevice.BeginGeneratingDeviceOrientationNotifications();
			_orientationObserver = NSNotificationCenter.DefaultCenter.AddObserver(UIDevice.OrientationDidChangeNotification, _ => DeviceOrientationChanged(weakController));
		}
  • Files reviewed: 3/3 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

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

@kubaflo
kubaflo changed the base branch from main to inflight/current August 31, 2026 13:33
@kubaflo
kubaflo merged commit 8c23a46 into dotnet:inflight/current Aug 31, 2026
171 of 179 checks passed
@github-actions github-actions Bot added this to the .NET 10 SR11 milestone Aug 31, 2026
kubaflo pushed a commit that referenced this pull request Sep 2, 2026
<!-- Please keep the note below for people who 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 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 #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.
<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #36546 

### Tested the behavior in the following platforms

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


| Before Issue Fix | After Issue Fix |
|----------|----------|
| <video
src="https://github.com/user-attachments/assets/364db60f-a126-42b4-bca9-96b48fb79cdb">
| <video
src="https://github.com/user-attachments/assets/5c2c12cf-9461-4429-82e2-5a97fa53e0b8">
|

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
kubaflo pushed a commit that referenced this pull request Sep 3, 2026
<!-- Please keep the note below for people who 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 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 #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.
<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #36546 

### Tested the behavior in the following platforms

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


| Before Issue Fix | After Issue Fix |
|----------|----------|
| <video
src="https://github.com/user-attachments/assets/364db60f-a126-42b4-bca9-96b48fb79cdb">
| <video
src="https://github.com/user-attachments/assets/5c2c12cf-9461-4429-82e2-5a97fa53e0b8">
|

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
kubaflo pushed a commit that referenced this pull request Sep 6, 2026
<!-- Please keep the note below for people who 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 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 #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.
<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #36546 

### Tested the behavior in the following platforms

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


| Before Issue Fix | After Issue Fix |
|----------|----------|
| <video
src="https://github.com/user-attachments/assets/364db60f-a126-42b4-bca9-96b48fb79cdb">
| <video
src="https://github.com/user-attachments/assets/5c2c12cf-9461-4429-82e2-5a97fa53e0b8">
|

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
kubaflo pushed a commit that referenced this pull request Sep 7, 2026
<!-- Please keep the note below for people who 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 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 #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.
<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #36546 

### Tested the behavior in the following platforms

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


| Before Issue Fix | After Issue Fix |
|----------|----------|
| <video
src="https://github.com/user-attachments/assets/364db60f-a126-42b4-bca9-96b48fb79cdb">
| <video
src="https://github.com/user-attachments/assets/5c2c12cf-9461-4429-82e2-5a97fa53e0b8">
|

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
kubaflo pushed a commit that referenced this pull request Sep 8, 2026
<!-- Please keep the note below for people who 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 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 #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.
<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #36546 

### Tested the behavior in the following platforms

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


| Before Issue Fix | After Issue Fix |
|----------|----------|
| <video
src="https://github.com/user-attachments/assets/364db60f-a126-42b4-bca9-96b48fb79cdb">
| <video
src="https://github.com/user-attachments/assets/5c2c12cf-9461-4429-82e2-5a97fa53e0b8">
|

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
kubaflo pushed a commit that referenced this pull request Sep 9, 2026
<!-- Please keep the note below for people who 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 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 #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.
<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #36546 

### Tested the behavior in the following platforms

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


| Before Issue Fix | After Issue Fix |
|----------|----------|
| <video
src="https://github.com/user-attachments/assets/364db60f-a126-42b4-bca9-96b48fb79cdb">
| <video
src="https://github.com/user-attachments/assets/5c2c12cf-9461-4429-82e2-5a97fa53e0b8">
|

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
kubaflo pushed a commit that referenced this pull request Sep 11, 2026
<!-- Please keep the note below for people who 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 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 #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.
<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #36546 

### Tested the behavior in the following platforms

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


| Before Issue Fix | After Issue Fix |
|----------|----------|
| <video
src="https://github.com/user-attachments/assets/364db60f-a126-42b4-bca9-96b48fb79cdb">
| <video
src="https://github.com/user-attachments/assets/5c2c12cf-9461-4429-82e2-5a97fa53e0b8">
|

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
kubaflo pushed a commit that referenced this pull request Sep 15, 2026
<!-- Please keep the note below for people who 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 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 #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.
<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #36546 

### Tested the behavior in the following platforms

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


| Before Issue Fix | After Issue Fix |
|----------|----------|
| <video
src="https://github.com/user-attachments/assets/364db60f-a126-42b4-bca9-96b48fb79cdb">
| <video
src="https://github.com/user-attachments/assets/5c2c12cf-9461-4429-82e2-5a97fa53e0b8">
|

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
kubaflo pushed a commit that referenced this pull request Sep 18, 2026
<!-- Please keep the note below for people who 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 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 #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.
<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #36546 

### Tested the behavior in the following platforms

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


| Before Issue Fix | After Issue Fix |
|----------|----------|
| <video
src="https://github.com/user-attachments/assets/364db60f-a126-42b4-bca9-96b48fb79cdb">
| <video
src="https://github.com/user-attachments/assets/5c2c12cf-9461-4429-82e2-5a97fa53e0b8">
|

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
kubaflo pushed a commit that referenced this pull request Sep 21, 2026
<!-- Please keep the note below for people who 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 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 #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.
<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #36546 

### Tested the behavior in the following platforms

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


| Before Issue Fix | After Issue Fix |
|----------|----------|
| <video
src="https://github.com/user-attachments/assets/364db60f-a126-42b4-bca9-96b48fb79cdb">
| <video
src="https://github.com/user-attachments/assets/5c2c12cf-9461-4429-82e2-5a97fa53e0b8">
|

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
kubaflo pushed a commit that referenced this pull request Sep 27, 2026
<!-- Please keep the note below for people who 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 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 #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.
<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #36546 

### Tested the behavior in the following platforms

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


| Before Issue Fix | After Issue Fix |
|----------|----------|
| <video
src="https://github.com/user-attachments/assets/364db60f-a126-42b4-bca9-96b48fb79cdb">
| <video
src="https://github.com/user-attachments/assets/5c2c12cf-9461-4429-82e2-5a97fa53e0b8">
|

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
kubaflo pushed a commit that referenced this pull request Sep 27, 2026
<!-- Please keep the note below for people who 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 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 #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.
<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #36546 

### Tested the behavior in the following platforms

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


| Before Issue Fix | After Issue Fix |
|----------|----------|
| <video
src="https://github.com/user-attachments/assets/364db60f-a126-42b4-bca9-96b48fb79cdb">
| <video
src="https://github.com/user-attachments/assets/5c2c12cf-9461-4429-82e2-5a97fa53e0b8">
|

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 1, 2026
@github-actions github-actions Bot modified the milestones: .NET 10 SR11, .NET 10 SR12 Oct 21, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-controls-collectionview CollectionView, CarouselView, IndicatorView collectionview-cv2 community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration platform/ios 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 s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review)

Projects

None yet

6 participants