-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[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
[Android] Controls Disappear When WebView is Used with Hardware Acceleration Disabled #28934
Conversation
Hey there @@praveenkumarkarunanithi! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
/azp run MAUI-UITests-public |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run MAUI-UITests-public |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run MAUI-UITests-public |
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR addresses an Android-specific rendering issue where WebView appears above other UI controls when hardware acceleration is disabled. The changes include modifying the WebViewHandler on Android to enforce software rendering and adding test cases in both Shared.Tests and HostApp to validate the fix.
Reviewed Changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated no comments.
File | Description |
---|---|
src/Core/src/Handlers/WebView/WebViewHandler.Android.cs | Updates WebView creation to call SetLayerType() for software rendering when hardware acceleration is disabled. |
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue28798.cs | Adds a test case to verify that controls remain visible under the issue conditions on Android. |
src/Controls/tests/TestCases.HostApp/Issues/Issue28798.cs | Provides a sample page for manual testing of the WebView rendering fix. |
Comments suppressed due to low confidence (2)
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue28798.cs:8
- [nitpick] The test case class is named 'Issue28798', but the PR metadata references issue #28902. Consider aligning the identifiers for clarity.
internal class Issue28798 : _IssuesUITest
src/Controls/tests/TestCases.HostApp/Issues/Issue28798.cs:1
- [nitpick] The file name uses 'Issue28798' whereas the PR metadata mentions issue #28902. It would be clearer if the identifiers were consistent.
namespace Maui.Controls.Sample.Issues;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AI says this will ot work, but so far your screenshot says it does.
From AI:
Doesn’t fix layout compositing problems between WebView and other views, because WebView uses a separate surface or texture layer, which is not affected by SetLayerType.
WebView itself ignores SetLayerType(), as it uses a separate SurfaceView or TextureView internally.
So since this can't make it worse, it is OK.
But Android may be wrong:
It looks like it is doing somehting with this method:
@Override
public void setLayerType(int layerType, Paint paint) {
super.setLayerType(layerType, paint);
mProvider.getViewDelegate().setLayerType(layerType, paint);
}
/rebase |
…IsDisabled.png updated google with example.com as google logo keeps changing.
I guess it may work since CI is accelerated... So technically the test is not doing much. @praveenkumarkarunanithi did you verify this works when using the |
I tested it here and it works. AI is wrong. So sad. |
if (OperatingSystem.IsAndroidVersionAtLeast(23) && Context?.ApplicationInfo?.Flags.HasFlag(Android.Content.PM.ApplicationInfoFlags.HardwareAccelerated) == false) | ||
{ | ||
platformView.SetLayerType(Android.Views.LayerType.Software, null); | ||
} |
There was a problem hiding this comment.
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");
@@ -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) |
There was a problem hiding this comment.
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.
3310b65
to
f8f04ff
Compare
…eration 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.
…eration 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.
…eration 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.
…eration 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.
…eration 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.
…eration 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.
…eration 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.
…eration 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.
Root Cause
When
android:hardwareAccelerated="false"
is set in Android applications, standard UI elements switch to software rendering, but WebView may continue using hardware optimization. This inconsistency causes WebView to occasionally render above other UI elements, disrupting the expected visual hierarchy.Description of Change
The solution involves setting the WebView to use the software rendering pipeline by applying
SetLayerType(Android.Views.LayerType.Software, null)
when hardware acceleration is disabled. This ensures that WebView aligns with the rendering behavior of other UI elements, maintaining correct layering and preventing any UI components from being obscured.Issues Fixed
Fixes #28902
Tested the behaviour in the following platforms
Note
This issue is specific to Android, as hardware acceleration settings are not applicable on other platforms.
Screenshots