Skip to content

Commit

Permalink
Add Padding for iOS Buttons in some scenarios (#24760)
Browse files Browse the repository at this point in the history
* Add padding for buttons that need it and UITest

* lost some spaces in the xaml

* android and windows screenshot
  • Loading branch information
tj-devel709 committed Sep 19, 2024
1 parent 9648523 commit 60076be
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Controls/src/Core/Button/Button.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,10 @@ Size ICrossPlatformLayout.CrossPlatformMeasure(double widthConstraint, double he
}
}

// 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
if (padding == ButtonHandler.DefaultPadding
&& image is not null
// if we are in a scenario with unlimited width and the image is on top or bottom,
// of if the horizontalOption is not fill 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.
if (image is not null
&& (widthConstraint == double.PositiveInfinity || button.HorizontalOptions != LayoutOptions.Fill)
&& (layout.Position == ButtonContentLayout.ImagePosition.Top || layout.Position == ButtonContentLayout.ImagePosition.Bottom))
{
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue24746.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Issues.Issue24746"
Title="Issue24746">
<VerticalStackLayout>
<HorizontalStackLayout>
<Button Text="Hello, longer world!" ImageSource="dotnet_bot_resized2.png"
Background="lightgray" ContentLayout="Top,0" AutomationId="TopButton"/>
</HorizontalStackLayout>

<HorizontalStackLayout>
<Button Text="Hello, longer world!" ImageSource="dotnet_bot_resized2.png"
Background="lightgreen" ContentLayout="Top,0" Padding="0" />
</HorizontalStackLayout>

<HorizontalStackLayout>
<Button Text="Hello, longer world!" ImageSource="dotnet_bot_resized2.png"
Background="lightblue" ContentLayout="Top,0" Padding="5" />
</HorizontalStackLayout>

<HorizontalStackLayout>
<Button Text="Hello, longer world!" ImageSource="dotnet_bot_resized2.png"
Background="purple" ContentLayout="Top,0" Padding="50,10" />
</HorizontalStackLayout>

<Button Text="Hello, longer world!" ImageSource="dotnet_bot_resized2.png"
Background="lightgray" ContentLayout="Top,0" HorizontalOptions="Center" />

<Button Text="Hello, longer world!" ImageSource="dotnet_bot_resized2.png" Padding="0"
Background="lightgreen" ContentLayout="Top,0" HorizontalOptions="Center" />

<Button Text="Hello, longer world!" ImageSource="dotnet_bot_resized2.png" Padding="5"
Background="lightblue" ContentLayout="Top,0" HorizontalOptions="Center" />

<Button Text="Hello, longer world!" ImageSource="dotnet_bot_resized2.png" Padding="50,10"
Background="purple" ContentLayout="Top,0" HorizontalOptions="Center" />

</VerticalStackLayout>
</ContentPage>
11 changes: 11 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue24746.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Maui.Controls.Sample.Issues;

[XamlCompilation(XamlCompilationOptions.Compile)]
[Issue(IssueTracker.Github, 24746, "iOS button padding is increased if needed", PlatformAffected.All)]
public partial class Issue24746 : ContentPage
{
public Issue24746()
{
InitializeComponent();
}
}
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 Issue24746 : _IssuesUITest
{
public Issue24746(TestDevice testDevice) : base(testDevice)
{
}

public override string Issue => "iOS button padding is increased if needed";

[Test]
[Category(UITestCategories.Button)]
public void ButtonPaddingIsAddedWhenNeeded()
{
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.

0 comments on commit 60076be

Please sign in to comment.