Skip to content
Merged
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 49 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue28798.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions src/Core/src/Handlers/WebView/WebViewHandler.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

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

The activities can have different hardware acceleration settings that override the app-level setting, but in out case, I think checking at app level is enough.

{
platformView.SetLayerType(Android.Views.LayerType.Software, null);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

(Optional) Could be nice to log this:

 System.Diagnostics.Debug.WriteLine(
                "WebView set to software rendering due to disabled hardware acceleration");


return platformView;
}

Expand Down