Skip to content

[main] [iOS/MacCatalyst] Fix RTL CollectionView item positioning after rotation - #39894

Merged
kubaflo merged 1 commit into
mainfrom
backport/pr-39891-to-main
Nov 4, 2026
Merged

kubaflo merged 1 commit into
mainfrom
backport/pr-39891-to-main

Conversation

@github-actions

@github-actions github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Backport of #39891 to main

/cc @sheiksyedm

…ion (#39891)

<!-- 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. !!!!!!!
-->

### Description of Change

RTL CollectionView items can become horizontally displaced after device
rotation and scrolling. During preferred sizing, the managed item is
arranged before UIKit applies the updated native bounds. RTL positioning
can therefore use the previous parent width. Existing layout
optimizations may skip a subsequent managed arrangement, leaving
recycled items incorrectly positioned.

This change:
- Tracks the native content width used during managed arrangement.
- Corrects the native item position when an RTL cell receives a
different content width.
- Reuses the existing native arrangement path without adding managed
subtree arrange passes.
- Adds LTR and RTL device tests covering initial sizing,
widening/narrowing, reuse, and managed-arrange counts.

The fix uses `TemplatedCell2.LayoutSubviews`. It does not modify
`ItemsViewController2` or restore the removed `ViewDidLayoutSubviews`
override.

Validation on iOS:
- Reproduced the issue in Sandbox using the post-revert SR13 source.
- Confirmed the RTL regression test fails without the fix: native X is
−200 instead of 0.
- Confirmed both RTL and LTR cases pass with the fix.
- Confirmed the Sandbox rotation-and-scroll scenario remains aligned.

### Regression reason

This regression issue was originally introduced by PR #37437. A fix was
later added through PR #38771 and merged into the candidate branch.
However, the fix was subsequently reverted by PR #39707 due to test
failures encountered during validation.

### 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 #38622

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->
@azure-pipelines

This comment has been minimized.

@kubaflo
kubaflo merged commit 5514fa3 into main Nov 4, 2026
1 of 11 checks passed
@kubaflo
kubaflo deleted the backport/pr-39891-to-main branch November 4, 2026 14:42
@github-actions github-actions Bot locked and limited conversation to collaborators Dec 5, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants