Added in 1.5.0-alpha17
class DrawerState(
initialValue: DrawerValue,
internal val confirmStateChange: (DrawerValue) -> Boolean = { true },
)
State of the ModalNavigationDrawer and DismissibleNavigationDrawer composable.
Parameters
| initialValue | The initial value of the state. |
| confirmStateChange | Optional callback invoked to confirm or veto a pending state change. |
Properties
isOpen
Added in 1.5.0-alpha17
val isOpen: Boolean
Whether the drawer is open.
isClosed
Added in 1.5.0-alpha17
val isClosed: Boolean
Whether the drawer is closed.
currentValue
Added in 1.5.0-alpha17
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
Added in 1.5.0-alpha17
val isAnimationRunning: Boolean
Whether the state is currently animating.
targetValue
Added in 1.5.0-alpha17
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.
offset
Deprecated
Please access the offset through currentOffset, which returns the value directly instead of wrapping it in a state object.
Added in 1.5.0-alpha17
Deprecated in 1.5.0-alpha17
val offset: State<Float>
The current position (in pixels) of the drawer sheet, or Float.NaN before the offset is initialized.
currentOffset
Added in 1.5.0-alpha17
Deprecated in 1.5.0-alpha17
val currentOffset: Float
The current position (in pixels) of the drawer sheet, or Float.NaN before the offset is initialized.
Functions
open
Added in 1.5.0-alpha17
Deprecated in 1.5.0-alpha17
suspend fun open() =
animateTo(targetValue = DrawerValue.Open, animationSpec = openDrawerMotionSpec)
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 |
close
Added in 1.5.0-alpha17
Deprecated in 1.5.0-alpha17
suspend fun close() =
animateTo(targetValue = DrawerValue.Closed, animationSpec = closeDrawerMotionSpec)
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 |
animateTo
Added in 1.5.0-alpha17
Deprecated in 1.5.0-alpha17
suspend fun animateTo(targetValue: DrawerValue, anim: AnimationSpec<Float>)
Set the state of the drawer with specific animation
Parameters
| targetValue | The new value to animate to. |
| anim | The animation that will be used to animate to the new value. |
snapTo
Added in 1.5.0-alpha17
Deprecated in 1.5.0-alpha17
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
Added in 1.5.0-alpha17
Deprecated in 1.5.0-alpha17
fun Saver(confirmStateChange: (DrawerValue) -> Boolean) =
Saver<DrawerState, DrawerValue>(
save = { it.currentValue },
restore = { DrawerState(it, confirmStateChange) },
)
The default Saver implementation for DrawerState.