Skip to content
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue7432.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 7432, "Android Image.Scale produces wrong layout", PlatformAffected.Android)]
public class Issue7432 : ContentPage
{
public Issue7432()
{
var grid = new Grid
{
BackgroundColor = Colors.Gray
};

var image = new Image
{
Source = "dotnet_bot.png",
BackgroundColor = Colors.Red,
WidthRequest = 100,
HeightRequest = 100,
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
Scale = 0.5,
AutomationId = "Image"
};

grid.Children.Add(image);

Content = grid;
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;
public class Issue7432 : _IssuesUITest
{
public Issue7432(TestDevice device) : base(device) { }

public override string Issue => "Android Image.Scale produces wrong layout";

[Test]
[Category(UITestCategories.Image)]
public void ImageShouldScaleProperly()
{
App.WaitForElement("Image");
VerifyScreenshot();
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
67 changes: 56 additions & 11 deletions src/Core/src/Platform/Android/ViewExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ public static partial class ViewExtensions
{
public static void Initialize(this AView platformView, IView view)
{
var pivotX = (float)(view.AnchorX * platformView.ToPixels(view.Frame.Width));
var pivotY = (float)(view.AnchorY * platformView.ToPixels(view.Frame.Height));
var wrapperView = platformView.Parent as WrapperView;
var transformView = wrapperView ?? platformView;

var pivotX = (float)(view.AnchorX * transformView.ToPixels(view.Frame.Width));
var pivotY = (float)(view.AnchorY * transformView.ToPixels(view.Frame.Height));

int visibility;

if (view is IActivityIndicator a)
Expand All @@ -39,21 +43,62 @@ public static void Initialize(this AView platformView, IView view)
visibility = (int)view.Visibility.ToPlatformVisibility();
}

// NOTE: use named arguments for clarity
PlatformInterop.Set(platformView,
if (wrapperView is not null)
{
// Apply transform properties to the wrapper
wrapperView.TranslationX = wrapperView.ToPixels(view.TranslationX);
wrapperView.TranslationY = wrapperView.ToPixels(view.TranslationY);
wrapperView.ScaleX = (float)(view.Scale * view.ScaleX);
wrapperView.ScaleY = (float)(view.Scale * view.ScaleY);
wrapperView.Rotation = (float)view.Rotation;
wrapperView.RotationX = (float)view.RotationX;
wrapperView.RotationY = (float)view.RotationY;
wrapperView.PivotX = pivotX;
wrapperView.PivotY = pivotY;

SetPlatformViewPropertiesWithTransform(platformView, view, visibility, translationX: 0,
translationY: 0,
scaleX: 1,
scaleY: 1,
rotation: 0,
rotationX: 0,
rotationY: 0,
pivotX: 0,
pivotY: 0);
}
else
{
// NOTE: use named arguments for clarity
SetPlatformViewPropertiesWithTransform(platformView, view, visibility, translationX: platformView.ToPixels(view.TranslationX),
translationY: platformView.ToPixels(view.TranslationY),
scaleX: (float)(view.Scale * view.ScaleX),
scaleY: (float)(view.Scale * view.ScaleY),
rotation: (float)view.Rotation,
rotationX: (float)view.RotationX,
rotationY: (float)view.RotationY,
pivotX: pivotX,
pivotY: pivotY);
}
}

static void SetPlatformViewPropertiesWithTransform(View platformView, IView view, int visibility, float translationX,
float translationY, float scaleX, float scaleY, float rotation, float rotationX, float rotationY, float pivotX, float pivotY)
{
PlatformInterop.Set(
platformView,
visibility: visibility,
layoutDirection: (int)GetLayoutDirection(view),
minimumHeight: (int)platformView.ToPixels(view.MinimumHeight),
minimumWidth: (int)platformView.ToPixels(view.MinimumWidth),
enabled: view.IsEnabled,
alpha: (float)view.Opacity,
translationX: platformView.ToPixels(view.TranslationX),
translationY: platformView.ToPixels(view.TranslationY),
scaleX: (float)(view.Scale * view.ScaleX),
scaleY: (float)(view.Scale * view.ScaleY),
rotation: (float)view.Rotation,
rotationX: (float)view.RotationX,
rotationY: (float)view.RotationY,
translationX: translationX,
translationY: translationY,
scaleX: scaleX,
scaleY: scaleY,
rotation: rotation,
rotationX: rotationX,
rotationY: rotationY,
pivotX: pivotX,
pivotY: pivotY
);
Expand Down
Loading