Skip to content

[Android] Controls Disappear When WebView is Used with Hardware Acceleration Disabled #28934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
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://google.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)
{
platformView.SetLayerType(Android.Views.LayerType.Software, null);
}

return platformView;
}

Expand Down
Loading