-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[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
base: main
Are you sure you want to change the base?
[iOS] Fix SearchBar Black Background Issue When Setting Transparent Background #29225
Conversation
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. |
There was a problem hiding this 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", |
There was a problem hiding this comment.
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.
Text = "SeachBar with default background", | |
Text = "SearchBar with default background", |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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;
}
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running now :)
/azp run MAUI-UITests-public |
Azure Pipelines successfully started running 1 pipeline(s). |
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.
Output Screenshot
Before_Fix.mov
After_Fix.mov