[Android] GraphicsView scaling after canvas.ResetState - fix#31183
[Android] GraphicsView scaling after canvas.ResetState - fix#31183PureWeen merged 1 commit intodotnet:inflight/currentfrom
Conversation
|
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. |
There was a problem hiding this comment.
Pull Request Overview
This PR fixes an Android-specific issue where GraphicsView would draw at half the expected size after calling canvas.ResetState(). The fix involves preserving the initial display scale factor in ScalingCanvas and restoring it properly during state reset operations.
- Modifies
ScalingCanvasto store and restore initial scale values instead of resetting to 1.0 - Updates
PlatformGraphicsViewon Android to pass the display density scale toScalingCanvas - Adds UI tests to verify the fix works correctly
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
ScalingCanvas.cs |
Adds initial scale tracking and new constructor; modifies ResetState/RestoreState to preserve initial scale |
PlatformGraphicsView.cs |
Updates ScalingCanvas instantiation to pass display density scale |
Issue31182.cs (test) |
Adds NUnit test to verify GraphicsView draws at correct size after ResetState |
Issue31182.cs (hostapp) |
Adds test UI page demonstrating the ResetState scaling issue |
| _blurrableCanvas = _canvas as IBlurrableCanvas; | ||
| } | ||
|
|
||
| internal ScalingCanvas(ICanvas wrapped, float scale) |
There was a problem hiding this comment.
Adding a new constructor to a public class like ScalingCanvas represents a potential breaking change to the public API. Since this is marked as 'internal', it may be acceptable, but please ensure this change is reviewed for API compatibility if ScalingCanvas is part of the public surface area.
| { | ||
| _canvas = wrapped; | ||
| _blurrableCanvas = _canvas as IBlurrableCanvas; | ||
| _initialScaleX = scale; |
There was a problem hiding this comment.
[nitpick] The new constructor assumes uniform scaling by setting both X and Y scales to the same value. Consider adding an overload that accepts separate X and Y scale values for more flexibility, or document this limitation.
Addresses issue dotnet#31182 where GraphicsView would draw at half size after calling canvas.ResetState() on Android. ScalingCanvas now preserves the initial scale and restores it after ResetState and RestoreState. Added related test cases to verify correct drawing behavior.
|
/azp run |
|
@softlion would you be able to test this out and let us know? :) |
|
Azure Pipelines successfully started running 3 pipeline(s). |
02e46cb to
784722d
Compare
Addresses issue #31182 where GraphicsView would draw at half size after calling canvas.ResetState() on Android. ScalingCanvas now preserves the initial scale and restores it after ResetState and RestoreState. Added related test cases to verify correct drawing behavior.
Addresses issue #31182 where GraphicsView would draw at half size after calling canvas.ResetState() on Android. ScalingCanvas now preserves the initial scale and restores it after ResetState and RestoreState. Added related test cases to verify correct drawing behavior.
Addresses issue #31182 where GraphicsView would draw at half size after calling canvas.ResetState() on Android. ScalingCanvas now preserves the initial scale and restores it after ResetState and RestoreState. Added related test cases to verify correct drawing behavior.
REVERTED 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 from this PR and let us know in a comment if this change resolves your issue. Thank you!
Description of Change
Addresses issue #31182 where GraphicsView would draw at half size after calling canvas.ResetState() on Android. ScalingCanvas now preserves the initial scale and restores it after ResetState and RestoreState. Added related test cases to verify correct drawing behavior.
Issues Fixed
Fixes #31182