Repository navigation
[iOS] Horizontal CollectionView jumps to beginning - #37307
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 37307Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 37307" |
|
Azure Pipelines: Successfully started running 1 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
|
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. |
b5290b3 to
8c05c3d
Compare
…earAfterRotatingTheDevice
|
/azp run maui-pr-uitests , maui-pr-devicetests |
|
Azure Pipelines: Successfully started running 2 pipeline(s). |
|
/azp run maui-pr-uitests , maui-pr-devicetests |
|
Azure Pipelines: Successfully started running 2 pipeline(s). |
|
/azp run maui-pr-uitests , maui-pr-devicetests |
|
Azure Pipelines: Successfully started running 2 pipeline(s). |
kubaflo
left a comment
There was a problem hiding this comment.
Could you please check the ai's suggestions?
@kubaflo I have checked the AI's suggestions and addressed the valid changes |
There was a problem hiding this comment.
🟢 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
|
/azp run maui-pr-uitests , maui-pr-devicetests |
|
Azure Pipelines: Successfully started running 2 pipeline(s). |
<!-- 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. -->
<!-- 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. -->
<!-- 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. -->
<!-- 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. -->
<!-- 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. -->
<!-- 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. -->
<!-- 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. -->
<!-- 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. -->
<!-- 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. -->
<!-- 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. -->
<!-- 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. -->
<!-- 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. -->
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
CustomUICollectionViewCompositionalLayoutfixes 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_currentSizetracking viaPrepareLayout()) toCustomUICollectionViewCompositionalLayoutinLayoutFactory2.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 defaultShouldInvalidateLayoutForBoundsChangereturnsfalseand 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:
ShouldInvalidateLayoutForBoundsChange(CGRect newBounds)override fromCustomUICollectionViewCompositionalLayoutinLayoutFactory2.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:
ItemsViewController2:_isRotatingand_orientationObserverfields.UIDevice.OrientationDidChangeNotificationinViewDidLoad(), setting_isRotating = truein theDeviceOrientationChangedhandler.Dispose(bool)to avoid leaks.ViewWillLayoutSubviews(), when_isRotatingis set, explicitly callCollectionView.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
falsefor 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.csinTestCases.HostApp/TestCases.Shared.Tests), which continues to apply here.Issues Fixed
Fixes #36546
Tested the behavior in the following platforms
BeforeFix36546.mov
AfterFix36546.mov