Add haptics to SliderItem

(cherry picked from commit f79f0a7e97a6a754a5fbe621faeda6d0e62993f8)
This commit is contained in:
arkon 2023-10-14 22:47:02 -04:00 committed by Jobobby04
parent 54caea4daa
commit 9584d95638

View File

@ -41,6 +41,8 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import tachiyomi.core.preference.Preference
@ -161,6 +163,8 @@ fun SliderItem(
valueText: String,
onChange: (Int) -> Unit,
) {
val haptic = LocalHapticFeedback.current
Row(
modifier = Modifier
.fillMaxWidth()
@ -181,7 +185,13 @@ fun SliderItem(
Slider(
value = value.toFloat(),
onValueChange = { onChange(it.toInt()) },
onValueChange = {
val newValue = it.toInt()
if (newValue != value) {
onChange(newValue)
haptic.performHapticFeedback(HapticFeedbackType.TextHandleMove)
}
},
modifier = Modifier.weight(1.5f),
valueRange = min.toFloat()..max.toFloat(),
steps = max - min,