Skip to content
Draft
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 @@ -935,6 +935,14 @@ void AttachSearchController()
}

_searchController = new UISearchController(_resultsRenderer?.ViewController);

// Fix for iPhone: Prevent the navigation bar from hiding during search presentation.
// When HidesNavigationBarDuringPresentation is true (the default), the search bar moves
// upward but the suggestions list doesn't follow, creating a visible gap.
// Setting these properties to false keeps the suggestions list attached to the search bar.
// iPad doesn't have this issue because the navigation bar layout differs.
_searchController.HidesNavigationBarDuringPresentation = false;
_searchController.ObscuresBackgroundDuringPresentation = false;
var visibility = SearchHandler.SearchBoxVisibility;
if (visibility != SearchBoxVisibility.Hidden)
{
Expand Down
25 changes: 25 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue32930.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<Shell xmlns:controls="clr-namespace:Maui.Controls.Sample.Issues"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Issues.Issue32930">
<ShellContent
Title="Home"
Route="MainPage">
<ContentPage>
<Shell.SearchHandler>
<controls:Issue32930SearchHandler
x:Name="searchHandler"
AutomationId="SearchHandler"
Placeholder="Type to search..."
Keyboard="Plain"
ShowsResults="True" />
</Shell.SearchHandler>
<StackLayout Padding="20">
<Label
AutomationId="Instructions"
Text="Tap the search bar. On iPhone, the suggestions list should follow the search bar upward with no gap." />
</StackLayout>
</ContentPage>
</ShellContent>
</Shell>
43 changes: 43 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue32930.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 32930, "[iOS] SearchHandler suggestions list does not follow the search bar upward movement on iPhone, creating a layout gap", PlatformAffected.iOS)]
public partial class Issue32930 : Shell
{
public Issue32930()
{
InitializeComponent();
}
}

public class Issue32930SearchHandler : SearchHandler
{
static readonly List<string> _allItems = new()
{
"Apple",
"Banana",
"Cherry",
"Date",
"Elderberry",
"Fig",
"Grape"
};

public Issue32930SearchHandler()
{
ItemsSource = _allItems;
}

protected override void OnQueryChanged(string oldValue, string newValue)
{
base.OnQueryChanged(oldValue, newValue);

if (string.IsNullOrEmpty(newValue))
{
ItemsSource = _allItems;
}
else
{
ItemsSource = _allItems.Where(s => s.Contains(newValue, StringComparison.OrdinalIgnoreCase)).ToList();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#if IOS
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue32930 : _IssuesUITest
{
public Issue32930(TestDevice testDevice) : base(testDevice)
{
}

public override string Issue => "[iOS] SearchHandler suggestions list does not follow the search bar upward movement on iPhone, creating a layout gap";

[Test]
[Category(UITestCategories.Shell)]
public void SearchHandlerSuggestionsListFollowsSearchBar()
{
// Wait for the page to load
App.WaitForElement("Instructions");

// Enter text in the search handler to trigger suggestions display
App.EnterText(AppiumQuery.ByXPath("//XCUIElementTypeSearchField"), "A");

// Wait for suggestions to appear
App.WaitForElement("Apple");

// Verify the suggestions list appears correctly
// If the fix works, the suggestions list should be visible and positioned directly under the search bar
// We use screenshot verification to ensure there is no visible gap between the search bar and suggestions
VerifyScreenshot();
}
}
#endif
Loading