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

joadar

02/17/2022, 4:27 PM
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

Sean Proctor

02/17/2022, 8:13 PM
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

Andrey Kulikov

02/17/2022, 8:28 PM
feel free to file a bug
j

joadar

02/18/2022, 8:11 AM
Okay, thank you guys 🙂