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.

    • 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)
        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

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

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

      • settle

         final Unit settle(Float velocity)

        Find the closest anchor taking into account the velocity and settle at it with an animation.