KEMBAR78
[Android] GraphicsView scaling after canvas.ResetState - fix by kubaflo · Pull Request #31183 · dotnet/maui · GitHub
Skip to content

Conversation

@kubaflo
Copy link
Contributor

@kubaflo kubaflo commented Aug 15, 2025

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

Before After

@Copilot Copilot AI review requested due to automatic review settings August 15, 2025 10:56
@kubaflo kubaflo requested a review from a team as a code owner August 15, 2025 10:56
@kubaflo kubaflo requested review from jfversluis and rmarinho August 15, 2025 10:56
@dotnet-policy-service
Copy link
Contributor

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.

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Aug 15, 2025
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 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 ScalingCanvas to store and restore initial scale values instead of resetting to 1.0
  • Updates PlatformGraphicsView on Android to pass the display density scale to ScalingCanvas
  • 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)
Copy link

Copilot AI Aug 15, 2025

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.

{
_canvas = wrapped;
_blurrableCanvas = _canvas as IBlurrableCanvas;
_initialScaleX = scale;
Copy link

Copilot AI Aug 15, 2025

Choose a reason for hiding this comment

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

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

Copilot uses AI. Check for mistakes.

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.
@kubaflo kubaflo self-assigned this Aug 15, 2025
@kubaflo kubaflo added platform/android area-drawing Shapes, Borders, Shadows, Graphics, BoxView, custom drawing labels Aug 15, 2025
@jfversluis
Copy link
Member

/azp run

@jfversluis
Copy link
Member

@softlion would you be able to test this out and let us know? :)

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@PureWeen PureWeen changed the base branch from main to inflight/current August 15, 2025 23:18
@PureWeen PureWeen merged commit f6cea0f into dotnet:inflight/current Aug 15, 2025
121 of 129 checks passed
github-actions bot pushed a commit that referenced this pull request Aug 15, 2025
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.
PureWeen added a commit that referenced this pull request Aug 19, 2025
github-actions bot pushed a commit that referenced this pull request Aug 19, 2025
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.
kubaflo added a commit to kubaflo/maui that referenced this pull request Aug 19, 2025
kubaflo added a commit to kubaflo/maui that referenced this pull request Aug 20, 2025
github-actions bot pushed a commit that referenced this pull request Aug 22, 2025
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.
@github-actions github-actions bot locked and limited conversation to collaborators Sep 19, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-drawing Shapes, Borders, Shadows, Graphics, BoxView, custom drawing community ✨ Community Contribution platform/android

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Android] GraphicsView draws at half size after canvas.ResetState() (issue appears on second Draw)

3 participants