5

I had three question

  1. There is setViewContent which accept composable function as input parameter similar to setContent. So, what is a difference between setViewContent and setContent and its use-cases. You can able to see setViewContent in androidx.compose package.
  2. setContent and setViewContent both return CompositionContext?. So, how and for what, we will use CompositionContent.
  3. Is there any way to integrate existing layout.xml with new compose ui in same activity or fragment.
amar_1995
  • 575
  • 3
  • 14

1 Answers1

2

Here are my comments and my understanding:

  1. setContent will make the composable passed as parameter as the root component of your activity/fragment. On the other hand, setViewContent will add a FrameLayout as root element of your activity/fragment which allow you to add another views on it.
  2. Both methods return a Composition object, which afaik, it's used just to display the content via setContent and clear the hierarchy that was created from the composition via dispose.
  3. Yes, in dev14 you can use AndroidView like this:
AndroidView(resId = R.layout.my_layout) { view ->
    val textView = view.findViewById<TextView>(R.id.textView)
    ...    
}
nglauber
  • 18,674
  • 6
  • 70
  • 75