From f00853dcc4f6cdc053ed331d45ee44837a6ecf95 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Wed, 13 Nov 2024 01:00:07 +0530 Subject: [PATCH] fix(comments): preserve scroll state --- .../dev/msfjarvis/claw/common/comments/CommentsPageImpl.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/CommentsPageImpl.kt b/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/CommentsPageImpl.kt index 8e290657..b29f4bb9 100644 --- a/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/CommentsPageImpl.kt +++ b/common/src/main/kotlin/dev/msfjarvis/claw/common/comments/CommentsPageImpl.kt @@ -28,6 +28,7 @@ import androidx.compose.foundation.layout.systemBars import androidx.compose.foundation.layout.windowInsetsBottomHeight import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items +import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface @@ -77,6 +78,7 @@ internal fun CommentsPageInternal( val context = LocalContext.current val commentNodes by commentsHandler.listItems.collectAsStateWithLifecycle() + val commentListState = rememberLazyListState() LaunchedEffect(key1 = details, key2 = commentState) { if (details.comments.isNotEmpty() && !commentState?.commentIds.isNullOrEmpty()) { @@ -94,7 +96,7 @@ internal fun CommentsPageInternal( } Surface(color = MaterialTheme.colorScheme.surfaceVariant) { - LazyColumn(modifier = modifier, contentPadding = contentPadding) { + LazyColumn(modifier = modifier, contentPadding = contentPadding, state = commentListState) { item { CommentsHeader( post = details,