Skip to content

RangeSliderPreference ​

RangeSliderPreference is a preference component in Miuix that combines a title/summary with a range slider control. The range slider is placed in the bottom action area of the BasicComponent, making it ideal for settings screens where users need to select a range of values such as price filters, frequency bands, or dual-threshold controls.

Import ​

kotlin
import top.yukonga.miuix.kmp.preference.RangeSliderPreference

Basic Usage ​

kotlin
var rangeValue by remember { mutableStateOf(0.2f..0.8f) }

RangeSliderPreference(
    value = rangeValue,
    onValueChange = { rangeValue = it },
    title = "Range Selection"
)

With Summary ​

kotlin
var priceRange by remember { mutableStateOf(100f..500f) }

RangeSliderPreference(
    value = priceRange,
    onValueChange = { priceRange = it },
    title = "Price Range",
    summary = "$${priceRange.start.roundToInt()} - $${priceRange.endInclusive.roundToInt()}",
    valueRange = 0f..1000f
)

Component States ​

Disabled State ​

kotlin
var rangeValue by remember { mutableStateOf(0.3f..0.7f) }

RangeSliderPreference(
    value = rangeValue,
    onValueChange = { rangeValue = it },
    title = "Disabled Range",
    summary = "This range slider is currently unavailable",
    enabled = false
)

Properties ​

RangeSliderPreference Properties ​

Property NameTypeDescriptionDefault ValueRequired
valueClosedFloatingPointRange<Float>Current values of the range slider. If either value is outside of valueRange, it will be coerced-Yes
onValueChange(ClosedFloatingPointRange<Float>) -> UnitLambda in which values should be updated-Yes
titleString?Title of the preferencenullNo
modifierModifierModifier applied to the componentModifierNo
titleColorBasicComponentColorsTitle text color configurationBasicComponentDefaults.titleColor()No
summaryString?Summary descriptionnullNo
summaryColorBasicComponentColorsSummary text color configurationBasicComponentDefaults.summaryColor()No
startAction@Composable (() -> Unit)?Custom start side contentnullNo
valueTextString?Current slider value text displayed in the end area with summary-style formatting. Rendered inside the Row layout with center-vertical alignment and weightnullNo
endActions@Composable (RowScope.() -> Unit)?Custom end side content, rendered after valueText within the same RownullNo
bottomAction@Composable (() -> Unit)?Custom content at the top of the bottom area, above the range slidernullNo
onClick(() -> Unit)?Callback triggered on click. When non-null, an arrow icon is displayed in the end areanullNo
holdDownStateBooleanWhether the component is in the pressed statefalseNo
enabledBooleanWhether the preference is enabledtrueNo
valueRangeClosedFloatingPointRange<Float>Range of values that range slider values can take. Passed value will be coerced to this range0f..1fNo
stepsIntAmount of discrete allowable values. If 0, the slider will behave continuously. Must not be negative0No
onValueChangeFinished(() -> Unit)?Called when value change has endednullNo
sliderHeightDpHeight of the range sliderSliderDefaults.MinHeightNo
sliderColorsSliderColorsColor configuration of the range sliderSliderDefaults.sliderColors()No
hapticEffectSliderDefaults.SliderHapticEffectType of haptic feedbackSliderDefaults.DefaultHapticEffectNo
showKeyPointsBooleanWhether to show key point indicators on the slider. Only works when keyPoints is not nullfalseNo
keyPointsList<Float>?Custom key point values to display on the slider. If null, uses step positions from steps parameter. Values should be within valueRangenullNo
magnetThresholdFloatMagnetic snap threshold as a fraction (0.0 to 1.0). When slider value is within this distance from a key point, it will snap to that point. Only applies when keyPoints is set0.02fNo
insideMarginPaddingValuesInternal content paddingBasicComponentDefaults.InsideMarginNo

Advanced Usage ​

Price Range Filter ​

kotlin
var priceRange by remember { mutableStateOf(100f..500f) }

RangeSliderPreference(
    value = priceRange,
    onValueChange = { priceRange = it },
    title = "Price Filter",
    summary = "$${priceRange.start.roundToInt()} - $${priceRange.endInclusive.roundToInt()}",
    valueRange = 0f..1000f,
    steps = 99
)

With Start Icon ​

kotlin
var frequencyRange by remember { mutableStateOf(20f..20000f) }

RangeSliderPreference(
    value = frequencyRange,
    onValueChange = { frequencyRange = it },
    title = "Frequency Range",
    summary = "${frequencyRange.start.roundToInt()}Hz - ${frequencyRange.endInclusive.roundToInt()}Hz",
    startAction = {
        Icon(
            imageVector = MiuixIcons.Basic.Audio,
            contentDescription = "Frequency Icon",
            tint = MiuixTheme.colorScheme.onBackground,
            modifier = Modifier.padding(end = 16.dp)
        )
    },
    valueRange = 20f..20000f,
    showKeyPoints = true,
    keyPoints = listOf(20f, 100f, 1000f, 5000f, 10000f, 20000f)
)

With Custom Key Points ​

kotlin
var range by remember { mutableStateOf(20f..80f) }

RangeSliderPreference(
    value = range,
    onValueChange = { range = it },
    title = "Custom Range",
    summary = "${range.start.roundToInt()}% - ${range.endInclusive.roundToInt()}%",
    valueRange = 0f..100f,
    showKeyPoints = true,
    keyPoints = listOf(0f, 20f, 40f, 60f, 80f, 100f),
    magnetThreshold = 0.03f
)

Changelog

Released under the Apache-2.0 License