Home > OS >  How can I keep expand item of a column control in Compose?
How can I keep expand item of a column control in Compose?

Time:11-13

The Code A is from the official sample code enter image description here

2- You can create a UI version of your model class and a extended property to your data class. You can

data class UiModel(
    ...
    var expanded: Boolean = false
)

This way you can store extended state in your ViewModel.

    LazyColumn(

        content = {

            items(tutorialList) { item: UiModel ->

                var isExpanded by remember(key1 = item.title) { mutableStateOf(item.expanded) }

                UiModel(
                    model = item,
                    onExpandClicked = {
                        item.expanded = !item.expanded
                        isExpanded = item.expanded
                    },
                    expanded = isExpanded
                )
            }
        }
    )

Result is

enter image description here

  • Related