Hello here, I want to always focus on the latest i...
# compose
j
Hello here, I want to always focus on the latest item from LazyColumn every time the list is updated, so I use
Copy code
val listState = rememberLazyListState(Int.MAX_VALUE, Int.MAX_VALUE)

    LaunchedEffect(messages) {
        coroutineScope.launch {
            listState.scrollToItem(Int.MAX_VALUE, Int.MAX_VALUE)
        }
    }
But my LazyColumn is like this:
Copy code
LazyColumn(state = listState) {
   items(messages) {...}
   if (something) { item {} }
   if (somethingElse) { item {} }
   if (somethingElse2) { item {} }
}
And the issue is that it doesn’t scroll every time automatically to the latest item displayed (either from the update in
items
or a single
item
). Am I doing something wrong?
s
My only experience with this is with Compose for desktop. This works there, but I haven't tried it with Android.
Copy code
LaunchedEffect(messages) {
    while (listState.isScrollInProgress) {
        delay(15)
    }
    // Do your scroll logic
}
a
feel free to file a bug
j
Okay, thank you guys 🙂