Fix crash after removing last category while it's active in library (#1450)

This commit is contained in:
Cuong-Tran 2024-11-07 21:20:27 +07:00 committed by GitHub
parent 57e6e198b8
commit 9df21583dc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -21,11 +21,12 @@ internal fun LibraryTabs(
getNumberOfMangaForCategory: (Category) -> Int?, getNumberOfMangaForCategory: (Category) -> Int?,
onTabItemClick: (Int) -> Unit, onTabItemClick: (Int) -> Unit,
) { ) {
val currentPageIndex = pagerState.currentPage.coerceAtMost(categories.lastIndex)
Column( Column(
modifier = Modifier.zIndex(1f), modifier = Modifier.zIndex(1f),
) { ) {
PrimaryScrollableTabRow( PrimaryScrollableTabRow(
selectedTabIndex = pagerState.currentPage, selectedTabIndex = currentPageIndex,
edgePadding = 0.dp, edgePadding = 0.dp,
// TODO: use default when width is fixed upstream // TODO: use default when width is fixed upstream
// https://issuetracker.google.com/issues/242879624 // https://issuetracker.google.com/issues/242879624
@ -33,7 +34,7 @@ internal fun LibraryTabs(
) { ) {
categories.forEachIndexed { index, category -> categories.forEachIndexed { index, category ->
Tab( Tab(
selected = pagerState.currentPage == index, selected = currentPageIndex == index,
onClick = { onTabItemClick(index) }, onClick = { onTabItemClick(index) },
text = { text = {
TabText( TabText(