Hi , I'm working on compose interoperability with ...
# compose
w
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.
Copy code
@Composable
fun Test(
  content: @Composable () -> Unit
) {
  Column {
    content()
  }
}

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

  var content by mutableStateOf<Composable?>(null)

  @Composable
  override fun Content() {
    content?.let {
      Test(
        content = {
          it
        },
      ) 
    }
  }
}
k
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?
w
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
a
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.