Yokan / rebuild
Course 1 8624561

EpisodeSeasonSelector.kt

composeApp/src/commonMain/kotlin/eu/friedcutlet/yokan/ui/screens/detail/EpisodeSeasonSelector.kt

implementation59 lines
1package eu.friedcutlet.yokan.ui.screens.detail23import androidx.compose.foundation.layout.Arrangement4import androidx.compose.foundation.layout.PaddingValues5import androidx.compose.foundation.layout.fillMaxWidth6import androidx.compose.foundation.layout.heightIn7import androidx.compose.foundation.lazy.LazyRow8import androidx.compose.foundation.lazy.items9import androidx.compose.foundation.lazy.rememberLazyListState10import androidx.compose.material3.FilterChip11import androidx.compose.material3.Text12import androidx.compose.runtime.Composable13import androidx.compose.runtime.LaunchedEffect14import androidx.compose.ui.Modifier15import androidx.compose.ui.unit.dp16import org.jetbrains.compose.resources.stringResource17import yokan.composeapp.generated.resources.Res18import yokan.composeapp.generated.resources.episodes_all_seasons19import yokan.composeapp.generated.resources.episodes_season_number2021@Composable22internal fun EpisodeSeasonSelector(23    seasons: List<Int>,24    selectedSeason: Int?,25    onSelect: (Int?) -> Unit,26    modifier: Modifier = Modifier,27) {28    if (seasons.isEmpty()) return29    val row = rememberLazyListState()30    LaunchedEffect(seasons, selectedSeason) {31        val index = if (selectedSeason == null) 0 else seasons.indexOf(selectedSeason).let { if (it < 0) 0 else it + 1 }32        val layout = row.layoutInfo33        val item = layout.visibleItemsInfo.firstOrNull { it.index == index }34        if (item == null || item.offset < layout.viewportStartOffset || item.offset + item.size > layout.viewportEndOffset) {35            row.scrollToItem(index)36        }37    }38    LazyRow(39        modifier = modifier.fillMaxWidth(),40        state = row,41        contentPadding = PaddingValues(horizontal = 16.dp, vertical = 4.dp),42        horizontalArrangement = Arrangement.spacedBy(8.dp),43    ) {44        item(key = "all", contentType = "season") {45            FilterChip(46                selected = selectedSeason == null, onClick = { onSelect(null) },47                label = { Text(stringResource(Res.string.episodes_all_seasons)) },48                modifier = Modifier.heightIn(min = 48.dp),49            )50        }51        items(seasons, key = { "season-$it" }, contentType = { "season" }) { season ->52            FilterChip(53                selected = selectedSeason == season, onClick = { onSelect(season) },54                label = { Text(stringResource(Res.string.episodes_season_number, season)) },55                modifier = Modifier.heightIn(min = 48.dp),56            )57        }58    }59}60

Search chapters, reference and source filenames.