Skip to content
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/Issue11677.cs
Original file line number Diff line number Diff line change
@@ -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,
}
}
};

}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -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();
}
}
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.
31 changes: 23 additions & 8 deletions src/Core/src/Platform/iOS/SearchBarExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading