I am trying to have a multiselect list using LazyC...
# compose-android
a
I am trying to have a multiselect list using LazyColumn in Jetpack Compose. I am trying to use a SnapShotStateList which doesn't consider a property change of an item as a change and hence, it doesn't recompose. Sample code is in thread.
Copy code
@Composable
fun TestLazyColumn(options: List<SelectionItemTest> = (1 .. 30).map {
    SelectionItemTest(it.toString(), "Lead $it", it == 3)
}) {
    var currentOptions by remember {
        mutableStateOf(options)
    }
    LazyColumn(modifier = Modifier.fillMaxSize()) {
        itemsIndexed(currentOptions, key = { index, item ->
            item.id
        }) {index, item ->
            Row(modifier = Modifier.fillMaxWidth().padding(10.dp)
                .clickable {
                    val new = currentOptions.toList()
                    new[index].isSelected = !new[index].isSelected
                    //currentOptions = new
            }) {
                Text(text = item.name)
                if(item.isSelected)
                    Icon(imageVector = Icons.Default.Check, contentDescription = "")
            }
        }
    }
}

data class SelectionItemTest(
    override val id: String,
    override val name: String,
    override var isSelected: Boolean = false
): ItemProperties
Even though the selected states are updated in the list, it is not considered a change and it is not getting recomposed. There are other ways to achieve this. But is there any optimal way to handle it?