-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Android] GraphicsView scaling after canvas.ResetState #31244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 a GraphicsView scaling issue on Android where content was being rendered at half size after calling canvas.ResetState(). The fix involves modifying the ScalingCanvas to preserve initial scale values when resetting state, eliminating the need for manual scaling in PlatformGraphicsView.
- Adds initial scale tracking to ScalingCanvas with new constructor parameter
- Removes redundant manual scaling call in PlatformGraphicsView.Draw method
- Adds comprehensive UI test to verify the fix
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/Graphics/src/Graphics/ScalingCanvas.cs | Adds initial scale tracking fields and constructor to preserve scale during ResetState() |
| src/Graphics/src/Graphics/Platforms/Android/PlatformGraphicsView.cs | Removes redundant Scale() call and uses new ScalingCanvas constructor with scale parameter |
| src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue31182.cs | Adds NUnit test to verify GraphicsView renders at correct size after ResetState() |
| src/Controls/tests/TestCases.HostApp/Issues/Issue31182.cs | Adds test page with GraphicsView that calls ResetState() to reproduce the issue |
| _blurrableCanvas = _canvas as IBlurrableCanvas; | ||
| } | ||
|
|
||
| internal ScalingCanvas(ICanvas wrapped, float scale) : this(wrapped) |
Copilot
AI
Aug 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This introduces a new public API constructor that could be a breaking change. Consider marking this constructor as internal to prevent external usage, or ensure this is documented as a new API addition if intended for public consumption.
Copilot uses AI. Check for mistakes.
|
Hey there @@kubaflo! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
| public void GraphicsViewShouldDrawAtFullSize() | ||
| { | ||
| App.WaitForElement("label"); | ||
| VerifyScreenshot(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pending snapshot on Windows and Android. Running a build.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test failing on Android:
at UITest.Appium.HelperExtensions.Wait(Func`1 query, Func`2 satisfactory, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2530
at UITest.Appium.HelperExtensions.WaitForAtLeastOne(Func`1 query, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2547
at UITest.Appium.HelperExtensions.WaitForElement(IApp app, String marked, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency, Nullable`1 postTimeout) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 743
at Microsoft.Maui.TestCases.Tests.Issues.Issue31182.GraphicsViewShouldDrawAtFullSize() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue31182.cs:line 17
at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
| public void GraphicsViewShouldDrawAtFullSize() | ||
| { | ||
| App.WaitForElement("label"); | ||
| VerifyScreenshot(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| public void GraphicsViewShouldDrawAtFullSize() | ||
| { | ||
| App.WaitForElement("label"); | ||
| VerifyScreenshot(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test failing on Android:
at UITest.Appium.HelperExtensions.Wait(Func`1 query, Func`2 satisfactory, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2530
at UITest.Appium.HelperExtensions.WaitForAtLeastOne(Func`1 query, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 2547
at UITest.Appium.HelperExtensions.WaitForElement(IApp app, String marked, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency, Nullable`1 postTimeout) in /_/src/TestUtils/src/UITest.Appium/HelperExtensions.cs:line 743
at Microsoft.Maui.TestCases.Tests.Issues.Issue31182.GraphicsViewShouldDrawAtFullSize() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue31182.cs:line 17
at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

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!
Description of Change
Follow-up to #31183
While reviewing the snapshots, I noticed that without calling canvas.ResetState(); in the Draw method, the rendered content size was doubled.
This change removes the unnecessary call to _scalingCanvas.Scale in PlatformGraphicsView. Scaling is already accounted for in the ResetState() method
Issues Fixed
Fixes #31182