SliderState


Class that holds information about Slider's active range.

Summary

Public companion functions

Saver<SliderState, *>
Saver(steps: Int, trackRange: ClosedFloatingPointRange<Float>)

The default Saver implementation for SliderState.

Cmn

Public constructors

@RememberInComposition
SliderState(
    value: Float,
    steps: @IntRange(from = 0) Int,
    trackRange: ClosedFloatingPointRange<Float>
)
Cmn

Public functions

open Unit

Dispatch drag delta in pixels avoiding all drag related priority mechanisms.

Cmn
open suspend Unit
drag(dragPriority: MutatePriority, block: suspend DragScope.() -> Unit)

Call this function to take control of drag logic.

Cmn

Public properties

Float

The fraction of the track that the thumb currently occupies.

Cmn
Boolean

Indicates whether the slider is currently being dragged.

Cmn
Boolean

Controls the auto-snapping mechanism for slider steps.

Cmn
@IntRange(from = 0) Int

if positive, specifies the amount of discrete allowable values between the endpoints of trackRange.

Cmn
ClosedFloatingPointRange<Float>

range of values that Slider values can take.

Cmn
Float

Float that indicates the value that the thumb currently is in respect to the track.

Cmn

Public companion functions

Saver

fun Saver(steps: Int, trackRange: ClosedFloatingPointRange<Float>): Saver<SliderState, *>

The default Saver implementation for SliderState.

Parameters
steps: Int

if positive, specifies the amount of discrete allowable values between the endpoints of trackRange.

trackRange: ClosedFloatingPointRange<Float>

range of values that Slider values can take. value will be coerced to this range.

Public constructors

SliderState

@RememberInComposition
SliderState(
    value: Float = 0.0f,
    steps: @IntRange(from = 0) Int = 0,
    trackRange: ClosedFloatingPointRange<Float> = 0f..1f
)
Parameters
value: Float = 0.0f

Float that indicates the initial position of the thumb. If outside of trackRange provided, value will be coerced to this range.

steps: @IntRange(from = 0) Int = 0

if positive, specifies the amount of discrete allowable values between the endpoints of trackRange. 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.

trackRange: ClosedFloatingPointRange<Float> = 0f..1f

range of values that Slider values can take. value will be coerced to this range.

Public functions

dispatchRawDelta

open fun dispatchRawDelta(delta: Float): Unit

Dispatch drag delta in pixels avoiding all drag related priority mechanisms.

NOTE: unlike drag, dispatching any delta with this method will bypass scrolling of any priority. This method will also ignore reverseDirection and other parameters set in draggable.

This method is used internally for low level operations, allowing implementers of DraggableState influence the consumption as suits them, e.g. introduce nested scrolling. Manually dispatching delta via this method will likely result in a bad user experience, you must prefer drag method over this one.

Parameters
delta: Float

amount of scroll dispatched in the nested drag process

drag

open suspend fun drag(
    dragPriority: MutatePriority = MutatePriority.Default,
    block: suspend DragScope.() -> Unit
): Unit

Call this function to take control of drag logic.

All actions that change the logical drag position must be performed within a drag block (even if they don't call any other methods on this object) in order to guarantee that mutual exclusion is enforced.

If drag is called from elsewhere with the dragPriority higher or equal to ongoing drag, ongoing drag will be canceled.

Parameters
dragPriority: MutatePriority = MutatePriority.Default

of the drag operation

block: suspend DragScope.() -> Unit

to perform drag in

Public properties

coercedValueAsFraction

val coercedValueAsFraction: Float

The fraction of the track that the thumb currently occupies.

The value is coerced (clamped) to the bounds of trackRange before calculating its fractional position (from 0f to 1f) on the track.

isDragging

val isDragging: Boolean

Indicates whether the slider is currently being dragged.

This is set to true when a drag gesture starts (either via user touch interaction or programmatically via drag) and set back to false when the gesture completes or is cancelled.

shouldAutoSnap

var shouldAutoSnap: Boolean

Controls the auto-snapping mechanism for slider steps.

When true (default), any updates to value will automatically snap to the nearest tick fraction based on the number of steps.

Disabling auto-snapping (false) allows value to be set to any continuous value between trackRange without snapping. This is particularly useful for programmatic animations, smooth transitions, or custom drag gestures where discrete step snapping is temporarily or permanently undesired.

Since this is defined on the state, it can be dynamically toggled during gestures or animations without triggering a full layout recomposition.

steps

val steps: @IntRange(from = 0) Int

if positive, specifies the amount of discrete allowable values between the endpoints of trackRange. 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.

trackRange

val trackRange: ClosedFloatingPointRange<Float>

range of values that Slider values can take. value will be coerced to this range.

value

var value: Float

Float that indicates the value that the thumb currently is in respect to the track.