public class SliderState public constructor(
value: Float = 0f,
@IntRange(from = 0) public val steps: Int = 0,
public val trackRange: ClosedFloatingPointRange<Float> = 0f..1f,
) : DraggableState
Class that holds information about Slider's active range.
Parameters
| value | Float that indicates the initial position of the thumb. If outside of trackRange provided, value will be coerced to this range. |
| steps | 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 | range of values that Slider values can take. value will be coerced to this range. |
Properties
value
public var value: Float
Float that indicates the value that the thumb currently is in respect to the track.
shouldAutoSnap
@get:JvmName("shouldAutoSnap") public var shouldAutoSnap: Boolean = true
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.
coercedValueAsFraction
public 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
public var isDragging: Boolean by mutableStateOf(false)
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.
Functions
drag
override suspend fun drag(
dragPriority: MutatePriority,
block: suspend DragScope.() -> Unit,
): Unit
dispatchRawDelta
override fun dispatchRawDelta(delta: Float)
Members
Companion
public companion object
Functions
Saver
public fun Saver(
steps: Int,
trackRange: ClosedFloatingPointRange<Float>,
): Saver<SliderState, *>
The default Saver implementation for SliderState.
Parameters
| steps | if positive, specifies the amount of discrete allowable values between the endpoints of trackRange. |
| trackRange | range of values that Slider values can take. value will be coerced to this range. |