Skip to content

[Android] Fix incorrect PivotX/PivotY when IView has initial Rotation binding#34235

Open
Shalini-Ashokan wants to merge 5 commits intodotnet:mainfrom
Shalini-Ashokan:fix-21068
Open

[Android] Fix incorrect PivotX/PivotY when IView has initial Rotation binding#34235
Shalini-Ashokan wants to merge 5 commits intodotnet:mainfrom
Shalini-Ashokan:fix-21068

Conversation

@Shalini-Ashokan
Copy link
Contributor

@Shalini-Ashokan Shalini-Ashokan commented Feb 25, 2026

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

  • Android
  • Windows
  • iOS
  • Mac

Issues Fixed

Fixes #21068

Output ScreenShot

Before After
21068-BeforeFix.mov
21068-AfterFix.mov

Copilot AI review requested due to automatic review settings February 25, 2026 08:30
@dotnet-policy-service dotnet-policy-service bot added community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration labels Feb 25, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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

@Shalini-Ashokan Shalini-Ashokan marked this pull request as draft February 26, 2026 05:15
@sheiksyedm
Copy link
Contributor

/azp run maui-pr-uitests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@sheiksyedm sheiksyedm marked this pull request as ready for review February 26, 2026 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Android] IView (such as image) with inital Rotation has Incorrect offsets of PivotX and PivotY

3 participants