Fix crashes on changing grouping

This commit is contained in:
Jobobby04 2022-12-31 17:50:57 -05:00
parent 141cd959f2
commit bc76490967
2 changed files with 10 additions and 3 deletions

View File

@ -8,6 +8,7 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.key
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.rememberCoroutineScope
@ -53,8 +54,10 @@ fun LibraryContent(
end = contentPadding.calculateEndPadding(LocalLayoutDirection.current), end = contentPadding.calculateEndPadding(LocalLayoutDirection.current),
), ),
) { ) {
val coercedCurrentPage = remember { currentPage().coerceIn(0, categories.lastIndex) } // SY -->
val pagerState = rememberPagerState(coercedCurrentPage) val coercedCurrentPage = remember(categories) { currentPage().coerceIn(0, categories.lastIndex) }
val pagerState = key(categories) { rememberPagerState(coercedCurrentPage) }
// SY <--
val scope = rememberCoroutineScope() val scope = rememberCoroutineScope()
var isRefreshing by remember(pagerState.currentPage) { mutableStateOf(false) } var isRefreshing by remember(pagerState.currentPage) { mutableStateOf(false) }

View File

@ -19,11 +19,15 @@ fun LibraryTabs(
getNumberOfMangaForCategory: (Category) -> Int?, getNumberOfMangaForCategory: (Category) -> Int?,
onTabItemClick: (Int) -> Unit, onTabItemClick: (Int) -> Unit,
) { ) {
// SY -->
@Suppress("NAME_SHADOWING")
val currentPageIndex = currentPageIndex.coerceAtMost(categories.lastIndex)
// SY <--
Column { Column {
ScrollableTabRow( ScrollableTabRow(
selectedTabIndex = currentPageIndex, selectedTabIndex = currentPageIndex,
edgePadding = 0.dp, edgePadding = 0.dp,
indicator = { TabIndicator(it[currentPageIndex]) }, indicator = { TabIndicator(it[currentPageIndex.coerceAtMost(categories.lastIndex)]) },
// 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
divider = {}, divider = {},