improve scrolling ux

This commit is contained in:
2026-06-02 20:08:00 +02:00
parent e1832f2d14
commit 7ec3d13590
@@ -13,9 +13,9 @@ import androidx.compose.material.icons.filled.ArrowDownward
import androidx.compose.material.icons.filled.ArrowUpward
import androidx.compose.material.icons.filled.Close
import androidx.compose.material.icons.filled.ContentCopy
import androidx.compose.material.icons.filled.Refresh
import androidx.compose.material.icons.outlined.ContentCopy
import androidx.compose.material3.*
import androidx.compose.material3.pulltorefresh.PullToRefreshBox
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
@@ -59,11 +59,6 @@ fun HistoryScreen(
contentDescription = "Close"
)
}
},
actions = {
IconButton(onClick = { vm.refresh() }) {
Icon(Icons.Default.Refresh, contentDescription = "Refresh")
}
}
)
}
@@ -95,6 +90,16 @@ fun HistoryScreen(
}
is HistoryState.Success -> {
val shouldLoadMore by remember {
derivedStateOf {
val lastVisible = listState.layoutInfo.visibleItemsInfo.lastOrNull()
val totalItems = listState.layoutInfo.totalItemsCount
lastVisible != null && lastVisible.index >= totalItems - 3
}
}
LaunchedEffect(shouldLoadMore) {
if (shouldLoadMore && s.canLoadMore) vm.loadMore()
}
if (s.payments.isEmpty()) {
Text(
text = "No payments yet.",
@@ -102,21 +107,15 @@ fun HistoryScreen(
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
} else {
} else PullToRefreshBox(
isRefreshing = s.isRefreshing,
onRefresh = { vm.refresh() }
) {
LazyColumn(
state = listState,
modifier = Modifier.fillMaxSize(),
contentPadding = PaddingValues(vertical = 8.dp)
) {
if (s.isRefreshing) {
item {
LinearProgressIndicator(
modifier = Modifier
.fillMaxWidth()
.padding(bottom = 4.dp)
)
}
}
items(
items = s.payments,
key = { it.paymentHash }
@@ -141,9 +140,10 @@ fun HistoryScreen(
.padding(16.dp),
contentAlignment = Alignment.Center
) {
OutlinedButton(onClick = { vm.loadMore() }) {
Text("More")
}
CircularProgressIndicator(
modifier = Modifier.size(24.dp),
strokeWidth = 2.dp
)
}
}
}