Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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,32 @@ 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)
{
var searchBar = new SearchBar
{
HeightRequest = requestedHeight,
};
Comment thread
devanathan-vaithiyanathan marked this conversation as resolved.

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

double actualHeight = 0;

if (platformControl is UIKit.UISearchBar uiSearchBar)
{
actualHeight = uiSearchBar.Frame.Height;
Comment thread
devanathan-vaithiyanathan marked this conversation as resolved.
}

Assert.True(actualHeight >= 44, $"Expected intrinsic SearchBar height to remain at least 44, but was {actualHeight} for HeightRequest={requestedHeight}.");
});
Comment thread
devanathan-vaithiyanathan marked this conversation as resolved.
}
#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 TestCases.HostApp.Issues;
Comment thread
devanathan-vaithiyanathan marked this conversation as resolved.
Outdated

[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
{
Comment thread
devanathan-vaithiyanathan marked this conversation as resolved.
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 };
}
}
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();
Comment thread
devanathan-vaithiyanathan marked this conversation as resolved.
}
}
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.
16 changes: 15 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,21 @@ public override Size GetDesiredSize(double widthConstraint, double heightConstra
{
PlatformView.SizeToFit();

double intrinsicHeight = PlatformView.Frame.Height;
Comment thread
devanathan-vaithiyanathan marked this conversation as resolved.
Outdated
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 44 can shrink only the background
// while the internal UITextField keeps its native size (platform limitation). Enforce a
// minimum height of 44 for explicitly-set smaller values; larger explicit heights still apply.
if (OperatingSystem.IsIOSVersionAtLeast(26) || OperatingSystem.IsMacCatalystVersionAtLeast(26))
{
if (IsExplicitSet(VirtualView.Height) && constrainedHeight < intrinsicHeight)
Comment thread
devanathan-vaithiyanathan marked this conversation as resolved.
Outdated
{
constrainedHeight = intrinsicHeight;
}
}

return new Size(constrainedWidth, constrainedHeight);
}

Expand Down
Loading