mirror of
https://github.com/mihonapp/mihon.git
synced 2025-06-26 11:07:51 +02:00
Cleanup Slider usage
This commit is contained in:
@ -28,7 +28,6 @@ import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.RadioButton
|
||||
import androidx.compose.material3.Slider
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
@ -46,6 +45,7 @@ import tachiyomi.core.common.preference.Preference
|
||||
import tachiyomi.core.common.preference.TriState
|
||||
import tachiyomi.core.common.preference.toggle
|
||||
import tachiyomi.presentation.core.components.material.DISABLED_ALPHA
|
||||
import tachiyomi.presentation.core.components.material.Slider
|
||||
import tachiyomi.presentation.core.components.material.padding
|
||||
import tachiyomi.presentation.core.i18n.stringResource
|
||||
import tachiyomi.presentation.core.theme.header
|
||||
@ -192,17 +192,14 @@ fun SliderItem(
|
||||
}
|
||||
|
||||
Slider(
|
||||
value = value.toFloat(),
|
||||
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 - 1,
|
||||
value = value,
|
||||
onValueChange = f@{
|
||||
if (it == value) return@f
|
||||
onChange(it)
|
||||
haptic.performHapticFeedback(HapticFeedbackType.TextHandleMove)
|
||||
},
|
||||
valueRange = min..max,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,48 @@
|
||||
package tachiyomi.presentation.core.components.material
|
||||
|
||||
import androidx.annotation.IntRange
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.material3.Slider
|
||||
import androidx.compose.material3.SliderColors
|
||||
import androidx.compose.material3.SliderDefaults
|
||||
import androidx.compose.material3.SliderState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Modifier
|
||||
|
||||
@Composable
|
||||
fun Slider(
|
||||
value: Int,
|
||||
onValueChange: (Int) -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
enabled: Boolean = true,
|
||||
valueRange: ClosedRange<Int> = 0..1,
|
||||
@IntRange(from = 0) steps: Int = with(valueRange) { (endInclusive - start) - 1 },
|
||||
onValueChangeFinished: (() -> Unit)? = null,
|
||||
colors: SliderColors = SliderDefaults.colors(),
|
||||
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
|
||||
thumb: @Composable (SliderState) -> Unit = {
|
||||
SliderDefaults.Thumb(
|
||||
interactionSource = interactionSource,
|
||||
colors = colors,
|
||||
enabled = enabled,
|
||||
)
|
||||
},
|
||||
track: @Composable (SliderState) -> Unit = { sliderState ->
|
||||
SliderDefaults.Track(colors = colors, enabled = enabled, sliderState = sliderState)
|
||||
},
|
||||
) {
|
||||
Slider(
|
||||
value = value.toFloat(),
|
||||
onValueChange = { onValueChange(it.toInt()) },
|
||||
modifier = modifier,
|
||||
enabled = enabled,
|
||||
valueRange = with(valueRange) { start.toFloat()..endInclusive.toFloat() },
|
||||
steps = steps,
|
||||
onValueChangeFinished = onValueChangeFinished,
|
||||
colors = colors,
|
||||
interactionSource = interactionSource,
|
||||
thumb = thumb,
|
||||
track = track,
|
||||
)
|
||||
}
|
Reference in New Issue
Block a user