diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/GradientImageButtonBackground.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/GradientImageButtonBackground.png index c6f91228670b..b070d5f156d0 100644 Binary files a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/GradientImageButtonBackground.png and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/GradientImageButtonBackground.png differ diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ImageButtonAspectFitWorks.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ImageButtonAspectFitWorks.png new file mode 100644 index 000000000000..d73d7be98891 Binary files /dev/null and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ImageButtonAspectFitWorks.png differ diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ImageButtonUITests_BorderColor.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ImageButtonUITests_BorderColor.png index d4e73da2ce46..54e6f2ab73b9 100644 Binary files a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ImageButtonUITests_BorderColor.png and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ImageButtonUITests_BorderColor.png differ diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ImageButtonUITests_BorderColor_WithBackground.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ImageButtonUITests_BorderColor_WithBackground.png index a3d0d6a926c8..81f4b3a5f167 100644 Binary files a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ImageButtonUITests_BorderColor_WithBackground.png and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ImageButtonUITests_BorderColor_WithBackground.png differ diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ImageButtonUITests_BorderWidth.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ImageButtonUITests_BorderWidth.png index 94fa27913462..95ba98077042 100644 Binary files a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ImageButtonUITests_BorderWidth.png and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ImageButtonUITests_BorderWidth.png differ diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ImageButtonUITests_BorderWidth_WithBackground.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ImageButtonUITests_BorderWidth_WithBackground.png index 1b4efc1c12dd..23096c338710 100644 Binary files a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ImageButtonUITests_BorderWidth_WithBackground.png and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ImageButtonUITests_BorderWidth_WithBackground.png differ diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ImageButtonUITests_CornerRadius.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ImageButtonUITests_CornerRadius.png index a4c167dba4f2..9febfad443c8 100644 Binary files a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ImageButtonUITests_CornerRadius.png and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ImageButtonUITests_CornerRadius.png differ diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ImageButtonUITests_CornerRadius_WithBackground.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ImageButtonUITests_CornerRadius_WithBackground.png index 8ff4308d5ba0..c4d20d9e4610 100644 Binary files a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ImageButtonUITests_CornerRadius_WithBackground.png and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ImageButtonUITests_CornerRadius_WithBackground.png differ diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue24856.xaml b/src/Controls/tests/TestCases.HostApp/Issues/Issue24856.xaml new file mode 100644 index 000000000000..6ac6c546db7d --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue24856.xaml @@ -0,0 +1,25 @@ + + + + + + + \ No newline at end of file diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue24856.xaml.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue24856.xaml.cs new file mode 100644 index 000000000000..005d1dbe08a1 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue24856.xaml.cs @@ -0,0 +1,17 @@ +namespace Maui.Controls.Sample.Issues +{ + + [Issue(IssueTracker.Github, 24856, "Android ImageButton Aspect=AspectFit not display correctly", PlatformAffected.Android)] + public partial class Issue24856 : TestContentPage + { + public Issue24856() + { + InitializeComponent(); + } + + protected override void Init() + { + + } + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.HostApp/Resources/Images/avatar.png b/src/Controls/tests/TestCases.HostApp/Resources/Images/avatar.png new file mode 100644 index 000000000000..64669bd69aba Binary files /dev/null and b/src/Controls/tests/TestCases.HostApp/Resources/Images/avatar.png differ diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue24856.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue24856.cs new file mode 100644 index 000000000000..68df3296741a --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue24856.cs @@ -0,0 +1,26 @@ +#if ANDROID +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues +{ + public class Issue24856 : _IssuesUITest + { + public override string Issue => "Android ImageButton Aspect=AspectFit not display correctly"; + + public Issue24856(TestDevice device) + : base(device) + { } + + [Test] + [Category(UITestCategories.ImageButton)] + public void ImageButtonAspectFitWorks() + { + App.WaitForElement("WaitForStubControl"); + + VerifyScreenshot(); + } + } +} +#endif \ No newline at end of file diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ImageButtonUITests_BorderColor.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ImageButtonUITests_BorderColor.png index fb76f6a6686d..346a8e9c0b58 100644 Binary files a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ImageButtonUITests_BorderColor.png and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ImageButtonUITests_BorderColor.png differ diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ImageButtonUITests_BorderColor_WithBackground.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ImageButtonUITests_BorderColor_WithBackground.png index 34a8f7bfe544..69f22f4936ab 100644 Binary files a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ImageButtonUITests_BorderColor_WithBackground.png and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ImageButtonUITests_BorderColor_WithBackground.png differ diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ImageButtonUITests_BorderWidth.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ImageButtonUITests_BorderWidth.png index 4e9303041bf1..9aa998c6613f 100644 Binary files a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ImageButtonUITests_BorderWidth.png and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ImageButtonUITests_BorderWidth.png differ diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ImageButtonUITests_BorderWidth_WithBackground.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ImageButtonUITests_BorderWidth_WithBackground.png index c882bdc86f82..97cd271b644b 100644 Binary files a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ImageButtonUITests_BorderWidth_WithBackground.png and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ImageButtonUITests_BorderWidth_WithBackground.png differ diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ImageButtonUITests_CornerRadius.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ImageButtonUITests_CornerRadius.png index 5881ef1362c1..35fc983accaa 100644 Binary files a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ImageButtonUITests_CornerRadius.png and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ImageButtonUITests_CornerRadius.png differ diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ImageButtonUITests_CornerRadius_WithBackground.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ImageButtonUITests_CornerRadius_WithBackground.png index eb96ceb4d7a1..babb5678ee08 100644 Binary files a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ImageButtonUITests_CornerRadius_WithBackground.png and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ImageButtonUITests_CornerRadius_WithBackground.png differ diff --git a/src/Core/src/Handlers/ImageButton/ImageButtonHandler.Android.cs b/src/Core/src/Handlers/ImageButton/ImageButtonHandler.Android.cs index 69f501d2c92c..2132103c7db5 100644 --- a/src/Core/src/Handlers/ImageButton/ImageButtonHandler.Android.cs +++ b/src/Core/src/Handlers/ImageButton/ImageButtonHandler.Android.cs @@ -53,11 +53,13 @@ public static void MapStrokeColor(IImageButtonHandler handler, IButtonStroke but public static void MapStrokeThickness(IImageButtonHandler handler, IButtonStroke buttonStroke) { handler.PlatformView?.UpdateStrokeThickness(buttonStroke); + handler.UpdateValue(nameof(IImageButton.Padding)); } public static void MapCornerRadius(IImageButtonHandler handler, IButtonStroke buttonStroke) { - handler.PlatformView.UpdateCornerRadius(buttonStroke); + handler.PlatformView?.UpdateCornerRadius(buttonStroke); + handler.UpdateValue(nameof(IImageButton.Padding)); } public static void MapPadding(IImageButtonHandler handler, IImageButton imageButton) diff --git a/src/Core/src/Handlers/ImageButton/ImageButtonHandler.Tizen.cs b/src/Core/src/Handlers/ImageButton/ImageButtonHandler.Tizen.cs index 9835989424fc..1355cbebb40e 100644 --- a/src/Core/src/Handlers/ImageButton/ImageButtonHandler.Tizen.cs +++ b/src/Core/src/Handlers/ImageButton/ImageButtonHandler.Tizen.cs @@ -41,11 +41,13 @@ public static void MapStrokeColor(IImageButtonHandler handler, IButtonStroke but public static void MapStrokeThickness(IImageButtonHandler handler, IButtonStroke buttonStroke) { handler.PlatformView.UpdateStrokeThickness(buttonStroke); + handler.UpdateValue(nameof(IImageButton.Padding)); } public static void MapCornerRadius(IImageButtonHandler handler, IButtonStroke buttonStroke) { handler.PlatformView.UpdateCornerRadius(buttonStroke); + handler.UpdateValue(nameof(IImageButton.Padding)); } [MissingMapper] diff --git a/src/Core/src/Handlers/ImageButton/ImageButtonHandler.Windows.cs b/src/Core/src/Handlers/ImageButton/ImageButtonHandler.Windows.cs index 9ba6791e9428..8e225bc079cc 100644 --- a/src/Core/src/Handlers/ImageButton/ImageButtonHandler.Windows.cs +++ b/src/Core/src/Handlers/ImageButton/ImageButtonHandler.Windows.cs @@ -78,11 +78,13 @@ public static void MapStrokeColor(IImageButtonHandler handler, IButtonStroke but public static void MapStrokeThickness(IImageButtonHandler handler, IButtonStroke buttonStroke) { (handler.PlatformView as Button)?.UpdateStrokeThickness(buttonStroke); + handler.UpdateValue(nameof(IImageButton.Padding)); } public static void MapCornerRadius(IImageButtonHandler handler, IButtonStroke buttonStroke) { (handler.PlatformView as Button)?.UpdateCornerRadius(buttonStroke); + handler.UpdateValue(nameof(IImageButton.Padding)); } public static void MapBackground(IImageButtonHandler handler, IImageButton imageButton) diff --git a/src/Core/src/Handlers/ImageButton/ImageButtonHandler.iOS.cs b/src/Core/src/Handlers/ImageButton/ImageButtonHandler.iOS.cs index 0dde70c97cfe..c9c988ccf839 100644 --- a/src/Core/src/Handlers/ImageButton/ImageButtonHandler.iOS.cs +++ b/src/Core/src/Handlers/ImageButton/ImageButtonHandler.iOS.cs @@ -45,11 +45,13 @@ public static void MapStrokeColor(IImageButtonHandler handler, IButtonStroke but public static void MapStrokeThickness(IImageButtonHandler handler, IButtonStroke buttonStroke) { handler.PlatformView?.UpdateStrokeThickness(buttonStroke); + handler.UpdateValue(nameof(IImageButton.Padding)); } public static void MapCornerRadius(IImageButtonHandler handler, IButtonStroke buttonStroke) { handler.PlatformView?.UpdateCornerRadius(buttonStroke); + handler.UpdateValue(nameof(IImageButton.Padding)); } public static void MapPadding(IImageButtonHandler handler, IImageButton imageButton) diff --git a/src/Core/src/Platform/Android/ImageButtonExtensions.cs b/src/Core/src/Platform/Android/ImageButtonExtensions.cs index 7606df45bd32..a081ba2cfbfa 100644 --- a/src/Core/src/Platform/Android/ImageButtonExtensions.cs +++ b/src/Core/src/Platform/Android/ImageButtonExtensions.cs @@ -23,6 +23,9 @@ public static void UpdateCornerRadius(this ShapeableImageView platformButton, IB public static async void UpdatePadding(this ShapeableImageView platformButton, IImageButton imageButton) { var padding = platformButton.Context!.ToPixels(imageButton.Padding); + var (strokeWidth, _, _) = imageButton.GetStrokeProperties(platformButton.Context!, true); + int additionalPadding = strokeWidth; + padding = new Thickness(padding.Left + additionalPadding, padding.Top + additionalPadding, padding.Right + additionalPadding, padding.Bottom + additionalPadding); // The simple operation we are trying to do. platformButton.SetContentPadding((int)padding.Left, (int)padding.Top, (int)padding.Right, (int)padding.Bottom); diff --git a/src/Core/src/Platform/iOS/ButtonExtensions.cs b/src/Core/src/Platform/iOS/ButtonExtensions.cs index 8a92700fed8e..91ba7fd4eaef 100644 --- a/src/Core/src/Platform/iOS/ButtonExtensions.cs +++ b/src/Core/src/Platform/iOS/ButtonExtensions.cs @@ -64,6 +64,9 @@ public static void UpdatePadding(this UIButton platformButton, Thickness padding if (padding.IsNaN) padding = defaultPadding ?? Thickness.Zero; + int additionalPadding = (int)platformButton.Layer.BorderWidth; + padding = new Thickness(padding.Left + additionalPadding, padding.Top + additionalPadding, padding.Right + additionalPadding, padding.Bottom + additionalPadding); + // top and bottom insets reset to a "default" if they are exactly 0 // however, internally they are floor-ed, so there is no actual fractions var top = padding.Top;