Skip to content

Commit b2d1c31

Browse files
kubaflojsuarezruiz
andauthored
ImageButton border (BorderWidth) overlaps the image instead of adding space - fix (#21259)
* ImageButton border (BorderWidth) overlaps the image * Modified snapshots * More samples * Added another UITest * Added pending snapshot --------- Co-authored-by: Javier Suárez <javiersuarezruiz@hotmail.com>
1 parent bd61427 commit b2d1c31

24 files changed

+83
-1
lines changed
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<controls:TestContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:controls="clr-namespace:Maui.Controls.Sample.Issues"
5+
xmlns:cmp="clr-namespace:Microsoft.Maui.Controls.Compatibility;assembly=Microsoft.Maui.Controls"
6+
x:Class="Maui.Controls.Sample.Issues.Issue24856">
7+
<ContentPage.Content>
8+
<VerticalStackLayout>
9+
<Label
10+
AutomationId="WaitForStubControl"
11+
Text="Issue 24856"/>
12+
<ImageButton
13+
Source="avatar.png"
14+
CornerRadius="10"
15+
BorderColor="Red"
16+
BorderWidth="3"
17+
Aspect="AspectFit"
18+
BackgroundColor="Yellow"
19+
WidthRequest="80"
20+
HeightRequest="80"
21+
HorizontalOptions="StartAndExpand"
22+
Margin="24"/>
23+
</VerticalStackLayout>
24+
</ContentPage.Content>
25+
</controls:TestContentPage>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace Maui.Controls.Sample.Issues
2+
{
3+
4+
[Issue(IssueTracker.Github, 24856, "Android ImageButton Aspect=AspectFit not display correctly", PlatformAffected.Android)]
5+
public partial class Issue24856 : TestContentPage
6+
{
7+
public Issue24856()
8+
{
9+
InitializeComponent();
10+
}
11+
12+
protected override void Init()
13+
{
14+
15+
}
16+
}
17+
}
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#if ANDROID
2+
using NUnit.Framework;
3+
using UITest.Appium;
4+
using UITest.Core;
5+
6+
namespace Microsoft.Maui.TestCases.Tests.Issues
7+
{
8+
public class Issue24856 : _IssuesUITest
9+
{
10+
public override string Issue => "Android ImageButton Aspect=AspectFit not display correctly";
11+
12+
public Issue24856(TestDevice device)
13+
: base(device)
14+
{ }
15+
16+
[Test]
17+
[Category(UITestCategories.ImageButton)]
18+
public void ImageButtonAspectFitWorks()
19+
{
20+
App.WaitForElement("WaitForStubControl");
21+
22+
VerifyScreenshot();
23+
}
24+
}
25+
}
26+
#endif
Loading
Loading
Loading

src/Core/src/Handlers/ImageButton/ImageButtonHandler.Android.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,13 @@ public static void MapStrokeColor(IImageButtonHandler handler, IButtonStroke but
5353
public static void MapStrokeThickness(IImageButtonHandler handler, IButtonStroke buttonStroke)
5454
{
5555
handler.PlatformView?.UpdateStrokeThickness(buttonStroke);
56+
handler.UpdateValue(nameof(IImageButton.Padding));
5657
}
5758

5859
public static void MapCornerRadius(IImageButtonHandler handler, IButtonStroke buttonStroke)
5960
{
60-
handler.PlatformView.UpdateCornerRadius(buttonStroke);
61+
handler.PlatformView?.UpdateCornerRadius(buttonStroke);
62+
handler.UpdateValue(nameof(IImageButton.Padding));
6163
}
6264

6365
public static void MapPadding(IImageButtonHandler handler, IImageButton imageButton)

src/Core/src/Handlers/ImageButton/ImageButtonHandler.Tizen.cs

+2
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ public static void MapStrokeColor(IImageButtonHandler handler, IButtonStroke but
4141
public static void MapStrokeThickness(IImageButtonHandler handler, IButtonStroke buttonStroke)
4242
{
4343
handler.PlatformView.UpdateStrokeThickness(buttonStroke);
44+
handler.UpdateValue(nameof(IImageButton.Padding));
4445
}
4546

4647
public static void MapCornerRadius(IImageButtonHandler handler, IButtonStroke buttonStroke)
4748
{
4849
handler.PlatformView.UpdateCornerRadius(buttonStroke);
50+
handler.UpdateValue(nameof(IImageButton.Padding));
4951
}
5052

5153
[MissingMapper]

src/Core/src/Handlers/ImageButton/ImageButtonHandler.Windows.cs

+2
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,13 @@ public static void MapStrokeColor(IImageButtonHandler handler, IButtonStroke but
7878
public static void MapStrokeThickness(IImageButtonHandler handler, IButtonStroke buttonStroke)
7979
{
8080
(handler.PlatformView as Button)?.UpdateStrokeThickness(buttonStroke);
81+
handler.UpdateValue(nameof(IImageButton.Padding));
8182
}
8283

8384
public static void MapCornerRadius(IImageButtonHandler handler, IButtonStroke buttonStroke)
8485
{
8586
(handler.PlatformView as Button)?.UpdateCornerRadius(buttonStroke);
87+
handler.UpdateValue(nameof(IImageButton.Padding));
8688
}
8789

8890
public static void MapBackground(IImageButtonHandler handler, IImageButton imageButton)

src/Core/src/Handlers/ImageButton/ImageButtonHandler.iOS.cs

+2
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,13 @@ public static void MapStrokeColor(IImageButtonHandler handler, IButtonStroke but
4545
public static void MapStrokeThickness(IImageButtonHandler handler, IButtonStroke buttonStroke)
4646
{
4747
handler.PlatformView?.UpdateStrokeThickness(buttonStroke);
48+
handler.UpdateValue(nameof(IImageButton.Padding));
4849
}
4950

5051
public static void MapCornerRadius(IImageButtonHandler handler, IButtonStroke buttonStroke)
5152
{
5253
handler.PlatformView?.UpdateCornerRadius(buttonStroke);
54+
handler.UpdateValue(nameof(IImageButton.Padding));
5355
}
5456

5557
public static void MapPadding(IImageButtonHandler handler, IImageButton imageButton)

src/Core/src/Platform/Android/ImageButtonExtensions.cs

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ public static void UpdateCornerRadius(this ShapeableImageView platformButton, IB
2323
public static async void UpdatePadding(this ShapeableImageView platformButton, IImageButton imageButton)
2424
{
2525
var padding = platformButton.Context!.ToPixels(imageButton.Padding);
26+
var (strokeWidth, _, _) = imageButton.GetStrokeProperties(platformButton.Context!, true);
27+
int additionalPadding = strokeWidth;
28+
padding = new Thickness(padding.Left + additionalPadding, padding.Top + additionalPadding, padding.Right + additionalPadding, padding.Bottom + additionalPadding);
2629

2730
// The simple operation we are trying to do.
2831
platformButton.SetContentPadding((int)padding.Left, (int)padding.Top, (int)padding.Right, (int)padding.Bottom);

src/Core/src/Platform/iOS/ButtonExtensions.cs

+3
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ public static void UpdatePadding(this UIButton platformButton, Thickness padding
6464
if (padding.IsNaN)
6565
padding = defaultPadding ?? Thickness.Zero;
6666

67+
int additionalPadding = (int)platformButton.Layer.BorderWidth;
68+
padding = new Thickness(padding.Left + additionalPadding, padding.Top + additionalPadding, padding.Right + additionalPadding, padding.Bottom + additionalPadding);
69+
6770
// top and bottom insets reset to a "default" if they are exactly 0
6871
// however, internally they are floor-ed, so there is no actual fractions
6972
var top = padding.Top;

0 commit comments

Comments
 (0)