Skip to content

[iOS] Fix SearchBar Black Background Issue When Setting Transparent Background #29225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

devanathan-vaithiyanathan
Copy link
Contributor

Issue details

Setting SearchBar background to transparent was showing black color on iOS.

Description of changes

Handled transparent background in SearchBar by setting an empty background image and UIColor.Clear. If the background is not transparent, reset the background image to null to allow applying backgrounds properly.

Issues Fixed

Fixes #11677

Tested the behavior in the following platforms.

  • Android
  • Windows
  • iOS
  • Mac

Output Screenshot

Before After
iOS
Before_Fix.mov
iOS
After_Fix.mov

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Apr 28, 2025
Copy link
Contributor

Hey there @@devanathan-vaithiyanathan! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@dotnet-policy-service dotnet-policy-service bot added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Apr 28, 2025
@devanathan-vaithiyanathan devanathan-vaithiyanathan marked this pull request as ready for review April 30, 2025 04:11
@Copilot Copilot AI review requested due to automatic review settings April 30, 2025 04:11
@devanathan-vaithiyanathan devanathan-vaithiyanathan requested a review from a team as a code owner April 30, 2025 04:11
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes an iOS bug where setting a transparent SearchBar background was resulting in a black display.

  • Updates SearchBarExtensions.cs to handle transparent backgrounds by resetting the background image and using UIColor.Clear.
  • Adds automated tests in TestCases.Shared.Tests and TestCases.HostApp to verify the transparent and default background behaviors.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

File Description
src/Core/src/Platform/iOS/SearchBarExtensions.cs Adjusts background handling for UISearchBar based on the brush type.
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue11677.cs Introduces a new automated test validating the SearchBar's background behavior.
src/Controls/tests/TestCases.HostApp/Issues/Issue11677.cs Provides a host app sample page with various SearchBar background configurations.

},
new Label
{
Text = "SeachBar with default background",
Copy link
Preview

Copilot AI Apr 30, 2025

Choose a reason for hiding this comment

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

Consider correcting the typo 'SeachBar' to 'SearchBar' for consistency.

Suggested change
Text = "SeachBar with default background",
Text = "SearchBar with default background",

Copilot uses AI. Check for mistakes.

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, there is a small typo.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed the typo, thanks for pointing it out.


if (background == null)
}
else if (background == null)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would move this to the top to returns immediately, avoiding extra checks.

if (searchBar?.Background is null)
{
    uiSearchBar.BarTintColor = UISearchBar.Appearance.BarTintColor;
    return;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jsuarezruiz , Moved the null case to the top as suggested.

uiSearchBar.BarTintColor = solidPaint.Color.ToPlatform();

if (background is GradientPaint gradientPaint)
if (background is SolidPaint solid)
Copy link
Contributor

Choose a reason for hiding this comment

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

Not necessarily but can eliminate nested if statements using a switch expression for better readability.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jsuarezruiz , Updated the code to use a switch expression for better clarity.

},
new Label
{
Text = "SeachBar with default background",
Copy link
Contributor

Choose a reason for hiding this comment

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

Right, there is a small typo.

public void VerifySearchBarBackground()
{
App.WaitForElement("Label");
VerifyScreenshot();
Copy link
Contributor

Choose a reason for hiding this comment

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

Pending snapshots on Mac and Windows.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jsuarezruiz , Can you please trigger the CI

Copy link
Contributor

Choose a reason for hiding this comment

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

Running now :)

@jsuarezruiz
Copy link
Contributor

/azp run MAUI-UITests-public

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-searchbar SearchBar control community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration platform/iOS 🍎
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[iOS][maccatalyst] SearchBar BackgroundColor is black when set to transparent
2 participants