Don't try to create slider state when slider can't or won't be rendered (#3941)

This commit is contained in:
AntsyLich
2026-09-12 22:34:39 +06:00
committed by GitHub
parent 6ef6e81814
commit 60e74b8d8f
@@ -77,14 +77,20 @@ fun ChapterNavigator(
) { ) {
val haptic = LocalHapticFeedback.current val haptic = LocalHapticFeedback.current
val state = key(totalPages) { val state = if (totalPages > 1) {
key(totalPages) {
rememberSliderState( rememberSliderState(
value = currentPage.toFloat(), value = currentPage.toFloat(),
steps = totalPages - 2, steps = totalPages - 2,
trackRange = 1f..totalPages.toFloat(), trackRange = 1f..totalPages.toFloat(),
) )
} }
state.value = currentPage.toFloat() .also {
it.value = currentPage.toFloat()
}
} else {
null
}
val interactionSource = remember { MutableInteractionSource() } val interactionSource = remember { MutableInteractionSource() }
val sliderDragged by interactionSource.collectIsDraggedAsState() val sliderDragged by interactionSource.collectIsDraggedAsState()
@@ -149,7 +155,7 @@ fun ChapterNavigator(
@Composable @Composable
fun HorizontalChapterNavigator( fun HorizontalChapterNavigator(
isRtl: Boolean, isRtl: Boolean,
state: SliderState, state: SliderState?,
onNextChapter: () -> Unit, onNextChapter: () -> Unit,
enabledNext: Boolean, enabledNext: Boolean,
onPreviousChapter: () -> Unit, onPreviousChapter: () -> Unit,
@@ -187,7 +193,7 @@ fun HorizontalChapterNavigator(
) )
} }
if (totalPages > 1) { if (state != null) {
CompositionLocalProvider(LocalLayoutDirection provides layoutDirection) { CompositionLocalProvider(LocalLayoutDirection provides layoutDirection) {
Row( Row(
modifier = Modifier modifier = Modifier
@@ -238,7 +244,7 @@ fun HorizontalChapterNavigator(
@Composable @Composable
fun VerticalChapterNavigator( fun VerticalChapterNavigator(
state: SliderState, state: SliderState?,
onNextChapter: () -> Unit, onNextChapter: () -> Unit,
enabledNext: Boolean, enabledNext: Boolean,
onPreviousChapter: () -> Unit, onPreviousChapter: () -> Unit,
@@ -271,7 +277,7 @@ fun VerticalChapterNavigator(
) )
} }
if (totalPages > 1) { if (state != null) {
Column( Column(
modifier = Modifier modifier = Modifier
.weight(1f) .weight(1f)