improve scrolling ux
This commit is contained in:
@@ -13,9 +13,9 @@ import androidx.compose.material.icons.filled.ArrowDownward
|
|||||||
import androidx.compose.material.icons.filled.ArrowUpward
|
import androidx.compose.material.icons.filled.ArrowUpward
|
||||||
import androidx.compose.material.icons.filled.Close
|
import androidx.compose.material.icons.filled.Close
|
||||||
import androidx.compose.material.icons.filled.ContentCopy
|
import androidx.compose.material.icons.filled.ContentCopy
|
||||||
import androidx.compose.material.icons.filled.Refresh
|
|
||||||
import androidx.compose.material.icons.outlined.ContentCopy
|
import androidx.compose.material.icons.outlined.ContentCopy
|
||||||
import androidx.compose.material3.*
|
import androidx.compose.material3.*
|
||||||
|
import androidx.compose.material3.pulltorefresh.PullToRefreshBox
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
@@ -59,11 +59,6 @@ fun HistoryScreen(
|
|||||||
contentDescription = "Close"
|
contentDescription = "Close"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
|
||||||
actions = {
|
|
||||||
IconButton(onClick = { vm.refresh() }) {
|
|
||||||
Icon(Icons.Default.Refresh, contentDescription = "Refresh")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -95,6 +90,16 @@ fun HistoryScreen(
|
|||||||
}
|
}
|
||||||
|
|
||||||
is HistoryState.Success -> {
|
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()) {
|
if (s.payments.isEmpty()) {
|
||||||
Text(
|
Text(
|
||||||
text = "No payments yet.",
|
text = "No payments yet.",
|
||||||
@@ -102,21 +107,15 @@ fun HistoryScreen(
|
|||||||
style = MaterialTheme.typography.bodyMedium,
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
)
|
)
|
||||||
} else {
|
} else PullToRefreshBox(
|
||||||
|
isRefreshing = s.isRefreshing,
|
||||||
|
onRefresh = { vm.refresh() }
|
||||||
|
) {
|
||||||
LazyColumn(
|
LazyColumn(
|
||||||
state = listState,
|
state = listState,
|
||||||
modifier = Modifier.fillMaxSize(),
|
modifier = Modifier.fillMaxSize(),
|
||||||
contentPadding = PaddingValues(vertical = 8.dp)
|
contentPadding = PaddingValues(vertical = 8.dp)
|
||||||
) {
|
) {
|
||||||
if (s.isRefreshing) {
|
|
||||||
item {
|
|
||||||
LinearProgressIndicator(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(bottom = 4.dp)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
items(
|
items(
|
||||||
items = s.payments,
|
items = s.payments,
|
||||||
key = { it.paymentHash }
|
key = { it.paymentHash }
|
||||||
@@ -141,9 +140,10 @@ fun HistoryScreen(
|
|||||||
.padding(16.dp),
|
.padding(16.dp),
|
||||||
contentAlignment = Alignment.Center
|
contentAlignment = Alignment.Center
|
||||||
) {
|
) {
|
||||||
OutlinedButton(onClick = { vm.loadMore() }) {
|
CircularProgressIndicator(
|
||||||
Text("More")
|
modifier = Modifier.size(24.dp),
|
||||||
}
|
strokeWidth = 2.dp
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user