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

SheetState

@ExperimentalMaterial3Api
public final class SheetState


State of a sheet composable, such as ModalBottomSheet

Contains states relating to its swipe position as well as animations between state values.

Summary

Nested types

public static class SheetState.Companion

Public constructors

SheetState(
    boolean skipPartiallyExpanded,
    @NonNull SheetValue initialValue,
    @NonNull Function1<@NonNull SheetValue, @NonNull Boolean> confirmValueChange,
    boolean skipHiddenState
)

This method is deprecated. This constructor is deprecated.

@ExperimentalMaterial3Api
SheetState(
    boolean skipPartiallyExpanded,
    @NonNull Density density,
    @NonNull SheetValue initialValue,
    @NonNull Function1<@NonNull SheetValue, @NonNull Boolean> confirmValueChange,
    boolean skipHiddenState
)

State of a sheet composable, such as ModalBottomSheet

Public methods

final void

Fully expand the bottom sheet with animation and suspend until it is fully expanded or animation has been cancelled.

final @NonNull SheetValue

The current value of the state.

final boolean

Whether the sheet has an expanded state defined.

final boolean

Whether the modal bottom sheet has a partially expanded state defined.

final @NonNull SheetValue

The target value of the bottom sheet state.

final void

Hide the bottom sheet with animation and suspend until it is fully hidden or animation has been cancelled.

final boolean

Whether the modal bottom sheet is visible.

final void

Animate the bottom sheet and suspend until it is partially expanded or animation has been cancelled.

final float

Require the current offset (in pixels) of the bottom sheet.

final void

Expand the bottom sheet with animation and suspend until it is PartiallyExpanded if defined else Expanded.

Public constructors

SheetState

public SheetState(
    boolean skipPartiallyExpanded,
    @NonNull SheetValue initialValue,
    @NonNull Function1<@NonNull SheetValue, @NonNull Boolean> confirmValueChange,
    boolean skipHiddenState
)
Parameters
boolean skipPartiallyExpanded

Whether the partially expanded state, if the sheet is large enough, should be skipped. If true, the sheet will always expand to the Expanded state and move to the Hidden state if available when hiding the sheet, either programmatically or by user interaction.

@NonNull SheetValue initialValue

The initial value of the state.

@NonNull Function1<@NonNull SheetValue, @NonNull Boolean> confirmValueChange

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

boolean skipHiddenState

Whether the hidden state should be skipped. If true, the sheet will always expand to the Expanded state and move to the PartiallyExpanded if available, either programmatically or by user interaction.

SheetState

@ExperimentalMaterial3Api
public SheetState(
    boolean skipPartiallyExpanded,
    @NonNull Density density,
    @NonNull SheetValue initialValue,
    @NonNull Function1<@NonNull SheetValue, @NonNull Boolean> confirmValueChange,
    boolean skipHiddenState
)

State of a sheet composable, such as ModalBottomSheet

Contains states relating to its swipe position as well as animations between state values.

Parameters
boolean skipPartiallyExpanded

Whether the partially expanded state, if the sheet is large enough, should be skipped. If true, the sheet will always expand to the Expanded state and move to the Hidden state if available when hiding the sheet, either programmatically or by user interaction.

@NonNull Density density

The density that this state can use to convert values to and from dp.

@NonNull SheetValue initialValue

The initial value of the state.

@NonNull Function1<@NonNull SheetValue, @NonNull Boolean> confirmValueChange

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

boolean skipHiddenState

Whether the hidden state should be skipped. If true, the sheet will always expand to the Expanded state and move to the PartiallyExpanded if available, either programmatically or by user interaction.

Public methods

expand

public final void expand()

Fully expand the bottom sheet with animation and suspend until it is fully expanded or animation has been cancelled.

Throws
CancellationException

if the animation is interrupted

getCurrentValue

public final @NonNull SheetValue getCurrentValue()

The current value of the state.

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

getHasExpandedState

public final boolean getHasExpandedState()

Whether the sheet has an expanded state defined.

getHasPartiallyExpandedState

public final boolean getHasPartiallyExpandedState()

Whether the modal bottom sheet has a partially expanded state defined.

getTargetValue

public final @NonNull SheetValue getTargetValue()

The target value of the bottom sheet state.

If a swipe is in progress, this is the value that the sheet 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.

hide

public final void hide()

Hide the bottom sheet with animation and suspend until it is fully hidden or animation has been cancelled.

Throws
CancellationException

if the animation is interrupted

isVisible

public final boolean isVisible()

Whether the modal bottom sheet is visible.

partialExpand

public final void partialExpand()

Animate the bottom sheet and suspend until it is partially expanded or animation has been cancelled.

Throws
CancellationException

if the animation is interrupted

kotlin.IllegalStateException

if skipPartiallyExpanded is set to true

requireOffset

public final float requireOffset()

Require the current offset (in pixels) of the bottom sheet.

The offset will be initialized during the first measurement phase of the provided sheet content.

These are the phases: Composition { -> Effects } -> Layout { Measurement -> Placement } -> Drawing

During the first composition, an IllegalStateException is thrown. In subsequent compositions, the offset will be derived from the anchors of the previous pass. Always prefer accessing the offset from a LaunchedEffect as it will be scheduled to be executed the next frame, after layout.

Throws
kotlin.IllegalStateException

If the offset has not been initialized yet

show

public final void show()

Expand the bottom sheet with animation and suspend until it is PartiallyExpanded if defined else Expanded.

Throws
CancellationException

if the animation is interrupted