ChapterNavigator: Always show buttons and fix steps visual (#9461)

(cherry picked from commit f0dd33ee4cf0a355eb9729d723ca78c80340973a)
This commit is contained in:
Ivan Iskandar 2023-05-06 22:15:39 +07:00 committed by Jobobby04
parent 02bc69fc22
commit c2e35a7806

View File

@ -90,21 +90,20 @@ fun ChapterNavigator(
val backgroundColor = MaterialTheme.colorScheme
.surfaceColorAtElevation(3.dp)
.copy(alpha = if (isSystemInDarkTheme()) 0.9f else 0.95f)
val isLeftEnabled = if (isRtl) enabledNext else enabledPrevious
if (isLeftEnabled) {
FilledIconButton(
onClick = if (isRtl) onNextChapter else onPreviousChapter,
colors = IconButtonDefaults.filledIconButtonColors(
val buttonColor = IconButtonDefaults.filledIconButtonColors(
containerColor = backgroundColor,
),
disabledContainerColor = backgroundColor,
)
FilledIconButton(
enabled = if (isRtl) enabledNext else enabledPrevious,
onClick = if (isRtl) onNextChapter else onPreviousChapter,
colors = buttonColor,
) {
Icon(
imageVector = Icons.Outlined.SkipPrevious,
contentDescription = stringResource(if (isRtl) R.string.action_next_chapter else R.string.action_previous_chapter),
)
}
}
if (totalPages > 1) {
CompositionLocalProvider(LocalLayoutDirection provides layoutDirection) {
@ -133,7 +132,7 @@ fun ChapterNavigator(
.padding(horizontal = 8.dp),
value = currentPage.toFloat(),
valueRange = 1f..totalPages.toFloat(),
steps = totalPages,
steps = totalPages - 2,
onValueChange = {
onSliderValueChange(it.toInt() - 1)
},
@ -147,13 +146,10 @@ fun ChapterNavigator(
Spacer(Modifier.weight(1f))
}
val isRightEnabled = if (isRtl) enabledPrevious else enabledNext
if (isRightEnabled) {
FilledIconButton(
enabled = if (isRtl) enabledPrevious else enabledNext,
onClick = if (isRtl) onPreviousChapter else onNextChapter,
colors = IconButtonDefaults.filledIconButtonColors(
containerColor = backgroundColor,
),
colors = buttonColor,
) {
Icon(
imageVector = Icons.Outlined.SkipNext,
@ -162,7 +158,6 @@ fun ChapterNavigator(
}
}
}
}
}
@Composable
@ -194,12 +189,14 @@ fun ChapterNavigatorVert(
.surfaceColorAtElevation(3.dp)
.copy(alpha = if (isSystemInDarkTheme()) 0.9f else 0.95f)
if (enabledPrevious) {
FilledIconButton(
onClick = onPreviousChapter,
colors = IconButtonDefaults.filledIconButtonColors(
val buttonColor = IconButtonDefaults.filledIconButtonColors(
containerColor = backgroundColor,
),
disabledContainerColor = backgroundColor,
)
FilledIconButton(
enabled = enabledPrevious,
onClick = onPreviousChapter,
colors = buttonColor,
) {
Icon(
imageVector = Icons.Outlined.SkipPrevious,
@ -207,7 +204,6 @@ fun ChapterNavigatorVert(
modifier = Modifier.rotate(90f),
)
}
}
if (totalPages > 1) {
Column(
@ -265,12 +261,10 @@ fun ChapterNavigatorVert(
Spacer(Modifier.weight(1f))
}
if (enabledNext) {
FilledIconButton(
enabled = enabledNext,
onClick = onNextChapter,
colors = IconButtonDefaults.filledIconButtonColors(
containerColor = backgroundColor,
),
colors = buttonColor,
) {
Icon(
imageVector = Icons.Outlined.SkipNext,
@ -279,5 +273,4 @@ fun ChapterNavigatorVert(
)
}
}
}
}