Jorn Hertsig
07/21/2023, 8:52 AMval data = remember { mutableStateListOf("One", "Two", "Three") }
var size = 0
Column(Modifier.padding(8.dp), Arrangement.spacedBy(4.dp)) {
while (size < data.size) {
val index = size++
Row(horizontalArrangement = Arrangement.spacedBy(4.dp), verticalAlignment = Alignment.CenterVertically) {
Button({ data.removeAt(index) }) { Text("X") }
Button({ data[index] += "!" }) { Text("!") }
Text(data[index])
}
}
Text("Size: $size")
Button({ data += "New ${size + 1}" }) { Text("Add") }
}
If I understand this correctly, the size
variable should go out of sync and show incorrect values. But how do I actually trigger that bug? Adding to, removing from and changing single elements in the list all don't do it.Jorn Hertsig
07/21/2023, 9:26 AMColumn(Modifier.padding(8.dp), Arrangement.spacedBy(4.dp)) {
println("Column")
var total = 0
Row {
println("Row 1")
var text by remember { mutableStateOf("") }
Button( { text += "!" }) {
println("Button 1")
Text("!")
total++
}
Text(text)
}
Row {
println("Row 2")
var text by remember { mutableStateOf("") }
Button( { text += "!" }) {
println("Button 2")
Text("!")
total++
}
Text(text)
}
Text("Rows: $total")
}
Still doesn't show the bug, because for some reason every button click recomposes the column and both rows. That makes no sense to mevide
07/21/2023, 9:56 AMdata
or text
in the latter example, it will recompose the whole block.vide
07/21/2023, 9:58 AMText(text)
reading the state. Remove it and you won't see recompositions.)Jorn Hertsig
07/21/2023, 11:51 AMText(text)
won't do it, then there are no recompositions at all, so the size won't ever changevide
07/21/2023, 12:11 PMvar count = 0
Button({ count += 1 }) { Text("Increment: $count") }
are you looking for something like this?Jorn Hertsig
07/21/2023, 12:19 PMvide
07/21/2023, 12:34 PM