Unstyled Anchored Draggable State
State of the unstyledAnchoredDraggable modifier. Use the constructor overload with anchors if the anchors are defined in composition, or update the anchors using updateAnchors.
This contains necessary information about any ongoing drag or animation and provides methods to change the state either immediately or by starting an animation.
Parameters
The initial value of the state.
The positional threshold, in px, to be used when calculating the target state while a drag is in progress and when settling after the drag ends. This is the distance from the start of a transition. It will be, depending on the direction of the interaction, added or subtracted from/to the origin offset. It should always be a positive value.
The velocity threshold (in px per second) that the end velocity has to exceed in order to animate to the next state, even if the positionalThreshold has not been reached.
The default animation spec that will be used to animate to a new state.
The animation spec that will be used when flinging with a large enough velocity to reach or cross the target state.
Optional callback invoked to confirm or veto a pending state change.
Constructors
Construct an UnstyledAnchoredDraggableState instance with anchors.
Properties
The current value of the UnstyledAnchoredDraggableState.
Whether an animation is currently in progress.
The velocity of the last known animation. Gets reset to 0f when an animation completes successfully, but does not get reset when an animation gets interrupted. You can use this value to provide smooth reconciliation behavior when re-targeting an animation.
The fraction of the progress going from settledValue to targetValue, within 0f..1f bounds, or 1f if the UnstyledAnchoredDraggableState is in a settled state.
The value the UnstyledAnchoredDraggableState is currently settled at.
The target value. This is the closest value to the current offset. If no interactions like animations or drags are in progress, this will be the current value.
Functions
Call this function to take control of drag logic and perform anchored drag with the latest anchors.
Call this function to take control of drag logic and perform anchored drag with the latest anchors and target.
Animate to a targetValue. If the targetValue is not in the set of anchors, the UnstyledAnchoredDraggableState.currentValue will be updated to the targetValue without updating the offset.
Attempt to animate using decay Animation to a targetValue. If the velocity is high enough to get to the target offset, we'll use UnstyledAnchoredDraggableState.decayAnimationSpec to get to that offset and return the consumed velocity. If the velocity is not high enough, we'll use UnstyledAnchoredDraggableState.snapAnimationSpec to reach the target offset.
Drag by the delta, coerce it in the bounds and dispatch it to the UnstyledAnchoredDraggableState.
Require the current offset.
Snap to a targetValue without any animation. If the targetValue is not in the set of anchors, the UnstyledAnchoredDraggableState.currentValue will be updated to the targetValue without updating the offset.
Update the anchors. If there is no ongoing anchoredDrag operation, snap to the newTarget, otherwise restart the ongoing anchoredDrag operation (e.g. an animation) with the new anchors.