So I’m playing around with WebViews and I can’t se...
# compose
b
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
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
The reason it’s frozen is because it doesn’t handle touch inputs
z
Which version of Compose are you using? Android views embedded in compositions have been processing touch events for a few releases now.
m
Not sure if all types of touch events are processed. I found some that don’t. @Shep Shapard can chip in here.
b
I am using Dev13
c
is emitView is internal? it shows compiler error. compose version 0.1.0-dev14
m
Maybe you’re looking for
AndroidView
?
c
"The
emitView
syntax just landed last week, so the current syntax in dev13 is a little different" Looking this case
z
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
Yeah I wasn’t sure if I needed to pass in something to have the AndroidView handle the touch inputs. 🙃
z
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
good idea. Here is the bug for anyone who might be following along: https://issuetracker.google.com/issues/159838005
👍 1
s
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!