Skip to content

Commit 105d087

Browse files
praveenkumarkarunanithiPureWeen
authored andcommitted
[Android] Controls Disappear When WebView is Used with Hardware Acceleration Disabled (#28934)
* Update WebViewHandler.Android.cs * Test case added * Update WebView.cs * fix updated * Update WebView.cs * Create ControlsShouldRemainVisibleWithWebViewWhenHardwareAccelerationIsDisabled.png * updated test case codes * Update ControlsShouldRemainVisibleWithWebViewWhenHardwareAccelerationIsDisabled.png * Update Issue28798.cs * Update ControlsShouldRemainVisibleWithWebViewWhenHardwareAccelerationIsDisabled.png updated google with example.com as google logo keeps changing.
1 parent 1c1e06a commit 105d087

File tree

4 files changed

+76
-0
lines changed

4 files changed

+76
-0
lines changed
Loading
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
namespace Maui.Controls.Sample.Issues;
2+
3+
[XamlCompilation(XamlCompilationOptions.Compile)]
4+
[Issue(IssueTracker.Github, 28798, "Controls Disappear When WebView is Used with Hardware Acceleration Disabled in Android", PlatformAffected.Android)]
5+
public partial class Issue28798 : ContentPage
6+
{
7+
public Issue28798()
8+
{
9+
var grid = new Grid
10+
{
11+
HeightRequest = 500,
12+
Background = Colors.Green,
13+
WidthRequest = 300
14+
};
15+
16+
grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
17+
grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
18+
grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
19+
20+
var label = new Label
21+
{
22+
Text = "Test",
23+
Background = Colors.Red,
24+
AutomationId = "TestLabel"
25+
};
26+
Grid.SetRow(label, 0);
27+
grid.Children.Add(label);
28+
29+
var button = new Button
30+
{
31+
Text = "button",
32+
Background = Colors.Blue
33+
};
34+
Grid.SetRow(button, 1);
35+
grid.Children.Add(button);
36+
37+
var webView = new WebView
38+
{
39+
Source = "https://example.com/",
40+
BackgroundColor = Colors.Transparent,
41+
HeightRequest = 300,
42+
WidthRequest = 300
43+
};
44+
Grid.SetRow(webView, 2);
45+
grid.Children.Add(webView);
46+
47+
Content = grid;
48+
}
49+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#if ANDROID
2+
using NUnit.Framework;
3+
using UITest.Appium;
4+
using UITest.Core;
5+
6+
namespace Microsoft.Maui.TestCases.Tests.Issues;
7+
8+
internal class Issue28798 : _IssuesUITest
9+
{
10+
public Issue28798(TestDevice device) : base(device) { }
11+
12+
public override string Issue => "Controls Disappear When WebView is Used with Hardware Acceleration Disabled in Android";
13+
14+
[Test]
15+
[Category(UITestCategories.WebView)]
16+
public void ControlsShouldRemainVisibleWithWebViewWhenHardwareAccelerationIsDisabled()
17+
{
18+
App.WaitForElement("TestLabel");
19+
VerifyScreenshot();
20+
}
21+
}
22+
#endif

src/Core/src/Handlers/WebView/WebViewHandler.Android.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ protected override AWebView CreatePlatformView()
2929
platformView.Settings.DomStorageEnabled = true;
3030
platformView.Settings.SetSupportMultipleWindows(true);
3131

32+
if (OperatingSystem.IsAndroidVersionAtLeast(23) && Context?.ApplicationInfo?.Flags.HasFlag(Android.Content.PM.ApplicationInfoFlags.HardwareAccelerated) == false)
33+
{
34+
platformView.SetLayerType(Android.Views.LayerType.Software, null);
35+
}
36+
3237
return platformView;
3338
}
3439

0 commit comments

Comments
 (0)