1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2025-01-10 01:10:33 +00:00

Improve comment loading smoothness

This commit is contained in:
Isira Seneviratne 2024-07-08 19:27:57 +05:30
parent ddbfcf89c7
commit 3c55d956a0

View File

@ -10,6 +10,9 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface import androidx.compose.material3.Surface
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.runtime.Composable 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.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
@ -39,7 +42,7 @@ fun CommentSection(
) { ) {
Surface(color = MaterialTheme.colorScheme.background) { Surface(color = MaterialTheme.colorScheme.background) {
val comments = commentsFlow.collectAsLazyPagingItems() val comments = commentsFlow.collectAsLazyPagingItems()
val refresh = comments.loadState.refresh val itemCount by remember { derivedStateOf { comments.itemCount } }
val listState = rememberLazyListState() val listState = rememberLazyListState()
LazyColumnScrollbar(state = listState) { LazyColumnScrollbar(state = listState) {
@ -51,8 +54,9 @@ fun CommentSection(
} }
} }
if (comments.itemCount == 0) { if (itemCount == 0) {
item { item {
val refresh = comments.loadState.refresh
if (refresh is LoadState.Loading) { if (refresh is LoadState.Loading) {
LoadingIndicator(modifier = Modifier.padding(top = 8.dp)) LoadingIndicator(modifier = Modifier.padding(top = 8.dp))
} else { } else {
@ -60,7 +64,7 @@ fun CommentSection(
} }
} }
} else { } else {
items(comments.itemCount) { items(itemCount) {
Comment(comment = comments[it]!!) Comment(comment = comments[it]!!)
} }
} }