[iOS][CV2] Fix CollectionView2 on iOS iPad jumps/scrolls randomly when item size changes - #32874
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a CollectionView2 issue on iPad where the view jumps or scrolls unexpectedly when item sizes change. The fix replaces the cell invalidation approach from using InvalidateLayout to using ReconfigureItems (iOS 15+), which is designed to handle size changes more efficiently without full cell recreation.
Changes:
- Adds a new code path that uses
ReconfigureItemsfor iOS 15+ when cells need layout invalidation - Wraps the reconfiguration in
UIView.PerformWithoutAnimationto prevent visual artifacts - Falls back to the existing
InvalidateLayoutapproach for older iOS versions
The issue reproduces only on iPad and not on the Mac version. Therefore, the agent’s suggestion is not applicable. |
|
Hi, @devanathan-vaithiyanathan are there any available artifacts or binary to test? I'm not able to find them into pipeline artifacts |
92c7444 to
ac7d895
Compare
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 32874Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 32874" |
81295ab to
34a8f02
Compare
…net#34527) <!-- Please let the below note in for people that 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 if this change resolves your issue. Thank you! ### Issue Details: Horizontalspacing / Verticalspacing is not not applied to the first column in GridItemLayout using CollectionView on Android platform. ### Root Cause: The grid spacing was not being distributed symmetrically across the active layout implementations, so edge items did not fully participate when spacing changed at runtime. ### Description of Change: - On Android, the fix in MauiRecyclerView.cs changes how RecyclerView padding is handled for GridItemsLayout. Android was already using SpacingItemDecoration, which applies half-spacing on all four sides of each item. Previously, negative RecyclerView padding canceled that spacing at the control edges. The branch keeps that negative-padding behavior for non-grid layouts, but disables it for GridItemsLayout, allowing the grid’s half-spacing to remain visible at the outer perimeter. This makes the first row and first column visually respond when spacing changes, but it also changes the grid behavior from spacing only between items to spacing around the outside edges as well. **Tested the behavior in the following platforms:** - [x] Android - [x] Windows - [ ] iOS - [ ] Mac ### Reference: N/A ### Issues Fixed: Fixes dotnet#34257 ### Screenshots | Before | After | |---------|--------| | <Video src="https://github.com/user-attachments/assets/578dda69-1d60-474c-a6d8-23b3f9d29a50" Width="300" Height="600"> | <Video src="https://github.com/user-attachments/assets/7f3826e6-5922-4b6f-a6b9-de581b7db6c3" Width="300" Height="600"> |
…n item size changes Use ReconfigureItems (iOS 15+/MacCatalyst 15+) instead of InvalidateLayout for cells with changed sizes, wrapped in PerformWithoutAnimation to prevent scroll position jumps on iPadOS 18+ with UICollectionViewCompositionalLayout. Fixes dotnet#32796 Fixes dotnet#33833
35d6351 to
9c4cb23
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…n item size changes (#32874) <!-- Please let the below note in for people that 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 if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details In CollectionView2, when an item’s size changes, the CollectionView jumps or scrolls unexpectedly instead of keeping its current position. ### Description of Change <!-- Enter description of the fix in this section --> Replaced the cell update logic from invalidateLayout to reconfigureItems for the affected cell. reconfigureItems (iOS 15+) is lighter and works correctly on iPad iOS 26. ### 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 #32796 Fixes #33833 <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. --> ### Regarding test case Since the issue reproduces only on iPadOS 26, I haven’t added a test case. **Tested the behavior in the following platforms.** - [ ] Android - [ ] Windows - [x] iOS - [ ] Mac | Before | After | |---------|--------| | **iOS**<br> <video src="https://github.com/user-attachments/assets/6b3d1860-fa1d-4085-a0f9-e57f48eea1ff" width="400" height="600"> | **iOS**<br> <video src="https://github.com/user-attachments/assets/89036aa6-010c-4c64-b4de-e7a503579c6f" width="400" height="600"> | --------- Co-authored-by: KarthikRajaKalaimani <92777139+KarthikRajaKalaimani@users.noreply.github.com>
…n item size changes (#32874) <!-- Please let the below note in for people that 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 if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details In CollectionView2, when an item’s size changes, the CollectionView jumps or scrolls unexpectedly instead of keeping its current position. ### Description of Change <!-- Enter description of the fix in this section --> Replaced the cell update logic from invalidateLayout to reconfigureItems for the affected cell. reconfigureItems (iOS 15+) is lighter and works correctly on iPad iOS 26. ### 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 #32796 Fixes #33833 <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. --> ### Regarding test case Since the issue reproduces only on iPadOS 26, I haven’t added a test case. **Tested the behavior in the following platforms.** - [ ] Android - [ ] Windows - [x] iOS - [ ] Mac | Before | After | |---------|--------| | **iOS**<br> <video src="https://github.com/user-attachments/assets/6b3d1860-fa1d-4085-a0f9-e57f48eea1ff" width="400" height="600"> | **iOS**<br> <video src="https://github.com/user-attachments/assets/89036aa6-010c-4c64-b4de-e7a503579c6f" width="400" height="600"> | --------- Co-authored-by: KarthikRajaKalaimani <92777139+KarthikRajaKalaimani@users.noreply.github.com>
…n item size changes (#32874) <!-- Please let the below note in for people that 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 if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details In CollectionView2, when an item’s size changes, the CollectionView jumps or scrolls unexpectedly instead of keeping its current position. ### Description of Change <!-- Enter description of the fix in this section --> Replaced the cell update logic from invalidateLayout to reconfigureItems for the affected cell. reconfigureItems (iOS 15+) is lighter and works correctly on iPad iOS 26. ### 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 #32796 Fixes #33833 <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. --> ### Regarding test case Since the issue reproduces only on iPadOS 26, I haven’t added a test case. **Tested the behavior in the following platforms.** - [ ] Android - [ ] Windows - [x] iOS - [ ] Mac | Before | After | |---------|--------| | **iOS**<br> <video src="https://github.com/user-attachments/assets/6b3d1860-fa1d-4085-a0f9-e57f48eea1ff" width="400" height="600"> | **iOS**<br> <video src="https://github.com/user-attachments/assets/89036aa6-010c-4c64-b4de-e7a503579c6f" width="400" height="600"> | --------- Co-authored-by: KarthikRajaKalaimani <92777139+KarthikRajaKalaimani@users.noreply.github.com>
…n item size changes (#32874) <!-- Please let the below note in for people that 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 if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details In CollectionView2, when an item’s size changes, the CollectionView jumps or scrolls unexpectedly instead of keeping its current position. ### Description of Change <!-- Enter description of the fix in this section --> Replaced the cell update logic from invalidateLayout to reconfigureItems for the affected cell. reconfigureItems (iOS 15+) is lighter and works correctly on iPad iOS 26. ### 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 #32796 Fixes #33833 <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. --> ### Regarding test case Since the issue reproduces only on iPadOS 26, I haven’t added a test case. **Tested the behavior in the following platforms.** - [ ] Android - [ ] Windows - [x] iOS - [ ] Mac | Before | After | |---------|--------| | **iOS**<br> <video src="https://github.com/user-attachments/assets/6b3d1860-fa1d-4085-a0f9-e57f48eea1ff" width="400" height="600"> | **iOS**<br> <video src="https://github.com/user-attachments/assets/89036aa6-010c-4c64-b4de-e7a503579c6f" width="400" height="600"> | --------- Co-authored-by: KarthikRajaKalaimani <92777139+KarthikRajaKalaimani@users.noreply.github.com>
…n item size changes (#32874) <!-- Please let the below note in for people that 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 if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details In CollectionView2, when an item’s size changes, the CollectionView jumps or scrolls unexpectedly instead of keeping its current position. ### Description of Change <!-- Enter description of the fix in this section --> Replaced the cell update logic from invalidateLayout to reconfigureItems for the affected cell. reconfigureItems (iOS 15+) is lighter and works correctly on iPad iOS 26. ### 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 #32796 Fixes #33833 <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. --> ### Regarding test case Since the issue reproduces only on iPadOS 26, I haven’t added a test case. **Tested the behavior in the following platforms.** - [ ] Android - [ ] Windows - [x] iOS - [ ] Mac | Before | After | |---------|--------| | **iOS**<br> <video src="https://github.com/user-attachments/assets/6b3d1860-fa1d-4085-a0f9-e57f48eea1ff" width="400" height="600"> | **iOS**<br> <video src="https://github.com/user-attachments/assets/89036aa6-010c-4c64-b4de-e7a503579c6f" width="400" height="600"> | --------- Co-authored-by: KarthikRajaKalaimani <92777139+KarthikRajaKalaimani@users.noreply.github.com>
…n item size changes (#32874) <!-- Please let the below note in for people that 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 if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details In CollectionView2, when an item’s size changes, the CollectionView jumps or scrolls unexpectedly instead of keeping its current position. ### Description of Change <!-- Enter description of the fix in this section --> Replaced the cell update logic from invalidateLayout to reconfigureItems for the affected cell. reconfigureItems (iOS 15+) is lighter and works correctly on iPad iOS 26. ### 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 #32796 Fixes #33833 <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. --> ### Regarding test case Since the issue reproduces only on iPadOS 26, I haven’t added a test case. **Tested the behavior in the following platforms.** - [ ] Android - [ ] Windows - [x] iOS - [ ] Mac | Before | After | |---------|--------| | **iOS**<br> <video src="https://github.com/user-attachments/assets/6b3d1860-fa1d-4085-a0f9-e57f48eea1ff" width="400" height="600"> | **iOS**<br> <video src="https://github.com/user-attachments/assets/89036aa6-010c-4c64-b4de-e7a503579c6f" width="400" height="600"> | --------- Co-authored-by: KarthikRajaKalaimani <92777139+KarthikRajaKalaimani@users.noreply.github.com>
…n item size changes (#32874) <!-- Please let the below note in for people that 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 if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details In CollectionView2, when an item’s size changes, the CollectionView jumps or scrolls unexpectedly instead of keeping its current position. ### Description of Change <!-- Enter description of the fix in this section --> Replaced the cell update logic from invalidateLayout to reconfigureItems for the affected cell. reconfigureItems (iOS 15+) is lighter and works correctly on iPad iOS 26. ### 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 #32796 Fixes #33833 <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. --> ### Regarding test case Since the issue reproduces only on iPadOS 26, I haven’t added a test case. **Tested the behavior in the following platforms.** - [ ] Android - [ ] Windows - [x] iOS - [ ] Mac | Before | After | |---------|--------| | **iOS**<br> <video src="https://github.com/user-attachments/assets/6b3d1860-fa1d-4085-a0f9-e57f48eea1ff" width="400" height="600"> | **iOS**<br> <video src="https://github.com/user-attachments/assets/89036aa6-010c-4c64-b4de-e7a503579c6f" width="400" height="600"> | --------- Co-authored-by: KarthikRajaKalaimani <92777139+KarthikRajaKalaimani@users.noreply.github.com>
…n item size changes (#32874) <!-- Please let the below note in for people that 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 if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details In CollectionView2, when an item’s size changes, the CollectionView jumps or scrolls unexpectedly instead of keeping its current position. ### Description of Change <!-- Enter description of the fix in this section --> Replaced the cell update logic from invalidateLayout to reconfigureItems for the affected cell. reconfigureItems (iOS 15+) is lighter and works correctly on iPad iOS 26. ### 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 #32796 Fixes #33833 <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. --> ### Regarding test case Since the issue reproduces only on iPadOS 26, I haven’t added a test case. **Tested the behavior in the following platforms.** - [ ] Android - [ ] Windows - [x] iOS - [ ] Mac | Before | After | |---------|--------| | **iOS**<br> <video src="https://github.com/user-attachments/assets/6b3d1860-fa1d-4085-a0f9-e57f48eea1ff" width="400" height="600"> | **iOS**<br> <video src="https://github.com/user-attachments/assets/89036aa6-010c-4c64-b4de-e7a503579c6f" width="400" height="600"> | --------- Co-authored-by: KarthikRajaKalaimani <92777139+KarthikRajaKalaimani@users.noreply.github.com>
…n item size changes (#32874) <!-- Please let the below note in for people that 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 if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details In CollectionView2, when an item’s size changes, the CollectionView jumps or scrolls unexpectedly instead of keeping its current position. ### Description of Change <!-- Enter description of the fix in this section --> Replaced the cell update logic from invalidateLayout to reconfigureItems for the affected cell. reconfigureItems (iOS 15+) is lighter and works correctly on iPad iOS 26. ### 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 #32796 Fixes #33833 <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. --> ### Regarding test case Since the issue reproduces only on iPadOS 26, I haven’t added a test case. **Tested the behavior in the following platforms.** - [ ] Android - [ ] Windows - [x] iOS - [ ] Mac | Before | After | |---------|--------| | **iOS**<br> <video src="https://github.com/user-attachments/assets/6b3d1860-fa1d-4085-a0f9-e57f48eea1ff" width="400" height="600"> | **iOS**<br> <video src="https://github.com/user-attachments/assets/89036aa6-010c-4c64-b4de-e7a503579c6f" width="400" height="600"> | --------- Co-authored-by: KarthikRajaKalaimani <92777139+KarthikRajaKalaimani@users.noreply.github.com>
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Issue Details
In CollectionView2, when an item’s size changes, the CollectionView jumps or scrolls unexpectedly instead of keeping its current position.
Description of Change
Replaced the cell update logic from invalidateLayout to reconfigureItems for the affected cell.
reconfigureItems (iOS 15+) is lighter and works correctly on iPad iOS 26.
Issues Fixed
Fixes #32796
Fixes #33833
Regarding test case
Since the issue reproduces only on iPadOS 26, I haven’t added a test case.
Tested the behavior in the following platforms.
Before.mov
After.mov