diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/VerifyWebViewBackgroundColor.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/VerifyWebViewBackgroundColor.png new file mode 100644 index 000000000000..5d766ec30d27 Binary files /dev/null and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/VerifyWebViewBackgroundColor.png differ diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/VerifyWebViewDynamicBackgroundColor.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/VerifyWebViewDynamicBackgroundColor.png new file mode 100644 index 000000000000..c45b5c0b710f Binary files /dev/null and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/VerifyWebViewDynamicBackgroundColor.png differ diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue28714.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue28714.cs new file mode 100644 index 000000000000..cfed66268745 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue28714.cs @@ -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 = @" + + + +

Welcome to WebView

+

+ + " + } + + }; + + var button = new Button + { + Text = "Change WebView BackgroundColor", + AutomationId = "button" + }; + button.Clicked += (s, e) => + { + webView.BackgroundColor = Colors.Red; + }; + + verticalStackLayout.Add(button); + verticalStackLayout.Add(webView); + + + + Content = verticalStackLayout; + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/VerifyWebViewBackgroundColor.png b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/VerifyWebViewBackgroundColor.png new file mode 100644 index 000000000000..e5c105c16b80 Binary files /dev/null and b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/VerifyWebViewBackgroundColor.png differ diff --git a/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/VerifyWebViewDynamicBackgroundColor.png b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/VerifyWebViewDynamicBackgroundColor.png new file mode 100644 index 000000000000..fe1457ef8baf Binary files /dev/null and b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/VerifyWebViewDynamicBackgroundColor.png differ diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue28714.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue28714.cs new file mode 100644 index 000000000000..7534ff1701b5 --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue28714.cs @@ -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 \ No newline at end of file diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/VerifyWebViewBackgroundColor.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/VerifyWebViewBackgroundColor.png new file mode 100644 index 000000000000..ac9ffc851094 Binary files /dev/null and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/VerifyWebViewBackgroundColor.png differ diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/VerifyWebViewDynamicBackgroundColor.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/VerifyWebViewDynamicBackgroundColor.png new file mode 100644 index 000000000000..31f60ca92976 Binary files /dev/null and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/VerifyWebViewDynamicBackgroundColor.png differ diff --git a/src/Core/src/Handlers/WebView/WebViewHandler.cs b/src/Core/src/Handlers/WebView/WebViewHandler.cs index 25551172681b..acd2be502103 100644 --- a/src/Core/src/Handlers/WebView/WebViewHandler.cs +++ b/src/Core/src/Handlers/WebView/WebViewHandler.cs @@ -30,6 +30,7 @@ public partial class WebViewHandler : IWebViewHandler [nameof(WebView.Settings)] = MapWebViewSettings #elif __IOS__ [nameof(WKUIDelegate)] = MapWKUIDelegate, + [nameof(IWebView.Background)] = MapBackground, #endif }; diff --git a/src/Core/src/Handlers/WebView/WebViewHandler.iOS.cs b/src/Core/src/Handlers/WebView/WebViewHandler.iOS.cs index d6d7da2d3dc2..7d7b83f0a58f 100644 --- a/src/Core/src/Handlers/WebView/WebViewHandler.iOS.cs +++ b/src/Core/src/Handlers/WebView/WebViewHandler.iOS.cs @@ -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)