DEV Community

Cover image for How to Implement Swipe-to-Action using AnchoredDraggable in Jetpack Compose
Nandani Sharma for Canopas Software

Posted on • Edited on • Originally published at canopas.com

How to Implement Swipe-to-Action using AnchoredDraggable in Jetpack Compose

AnchoredDraggable is designed to create components you can drag between specific states, just like those modal bottom sheets you’ve seen.

The best part? This API takes over the role of Material’s Swipeable API, offering a more versatile approach.

Table of Contents

  • Add Dependency
  • AnchoredDraggable Modifier
  • BehindMotionSwipe example
  • ScrollMotionSwipe example
  • DrawerMotionSwipe example

Let’s see what we implement in this blog.
Three variants of swipe-to-action:

Image description

 BehindMotionSwipe    
Enter fullscreen mode Exit fullscreen mode

Image description

ScrollMotionSwipe 
Enter fullscreen mode Exit fullscreen mode

Image description

DrawerMotionSwipe

Enter fullscreen mode Exit fullscreen mode

What is AnchoredDraggableState?

The AnchoredDraggableState helps you manage and control draggable elements with anchor points in your app.

Now, let's dive into the code and bring your UI to life.

To get started, head over to the Coding Page and embark on this journey to unlock the potential of Swipe-to-Action in Jetpack Compose.

To unlock the full potential of this innovative technique and discover more exciting tips and tricks for app development, visit to Canopas Blog.

Follow Canopas for our latest technical blog posts!

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more