Код: Выделить всё
@Composable
fun Sandbox() {
val state = rememberLazyListState()
LazyColumn(
state = state,
modifier = Modifier.height(200.dp)
) {
// This line of code leads to sporadic recompositions.
// No recompositions once that line is commented out.
val test = DoSomething(state)
items(count = 50, key = {index -> index}) { index ->
Text(text = "Item: $index")
}
}
}
// note that this is not a composable function, that's intended from my side
// as I want to return values (not possible with composable functions)
fun DoSomething(state: LazyListState) : Int? {
val items = state.layoutInfo.visibleItemsInfo
return null
}
[img]https://i. stack.imgur.com/d85xK.png[/img]
Как только я удаляю вызов DoSomething(state), у меня нет этой проблемы. Почему чтение состояния приводит к перекомпозициям?
Подробнее здесь: https://stackoverflow.com/questions/783 ... mpositions
Мобильная версия