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

Bradleycorn

11/25/2020, 3:53 PM
Have I found a defect with
AndroidView
when used with a
WebView
, or am I doing something wrong? I have the following Composables that setup a screen containing a Column with some images and text, and then an AndroidView with a WebView. When the screen is composed, None of the top composables seem to get rendered, including the root level Surface that draws the entire screen with a dark background color (I have darkmode enabled). The ONLY thing that gets rendered is the AndroidView/WebView … Oddly enough, if I scroll in the WebView a little bit, all of a sudden the top views and Surface are rendered and magically appear ( have checked, nothing is recomposed, they just all of a sudden get rendered). Have I done something wrong, or is this a defect? Here are my composables:
Copy code
@Composable
fun PostContent(post: Post, postContent: String) {
   Column {
        PostImage(url = post.imageUrl)
        Column(modifier = Modifier.padding(horizontal = 16.dp)) {
            Spacer(modifier = Modifier.height(8.dp))
            Providers(AmbientContentAlpha provides ContentAlpha.high) {
                Text(
                    text = post.title,
                    style = MaterialTheme.typography.h5,
                    color = MaterialTheme.colors.primaryOnSurface
                )
            }
            Spacer(modifier = Modifier.height(8.dp))
            Row(modifier = Modifier.padding(vertical = 8.dp)) {
                CoilImage(
                    data = post.authorImage ?: "",
                    requestBuilder = {
                        transformations(CircleCropTransformation())
                    },
                    modifier = Modifier.width(36.dp).height(36.dp)
                        .align(Alignment.CenterVertically),
                    contentScale = ContentScale.Fit
                )

                Column(modifier = Modifier.padding(horizontal = 8.dp)) {
                    Text(text = post.author)
                    Providers(AmbientContentAlpha provides ContentAlpha.medium) {
                        Text(text = post.datePosted.toString("MMMM dd, h:mm a"))
                    }
                }
            }
            Spacer(modifier = Modifier.height(8.dp))
            PostBody(postContent)
        }

    }
}


@SuppressLint("SetJavaScriptEnabled")
@Composable
fun PostBody(html: String, modifier: Modifier = Modifier) {
    val darkModeEnabled = !MaterialTheme.colors.isLight

    AndroidView(viewBlock = { context ->
        WebView(context).apply {
            webViewClient = WebViewClient()
            settings.javaScriptEnabled = true
            settings.loadWithOverviewMode = true
            settings.useWideViewPort = true
            isVerticalScrollBarEnabled = false
            setBackgroundColor(context.getColorFromAttr(R.attr.colorSurface))
            if (darkModeEnabled) {
                if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK)) {
                    WebSettingsCompat.setForceDark(settings, WebSettingsCompat.FORCE_DARK_ON);
                }
            }
            if(WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK_STRATEGY)) {
                WebSettingsCompat.setForceDarkStrategy(settings, WebSettingsCompat.DARK_STRATEGY_USER_AGENT_DARKENING_ONLY);
            }
        }
    },
    update = {
        it.loadDataWithBaseURL("file:///android_asset/", html, "text/html", "base64", null)
    })
}
👍 3
And here’s a video of what happens on a device:
@Adam Powell - any idea what’s going on here?
a

Adam Powell

11/25/2020, 8:04 PM
looks like a bug
b

Bradleycorn

11/25/2020, 8:08 PM
Sure seems like it. Wanted to get some 👀 on it before I submitted on the issue tracker. I'm still VERY new to compose so there's always a good chance it's just me doing stuff wrong 😁
👍 1
a

Adam Powell

11/25/2020, 8:09 PM
does this repro on an emulator or is it one specific device?
b

Bradleycorn

11/25/2020, 8:10 PM
couple devices and the emulator
and if I change the top level
Column
to a
ScrollableColumn
, whoa boy, things get REALLY interesting
😄 1
I’ve filed an issue for this. If anyone else is seeing this issue, then head to the link and it. https://issuetracker.google.com/issues/174233728
29 Views