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

DrawerState

public final class DrawerState


State of the ModalNavigationDrawer and DismissibleNavigationDrawer composable.

Summary

Nested types

public static class DrawerState.Companion

Public constructors

DrawerState(
    @NonNull DrawerValue initialValue,
    @NonNull Function1<@NonNull DrawerValue, @NonNull Boolean> confirmStateChange
)

Public methods

final void
animateTo(
    @NonNull DrawerValue targetValue,
    @NonNull AnimationSpec<@NonNull Float> anim
)

This method is deprecated. This method has been replaced by the open and close methods.

final void

Close the drawer with animation and suspend until it if fully closed or animation has been cancelled.

final float

The current position (in pixels) of the drawer sheet, or Float.NaN before the offset is initialized.

final @NonNull DrawerValue

The current value of the state.

final @NonNull State<@NonNull Float>

The current position (in pixels) of the drawer sheet, or Float.NaN before the offset is initialized.

final @NonNull DrawerValue

The target value of the drawer state.

final boolean

Whether the state is currently animating.

final boolean

Whether the drawer is closed.

final boolean

Whether the drawer is open.

final void

Open the drawer with animation and suspend until it if fully opened or animation has been cancelled.

final void
snapTo(@NonNull DrawerValue targetValue)

Set the state without any animation and suspend until it's set

Public constructors

DrawerState

public DrawerState(
    @NonNull DrawerValue initialValue,
    @NonNull Function1<@NonNull DrawerValue, @NonNull Boolean> confirmStateChange
)
Parameters
@NonNull DrawerValue initialValue

The initial value of the state.

@NonNull Function1<@NonNull DrawerValue, @NonNull Boolean> confirmStateChange

Optional callback invoked to confirm or veto a pending state change.

Public methods

animateTo

public final void animateTo(
    @NonNull DrawerValue targetValue,
    @NonNull AnimationSpec<@NonNull Float> anim
)

Set the state of the drawer with specific animation

Parameters
@NonNull DrawerValue targetValue

The new value to animate to.

@NonNull AnimationSpec<@NonNull Float> anim

The animation that will be used to animate to the new value.

close

public final void close()

Close the drawer with animation and suspend until it if fully closed or animation has been cancelled. This method will throw CancellationException if the animation is interrupted

Returns
void

the reason the close animation ended

getCurrentOffset

public final float getCurrentOffset()

The current position (in pixels) of the drawer sheet, or Float.NaN before the offset is initialized.

See also
offset

for more information.

getCurrentValue

public final @NonNull DrawerValue getCurrentValue()

The current value of the state.

If no swipe or animation is in progress, this corresponds to the start the drawer currently in. If a swipe or an animation is in progress, this corresponds the state drawer was in before the swipe or animation started.

getOffset

public final @NonNull State<@NonNull FloatgetOffset()

The current position (in pixels) of the drawer sheet, or Float.NaN before the offset is initialized.

See also
offset

for more information.

getTargetValue

public final @NonNull DrawerValue getTargetValue()

The target value of the drawer state.

If a swipe is in progress, this is the value that the Drawer would animate to if the swipe finishes. If an animation is running, this is the target value of that animation. Finally, if no swipe or animation is in progress, this is the same as the currentValue.

isAnimationRunning

public final boolean isAnimationRunning()

Whether the state is currently animating.

isClosed

public final boolean isClosed()

Whether the drawer is closed.

isOpen

public final boolean isOpen()

Whether the drawer is open.

open

public final void open()

Open the drawer with animation and suspend until it if fully opened or animation has been cancelled. This method will throw CancellationException if the animation is interrupted

Returns
void

the reason the open animation ended

snapTo

public final void snapTo(@NonNull DrawerValue targetValue)

Set the state without any animation and suspend until it's set

Parameters
@NonNull DrawerValue targetValue

The new target value