Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Padding for iOS Buttons in some scenarios #24760

Merged
merged 3 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Loading