Skip to content

Commit d51a376

Browse files
tj-devel709redducks100
authored andcommitted
Add Padding for iOS Buttons in some scenarios (dotnet#24760)
* Add padding for buttons that need it and UITest * lost some spaces in the xaml * android and windows screenshot
1 parent 7f955ca commit d51a376

7 files changed

Lines changed: 77 additions & 3 deletions

File tree

src/Controls/src/Core/Button/Button.iOS.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,10 @@ Size ICrossPlatformLayout.CrossPlatformMeasure(double widthConstraint, double he
144144
}
145145
}
146146

147-
// if we are in a scenario with unlimited width and the image is on top or bottom, let's make sure the title is not cut off by ensuring we have enough padding for the image and title
148-
if (padding == ButtonHandler.DefaultPadding
149-
&& image is not null
147+
// if we are in a scenario with unlimited width and the image is on top or bottom,
148+
// of if the horizontalOption is not fill and the image is on top or bottom,
149+
// let's make sure the title is not cut off by ensuring we have enough padding for the image and title.
150+
if (image is not null
150151
&& (widthConstraint == double.PositiveInfinity || button.HorizontalOptions != LayoutOptions.Fill)
151152
&& (layout.Position == ButtonContentLayout.ImagePosition.Top || layout.Position == ButtonContentLayout.ImagePosition.Bottom))
152153
{
150 KB
Loading
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
x:Class="Maui.Controls.Sample.Issues.Issue24746"
5+
Title="Issue24746">
6+
<VerticalStackLayout>
7+
<HorizontalStackLayout>
8+
<Button Text="Hello, longer world!" ImageSource="dotnet_bot_resized2.png"
9+
Background="lightgray" ContentLayout="Top,0" AutomationId="TopButton"/>
10+
</HorizontalStackLayout>
11+
12+
<HorizontalStackLayout>
13+
<Button Text="Hello, longer world!" ImageSource="dotnet_bot_resized2.png"
14+
Background="lightgreen" ContentLayout="Top,0" Padding="0" />
15+
</HorizontalStackLayout>
16+
17+
<HorizontalStackLayout>
18+
<Button Text="Hello, longer world!" ImageSource="dotnet_bot_resized2.png"
19+
Background="lightblue" ContentLayout="Top,0" Padding="5" />
20+
</HorizontalStackLayout>
21+
22+
<HorizontalStackLayout>
23+
<Button Text="Hello, longer world!" ImageSource="dotnet_bot_resized2.png"
24+
Background="purple" ContentLayout="Top,0" Padding="50,10" />
25+
</HorizontalStackLayout>
26+
27+
<Button Text="Hello, longer world!" ImageSource="dotnet_bot_resized2.png"
28+
Background="lightgray" ContentLayout="Top,0" HorizontalOptions="Center" />
29+
30+
<Button Text="Hello, longer world!" ImageSource="dotnet_bot_resized2.png" Padding="0"
31+
Background="lightgreen" ContentLayout="Top,0" HorizontalOptions="Center" />
32+
33+
<Button Text="Hello, longer world!" ImageSource="dotnet_bot_resized2.png" Padding="5"
34+
Background="lightblue" ContentLayout="Top,0" HorizontalOptions="Center" />
35+
36+
<Button Text="Hello, longer world!" ImageSource="dotnet_bot_resized2.png" Padding="50,10"
37+
Background="purple" ContentLayout="Top,0" HorizontalOptions="Center" />
38+
39+
</VerticalStackLayout>
40+
</ContentPage>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace Maui.Controls.Sample.Issues;
2+
3+
[XamlCompilation(XamlCompilationOptions.Compile)]
4+
[Issue(IssueTracker.Github, 24746, "iOS button padding is increased if needed", PlatformAffected.All)]
5+
public partial class Issue24746 : ContentPage
6+
{
7+
public Issue24746()
8+
{
9+
InitializeComponent();
10+
}
11+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using NUnit.Framework;
2+
using UITest.Appium;
3+
using UITest.Core;
4+
5+
namespace Microsoft.Maui.TestCases.Tests.Issues
6+
{
7+
public class Issue24746 : _IssuesUITest
8+
{
9+
public Issue24746(TestDevice testDevice) : base(testDevice)
10+
{
11+
}
12+
13+
public override string Issue => "iOS button padding is increased if needed";
14+
15+
[Test]
16+
[Category(UITestCategories.Button)]
17+
public void ButtonPaddingIsAddedWhenNeeded()
18+
{
19+
VerifyScreenshot();
20+
}
21+
}
22+
}
35 KB
Loading
181 KB
Loading

0 commit comments

Comments
 (0)