Feel like I’m missing something super obvious; in ...
# compose
t
Feel like I’m missing something super obvious; in `AbstractComposeView`s, should we be declaring click listeners and other “event” lambdas as `MutableState`s or just simple `var`s? I thought I noticed both approaches working 🤔. Code in 🧵
Copy code
class FooView : AbstractComposeView {
    // Consumers can set click listener
    // Does this need to be a mutable state?
    val clickListenerState: MutableState<() -> Unit> = mutableStateOf({})
    // Or does this suffice?
    var clickListenerNotState: () -> Unit = {}

    @Composable
    override fun Content() {
        Button(
            onClick = clickListenerNotState // OR clickListenerState.value
        )
    }
}
z
If you change the value of that property after the initial composition, it needs to be in a snapshot state holder.
t
Ahh 🤦🏼 I only tried with setting the listener as soon as
FooView
was inflated and didn’t try with subsequent changes to it (oh Mondays). Thanks for the sanity check 😅!
Thats interesting; I would assume that the content is already composed once the view is inflated, and therefore setting the value for the “first time” shouldn’t work either (but it does even if its not a snapshot state) 🤔
z
The important thing is that it needs to be in a snapshot state if it changes, otherwise there's no guarantee the composition will see the latest values
👍🏼 1