Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
48 changes: 48 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue28714.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 28714, "[iOS] WebView BackgroundColor is not setting correctly", PlatformAffected.iOS)]
public partial class Issue28714 : ContentPage
{
public Issue28714()
{
BackgroundColor = Colors.YellowGreen;
var verticalStackLayout = new VerticalStackLayout();
verticalStackLayout.Spacing = 20;

var webView = new WebView()
{
HeightRequest = 300,
WidthRequest = 400,
BackgroundColor = Colors.Transparent,
Source = new HtmlWebViewSource
{
Html = @"
<!DOCTYPE html>
<html lang='en'>
<body>
<h1>Welcome to WebView</h1>
<p id='message'></p>
</body>
</html>"
}

};

var button = new Button
{
Text = "Change WebView BackgroundColor",
AutomationId = "button"
Copy link
Preview

Copilot AI Apr 7, 2025

Choose a reason for hiding this comment

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

The AutomationId 'button' is quite generic and may not be unique across the app; consider using a more descriptive and unique identifier (e.g., 'Issue28714ChangeBackgroundButton') to prevent potential clashes in UI testing.

Copilot uses AI. Check for mistakes.

};
button.Clicked += (s, e) =>
{
webView.BackgroundColor = Colors.Red;
};

verticalStackLayout.Add(button);
verticalStackLayout.Add(webView);



Content = verticalStackLayout;
}
}
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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#if TEST_FAILS_ON_WINDOWS // The transparent background color is not working on Windows, refer to https://github.com/microsoft/microsoft-ui-xaml/issues/6527
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;
public class Issue28714 : _IssuesUITest
{
public override string Issue => "[iOS] WebView BackgroundColor is not setting correctly";

public Issue28714(TestDevice device)
: base(device)
{ }

[Test, Order(1)]
[Category(UITestCategories.WebView)]
public void VerifyWebViewBackgroundColor()
{
App.WaitForElement("button");
VerifyScreenshot();
}

[Test, Order(2)]
[Category(UITestCategories.WebView)]
public void VerifyWebViewDynamicBackgroundColor()
{
App.WaitForElement("button");
App.Tap("button");
VerifyScreenshot();
}
}
#endif
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.
1 change: 1 addition & 0 deletions src/Core/src/Handlers/WebView/WebViewHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public partial class WebViewHandler : IWebViewHandler
[nameof(WebView.Settings)] = MapWebViewSettings
#elif __IOS__
[nameof(WKUIDelegate)] = MapWKUIDelegate,
[nameof(IWebView.Background)] = MapBackground,
#endif
};

Expand Down
8 changes: 8 additions & 0 deletions src/Core/src/Handlers/WebView/WebViewHandler.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@ protected override WKWebView CreatePlatformView() =>
public static void MapWKUIDelegate(IWebViewHandler handler, IWebView webView)
{
if (handler is WebViewHandler platformHandler)
{
handler.PlatformView.UIDelegate = platformHandler._delegate ??= new MauiWebViewUIDelegate(handler);
}
}

static void MapBackground(IWebViewHandler handler, IWebView webView)
{
handler.PlatformView.Opaque = webView.Background is null;
handler.PlatformView.UpdateBackground(webView);
}

public static void MapSource(IWebViewHandler handler, IWebView webView)
Expand Down
Loading