diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ControlsShouldRemainVisibleWithWebViewWhenHardwareAccelerationIsDisabled.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ControlsShouldRemainVisibleWithWebViewWhenHardwareAccelerationIsDisabled.png new file mode 100644 index 000000000000..6024d49bfca3 Binary files /dev/null and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ControlsShouldRemainVisibleWithWebViewWhenHardwareAccelerationIsDisabled.png differ diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue28798.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue28798.cs new file mode 100644 index 000000000000..ed03fd7a8e63 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue28798.cs @@ -0,0 +1,49 @@ +namespace Maui.Controls.Sample.Issues; + +[XamlCompilation(XamlCompilationOptions.Compile)] +[Issue(IssueTracker.Github, 28798, "Controls Disappear When WebView is Used with Hardware Acceleration Disabled in Android", PlatformAffected.Android)] +public partial class Issue28798 : ContentPage +{ + public Issue28798() + { + var grid = new Grid + { + HeightRequest = 500, + Background = Colors.Green, + WidthRequest = 300 + }; + + grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); + grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); + grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); + + var label = new Label + { + Text = "Test", + Background = Colors.Red, + AutomationId = "TestLabel" + }; + Grid.SetRow(label, 0); + grid.Children.Add(label); + + var button = new Button + { + Text = "button", + Background = Colors.Blue + }; + Grid.SetRow(button, 1); + grid.Children.Add(button); + + var webView = new WebView + { + Source = "https://example.com/", + BackgroundColor = Colors.Transparent, + HeightRequest = 300, + WidthRequest = 300 + }; + Grid.SetRow(webView, 2); + grid.Children.Add(webView); + + Content = grid; + } +} diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue28798.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue28798.cs new file mode 100644 index 000000000000..1ed1723230d3 --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue28798.cs @@ -0,0 +1,22 @@ +#if ANDROID +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues; + +internal class Issue28798 : _IssuesUITest +{ + public Issue28798(TestDevice device) : base(device) { } + + public override string Issue => "Controls Disappear When WebView is Used with Hardware Acceleration Disabled in Android"; + + [Test] + [Category(UITestCategories.WebView)] + public void ControlsShouldRemainVisibleWithWebViewWhenHardwareAccelerationIsDisabled() + { + App.WaitForElement("TestLabel"); + VerifyScreenshot(); + } +} +#endif diff --git a/src/Core/src/Handlers/WebView/WebViewHandler.Android.cs b/src/Core/src/Handlers/WebView/WebViewHandler.Android.cs index c2654636c14f..e824bcc9ad65 100644 --- a/src/Core/src/Handlers/WebView/WebViewHandler.Android.cs +++ b/src/Core/src/Handlers/WebView/WebViewHandler.Android.cs @@ -29,6 +29,11 @@ protected override AWebView CreatePlatformView() platformView.Settings.DomStorageEnabled = true; platformView.Settings.SetSupportMultipleWindows(true); + if (OperatingSystem.IsAndroidVersionAtLeast(23) && Context?.ApplicationInfo?.Flags.HasFlag(Android.Content.PM.ApplicationInfoFlags.HardwareAccelerated) == false) + { + platformView.SetLayerType(Android.Views.LayerType.Software, null); + } + return platformView; }