# DrawerState

Artifact: [androidx.compose.material3:material3](https://developer.android.com/jetpack/androidx/releases/compose-material3) [View Source](https://cs.android.com/search?q=file:androidx/compose/material3/NavigationDrawer.kt+class:androidx.compose.material3.DrawerState) Common/AllAndroid/JVM
- Cmn

  ```
  class DrawerState
  ```

*** ** * ** ***

State of the `https://developer.android.com/reference/kotlin/androidx/compose/material3/ModalNavigationDrawer.composable#ModalNavigationDrawer(kotlin.Function0,androidx.compose.ui.Modifier,androidx.compose.material3.DrawerState,kotlin.Boolean,androidx.compose.ui.graphics.Color,kotlin.Function0)` and `https://developer.android.com/reference/kotlin/androidx/compose/material3/DismissibleNavigationDrawer.composable#DismissibleNavigationDrawer(kotlin.Function0,androidx.compose.ui.Modifier,androidx.compose.material3.DrawerState,kotlin.Boolean,kotlin.Function0)` composable.

## Summary

| ### Public companion functions |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/saveable/Saver<https://developer.android.com/reference/kotlin/androidx/compose/material3/DrawerState, https://developer.android.com/reference/kotlin/androidx/compose/material3/DrawerValue>` | `https://developer.android.com/reference/kotlin/androidx/compose/material3/DrawerState#Saver(kotlin.Function1)(confirmStateChange: (https://developer.android.com/reference/kotlin/androidx/compose/material3/DrawerValue) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` The default `https://developer.android.com/reference/kotlin/androidx/compose/material3/DrawerState#Saver(kotlin.Function1)` implementation for `https://developer.android.com/reference/kotlin/androidx/compose/material3/DrawerState`. | Cmn |

| ### Public constructors |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/material3/DrawerState#DrawerState(androidx.compose.material3.DrawerValue,kotlin.Function1)( initialValue: https://developer.android.com/reference/kotlin/androidx/compose/material3/DrawerValue, confirmStateChange: (https://developer.android.com/reference/kotlin/androidx/compose/material3/DrawerValue) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html )` | Cmn |

| ### Public functions |
|---|---|---|
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `[animateTo](https://developer.android.com/reference/kotlin/androidx/compose/material3/DrawerState#animateTo(androidx.compose.material3.DrawerValue,androidx.compose.animation.core.AnimationSpec))(targetValue: https://developer.android.com/reference/kotlin/androidx/compose/material3/DrawerValue, anim: https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationSpec<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html>)` **This function is deprecated.** This method has been replaced by the open and close methods. | Cmn |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/material3/DrawerState#close()()` Close the drawer with animation and suspend until it if fully closed or animation has been cancelled. | Cmn |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/material3/DrawerState#open()()` Open the drawer with animation and suspend until it if fully opened or animation has been cancelled. | Cmn |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/material3/DrawerState#snapTo(androidx.compose.material3.DrawerValue)(targetValue: https://developer.android.com/reference/kotlin/androidx/compose/material3/DrawerValue)` Set the state without any animation and suspend until it's set | Cmn |

| ### Public properties |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/material3/DrawerState#currentOffset()` The current position (in pixels) of the drawer sheet, or Float.NaN before the offset is initialized. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/material3/DrawerValue` | `https://developer.android.com/reference/kotlin/androidx/compose/material3/DrawerState#currentValue()` The current value of the state. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/material3/DrawerState#isAnimationRunning()` Whether the state is currently animating. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/material3/DrawerState#isClosed()` Whether the drawer is closed. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/material3/DrawerState#isOpen()` Whether the drawer is open. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html>` | `https://developer.android.com/reference/kotlin/androidx/compose/material3/DrawerState#offset()` **This property is deprecated.** Please access the offset through currentOffset, which returns the value directly instead of wrapping it in a state object. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/material3/DrawerValue` | `https://developer.android.com/reference/kotlin/androidx/compose/material3/DrawerState#targetValue()` The target value of the drawer state. | Cmn |

## Public companion functions

### Saver

Cmn

```
fun Saver(confirmStateChange: (DrawerValue) -> Boolean): Saver<DrawerState, DrawerValue>
```

The default `https://developer.android.com/reference/kotlin/androidx/compose/material3/DrawerState#Saver(kotlin.Function1)` implementation for `https://developer.android.com/reference/kotlin/androidx/compose/material3/DrawerState`.

## Public constructors

### DrawerState

Cmn

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

| Parameters |
|---|---|
| `initialValue: https://developer.android.com/reference/kotlin/androidx/compose/material3/DrawerValue` | The initial value of the state. |
| `confirmStateChange: (https://developer.android.com/reference/kotlin/androidx/compose/material3/DrawerValue) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html = { true }` | Optional callback invoked to confirm or veto a pending state change. |

## Public functions

### animateTo

Cmn

```
suspend fun [animateTo](https://developer.android.com/reference/kotlin/androidx/compose/material3/DrawerState#animateTo(androidx.compose.material3.DrawerValue,androidx.compose.animation.core.AnimationSpec))(targetValue: DrawerValue, anim: AnimationSpec<Float>): Unit
```

> [!CAUTION]
> **This function is deprecated.**   
> This method has been replaced by the open and close methods. The animation spec is now an implementation detail of ModalDrawer.

Set the state of the drawer with specific animation

| Parameters |
|---|---|
| `targetValue: https://developer.android.com/reference/kotlin/androidx/compose/material3/DrawerValue` | The new value to animate to. |
| `anim: https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationSpec<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html>` | The animation that will be used to animate to the new value. |

### close

Cmn

```
suspend fun close(): Unit
```

Close the drawer with animation and suspend until it if fully closed or animation has been cancelled. This method will throw `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-cancellation-exception/index.html` if the animation is interrupted

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | the reason the close animation ended |

### open

Cmn

```
suspend fun open(): Unit
```

Open the drawer with animation and suspend until it if fully opened or animation has been cancelled. This method will throw `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-cancellation-exception/index.html` if the animation is interrupted

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | the reason the open animation ended |

### snapTo

Cmn

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

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

| Parameters |
|---|---|
| `targetValue: https://developer.android.com/reference/kotlin/androidx/compose/material3/DrawerValue` | The new target value |

## Public properties

### currentOffset

Cmn

```
val currentOffset: Float
```

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

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#offset()` | for more information. |

### currentValue

Cmn

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

### isAnimationRunning

Cmn

```
val isAnimationRunning: Boolean
```

Whether the state is currently animating.

### isClosed

Cmn

```
val isClosed: Boolean
```

Whether the drawer is closed.

### isOpen

Cmn

```
val isOpen: Boolean
```

Whether the drawer is open.

### offset

Cmn

```
val offset: State<Float>
```

> [!CAUTION]
> **This property is deprecated.**   
> Please access the offset through currentOffset, which returns the value directly instead of wrapping it in a state object, use this instead:
>
> ```kotlin
> currentOffset
> ```

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

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#offset()` | for more information. |

### targetValue

Cmn

```
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 `https://developer.android.com/reference/kotlin/androidx/compose/material3/DrawerState#currentValue()`.