Skip to content

[Android] Fixed TransformProperties issue when a wrapper view is present #29228

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

Ahamed-Ali
Copy link
Contributor

Root Cause of the issue

  • When a background color is applied to an image, the image is wrapped inside a container view(WrapperView). However, when scaling is applied to the image, the container view (WrapperView) does not account for the scaling, resulting in incorrect rendering.

Description of Change

  • Apply the scaling to the container view itself when a background color is present, ensuring proper rendering and consistent behavior.

Issues Fixed

Fixes #7432

Tested the behaviour in the following platforms

  • Android
  • Windows
  • iOS
  • Mac

Screenshot

Before Issue Fix After Issue Fix

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Apr 28, 2025
Copy link
Contributor

Hey there @@Ahamed-Ali! 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 partner/syncfusion Issues / PR's with Syncfusion collaboration label Apr 28, 2025
@Ahamed-Ali Ahamed-Ali marked this pull request as ready for review April 29, 2025 09:19
@Copilot Copilot AI review requested due to automatic review settings April 29, 2025 09:19
@Ahamed-Ali Ahamed-Ali requested a review from a team as a code owner April 29, 2025 09:19
Copy link
Contributor

@Copilot 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 the issue where the scaling transformation was not applied correctly when an image is wrapped inside a container view (WrapperView) on Android. The changes update the transform properties calculation to apply these properties to the WrapperView instead of the inner view and add corresponding UI tests to validate the fix.

  • Calculate pivot points and other transform properties based on the actual view (either the WrapperView or the original view).
  • When a WrapperView is detected, apply transform properties on it and reset non-transform values on the inner view.
  • Added automated tests in both the shared and host app test suites to verify the corrected behavior.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/Core/src/Platform/Android/ViewExtensions.cs Updated transform properties calculations to account for WrapperView presence
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue7432.cs Added automated UI test for Issue7432
src/Controls/tests/TestCases.HostApp/Issues/Issue7432.cs Added test UI page for Issue7432 to simulate the issue

Comment on lines +32 to +34
var pivotX = (float)(view.AnchorX * transformView.ToPixels(view.Frame.Width));
var pivotY = (float)(view.AnchorY * transformView.ToPixels(view.Frame.Height));

Copy link
Preview

Copilot AI Apr 29, 2025

Choose a reason for hiding this comment

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

Ensure that using 'transformView' for calculating pivot accurately reflects the intended pixel conversion when a WrapperView is present. Verify that the view.Frame dimensions used remain valid for the WrapperView's coordinate context.

Suggested change
var pivotX = (float)(view.AnchorX * transformView.ToPixels(view.Frame.Width));
var pivotY = (float)(view.AnchorY * transformView.ToPixels(view.Frame.Height));
float pivotX, pivotY;
if (wrapperView is not null)
{
// Use WrapperView's coordinate context for pixel conversion
pivotX = (float)(view.AnchorX * wrapperView.ToPixels(view.Frame.Width));
pivotY = (float)(view.AnchorY * wrapperView.ToPixels(view.Frame.Height));
}
else
{
// Use platformView's coordinate context for pixel conversion
pivotX = (float)(view.AnchorX * platformView.ToPixels(view.Frame.Width));
pivotY = (float)(view.AnchorY * platformView.ToPixels(view.Frame.Height));
}

Copilot uses AI. Check for mistakes.

@jsuarezruiz jsuarezruiz added area-animation Animation, Transitions, Transforms platform/android 🤖 labels Apr 30, 2025
public void ImageShouldScaleProperly()
{
App.WaitForElement("Image");
VerifyScreenshot();
Copy link
Contributor

Choose a reason for hiding this comment

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

Pending snapshot for iOS, Mac and Windows.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Once the CI is triggered, we can add the pending Mac and Windows snapshots @jsuarezruiz

wrapperView.PivotY = pivotY;

// Apply non-transform properties to the inner view
PlatformInterop.Set(platformView,
Copy link
Contributor

Choose a reason for hiding this comment

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

This is duplicated two times, can create a method with all the transformation properties as parameters?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have made the changes. please let me know if you have any other concerns. @jsuarezruiz

@jsuarezruiz
Copy link
Contributor

/azp run MAUI-UITests-public

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-animation Animation, Transitions, Transforms community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration platform/android 🤖
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Android Image.Scale produces wrong layout
2 participants