I'm trying to inject a simple Text Banner into an existing Fragment/layout. It embeds fine (per https://developer.android.com/jetpack/compose/interop/interop-apis#compose-in-fragments). But I need to hoist some state (I think) into the fragment. I have a value at the Fragment level in a LiveData. But it's unclear to me how to change my ComposeFunction to become aware of that value and recompose when it changes. I'm successfully able to pass the LiveData as an arg to the @Composable function and compose the original view. But updates to the LiveData don't cause it to recompose. I looked for
observeAsState
per the docs, but it doesn't seem to find that. Nor is it clear where to invoke that at...
Hmmm... Now I wonder if I really want/need a (KT)LiveData. I have a Fragment. I just need a slot of some sort, stored/updated at the Fragment level, that will cause the Compose subelement to recompse when it gets updated. Can I use a MutableState at the Fragment level. Really struggling to get the light bulbs here 😞
a
Adam Powell
09/19/2022, 10:53 PM
Yes you can use mutableStateOf in your fragments
z
Zaki Shaikh
09/20/2022, 1:45 AM
You can declare top level mutable state object in fragment or in viewModel if you have.