DEV Community

Cover image for Jetpack compose onDragStopped animation
Tristan Elliott
Tristan Elliott

Posted on • Edited on

Jetpack compose onDragStopped animation

Resources

Just show me the code

    var offsetX by remember { mutableStateOf(0f) }
    val draggableState = DraggableState { delta ->
            offsetX += delta
    }
   Box(
        modifier = Modifier.draggable(
            orientation = Orientation.Horizontal,
            state = draggableState,
            onDragStopped = {

                draggableState.drag(MutatePriority.PreventUserInput) {
                    Animatable(offsetX).animateTo(
                        targetValue = 0f,
                        tween(durationMillis = 300)
                    ) {
                        dragBy(value - offsetX)
                    }
                }
            }
    )
    ){
       //The Column is the item that will do the moving
        Column(
            modifier = Modifier
                .offset { IntOffset(offsetX.roundToInt(), 0) }
                ) {
      }
}

Enter fullscreen mode Exit fullscreen mode

Conclusion

  • Thank you for taking the time out of your day to read this blog post of mine. If you have any questions or concerns please comment below or reach out to me on Twitter.

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up