SliderState
-
Cmn
@ExperimentalMaterial3Api
class SliderState : DraggableState
Class that holds information about Slider's active range.
Summary
Public companion functions |
||
|---|---|---|
Saver<SliderState, *> |
Saver(The default |
Cmn
|
Public constructors |
|
|---|---|
SliderState( |
Cmn
|
Public functions |
||
|---|---|---|
open Unit |
dispatchRawDelta(delta: Float)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 is in. |
Cmn
|
Boolean |
Cmn
|
|
((Float) -> Unit)? |
Callback in which value should be updated. |
Cmn
|
(() -> Unit)? |
lambda to be invoked when value change has ended. |
Cmn
|
Boolean |
Controls the auto-snapping mechanism, disabling it may be useful for custom animations. |
Cmn
|
Int |
if positive, specifies the amount of discrete allowable values between the endpoints of |
Cmn
|
Float |
|
Cmn
|
ClosedFloatingPointRange<Float> |
range of values that Slider values can take. |
Cmn
|
Public companion functions
Saver
fun Saver(
onValueChangeFinished: (() -> Unit)?,
valueRange: ClosedFloatingPointRange<Float>
): Saver<SliderState, *>
The default Saver implementation for SliderState.
| Parameters | |
|---|---|
onValueChangeFinished: (() -> Unit)? |
lambda to be invoked when value change has ended. This callback shouldn't be used to update the range slider values (use |
valueRange: ClosedFloatingPointRange<Float> |
range of values that Slider values can take. |
Public constructors
SliderState
SliderState(
value: Float = 0.0f,
steps: @IntRange(from = 0) Int = 0,
onValueChangeFinished: (() -> Unit)? = null,
valueRange: 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 |
onValueChangeFinished: (() -> Unit)? = null |
lambda to be invoked when value change has ended. This callback shouldn't be used to update the range slider values (use |
valueRange: ClosedFloatingPointRange<Float> = 0f..1f |
range of values that Slider values can take. |
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, 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 |
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 is in.
onValueChangeFinished
var onValueChangeFinished: (() -> Unit)?
lambda to be invoked when value change has ended. This callback shouldn't be used to update the range slider values (use onValueChange for that), but rather to know when the user has completed selecting a new value by ending a drag or a click.
shouldAutoSnap
var shouldAutoSnap: Boolean
Controls the auto-snapping mechanism, disabling it may be useful for custom animations.
steps
val steps: Int
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.
value
var value: Float
Float that indicates the value that the thumb currently is in respect to the track.
valueRange
val valueRange: ClosedFloatingPointRange<Float>
range of values that Slider values can take. value will be coerced to this range.