Guard against navigating to a non-existant tab (#629)

Just make sure we don't crash if the selectedTabIndex isn't a positive
int. Fixes #628.

---------

Co-authored-by: Damontecres <damontecres@gmail.com>
This commit is contained in:
joshjryan 2026-01-03 16:38:07 -07:00 committed by GitHub
parent 9345d0a698
commit 3d4b06db44
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 3 deletions

View file

@ -51,8 +51,10 @@ fun TabRow(
) {
val state = rememberLazyListState()
LaunchedEffect(selectedTabIndex) {
if (selectedTabIndex >= 0) {
state.animateScrollToItem(selectedTabIndex, -(state.layoutInfo.viewportSize.width / 3.5).toInt())
}
}
val focusRequesters = remember(tabs) { List(tabs.size) { FocusRequester() } }
var rowHasFocus by remember { mutableStateOf(false) }
LazyRow(

View file

@ -161,7 +161,7 @@ class SeriesViewModel
} ?: 0
Timber.v("Got initial season index: $index")
position.update {
it.copy(seasonTabIndex = index)
it.copy(seasonTabIndex = index.coerceAtLeast(0))
}
}
}
@ -547,7 +547,10 @@ private suspend fun findIndexOf(
val index =
if (targetId != null && (targetNum == null || targetNum !in pager.indices)) {
// No hint info, so have to check everything
pager.indexOfBlocking { equalsNotNull(it?.id, targetId) }
pager.indexOfBlocking {
equalsNotNull(it?.indexNumber, targetNum) ||
equalsNotNull(it?.id, targetId)
}
} else if (targetNum != null && targetNum in pager.indices) {
// Start searching from the season number and choose direction from there
val num = pager.getBlocking(targetNum)?.indexNumber