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.
23 changes: 23 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue25558.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 25558, "ImageButton does not scale Image correctly", PlatformAffected.Android)]
public class Issue25558 : ContentPage
{
public Issue25558()
{
var verticalStackLayout = new VerticalStackLayout
{
Padding = 10
};

var imageButton = new ImageButton
{
AutomationId = "imageButton",
Source = "groceries.png",
BackgroundColor = Colors.Blue
};

verticalStackLayout.Add(imageButton);
Content = verticalStackLayout;
}
}
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,22 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue25558 : _IssuesUITest
{
public override string Issue => "ImageButton does not scale Image correctly";

public Issue25558(TestDevice device) : base(device)
{
}

[Test]
[Category(UITestCategories.ImageButton)]
public void Issue25558VerifyImageButtonAspects()
Copy link
Contributor

Choose a reason for hiding this comment

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

This test is failing on Windows:

   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 2367
   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 2384
   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 665
   at Microsoft.Maui.TestCases.Tests.Issues.Issue25558.Issue25558VerifyImageButtonAspects() in /_/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue25558.cs:line 19
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jsuarezruiz, I have modified the test to resolve the failing.

{
App.WaitForElement("imageButton");
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 snapshots on Mac and Windows. Already available in the latest build.

Example, Mac:
image

Could you commit the images?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jsuarezruiz, I have committed the image.

}
}
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.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ protected override ShapeableImageView CreatePlatformView()
// These set the defaults so visually it matches up with other platforms
platformView.SetPadding(0, 0, 0, 0);
platformView.SoundEffectsEnabled = false;
platformView.SetAdjustViewBounds(true);

return platformView;
}
Expand Down
12 changes: 6 additions & 6 deletions src/Core/src/Platform/Android/ImageViewExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ public static void Clear(this ImageView imageView)

public static void UpdateAspect(this ImageView imageView, IImage image)
{
// Apply bounds adjustment only for the Image control, not for the ImageButton control. ShapeableImageView serves as the platform view for ImageButton
if (imageView is not ShapeableImageView)
if (image.Aspect == Aspect.AspectFill)
{
if (image.Aspect == Aspect.AspectFill)
imageView.SetAdjustViewBounds(false);
else
imageView.SetAdjustViewBounds(true);
imageView.SetAdjustViewBounds(false);
}
else
{
imageView.SetAdjustViewBounds(true);
}

imageView.SetScaleType(image.Aspect.ToScaleType());
Expand Down
Loading