From 672b635ea9909d63770db33809a07a567aa6bbf6 Mon Sep 17 00:00:00 2001 From: Cuong-Tran Date: Wed, 6 Nov 2024 22:29:20 +0700 Subject: [PATCH] Fix crash when delete last category while library being on that category --- .../eu/kanade/presentation/library/components/LibraryTabs.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/kanade/presentation/library/components/LibraryTabs.kt b/app/src/main/java/eu/kanade/presentation/library/components/LibraryTabs.kt index 1904d39c22..a3d48d404a 100644 --- a/app/src/main/java/eu/kanade/presentation/library/components/LibraryTabs.kt +++ b/app/src/main/java/eu/kanade/presentation/library/components/LibraryTabs.kt @@ -21,11 +21,12 @@ internal fun LibraryTabs( getNumberOfMangaForCategory: (Category) -> Int?, onTabItemClick: (Int) -> Unit, ) { + val currentPageIndex = pagerState.currentPage.coerceAtMost(categories.lastIndex) Column( modifier = Modifier.zIndex(1f), ) { PrimaryScrollableTabRow( - selectedTabIndex = pagerState.currentPage, + selectedTabIndex = currentPageIndex, edgePadding = 0.dp, // TODO: use default when width is fixed upstream // https://issuetracker.google.com/issues/242879624 @@ -33,7 +34,7 @@ internal fun LibraryTabs( ) { categories.forEachIndexed { index, category -> Tab( - selected = pagerState.currentPage == index, + selected = currentPageIndex == index, onClick = { onTabItemClick(index) }, text = { TabText(