https://kotlinlang.org logo
#compose
Title
# compose
v

Vince Rickey

11/16/2020, 3:50 PM
I have a WebComponent Composable that's implemented with the legacy view interop:
AndroidView(viewBlock = { webView })
. This will load most webpages, but it fails to load resource intensive iFrames such as an interactive elections map graphic. I added the hardware acceleration tag to the app's Manifest, but still no luck. A log shows that the Fragment's rootview is hardware accelerated, but the Composable's AndroidView is not. The docs state that hardware acceleration is only possible through the Manifest's application or activity tags, or programmatically through the Window. I'm wondering if AndroidView doesn't support this yet if it isn't attached to the Activity or Window under the hood. Has anyone else encountered difficulty with hardware acceleration with AndroidView interop? Code snippet in the thread.
Copy code
<application android:hardwareAccelerated="true" ...>
Copy code
@Composable
fun WebComponent() {
    val webView = remember {
        WebView(context).apply {
            settings.javaScriptEnabled = true
            webViewClient = WebViewClientCompat()
            ...
        }
    }
    AndroidView(viewBlock = { webView }) { view ->
        Log.d("WebComponent", "WebComponent is hardware accelerated: ${view.isHardwareAccelerated}")
        ...
    }
}
r

romainguy

11/16/2020, 6:48 PM
That manifest attribute isn’t required since Android 4.x btw. Hardware acceleration is on by default
Note that
isHardwareAccelerated
will only return
true
once the
View
is attached to the window. You are logging it too early to know what’s going on
But since you are talking about a failure to load, I doubt it’s related to hardware acceleration
v

Vince Rickey

11/16/2020, 7:20 PM
Great, thanks for the clarification. I will report back here when I find out the root cause of my bug if it happens to be implementation related.