Skip to content

Commit 06bbf70

Browse files
Tamilarasan-Paranthamanrmarinho
authored andcommitted
[iOS] Fixed Shell.SearchHandler ClearPlaceholderIcon Color Issue (#28601)
* SearchHandler ClearPlaceholderIcon color fix * Added Mac snapshot * Updated SearchBar Icon changes * Test script changes. * Revert unwanted changes * Updated custom icon changes
1 parent 42f5225 commit 06bbf70

File tree

6 files changed

+85
-4
lines changed

6 files changed

+85
-4
lines changed

src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellPageRendererTracker.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,14 @@ void SearchButtonClicked(object sender, EventArgs e)
807807

808808
void SetSearchBarIcon(UISearchBar searchBar, ImageSource source, UISearchBarIcon icon)
809809
{
810-
source.LoadImage(source.FindMauiContext(), image =>
810+
var mauiContext = source.FindMauiContext(true);
811+
812+
if (mauiContext is null)
813+
{
814+
return;
815+
}
816+
817+
source.LoadImage(mauiContext, image =>
811818
{
812819
var result = image?.Value;
813820
if (result != null)
@@ -833,6 +840,11 @@ void OnPageLoaded(object sender, EventArgs e)
833840
}
834841

835842
UpdateToolbarItemsInternal();
843+
844+
//UIKIt will try to override our colors when the SearchController is inside the NavigationBar
845+
//Best way was to force them to be set again when page is loaded / ViewDidLoad
846+
_searchHandlerAppearanceTracker?.UpdateSearchBarColors();
847+
836848
CheckAppeared();
837849
}
838850

@@ -854,9 +866,6 @@ void SetAppeared()
854866
return;
855867

856868
_isVisiblePage = true;
857-
//UIKIt will try to override our colors when the SearchController is inside the NavigationBar
858-
//Best way was to force them to be set again when page is Appearing / ViewDidLoad
859-
_searchHandlerAppearanceTracker?.UpdateSearchBarColors();
860869
UpdateShellToMyPage();
861870

862871
if (_context.Shell.Toolbar != null)
21.6 KB
Loading
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
namespace Maui.Controls.Sample.Issues;
2+
3+
[Issue(IssueTracker.Github, 20250, "[iOS] SearchHandler ClearPlaceholderIcon color", PlatformAffected.iOS)]
4+
public partial class Issue20250 : TestShell
5+
{
6+
7+
protected override void Init()
8+
{
9+
this.FlyoutBehavior = FlyoutBehavior.Flyout;
10+
11+
var shellContent = new ShellContent
12+
{
13+
Title = "Home",
14+
Route = "MainPage",
15+
Content = new Issue20250ContentPage() { Title = "Home" }
16+
};
17+
18+
Items.Add(shellContent);
19+
20+
}
21+
class Issue20250ContentPage : ContentPage
22+
{
23+
public Issue20250ContentPage()
24+
{
25+
Shell.SetSearchHandler(this, new SearchHandler
26+
{
27+
AutomationId = "searchHandler",
28+
Placeholder = "Search",
29+
TextColor = Colors.Red,
30+
ClearPlaceholderEnabled = true,
31+
ClearPlaceholderIcon = "bank.png",
32+
33+
});
34+
35+
this.SetBinding(TitleProperty, new Binding("Title", source: Shell.Current));
36+
37+
Content = new Label
38+
{
39+
Text = "SearchHandler",
40+
AutomationId = "label",
41+
HorizontalOptions = LayoutOptions.Center,
42+
VerticalOptions = LayoutOptions.Center,
43+
};
44+
}
45+
}
46+
}
9.54 KB
Loading
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#if TEST_FAILS_ON_WINDOWS // On Windows, the ClearPlaceholderIcon is not displayed in the SearchHandler.
2+
// Issue: https://github.com/dotnet/maui/issues/28619
3+
using NUnit.Framework;
4+
using UITest.Appium;
5+
using UITest.Core;
6+
7+
namespace Microsoft.Maui.TestCases.Tests.Issues;
8+
9+
public class Issue20250 : _IssuesUITest
10+
{
11+
public override string Issue => "[iOS] SearchHandler ClearPlaceholderIcon color";
12+
13+
public Issue20250(TestDevice device)
14+
: base(device)
15+
{ }
16+
17+
[Test]
18+
[Category(UITestCategories.Shell)]
19+
public void VerifySearchHandlerClearPlaceholderIconColor()
20+
{
21+
App.WaitForElement("label");
22+
VerifyScreenshot();
23+
}
24+
}
25+
26+
#endif
29.9 KB
Loading

0 commit comments

Comments
 (0)