Compose Component

RangeSlider

Material Design range slider Range Sliders expand upon Slider using the same concepts but allow the user to select 2 values.

RangeSlider social preview

RangeSlider

Source set: Common
@Deprecated(
    message =
        "Use the RangeSlider overload that accepts RangeSliderState, onValueChange, and onValueChangeFinished instead.",
    replaceWith =
        ReplaceWith(
            "RangeSlider(state = rememberRangeSliderState(value.start, value.endInclusive, steps, trackRange = valueRange), onValueChange = onValueChange, modifier = modifier, enabled = enabled, onValueChangeFinished = onValueChangeFinished, colors = colors)"
        ),
)
@Composable
public fun RangeSlider(
    value: ClosedFloatingPointRange<Float>,
    onValueChange: (ClosedFloatingPointRange<Float>) -> Unit,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    valueRange: ClosedFloatingPointRange<Float> = 0f..1f,
    @IntRange(from = 0) steps: Int = 0,
    onValueChangeFinished: (() -> Unit)? = null,
    colors: SliderColors = SliderDefaults.colors(),
)

Parameters

value current values of the RangeSlider. If either value is outside of valueRange provided, it will be coerced to this range.
onValueChange lambda in which values should be updated
modifier modifiers for the Range Slider layout
enabled whether or not component is enabled and can we interacted with or not
valueRange range of values that Range Slider values can take. Passed value will be coerced to this range
steps if positive, specifies the amount of discrete allowable values between the endpoints of valueRange. For example, a range from 0 to 10 with 4 steps allows 4 values evenly distributed between 0 and 10 (i.e., 2, 4, 6, 8). If steps is 0, the slider will behave continuously and allow any value from the range. Must not be negative.
onValueChangeFinished called when value change has ended. This should not be used to update the range slider value (use onValueChange instead), but rather to know when the user has completed selecting a new value by ending a drag or a click. For keyboard movements, this is called on every step.
colors SliderColors that will be used to determine the color of the Range Slider parts in different state. See SliderDefaults.colors to customize.

RangeSlider

Source set: Common
@Composable
public fun RangeSlider(
    state: RangeSliderState,
    onValueChange: (ClosedFloatingPointRange<Float>) -> Unit,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    onValueChangeFinished: (() -> Unit)? = null,
    colors: SliderColors = SliderDefaults.colors(),
    startThumbInteractionSource: MutableInteractionSource = remember { MutableInteractionSource() },
    endThumbInteractionSource: MutableInteractionSource = remember { MutableInteractionSource() },
    startThumb: @Composable (RangeSliderState) -> Unit = {
        SliderDefaults.Thumb(
            interactionSource = startThumbInteractionSource,
            colors = colors,
            enabled = enabled,
        )
    },
    endThumb: @Composable (RangeSliderState) -> Unit = {
        SliderDefaults.Thumb(
            interactionSource = endThumbInteractionSource,
            colors = colors,
            enabled = enabled,
        )
    },
    track: @Composable (RangeSliderState) -> Unit = { rangeSliderState ->
        SliderDefaults.Track(
            colors = colors,
            enabled = enabled,
            rangeSliderState = rangeSliderState,
        )
    },
)

Parameters

state RangeSliderState which contains the current values of the RangeSlider.
onValueChange callback in which values should be updated from the state (e.g. state.startValue = it.start and state.endValue = it.endInclusive)
modifier modifiers for the Range Slider layout
enabled whether or not component is enabled and can we interacted with or not
onValueChangeFinished called when value change has ended. This should not be used to update the range slider value (use onValueChange instead), but rather to know when the user has completed selecting a new value by ending a drag or a click. For keyboard movements, this is called on every step.
colors SliderColors that will be used to determine the color of the Range Slider parts in different state. See SliderDefaults.colors to customize.
startThumbInteractionSource the MutableInteractionSource representing the stream of Interactions for the start thumb. You can create and pass in your own remembered instance to observe.
endThumbInteractionSource the MutableInteractionSource representing the stream of Interactions for the end thumb. You can create and pass in your own remembered instance to observe.
startThumb the start thumb to be displayed on the Range Slider. The lambda receives a RangeSliderState which is used to obtain the current active track.
endThumb the end thumb to be displayed on the Range Slider. The lambda receives a RangeSliderState which is used to obtain the current active track.
track the track to be displayed on the range slider, it is placed underneath the thumb. The lambda receives a RangeSliderState which is used to obtain the current active track.

RangeSlider

Source set: Common
@Deprecated(message = "Maintained for binary compatibility.", level = DeprecationLevel.HIDDEN)
@Composable
public fun RangeSlider(
    state: RangeSliderState,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    onValueChange: ((ClosedFloatingPointRange<Float>) -> Unit)? = null,
    onValueChangeFinished: (() -> Unit)? = null,
    colors: SliderColors = SliderDefaults.colors(),
    startThumbInteractionSource: MutableInteractionSource = remember { MutableInteractionSource() },
    endThumbInteractionSource: MutableInteractionSource = remember { MutableInteractionSource() },
    startThumb: @Composable (RangeSliderState) -> Unit = {
        SliderDefaults.Thumb(
            interactionSource = startThumbInteractionSource,
            colors = colors,
            enabled = enabled,
        )
    },
    endThumb: @Composable (RangeSliderState) -> Unit = {
        SliderDefaults.Thumb(
            interactionSource = endThumbInteractionSource,
            colors = colors,
            enabled = enabled,
        )
    },
    track: @Composable (RangeSliderState) -> Unit = { rangeSliderState ->
        SliderDefaults.Track(
            colors = colors,
            enabled = enabled,
            rangeSliderState = rangeSliderState,
        )
    },
)

Parameters

state RangeSliderState which contains the current values of the RangeSlider.
modifier modifiers for the Range Slider layout
enabled whether or not component is enabled and can we interacted with or not
onValueChange callback in which values should be updated
onValueChangeFinished called when value change has ended. This should not be used to update the range slider value (use onValueChange instead), but rather to know when the user has completed selecting a new value by ending a drag or a click. For keyboard movements, this is called on every step.
colors SliderColors that will be used to determine the color of the Range Slider parts in different state. See SliderDefaults.colors to customize.
startThumbInteractionSource the MutableInteractionSource representing the stream of Interactions for the start thumb. You can create and pass in your own remembered instance to observe.
endThumbInteractionSource the MutableInteractionSource representing the stream of Interactions for the end thumb. You can create and pass in your own remembered instance to observe.
startThumb the start thumb to be displayed on the Range Slider. The lambda receives a RangeSliderState which is used to obtain the current active track.
endThumb the end thumb to be displayed on the Range Slider. The lambda receives a RangeSliderState which is used to obtain the current active track.
track the track to be displayed on the range slider, it is placed underneath the thumb. The lambda receives a RangeSliderState which is used to obtain the current active track.

Content updated: