diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/VerifySearchBarBackground.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/VerifySearchBarBackground.png new file mode 100644 index 000000000000..f67c72e9ad72 Binary files /dev/null and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/VerifySearchBarBackground.png differ diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue11677.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue11677.cs new file mode 100644 index 000000000000..efc6de421774 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue11677.cs @@ -0,0 +1,47 @@ +namespace Maui.Controls.Sample.Issues; + +[Issue(IssueTracker.Github, 11677, "[iOS][maccatalyst] SearchBar BackgroundColor is black when set to transparent", PlatformAffected.iOS)] +public class Issue11677 : ContentPage +{ + public Issue11677() + { + Content = new VerticalStackLayout + { + Children = + { + new Label + { + Text = "SearchBar Transparent BackgroundColor", + FontSize = 16, + TextColor = Colors.Black, + AutomationId = "Label" + }, + new SearchBar + { + BackgroundColor = Colors.Transparent, + }, + new Label + { + Text = "SearchBar with null background", + FontSize = 16, + TextColor = Colors.Black, + }, + new SearchBar + { + BackgroundColor = null, + }, + new Label + { + Text = "SearchBar with default background", + FontSize = 16, + TextColor = Colors.Black, + }, + new SearchBar + { + Background = Brush.Default, + } + } + }; + + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/VerifySearchBarBackground.png b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/VerifySearchBarBackground.png new file mode 100644 index 000000000000..5d18ea9a4b15 Binary files /dev/null and b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/VerifySearchBarBackground.png differ diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue11677.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue11677.cs new file mode 100644 index 000000000000..6dbf822ace7c --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue11677.cs @@ -0,0 +1,21 @@ +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues; +public class Issue11677 : _IssuesUITest +{ + public Issue11677(TestDevice testDevice) : base(testDevice) + { + } + + public override string Issue => "[iOS][maccatalyst] SearchBar BackgroundColor is black when set to transparent"; + + [Test] + [Category(UITestCategories.SearchBar)] + public void VerifySearchBarBackground() + { + App.WaitForElement("Label"); + VerifyScreenshot(); + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifySearchBarBackground.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifySearchBarBackground.png new file mode 100644 index 000000000000..256536cd1081 Binary files /dev/null and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifySearchBarBackground.png differ diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/VerifySearchBarBackground.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/VerifySearchBarBackground.png new file mode 100644 index 000000000000..bdd15a7649f6 Binary files /dev/null and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/VerifySearchBarBackground.png differ diff --git a/src/Core/src/Platform/iOS/SearchBarExtensions.cs b/src/Core/src/Platform/iOS/SearchBarExtensions.cs index ec3a3853df32..74a3947043fa 100644 --- a/src/Core/src/Platform/iOS/SearchBarExtensions.cs +++ b/src/Core/src/Platform/iOS/SearchBarExtensions.cs @@ -35,14 +35,29 @@ internal static void UpdateBackground(this UISearchBar uiSearchBar, ISearchBar s { var background = searchBar.Background; - if (background is SolidPaint solidPaint) - uiSearchBar.BarTintColor = solidPaint.Color.ToPlatform(); - - if (background is GradientPaint gradientPaint) - ViewExtensions.UpdateBackground(uiSearchBar, gradientPaint); - - if (background == null) - uiSearchBar.BarTintColor = UISearchBar.Appearance.BarTintColor; + switch (background) + { + case null: + uiSearchBar.BarTintColor = UISearchBar.Appearance.BarTintColor; + break; + + case SolidPaint solid: + if (solid.Color == Colors.Transparent) + { + uiSearchBar.BackgroundImage = new UIImage(); + uiSearchBar.BarTintColor = UIColor.Clear; + } + else + { + uiSearchBar.BackgroundImage = null; + uiSearchBar.BarTintColor = solid.Color.ToPlatform(); + } + break; + + case GradientPaint gradientPaint: + ViewExtensions.UpdateBackground(uiSearchBar, gradientPaint); + break; + } } public static void UpdateIsEnabled(this UISearchBar uiSearchBar, ISearchBar searchBar)