Vsevolod Ganin
10/19/2020, 11:07 PMLazyColumnFor
. When I use positional remember
inside itemContent
, it remembers everything for that particular index in the list. So when I remove an item in the source list, the (index + 1) item takes its place and inherits the memory of its predecessor. I think that’s because of the usage of key(index)
in LazyColumnFor
implementation. Is this intended?@Preview
@Composable
fun Repro() {
val list = remember { mutableStateListOf("a", "b", "c", "d", "e") }
LazyColumnForIndexed(items = list) { index, item ->
val randomNumber = remember { Random.nextInt(0..1000) }
Text(
text = "$item: $randomNumber",
modifier = Modifier.clickable(onClick = {
list.removeAt(index)
})
)
}
}
key(item)
inside itemContent
makes it behave as I wantedZach Klippenstein (he/him) [MOD]
10/19/2020, 11:12 PMVsevolod Ganin
10/19/2020, 11:31 PM