[Android] Fix incorrect PivotX/PivotY when IView has initial Rotation binding#34235
Open
Shalini-Ashokan wants to merge 5 commits intodotnet:mainfrom
Open
[Android] Fix incorrect PivotX/PivotY when IView has initial Rotation binding#34235Shalini-Ashokan wants to merge 5 commits intodotnet:mainfrom
Shalini-Ashokan wants to merge 5 commits intodotnet:mainfrom
Conversation
This reverts commit 27faf8a.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes an Android-specific issue where views with initial Rotation set via binding render incorrectly due to negative pivot values being calculated before layout completes. The fix clamps negative frame dimensions to 0 during handler initialization, preventing incorrect pivot calculations.
Changes:
- Core fix: Clamp negative frame dimensions to 0 in
ViewExtensions.Initialize()to prevent incorrect PivotX/PivotY values on Android - Tests: Add UI tests to verify rotation works correctly with initial binding and subsequent binding updates
Reviewed changes
Copilot reviewed 3 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Core/src/Platform/Android/ViewExtensions.cs | Add Math.Max(0, ...) to clamp negative frame dimensions before pivot calculation |
| src/Controls/tests/TestCases.HostApp/Issues/Issue21068.cs | HostApp test page with Image rotated via binding to reproduce the issue |
| src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue21068.cs | NUnit UI tests to verify initial rotation and binding updates work correctly |
| src/Controls/tests/TestCases.Android.Tests/snapshots/android/InitialBoundRotationShouldRotateAroundCenter.png | Screenshot baseline for initial rotation test |
| src/Controls/tests/TestCases.Android.Tests/snapshots/android/ChangingRotationViaBindingShouldRotateCorrectly.png | Screenshot baseline for rotation change test |
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue21068.cs
Outdated
Show resolved
Hide resolved
Contributor
|
/azp run maui-pr-uitests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
On Android, when a view has an initial Rotation set (e.g. via binding), it rotates around an incorrect point, causing the view to appear visually shifted or offset.
Root Cause
The default frame dimensions are -1 before layout, so the rotation pivot is computed as a negative value, setting the wrong rotation center on the Android view.
Description of Change
Clamped the frame dimensions to a minimum of 0 when computing pivot values, preventing negative pivots and ensuring correct rotation behavior.
Validated the behavior in the following platforms
Issues Fixed
Fixes #21068
Output ScreenShot
21068-BeforeFix.mov
21068-AfterFix.mov