https://kotlinlang.org logo
#compose
Title
# compose
d

Denis

02/06/2021, 10:03 AM
Could you help me to understand recomposition? This code adds a different number to
counts
list on each tap. I expect it to render a new
Count
and somehow move previous rows down without calling
Count
again. Is it possible?
Copy code
@Composable
fun CounterApp() {
    var counts by remember { mutableStateOf(listOf<Int>()) }
    var taps by remember { mutableStateOf(0) }
    Column(
        modifier = Modifier.fillMaxSize().clickable(onClick = {
            counts = listOf(taps) + counts; taps++
        })
    ) { Text("$taps"); Divider(); counts.forEach { Count(it) } }
}

@Composable
fun Count(n: Int) {
    Log.d("Count", "$n")
    Text("$n")
}
r

Rafs

02/06/2021, 10:24 AM
instead of using a
mutableStateOf(listOf<Int>))
you should be using
mutableStateListOf<Int>
d

Denis

02/07/2021, 6:57 AM
Thanks @Rafs. I'm trying to make it work, but I need some help. Could you check this question? https://kotlinlang.slack.com/archives/CJLTWPH7S/p1612680988453000
2 Views