RevealState
class RevealState
A class to keep track of the state of the composable. It can be used to customise the behavior and state of the composable.
Summary
Public constructors |
|---|
@RememberInCompositionCreate a |
Public functions |
|
|---|---|
suspend Unit |
animateTo(targetValue: RevealValue)Animates to the |
Float |
dispatchRawDelta(delta: Float)Drag by the supplied |
suspend Unit |
drag(dragPriority: MutatePriority, block: suspend SwipeToRevealDragScope.() -> Unit)Call this function to take control of the drag logic and mutate the offset. |
Float |
positionOf(revealValue: RevealValue)Get the offset position for an associated |
suspend Unit |
snapTo(targetValue: RevealValue)Snaps to the |
Public properties |
|
|---|---|
RevealValue |
The current |
Boolean |
Returns whether the animation is running or not. |
Float |
The current amount by which the revealable content has been revealed. |
RevealValue |
The target |
Public constructors
RevealState
@RememberInComposition
RevealState(initialValue: RevealValue)
Create a RevealState.
| Parameters | |
|---|---|
initialValue: RevealValue |
The initial value of this state. |
Public functions
animateTo
suspend fun animateTo(targetValue: RevealValue): Unit
Animates to the targetValue with the animation spec provided.
| Parameters | |
|---|---|
targetValue: RevealValue |
The target |
| Throws | |
|---|---|
IllegalStateException |
if the target |
dispatchRawDelta
fun dispatchRawDelta(delta: Float): Float
Drag by the supplied delta, coerce it in the swipe bounds and return the remaining available. These bounds are determined by the screen width and the configured RevealDirection.
| Parameters | |
|---|---|
delta: Float |
The delta (positive or negative) to drag |
| Returns | |
|---|---|
Float |
The consumed delta |
drag
suspend fun drag(
dragPriority: MutatePriority = MutatePriority.Default,
block: suspend SwipeToRevealDragScope.() -> Unit
): Unit
Call this function to take control of the drag logic and mutate the offset.
All actions that change the offset of this RevealState must be performed within a drag block (even if they don't call any other methods on this object) in order to guarantee that mutual exclusion is enforced. The offset provided to SwipeToRevealDragScope.dragTo will be coerced to the interval of the min/max offset values of RevealValue.
If drag is called from elsewhere with the dragPriority higher or equal to ongoing drag, the ongoing drag will be cancelled.
If layout dimensions change while the block is being executed, it will be cancelled and re-executed.
| Parameters | |
|---|---|
dragPriority: MutatePriority = MutatePriority.Default |
of the drag operation |
block: suspend SwipeToRevealDragScope.() -> Unit |
The suspending block where the drag mutations are performed |
positionOf
fun positionOf(revealValue: RevealValue): Float
Get the offset position for an associated RevealValue
| Parameters | |
|---|---|
revealValue: RevealValue |
The value to look up |
snapTo
suspend fun snapTo(targetValue: RevealValue): Unit
Snaps to the targetValue without any animation (if a previous item was already revealed, that item will be reset to the covered state with animation).
| Parameters | |
|---|---|
targetValue: RevealValue |
The target |
Public properties
currentValue
val currentValue: RevealValue
The current RevealValue based on the status of the component.
isAnimationRunning
val isAnimationRunning: Boolean
Returns whether the animation is running or not.
offset
val offset: Float
The current amount by which the revealable content has been revealed.
targetValue
val targetValue: RevealValue
The target RevealValue based on the status of the component. This will be equal to the currentValue if there is no animation running or swiping has stopped. Otherwise, this returns the next RevealValue based on the animation/swipe direction.