Does anyone know the difference between `ViewGroup...
# compose
f
Does anyone know the difference between
ViewGroup.setContent
(in Wrapper) and
ViewGroup.setViewContent
(in Compose)?
l
Well, they internally call a different implementation of
Compose.composeInto
one of them returns a nullable
CompositionContext
the other instead does not allows nullable
f
Sorry, I meant the difference between the purpose of them.
a
setContent is adding our AndroidComposeView which allows using Compose UI composables as a content. setViewContent is not really should be used for now, but this allows using compose runtime with just Android plain Views, see the example: https://android.googlesource.com/platform/frameworks/support/+/androidx-master-dev/ui/ui-material/integration-tests/material-demos/src/main/java/androidx/ui/material/demos/RippleActivity.kt. Note that this mode is not fully tested and it is not yet decided afaik in what shape it will be supported in funute. We would probably use it for compatibility to allow using some Views inside Compose UI composables
f
@Andrey Kulikov Thanks for your explanation. I tried
setViewContent
, but the code can not be complied:
Copy code
class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setViewContent {
            TextView(this)
        }
    }
}
a
as you can see in my example you don't need to pass context. so if you remove
this
and instead add something like
text = "Test"
it should compile
f
It works! AS marks the construction statement as an error, but it can be compiled. Seams that something magical happened. Cool. 😝
a
yeah, that what I meant by "not really should be used"
f
I see. Thanks again.