{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

SliderState

@ExperimentalMaterial3Api
public final class SliderState implements DraggableState


Class that holds information about Slider's active range.

Summary

Public constructors

SliderState(
    float value,
    @IntRange int steps,
    Function0<Unit> onValueChangeFinished,
    @NonNull ClosedFloatingPointRange<@NonNull Float> valueRange
)

Public methods

void
dispatchRawDelta(float delta)

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

void
drag(
    @NonNull MutatePriority dragPriority,
    @ExtensionFunctionType @NonNull SuspendFunction1<@NonNull DragScopeUnit> block
)

Call this function to take control of drag logic.

final Function0<Unit>

lambda to be invoked when value change has ended.

final int

if greater than 0, specifies the amounts of discrete values, evenly distributed between across the whole value range.

final float

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

final @NonNull ClosedFloatingPointRange<@NonNull Float>

range of values that Slider values can take.

final void
setValue(float value)

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

Public constructors

SliderState

public SliderState(
    float value,
    @IntRange int steps,
    Function0<Unit> onValueChangeFinished,
    @NonNull ClosedFloatingPointRange<@NonNull Float> valueRange
)
Parameters
float value

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

@IntRange int steps

if greater than 0, specifies the amounts of discrete values, evenly distributed between across the whole value range. If 0, range slider will behave as a continuous slider and allow to choose any value from the range specified. Must not be negative.

Function0<Unit> onValueChangeFinished

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.

@NonNull ClosedFloatingPointRange<@NonNull Float> valueRange

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

Public methods

dispatchRawDelta

public void dispatchRawDelta(float delta)

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
float delta

amount of scroll dispatched in the nested drag process

drag

public void drag(
    @NonNull MutatePriority dragPriority,
    @ExtensionFunctionType @NonNull SuspendFunction1<@NonNull DragScopeUnit> block
)

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
@NonNull MutatePriority dragPriority

of the drag operation

@ExtensionFunctionType @NonNull SuspendFunction1<@NonNull DragScopeUnit> block

to perform drag in

getOnValueChangeFinished

public final Function0<UnitgetOnValueChangeFinished()

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.

getSteps

public final int getSteps()

if greater than 0, specifies the amounts of discrete values, evenly distributed between across the whole value range. If 0, range slider will behave as a continuous slider and allow to choose any value from the range specified. Must not be negative.

getValue

public final float getValue()

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

getValueRange

public final @NonNull ClosedFloatingPointRange<@NonNull FloatgetValueRange()

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

setValue

public final void setValue(float value)

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