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

kelvinharron

02/02/2022, 3:49 PM
Hey folks, I’d like to follow up this post I found in search with a question: https://kotlinlang.slack.com/archives/CJLTWPH7S/p1637659659341600 This is most related to the issue I’m having where I can’t see previews of compose objects in XML (see attached image). We’re integrated compose into our databinding layouts and we aren’t able to get any previews. Given how
<androidx.compose.ui.platform.ComposeView
works, and points to something like:
Copy code
binding.payButtonLayout.composeButton.apply {
    setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnDetachedFromWindow)
    setContent {
        MaterialTheme {
            Button(onClick = {}) {
                Text("My button")
            }
        }
    }
}
I’ve tried using the
tools:composableName="androidx.compose.material.ButtonKt"
,
<androidx.compose.ui.tooling.ComposeViewAdapter
and even making my own view by inheriting from
AbstractComposeView
but still no preview. Would I be correct in saying that this just isn’t possible to do? Thanks in advance!
d

Dragos Rachieru

02/03/2022, 2:51 PM
Can you show the code of your class that extends
ComposeView
?
6 Views