Skip to content
Open
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;
Comment on lines +943 to +945

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[major] Test coverage / CI discovery - Wrapping the whole test file in #if IOS makes Android test discovery match zero tests when the gate filters to Issue32930, which is the known gate failure. Keep the fixture/method discoverable and skip/guard the body on non-iOS, or use the test infrastructure's platform filtering so non-iOS discovery does not fail with 0 tests.

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