Skip to content

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

Merged
kubaflo merged 11 commits intodotnet:inflight/currentfrom
devanathan-vaithiyanathan:fix-11677
Mar 21, 2026
Merged

[iOS] Fix SearchBar Black Background Issue When Setting Transparent Background #29225
kubaflo merged 11 commits intodotnet:inflight/currentfrom
devanathan-vaithiyanathan:fix-11677

Conversation

@devanathan-vaithiyanathan
Copy link
Copy Markdown
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
@dotnet-policy-service
Copy link
Copy Markdown
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 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
Copy Markdown
Contributor

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

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

@jsuarezruiz
Copy link
Copy Markdown
Contributor

/azp run MAUI-UITests-public

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@jsuarezruiz
Copy link
Copy Markdown
Contributor

/azp run MAUI-UITests-public

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).


[Test]
[Category(UITestCategories.SearchBar)]
public void VerifySearchBarBackground()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Failing test on iOS:
image
In red the differences with the reference snapshot.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@jsuarezruiz , I have modified the snapshot. Please let me know if you have any concerns

@jsuarezruiz
Copy link
Copy Markdown
Contributor

/azp run MAUI-UITests-public

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Dec 9, 2025

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 29225

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 29225"

@MauiBot
Copy link
Copy Markdown
Collaborator

MauiBot commented Mar 21, 2026

🤖 AI Summary

📊 Expand Full Reviewa2d1a97 · new image added
🔍 Pre-Flight — Context & Validation

Issue: #11677 - [iOS][maccatalyst] SearchBar BackgroundColor is black when set to transparent
PR: #29225 - [iOS] Fix SearchBar Black Background Issue When Setting Transparent Background
Platforms Affected: iOS, MacCatalyst
Files Changed: 1 implementation, 2 test source, 4 snapshot assets

Key Findings

  • The linked issue reports that explicitly setting SearchBar.BackgroundColor to Transparent turns the background black on iOS and MacCatalyst, while Android and Windows are unaffected.
  • The PR changes src/Core/src/Platform/iOS/SearchBarExtensions.cs to special-case transparent SolidPaint by clearing the native background image and setting BarTintColor to UIColor.Clear.
  • The PR adds a new UI test page and _IssuesUITest screenshot test for Issue11677, plus snapshots for Android, iOS, Mac, and WinUI.
  • Review discussion shows follow-up cleanup requests were addressed (null case placement, switch-based structure, typo fix), but later feedback reported an iOS snapshot mismatch and the snapshot was updated in response.
  • Issue comments mention related edge behavior beyond the exact repro: default/no-color SearchBar rendering black on iOS, style-based workarounds using SearchBarStyle=Minimal, and runtime style/background changes.
  • No prior PRAgent review output was found in PR comments.

Fix Candidates

# Source Approach Test Result Files Changed Notes
PR PR #29225 Handle transparent SearchBar background on iOS by using an empty BackgroundImage and UIColor.Clear, while restoring default handling for null/non-transparent PENDING (Gate) src/Core/src/Platform/iOS/SearchBarExtensions.cs, src/Controls/tests/TestCases.HostApp/Issues/Issue11677.cs, src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue11677.cs Snapshot assets added for platform verification backgrounds

Issue: #11677 - [iOS][maccatalyst] SearchBar BackgroundColor is black when set to transparent
PR: #29225 - [iOS] Fix SearchBar Black Background Issue When Setting Transparent Background
Platforms Affected: iOS, MacCatalyst
Files Changed: 1 implementation, 2 test source, 4 snapshot assets

Key Findings

  • On iOS/macCatalyst, explicitly setting SearchBar.BackgroundColor to Transparent renders the background black, while Android and Windows are unaffected.
  • The PR modifies SearchBarExtensions.cs to special-case transparent SolidPaint by setting an empty background image and UIColor.Clear as BarTintColor.
  • For non-transparent/null backgrounds, the previous default behavior is restored.
  • Reviewer feedback addressed: null case moved to top, switch expression used for clarity, typo SeachBarSearchBar fixed.
  • Snapshots were updated once after a CI iOS snapshot mismatch was reported by jsuarezruiz.
  • A UI test (Issue11677) was added with screenshot verification across all 4 platforms.
  • PR labels indicate prior agent review already resulted in s/agent-approved and s/agent-fix-pr-picked.

Inline Review Feedback (Addressed)

  • jsuarezruiz: Move null-background early-return to top — ✅ Done
  • jsuarezruiz: Use switch expression instead of nested ifs — ✅ Done
  • jsuarezruiz/Copilot: Fix typo SeachBarSearchBar in test host — ✅ Done
  • jsuarezruiz: iOS snapshot mismatch reported — ✅ Snapshot updated

Fix Candidates

# Source Approach Test Result Files Changed Notes
PR PR #29225 Handle transparent SearchBar on iOS: set empty BackgroundImage + UIColor.Clear; restore default for non-transparent/null ⏳ PENDING (Gate) SearchBarExtensions.cs, Issue11677.cs (HostApp), Issue11677.cs (SharedTests) + 4 snapshots Original PR

🚦 Gate — Test Verification

Gate Result PASSED:

Platform: ios
Mode: Full Verification

  • Tests FAIL without fix:
  • Tests PASS with fix:

Gate Result: ✅ PASSED

Platform: ios

Tests Detected

# Type Test Name Filter
1 UITest Issue11677 Issue11677

Verification

Step Expected Actual Result
Tests WITHOUT fix FAIL FAIL (14.63% snapshot diff on VerifySearchBarBackground.png)
Tests WITH fix PASS PASS (VerifySearchBarBackground 280ms)

Fix Files Reverted

  • src/Core/src/Platform/iOS/SearchBarExtensions.cs

Notes

The verify-tests-fail-without-fix skill script exited with code 1 due to a result-parsing false negative, but direct inspection of dotnet test output confirmed Test Run Successful. Passed: 1 for the with-fix run and a 14.63% snapshot diff failure for the without-fix run. Gate is PASSED based on empirical evidence.


🔧 Fix — Analysis & Comparison

Gate Result PASSED:

Platform: ios
Mode: Full Verification

  • Tests FAIL without fix:
  • Tests PASS with fix:

Fix Candidates

# Source Approach Test Result Files Changed Notes
1 try-fix (claude-opus-4.6) Use UISearchBarStyle.Minimal to natively remove opaque background instead of BackgroundImage + BarTintColor ✅ PASS 1 file Platform-native style API; simpler single-property solution
2 try-fix (claude-sonnet-4.6) UIView.BackgroundColor + CALayer.BackgroundColor + Translucent=true pipeline ❌ FAIL 1 file BarTintColor/BackgroundColor/CALayer don't suppress UISearchBar's internal compositor; Translucent=true activates blur material (14.63% pixel diff)
3 try-fix (gpt-5.3-codex) Alpha-aware transparent handling: generate 1x1 color image via SetBackgroundImage for any SolidPaint with Alpha < 1 (broader than exact transparent check) ✅ PASS 1 file More general than PR — handles semi-transparent colors too
4 try-fix (gemini-3-pro-preview) Add uiSearchBar.BackgroundColor = UIColor.Clear alongside BackgroundImage + BarTintColor; explicitly set BackgroundColor = null for non-transparent reset ✅ PASS 1 file Similar to PR but adds explicit UIView.BackgroundColor; diff is minor
PR PR #29225 Set BackgroundImage = new UIImage() + UIColor.Clear for transparent; restore defaults for non-transparent ✅ PASSED (Gate) 3 source files + snapshots Original PR; validated by gate on iOS

Cross-Pollination

In progress — Round 1 not yet complete

Exhausted: No
Selected Fix: TBD — pending remaining attempts


📋 Report — Final Recommendation

Gate Result PASSED:

Platform: ios
Mode: Full Verification

  • Tests FAIL without fix:
  • Tests PASS with fix:

@MauiBot MauiBot added s/agent-approved AI agent recommends approval - PR fix is correct and optimal s/agent-fix-pr-picked AI could not beat the PR fix - PR is the best among all candidates s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review) labels Mar 21, 2026
@kubaflo kubaflo changed the base branch from main to inflight/current March 21, 2026 19:01
@kubaflo kubaflo merged commit 5753aa6 into dotnet:inflight/current Mar 21, 2026
178 of 184 checks passed
PureWeen pushed a commit that referenced this pull request Mar 24, 2026
…ackground (#29225)

### 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.


<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #11677 

**Tested the behavior in the following platforms.**
- [x] Android
- [x] Windows
- [x] iOS
- [x] Mac

### Output Screenshot

| Before  | After  |
|---------|--------|
| **iOS**<br> <video
src="https://github.com/user-attachments/assets/80fdaaa1-8ddf-4315-bffa-cf3463a88a98"
width="300" height="600"> | **iOS**<br> <video
src="https://github.com/user-attachments/assets/51ba2b0e-2a05-4e8a-8e75-0c448ad253c8"
width="300" height="600"> |
@MauiBot MauiBot added s/agent-review-incomplete AI agent could not complete all phases (blocker, timeout, error) and removed s/agent-approved AI agent recommends approval - PR fix is correct and optimal labels Mar 26, 2026
KarthikRajaKalaimani pushed a commit to KarthikRajaKalaimani/maui that referenced this pull request Mar 30, 2026
…ackground (dotnet#29225)

### 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.


<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes dotnet#11677 

**Tested the behavior in the following platforms.**
- [x] Android
- [x] Windows
- [x] iOS
- [x] Mac

### Output Screenshot

| Before  | After  |
|---------|--------|
| **iOS**<br> <video
src="https://github.com/user-attachments/assets/80fdaaa1-8ddf-4315-bffa-cf3463a88a98"
width="300" height="600"> | **iOS**<br> <video
src="https://github.com/user-attachments/assets/51ba2b0e-2a05-4e8a-8e75-0c448ad253c8"
width="300" height="600"> |
sheiksyedm pushed a commit that referenced this pull request Apr 4, 2026
…ackground (#29225)

### 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.


<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

<!-- Enter description of the fix in this section -->

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #11677 

**Tested the behavior in the following platforms.**
- [x] Android
- [x] Windows
- [x] iOS
- [x] Mac

### Output Screenshot

| Before  | After  |
|---------|--------|
| **iOS**<br> <video
src="https://github.com/user-attachments/assets/80fdaaa1-8ddf-4315-bffa-cf3463a88a98"
width="300" height="600"> | **iOS**<br> <video
src="https://github.com/user-attachments/assets/51ba2b0e-2a05-4e8a-8e75-0c448ad253c8"
width="300" height="600"> |
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 s/agent-fix-pr-picked AI could not beat the PR fix - PR is the best among all candidates s/agent-review-incomplete AI agent could not complete all phases (blocker, timeout, error) s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

7 participants