dimsuz
09/14/2021, 1:53 PMLazyList
state causes the endless recomposition loop, I can't fully understand why. Minimal sample is in the thread.dimsuz
09/14/2021, 1:54 PM@Composable
fun Component() {
val content = (1..80).map { "Item $it" }
val state = rememberLazyListState()
val value = (state.layoutInfo.visibleItemsInfo.lastOrNull()?.index ?: 0) // !!!
println("recomposing")
LazyColumn(modifier = Modifier.fillMaxSize(), state = state) {
items(content) {
Text(text = it)
}
}
}
The code above causes an endless stream of "recomposing" in the logcat.
But if I comment out the line marked with !!!
only one "recomposing" is printed and there's no endless loop. What happens here?Didier Villevalois
09/14/2021, 1:56 PMcontent
at each composition?dimsuz
09/14/2021, 1:57 PM!!!
line stops this endless loop?Dominaezzz
09/14/2021, 1:58 PMdimsuz
09/14/2021, 1:59 PMDominaezzz
09/14/2021, 2:03 PMdimsuz
09/14/2021, 2:03 PMdimsuz
09/14/2021, 2:04 PMDominaezzz
09/14/2021, 2:05 PMZach Klippenstein (he/him) [MOD]
09/14/2021, 2:28 PMZach Klippenstein (he/him) [MOD]
09/14/2021, 2:37 PMvalue
actually different each time?dimsuz
09/14/2021, 3:12 PMDominaezzz
09/14/2021, 3:25 PMZach Klippenstein (he/him) [MOD]
09/14/2021, 3:37 PMAndrey Kulikov
09/15/2021, 11:25 AMAndrey Kulikov
09/15/2021, 11:26 AMdimsuz
09/15/2021, 2:38 PMderivedStateOf
helped to fix this.
Thank you for explanation!