Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,40 @@ await InvokeOnMainThreadAsync(() =>
Assert.Equal(requestedHeight, actualHeight);
});
}

[Theory(DisplayName = "SearchBar small HeightRequest keeps intrinsic minimum height on iOS/Mac")]
[InlineData(35)]
[InlineData(20)]
public async Task ValidateSearchBarSmallHeightRequestRendering(double requestedHeight)
{
// This test is gated to iOS/MacCatalyst 26+ where the handler clamp is applied
if (!OperatingSystem.IsIOSVersionAtLeast(26) && !OperatingSystem.IsMacCatalystVersionAtLeast(26))
{
return;
}

var searchBar = new SearchBar
{
HeightRequest = requestedHeight,
};

await InvokeOnMainThreadAsync(() =>
{
var handler = CreateHandler<SearchBarHandler>(searchBar);
var platformControl = GetPlatformControl(handler);

double actualHeight = 0;
double intrinsicHeight = 0;

if (platformControl is UIKit.UISearchBar uiSearchBar)
{
actualHeight = uiSearchBar.Frame.Height;
intrinsicHeight = uiSearchBar.IntrinsicContentSize.Height;
}

Assert.True(actualHeight >= intrinsicHeight, $"Expected SearchBar height to remain at least the intrinsic height ({intrinsicHeight}), but was {actualHeight} for HeightRequest={requestedHeight}.");
});
}
#endif
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 47 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue35286.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 35286, "Spacing problem with SearchBar", PlatformAffected.iOS | PlatformAffected.macOS)]
public class Issue35286 : ContentPage
{
public Issue35286()
{
var content = new VerticalStackLayout
{
Padding = 10,
Spacing = 10,
Children =
{
new Label
{
Text = "SearchBar with HeightRequest=35",
AutomationId = "Issue35286Label1"
},
// SearchBar with small HeightRequest - this should NOT have spacing issues
new SearchBar
{
Placeholder = "Search with HeightRequest=35",
HeightRequest = 35,
BackgroundColor = Colors.LightBlue,
AutomationId = "Issue35286SearchBar1"
},

new Label
{
Text = "SearchBar with HeightRequest=100",
AutomationId = "Issue35286Label2",
Margin = new Thickness(0, 20, 0, 0)
},
// SearchBar with large HeightRequest - should work normally
new SearchBar
{
Placeholder = "Search with HeightRequest=100",
HeightRequest = 100,
BackgroundColor = Colors.LightBlue,
AutomationId = "Issue35286SearchBar2"
},
}
};

Content = new ScrollView { Content = content };
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue35286 : _IssuesUITest
{
public Issue35286(TestDevice device) : base(device) { }

public override string Issue => "Spacing problem with SearchBar";

[Test]
[Category(UITestCategories.SearchBar)]
public void VerifySearchBarHeightRequestValues()
{
App.WaitForElement("Issue35286Label1");
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
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.
12 changes: 11 additions & 1 deletion src/Core/src/Handlers/SearchBar/SearchBarHandler.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Foundation;
using Microsoft.Maui.Graphics;
using UIKit;
using static Microsoft.Maui.Primitives.Dimension;

namespace Microsoft.Maui.Handlers
{
Expand Down Expand Up @@ -42,8 +43,17 @@ public override Size GetDesiredSize(double widthConstraint, double heightConstra
{
PlatformView.SizeToFit();

double intrinsicHeight = PlatformView.IntrinsicContentSize.Height;
double constrainedWidth = ViewHandlerExtensions.ResolveConstraints(PlatformView.Frame.Width, VirtualView.Width, VirtualView.MinimumWidth, VirtualView.MaximumWidth);
double constrainedHeight = ViewHandlerExtensions.ResolveConstraints(PlatformView.Frame.Height, VirtualView.Height, VirtualView.MinimumHeight, VirtualView.MaximumHeight);
double constrainedHeight = ViewHandlerExtensions.ResolveConstraints(intrinsicHeight, VirtualView.Height, VirtualView.MinimumHeight, VirtualView.MaximumHeight);

// On iOS/MacCatalyst 26, setting SearchBar height below its intrinsic size can shrink only the background
// while the internal UITextField keeps its native size (platform limitation). Clamp height to the intrinsic minimum.
if (OperatingSystem.IsIOSVersionAtLeast(26) || OperatingSystem.IsMacCatalystVersionAtLeast(26))
{
constrainedHeight = Math.Max(constrainedHeight, intrinsicHeight);
}

return new Size(constrainedWidth, constrainedHeight);
}

Expand Down
Loading