01/26/2023, 1:06 AM
Hi , I'm working on compose interoperability with view system. I have a usecase where I have to pass the composable as content to a custom view which I created which internally calls a composable. Attaching the code for reference.
fun Test(
  content: @Composable () -> Unit
) {
  Column {

class TestView @JvmOverloads constructor(
  context: Context,
  attrs: AttributeSet? = null,
  defStyle: Int = 0
) : AbstractComposeView(context, attrs, defStyle) {

  var content by mutableStateOf<Composable?>(null)

  override fun Content() {
    content?.let {
        content = {
Can someone help on this

Kirill Grouchnikov

01/26/2023, 12:39 PM
There's no question here. Is the code not compiling? Crashing at runtime? Partially displaying? Not displaying anything? Displaying the view but not allowing to interact with it? Something else?


01/26/2023, 12:42 PM
My question is , there is content which is var content by mutableStateOf<Composable?>(null) So from an activity which uses view system , how can I set a view to this content object

Andy Himberger

01/27/2023, 5:30 PM
Who sets it / it needs to dynamically change? Probably the 'compose' way to do this would be to use navigation and the thing wanting to change content would navigate to the right composable, but you need to define all the possible destinations. We have a couple test apps not using navigation yet doing something similar to what you have, except we don't store a Composable in state, we have an enum class where one of the values is a Composable, and we store the enum in state, that seems to work.