Class SwipeableV2State
-
- All Implemented Interfaces:
public final class SwipeableV2State<T extends Object>
State of the swipeableV2 modifier.
This contains necessary information about any ongoing swipe or animation and provides methods to change the state either immediately or by starting an animation. To create and remember a SwipeableV2State use rememberSwipeableV2State.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public class
SwipeableV2State.Companion
-
Field Summary
Fields Modifier and Type Field Description private final T
currentValue
private final T
targetValue
private final Float
offset
private final Boolean
isAnimationRunning
private final Float
progress
private final Float
lastVelocity
private final <Error class: unknown class>
minOffset
private final <Error class: unknown class>
maxOffset
public final static SwipeableV2State.Companion
Companion
-
Method Summary
Modifier and Type Method Description final T
getCurrentValue()
The current value of the SwipeableV2State. final T
getTargetValue()
The target value. final Float
getOffset()
The current offset, or null if it has not been initialized yet. final Boolean
isAnimationRunning()
final Float
getProgress()
The fraction of the progress going from currentValue to targetValue, within 0f.. final Float
getLastVelocity()
The velocity of the last known animation. final <Error class: unknown class>
getMinOffset()
The minimum offset this state can reach. final <Error class: unknown class>
getMaxOffset()
The maximum offset this state can reach. final Float
requireOffset()
Require the current offset. final Boolean
hasAnchorForValue(T value)
Whether the value has an anchor associated with it. final Unit
snapTo(T targetValue)
Snap to a targetValue without any animation. final Unit
animateTo(T targetValue, Float velocity)
Animate to a targetValue. final Unit
settle(Float velocity)
Find the closest anchor taking into account the velocity and settle at it with an animation. final Float
dispatchRawDelta(Float delta)
Swipe by the delta, coerce it in the bounds and dispatch it to the draggableState. -
-
Constructor Detail
-
SwipeableV2State
SwipeableV2State(T initialValue, <Error class: unknown class><Float> animationSpec, Function1<T, Boolean> confirmValueChange, Function2<<Error class: unknown class>, Float, Float> positionalThreshold, <Error class: unknown class> velocityThreshold)
- Parameters:
initialValue
- The initial value of the state.animationSpec
- The default animation that will be used to animate to a new state.confirmValueChange
- Optional callback invoked to confirm or veto a pending state change.positionalThreshold
- The positional threshold to be used when calculating the target state while a swipe is in progress and when settling after the swipe ends.velocityThreshold
- The velocity threshold (in dp 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.
-
-
Method Detail
-
getCurrentValue
final T getCurrentValue()
The current value of the SwipeableV2State.
-
getTargetValue
final T getTargetValue()
The target value. This is the closest value to the current offset (taking into account positional thresholds). If no interactions like animations or drags are in progress, this will be the current value.
-
getOffset
final Float getOffset()
The current offset, or null if it has not been initialized yet.
The offset will be initialized during the first measurement phase of the node that the swipeableV2 modifier is attached to. These are the phases: Composition { -> Effects } -> Layout { Measurement -> Placement } -> Drawing During the first composition, the offset will be null. In subsequent compositions, the offset will be derived from the anchors of the previous pass. Always prefer accessing the offset from a LaunchedEffect as it will be scheduled to be executed the next frame, after layout.
To guarantee stricter semantics, consider using requireOffset.
-
isAnimationRunning
final Boolean isAnimationRunning()
-
getProgress
final Float getProgress()
The fraction of the progress going from currentValue to targetValue, within 0f..1f bounds.
-
getLastVelocity
final Float getLastVelocity()
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.
-
getMinOffset
final <Error class: unknown class> getMinOffset()
The minimum offset this state can reach. This will be the smallest anchor, or Float.NEGATIVE_INFINITY if the anchors are not initialized yet.
-
getMaxOffset
final <Error class: unknown class> getMaxOffset()
The maximum offset this state can reach. This will be the biggest anchor, or Float.POSITIVE_INFINITY if the anchors are not initialized yet.
-
requireOffset
final Float requireOffset()
Require the current offset.
-
hasAnchorForValue
final Boolean hasAnchorForValue(T value)
Whether the value has an anchor associated with it.
-
snapTo
final Unit snapTo(T targetValue)
Snap to a targetValue without any animation. If the targetValue is not in the set of anchors, the currentValue will be updated to the targetValue without updating the offset.
- Parameters:
targetValue
- The target value of the animation
-
animateTo
final Unit animateTo(T targetValue, Float velocity)
Animate to a targetValue. If the targetValue is not in the set of anchors, the currentValue will be updated to the targetValue without updating the offset.
- Parameters:
targetValue
- The target value of the animationvelocity
- The velocity the animation should start with, lastVelocity by default
-
settle
final Unit settle(Float velocity)
Find the closest anchor taking into account the velocity and settle at it with an animation.
-
dispatchRawDelta
final Float dispatchRawDelta(Float delta)
Swipe by the delta, coerce it in the bounds and dispatch it to the draggableState.
-
-
-
-