I have a LazyColumn where the items in it can be e...
# compose-android
a
I have a LazyColumn where the items in it can be expanded to reveal more. To maintain expanded states across recompositions/reuse this is what I've done:
Copy code
@Stable
data class Item(/* normal values */) {
    /** initially collapsed */
    val expanded = mutableStateOf(false)
}
Then, in the composable:
Copy code
LazyColumn {
    items(list) {
        var expanded by remember { item.expanded } // toggled when user clicks on something
        AlwaysVisibleContent()
        AnimatedVisibility(expanded) { OtherContent() }
    }
}
It works of course, but are there any pitfalls to sticking a MutableState into the Item class? I'd rather keep Compose-specific stuff in composables only.
103 Views