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,20 +90,19 @@ fun ChapterNavigator(
val backgroundColor = MaterialTheme.colorScheme val backgroundColor = MaterialTheme.colorScheme
.surfaceColorAtElevation(3.dp) .surfaceColorAtElevation(3.dp)
.copy(alpha = if (isSystemInDarkTheme()) 0.9f else 0.95f) .copy(alpha = if (isSystemInDarkTheme()) 0.9f else 0.95f)
val buttonColor = IconButtonDefaults.filledIconButtonColors(
val isLeftEnabled = if (isRtl) enabledNext else enabledPrevious containerColor = backgroundColor,
if (isLeftEnabled) { disabledContainerColor = backgroundColor,
FilledIconButton( )
onClick = if (isRtl) onNextChapter else onPreviousChapter, FilledIconButton(
colors = IconButtonDefaults.filledIconButtonColors( enabled = if (isRtl) enabledNext else enabledPrevious,
containerColor = backgroundColor, onClick = if (isRtl) onNextChapter else onPreviousChapter,
), colors = buttonColor,
) { ) {
Icon( Icon(
imageVector = Icons.Outlined.SkipPrevious, imageVector = Icons.Outlined.SkipPrevious,
contentDescription = stringResource(if (isRtl) R.string.action_next_chapter else R.string.action_previous_chapter), contentDescription = stringResource(if (isRtl) R.string.action_next_chapter else R.string.action_previous_chapter),
) )
}
} }
if (totalPages > 1) { if (totalPages > 1) {
@ -133,7 +132,7 @@ fun ChapterNavigator(
.padding(horizontal = 8.dp), .padding(horizontal = 8.dp),
value = currentPage.toFloat(), value = currentPage.toFloat(),
valueRange = 1f..totalPages.toFloat(), valueRange = 1f..totalPages.toFloat(),
steps = totalPages, steps = totalPages - 2,
onValueChange = { onValueChange = {
onSliderValueChange(it.toInt() - 1) onSliderValueChange(it.toInt() - 1)
}, },
@ -147,19 +146,15 @@ fun ChapterNavigator(
Spacer(Modifier.weight(1f)) Spacer(Modifier.weight(1f))
} }
val isRightEnabled = if (isRtl) enabledPrevious else enabledNext FilledIconButton(
if (isRightEnabled) { enabled = if (isRtl) enabledPrevious else enabledNext,
FilledIconButton( onClick = if (isRtl) onPreviousChapter else onNextChapter,
onClick = if (isRtl) onPreviousChapter else onNextChapter, colors = buttonColor,
colors = IconButtonDefaults.filledIconButtonColors( ) {
containerColor = backgroundColor, Icon(
), imageVector = Icons.Outlined.SkipNext,
) { contentDescription = stringResource(if (isRtl) R.string.action_previous_chapter else R.string.action_next_chapter),
Icon( )
imageVector = Icons.Outlined.SkipNext,
contentDescription = stringResource(if (isRtl) R.string.action_previous_chapter else R.string.action_next_chapter),
)
}
} }
} }
} }
@ -194,19 +189,20 @@ fun ChapterNavigatorVert(
.surfaceColorAtElevation(3.dp) .surfaceColorAtElevation(3.dp)
.copy(alpha = if (isSystemInDarkTheme()) 0.9f else 0.95f) .copy(alpha = if (isSystemInDarkTheme()) 0.9f else 0.95f)
if (enabledPrevious) { val buttonColor = IconButtonDefaults.filledIconButtonColors(
FilledIconButton( containerColor = backgroundColor,
onClick = onPreviousChapter, disabledContainerColor = backgroundColor,
colors = IconButtonDefaults.filledIconButtonColors( )
containerColor = backgroundColor, FilledIconButton(
), enabled = enabledPrevious,
) { onClick = onPreviousChapter,
Icon( colors = buttonColor,
imageVector = Icons.Outlined.SkipPrevious, ) {
contentDescription = stringResource(R.string.action_previous_chapter), Icon(
modifier = Modifier.rotate(90f), imageVector = Icons.Outlined.SkipPrevious,
) contentDescription = stringResource(R.string.action_previous_chapter),
} modifier = Modifier.rotate(90f),
)
} }
if (totalPages > 1) { if (totalPages > 1) {
@ -265,19 +261,16 @@ fun ChapterNavigatorVert(
Spacer(Modifier.weight(1f)) Spacer(Modifier.weight(1f))
} }
if (enabledNext) { FilledIconButton(
FilledIconButton( enabled = enabledNext,
onClick = onNextChapter, onClick = onNextChapter,
colors = IconButtonDefaults.filledIconButtonColors( colors = buttonColor,
containerColor = backgroundColor, ) {
), Icon(
) { imageVector = Icons.Outlined.SkipNext,
Icon( contentDescription = stringResource(R.string.action_next_chapter),
imageVector = Icons.Outlined.SkipNext, modifier = Modifier.rotate(90f),
contentDescription = stringResource(R.string.action_next_chapter), )
modifier = Modifier.rotate(90f),
)
}
} }
} }
} }