diff --git a/app/src/main/java/org/schabi/newpipe/compose/comment/CommentSection.kt b/app/src/main/java/org/schabi/newpipe/compose/comment/CommentSection.kt index a26bab8b7..1e32e14dd 100644 --- a/app/src/main/java/org/schabi/newpipe/compose/comment/CommentSection.kt +++ b/app/src/main/java/org/schabi/newpipe/compose/comment/CommentSection.kt @@ -10,6 +10,9 @@ import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.derivedStateOf +import androidx.compose.runtime.getValue +import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource @@ -39,7 +42,7 @@ fun CommentSection( ) { Surface(color = MaterialTheme.colorScheme.background) { val comments = commentsFlow.collectAsLazyPagingItems() - val refresh = comments.loadState.refresh + val itemCount by remember { derivedStateOf { comments.itemCount } } val listState = rememberLazyListState() LazyColumnScrollbar(state = listState) { @@ -51,8 +54,9 @@ fun CommentSection( } } - if (comments.itemCount == 0) { + if (itemCount == 0) { item { + val refresh = comments.loadState.refresh if (refresh is LoadState.Loading) { LoadingIndicator(modifier = Modifier.padding(top = 8.dp)) } else { @@ -60,7 +64,7 @@ fun CommentSection( } } } else { - items(comments.itemCount) { + items(itemCount) { Comment(comment = comments[it]!!) } }