1
0
mirror of https://github.com/TeamNewPipe/NewPipe.git synced 2024-11-24 20:15:16 +01:00

Improve comment loading smoothness

This commit is contained in:
Isira Seneviratne 2024-07-08 19:27:57 +05:30
parent d131d3399a
commit ac1ca1412d

View File

@ -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]!!)
}
}