mirror of
https://github.com/mihonapp/mihon.git
synced 2025-06-26 02:57:50 +02:00
Cleanup Slider usage
This commit is contained in:
@ -56,7 +56,7 @@ fun ReaderAppBars(
|
||||
enabledPrevious: Boolean,
|
||||
currentPage: Int,
|
||||
totalPages: Int,
|
||||
onSliderValueChange: (Int) -> Unit,
|
||||
onPageIndexChange: (Int) -> Unit,
|
||||
|
||||
readingMode: ReadingMode,
|
||||
onClickReadingMode: () -> Unit,
|
||||
@ -176,9 +176,8 @@ fun ReaderAppBars(
|
||||
enabledPrevious = enabledPrevious,
|
||||
currentPage = currentPage,
|
||||
totalPages = totalPages,
|
||||
onSliderValueChange = onSliderValueChange,
|
||||
onPageIndexChange = onPageIndexChange,
|
||||
)
|
||||
|
||||
BottomReaderBar(
|
||||
backgroundColor = backgroundColor,
|
||||
readingMode = readingMode,
|
||||
|
@ -4,6 +4,7 @@ import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.interaction.collectIsDraggedAsState
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
@ -16,7 +17,6 @@ import androidx.compose.material3.FilledIconButton
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButtonDefaults
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Slider
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.surfaceColorAtElevation
|
||||
import androidx.compose.runtime.Composable
|
||||
@ -29,6 +29,7 @@ import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
||||
import androidx.compose.ui.platform.LocalHapticFeedback
|
||||
import androidx.compose.ui.platform.LocalLayoutDirection
|
||||
@ -38,8 +39,8 @@ import androidx.compose.ui.unit.dp
|
||||
import eu.kanade.presentation.theme.TachiyomiPreviewTheme
|
||||
import eu.kanade.presentation.util.isTabletUi
|
||||
import tachiyomi.i18n.MR
|
||||
import tachiyomi.presentation.core.components.material.Slider
|
||||
import tachiyomi.presentation.core.i18n.stringResource
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
@Composable
|
||||
fun ChapterNavigator(
|
||||
@ -50,7 +51,7 @@ fun ChapterNavigator(
|
||||
enabledPrevious: Boolean,
|
||||
currentPage: Int,
|
||||
totalPages: Int,
|
||||
onSliderValueChange: (Int) -> Unit,
|
||||
onPageIndexChange: (Int) -> Unit,
|
||||
) {
|
||||
val isTabletUi = isTabletUi()
|
||||
val horizontalPadding = if (isTabletUi) 24.dp else 8.dp
|
||||
@ -97,7 +98,11 @@ fun ChapterNavigator(
|
||||
.padding(horizontal = 16.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Text(text = currentPage.toString())
|
||||
Box(contentAlignment = Alignment.CenterEnd) {
|
||||
Text(text = currentPage.toString())
|
||||
// Taking up full length so the slider doesn't shift when 'currentPage' length changes
|
||||
Text(text = totalPages.toString(), color = Color.Transparent)
|
||||
}
|
||||
|
||||
val interactionSource = remember { MutableInteractionSource() }
|
||||
val sliderDragged by interactionSource.collectIsDraggedAsState()
|
||||
@ -110,14 +115,11 @@ fun ChapterNavigator(
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.padding(horizontal = 8.dp),
|
||||
value = currentPage.toFloat(),
|
||||
valueRange = 1f..totalPages.toFloat(),
|
||||
steps = totalPages - 2,
|
||||
onValueChange = {
|
||||
val new = it.roundToInt() - 1
|
||||
if (new != currentPage) {
|
||||
onSliderValueChange(new)
|
||||
}
|
||||
value = currentPage,
|
||||
valueRange = 1..totalPages,
|
||||
onValueChange = f@{
|
||||
if (it == currentPage) return@f
|
||||
onPageIndexChange(it - 1)
|
||||
},
|
||||
interactionSource = interactionSource,
|
||||
)
|
||||
@ -158,7 +160,7 @@ private fun ChapterNavigatorPreview() {
|
||||
enabledPrevious = true,
|
||||
currentPage = currentPage,
|
||||
totalPages = 10,
|
||||
onSliderValueChange = { currentPage = it },
|
||||
onPageIndexChange = { currentPage = (it + 1) },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -401,7 +401,7 @@ class ReaderActivity : BaseActivity() {
|
||||
enabledPrevious = state.viewerChapters?.prevChapter != null,
|
||||
currentPage = state.currentPage,
|
||||
totalPages = state.totalPages,
|
||||
onSliderValueChange = {
|
||||
onPageIndexChange = {
|
||||
isScrollingThroughPages = true
|
||||
moveToPageIndex(it)
|
||||
},
|
||||
|
Reference in New Issue
Block a user