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), 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 pagerState = rememberPagerState(coercedCurrentPage)
val scope = rememberCoroutineScope() val scope = rememberCoroutineScope()
@ -79,7 +79,7 @@ fun LibraryContent(
PullRefresh( PullRefresh(
refreshing = isRefreshing, refreshing = isRefreshing,
onRefresh = { onRefresh = {
val started = onRefresh(categories[currentPage()]) val started = onRefresh(categories.getOrNull(currentPage()) ?: return@PullRefresh)
if (!started) return@PullRefresh if (!started) return@PullRefresh
scope.launch { scope.launch {
// Fake refresh status but hide it after a second as it's a long running task // Fake refresh status but hide it after a second as it's a long running task