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

bohregard

06/23/2020, 1:43 AM
So I’m playing around with WebViews and I can’t seem to get the view to load changes. It appears frozen
Copy code
Box(
        modifier = Modifier.fillMaxWidth() + Modifier.fillMaxHeight()
    ) {
        AndroidView(view = webView(ContextAmbient.current, "<https://google.com>"))
    }

fun webView(context: Context, url: String) = WebView(context).apply {
    loadUrl(url)
    settings.apply {
        javaScriptEnabled = true
        domStorageEnabled = true
    }

    webViewClient = client
}
Any ideas why it would be frozen?
z

Zach Klippenstein (he/him) [MOD]

06/23/2020, 5:44 AM
I'm not sure it would be frozen, but I don't think that's the correct way to use
AndroidView
- I think you need to
remember
it or create the webview using the compose hooks. I believe compose also ships with a built-in helper for webview specifically that acts as a good sample: https://cs.android.com/androidx/platform/frameworks/support/+/androidx-master-dev:ui/ui-android-view/src/main/java/androidx/ui/androidview/WebComponent.kt The
emitView
syntax just landed last week, so the current syntax in dev13 is a little different, but I think you can just use WebComponent directly (or look at the history on that page to see what it used to be)
m

Manuel Vivo

06/23/2020, 6:32 AM
The reason it’s frozen is because it doesn’t handle touch inputs
z

Zach Klippenstein (he/him) [MOD]

06/23/2020, 2:03 PM
Which version of Compose are you using? Android views embedded in compositions have been processing touch events for a few releases now.
m

Manuel Vivo

06/23/2020, 2:16 PM
Not sure if all types of touch events are processed. I found some that don’t. @Shep Shapard can chip in here.
b

bohregard

06/23/2020, 2:17 PM
I am using Dev13
c

coolchandrakumar

06/25/2020, 4:18 AM
is emitView is internal? it shows compiler error. compose version 0.1.0-dev14
m

Manuel Vivo

06/25/2020, 8:25 AM
Maybe you’re looking for
AndroidView
?
c

coolchandrakumar

06/25/2020, 8:29 AM
"The
emitView
syntax just landed last week, so the current syntax in dev13 is a little different" Looking this case
z

Zach Klippenstein (he/him) [MOD]

06/25/2020, 12:39 PM
The
emitView
stuff landed on June 18, which I believe was the day after dev14 was cut, so I think it will only be available in dev15. Also it's not mentioned in the release notes for dev14. You can click the History button at the bottom of the file to see how it was done before.
👍 1
I thought it should handle them, and should have for a couple releases, unrelated to that, but I've never used that particular integration (I've used other Android views that get touch events though). I'm out of ideas 🙈
b

bohregard

06/25/2020, 1:22 PM
Yeah I wasn’t sure if I needed to pass in something to have the AndroidView handle the touch inputs. 🙃
z

Zach Klippenstein (he/him) [MOD]

06/25/2020, 1:23 PM
It should just work. If it's not, it sounds like a bug, and I would file it. Issue tracker is in the channel topic.
b

bohregard

06/25/2020, 1:42 PM
good idea. Here is the bug for anyone who might be following along: https://issuetracker.google.com/issues/159838005
👍 1
s

Shep Shapard

08/26/2020, 7:20 PM
Hi there. I need to do a better job at following along in Slack. Are you still having issues with webview and touch? There are some lingering bugs around some positioning issues in some cases that I need to investigate, but I believe the previous issues that existed should now be fixed.
Hey bohregard. I tried out your sample and it seems to now work!
16 Views