Merge pull request #2676 from vitorpamplona/claude/fix-chat-scroll-behavior-Ig1YE

Auto-scroll to newest messages in chat when new messages arrive
This commit is contained in:
Vitor Pamplona
2026-04-30 21:17:40 -04:00
committed by GitHub
2 changed files with 27 additions and 0 deletions
@@ -35,6 +35,7 @@ import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
@@ -100,6 +101,19 @@ internal fun ColumnScope.NestChatPanel(
val listState = rememberLazyListState()
// Auto-stick to the newest message. With reverseLayout=true, item 0
// is the bottom of the viewport (newest). When a new message is
// prepended, LazyColumn preserves visual position by shifting
// firstVisibleItemIndex from 0 → 1, leaving the new message just
// below the viewport. If the user was at (or near) the bottom,
// scroll back to 0 so the new message becomes visible. If they're
// reading older history, leave them where they are.
LaunchedEffect(messages.firstOrNull()?.idHex) {
if (listState.firstVisibleItemIndex <= 1) {
listState.animateScrollToItem(0)
}
}
Column(modifier = modifier.fillMaxWidth()) {
Box(
modifier =
@@ -164,6 +164,19 @@ private fun NestLobbyContent(
val listState = rememberLazyListState()
val scope = rememberCoroutineScope()
// Auto-stick to the newest message. With reverseLayout=true, item 0
// is the bottom of the viewport (newest). When a new message is
// prepended, LazyColumn preserves visual position by shifting
// firstVisibleItemIndex from 0 → 1, leaving the new message just
// below the viewport. If the user was at (or near) the bottom,
// scroll back to 0 so the new message becomes visible. If they're
// reading older history, leave them where they are.
LaunchedEffect(messages.firstOrNull()?.idHex) {
if (listState.firstVisibleItemIndex <= 1) {
listState.animateScrollToItem(0)
}
}
Scaffold(
contentWindowInsets = WindowInsets(0),
topBar = {