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:
+14
@@ -35,6 +35,7 @@ import androidx.compose.foundation.lazy.rememberLazyListState
|
|||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.collectAsState
|
import androidx.compose.runtime.collectAsState
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
@@ -100,6 +101,19 @@ internal fun ColumnScope.NestChatPanel(
|
|||||||
|
|
||||||
val listState = rememberLazyListState()
|
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()) {
|
Column(modifier = modifier.fillMaxWidth()) {
|
||||||
Box(
|
Box(
|
||||||
modifier =
|
modifier =
|
||||||
|
|||||||
+13
@@ -164,6 +164,19 @@ private fun NestLobbyContent(
|
|||||||
val listState = rememberLazyListState()
|
val listState = rememberLazyListState()
|
||||||
val scope = rememberCoroutineScope()
|
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(
|
Scaffold(
|
||||||
contentWindowInsets = WindowInsets(0),
|
contentWindowInsets = WindowInsets(0),
|
||||||
topBar = {
|
topBar = {
|
||||||
|
|||||||
Reference in New Issue
Block a user