SliderState
-
Cmn
class SliderState : DraggableState
Class that holds information about Slider's active range.
Summary
Public companion functions |
||
|---|---|---|
Saver<SliderState, *> |
Saver(steps: Int, trackRange: ClosedFloatingPointRange<Float>)The default |
Cmn
|
Public constructors |
|
|---|---|
@RememberInComposition |
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 |
Whether the slider is vertical. |
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 |
Cmn
|
ClosedFloatingPointRange<Float> |
range of values that Slider values can take. |
Cmn
|
Float |
|
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: ClosedFloatingPointRange<Float> |
range of values that Slider values can take. |
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 |
|
steps: @IntRange(from = 0) Int = 0 |
if positive, specifies the amount of discrete allowable values between the endpoints of |
trackRange: ClosedFloatingPointRange<Float> = 0f..1f |
range of values that Slider values can take. |
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.