Don't try to create slider state when slider can't or won't be rendered (#3941)
This commit is contained in:
@@ -77,14 +77,20 @@ fun ChapterNavigator(
|
||||
) {
|
||||
val haptic = LocalHapticFeedback.current
|
||||
|
||||
val state = key(totalPages) {
|
||||
val state = if (totalPages > 1) {
|
||||
key(totalPages) {
|
||||
rememberSliderState(
|
||||
value = currentPage.toFloat(),
|
||||
steps = totalPages - 2,
|
||||
trackRange = 1f..totalPages.toFloat(),
|
||||
)
|
||||
}
|
||||
state.value = currentPage.toFloat()
|
||||
.also {
|
||||
it.value = currentPage.toFloat()
|
||||
}
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
val interactionSource = remember { MutableInteractionSource() }
|
||||
val sliderDragged by interactionSource.collectIsDraggedAsState()
|
||||
@@ -149,7 +155,7 @@ fun ChapterNavigator(
|
||||
@Composable
|
||||
fun HorizontalChapterNavigator(
|
||||
isRtl: Boolean,
|
||||
state: SliderState,
|
||||
state: SliderState?,
|
||||
onNextChapter: () -> Unit,
|
||||
enabledNext: Boolean,
|
||||
onPreviousChapter: () -> Unit,
|
||||
@@ -187,7 +193,7 @@ fun HorizontalChapterNavigator(
|
||||
)
|
||||
}
|
||||
|
||||
if (totalPages > 1) {
|
||||
if (state != null) {
|
||||
CompositionLocalProvider(LocalLayoutDirection provides layoutDirection) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
@@ -238,7 +244,7 @@ fun HorizontalChapterNavigator(
|
||||
|
||||
@Composable
|
||||
fun VerticalChapterNavigator(
|
||||
state: SliderState,
|
||||
state: SliderState?,
|
||||
onNextChapter: () -> Unit,
|
||||
enabledNext: Boolean,
|
||||
onPreviousChapter: () -> Unit,
|
||||
@@ -271,7 +277,7 @@ fun VerticalChapterNavigator(
|
||||
)
|
||||
}
|
||||
|
||||
if (totalPages > 1) {
|
||||
if (state != null) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
|
||||
Reference in New Issue
Block a user