, 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?
Vsevolod Ganin
10/19/2020, 11:09 PM
A small repro
Copy code
@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)
})
)
}
}
Vsevolod Ganin
10/19/2020, 11:10 PM
Using
key(item)
inside
itemContent
makes it behave as I wanted
z
Zach Klippenstein (he/him) [MOD]
10/19/2020, 11:12 PM
Seems like a bug to me too, that behavior is really surprising. I’d just go ahead and file a bug.