---
title: "DrawerState"
description: "State of the [ModalDrawer] composable."
type: "class"
---

<div class='type'>Class</div>


<a id='references'></a>

<div class='sourceset sourceset-common'>Common</div>


```kotlin
class DrawerState(
    initialValue: DrawerValue,
    confirmStateChange: (DrawerValue) -> Boolean = { true },
)
```


State of the `ModalDrawer` composable.

#### Parameters

| | |
| --- | --- |
| initialValue | The initial value of the state. |
| confirmStateChange | Optional callback invoked to confirm or veto a pending state change. |



## Properties

<div class='sourceset sourceset-common'>Common</div>


```kotlin
val isOpen: Boolean
```


Whether the drawer is open.



<div class='sourceset sourceset-common'>Common</div>


```kotlin
val isClosed: Boolean
```


Whether the drawer is closed.



<div class='sourceset sourceset-common'>Common</div>


```kotlin
val currentValue: DrawerValue
```


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.



<div class='sourceset sourceset-common'>Common</div>


```kotlin
val isAnimationRunning: Boolean
```


Whether the state is currently animating.



<div class='sourceset sourceset-common'>Common</div>


```kotlin
@ExperimentalMaterialApi
val targetValue: DrawerValue
```


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`.



<div class='sourceset sourceset-common'>Common</div>


```kotlin
@ExperimentalMaterialApi
val offset: Float
```


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



## Functions

```kotlin
suspend fun open() = anchoredDraggableState.animateTo(DrawerValue.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

| | |
| --- | --- |
|  | the reason the open animation ended |



```kotlin
suspend fun close() = anchoredDraggableState.animateTo(DrawerValue.Closed)
```


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

| | |
| --- | --- |
|  | the reason the close animation ended |



```kotlin
@ExperimentalMaterialApi
    
    suspend fun animateTo(
        targetValue: DrawerValue,
        @Suppress("UNUSED_PARAMETER") anim: AnimationSpec<Float>,
    )
```


Set the state of the drawer with specific animation

#### Parameters

| | |
| --- | --- |
| targetValue | The new value to animate to. |
| anim | Set the state of the drawer with specific animation |



```kotlin
suspend fun snapTo(targetValue: DrawerValue)
```


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

#### Parameters

| | |
| --- | --- |
| targetValue | The new target value |



## Companion Object

#### Methods

<div class='sourceset sourceset-common'>Common</div>


```kotlin
fun Saver(confirmStateChange: (DrawerValue) -> Boolean) =
            Saver<DrawerState, DrawerValue>(
                save = { it.currentValue },
                restore = { DrawerState(it, confirmStateChange) },
            )
```


The default `Saver` implementation for `DrawerState`.





