From 9df21583dc1da6da4041709a6d059848c6c9bda0 Mon Sep 17 00:00:00 2001 From: Cuong-Tran Date: Thu, 7 Nov 2024 21:20:27 +0700 Subject: [PATCH] Fix crash after removing last category while it's active in library (#1450) --- .../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 1904d39c2..a3d48d404 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(