Coerce current pager page better

This commit is contained in:
Jobobby04 2022-12-21 13:27:37 -05:00
parent a9e2394c6d
commit 8d3888a572

View File

@ -53,7 +53,7 @@ fun LibraryContent(
end = contentPadding.calculateEndPadding(LocalLayoutDirection.current),
),
) {
val coercedCurrentPage = remember { currentPage().coerceAtMost(categories.lastIndex) }
val coercedCurrentPage = remember { currentPage().coerceIn(0, categories.lastIndex) }
val pagerState = rememberPagerState(coercedCurrentPage)
val scope = rememberCoroutineScope()
@ -79,7 +79,7 @@ fun LibraryContent(
PullRefresh(
refreshing = isRefreshing,
onRefresh = {
val started = onRefresh(categories[currentPage()])
val started = onRefresh(categories.getOrNull(currentPage()) ?: return@PullRefresh)
if (!started) return@PullRefresh
scope.launch {
// Fake refresh status but hide it after a second as it's a long running task