Blog Infos
Author
Published
Topics
,
Published

It’s one of the common UX across apps to provide swipe to dismiss so as to delete the list item or take some other action such as archive. However, adding this functionality is a bit tricky with the existing UI toolkit but with Jetpack Compose it’s just a matter of calling a single composable.

SwipeToDismiss Composable

Well swipe to dismiss capability is directly offered through the compose-material library that means you need not have to write custom logic to add such feature.

implementation “androidx.compose.material:

material:$compose_version”

Let’s see about each of the parameters that SwipeToDismiss composable takes.

State
It plays a very vital role as through the state itself we decide what should happen when the user completely swipes the item, we write our logic inside lambda for confirmStateChange parameter of rememberDismissStatemethod.

Modifier
This is a usual concept that is common across all composable which helps to add different kinds of functionalities like border, padding, etc.

Directions
With this parameter, you can specify the direction for swipe either left to right or right to left. The best thing is that if you want to enable swipe for both the directions then that’s also possible, rather that’s the default value for directions.

Dismiss Thresholds
Generally swipe to dismiss will have a target value which determines the dismiss value as Default, DismissedToEnd, DismissedToStart which helps to set the threshold, that means till what point user has to swipe after that even if the user leaves it will auto swipe in that particular direction.

dismissThresholds = { FractionalThreshold(0.2f) }

 

Job Offers

Job Offers


    Android Build Engineer

    Pinterest
    San Francisco, CA | Seattle, WA
    • Full Time
    apply now

    Android Developer

    Small and Modern GmbH
    Hamburg, Remote (Germany)
    • Full Time
    apply now

    Senior Android Developer (Remote)

    Komoot
    Europe
    • Full Time
    apply now
Load more listings

OUR VIDEO RECOMMENDATION

,

Keep Rules in the Age of Kotlin

ProGuard has been the industry standard for obfuscating, shrinking and optimizing Java & Android apps for close to 20 years. ProGuard, and the compatible R8 shrinker, usually need some configuration since it’s not always technically…
Watch Video

Jobs

Here threshold value is set 20% and the default is 50%

Background
Here you can specify the background of the item that will be displayed as the user swipes the item. Generally, you might add a red color background with some icons to indicate swipe to delete.

Dismiss Content
That’s the place where you will have the list item UI that will be shown to the user.

Complete Code

Here is the complete tutorial which I have uploaded on my YouTube channel — All Techies where I have shown how to add swipe to dismiss. Please don’t forget to hit the subscribe button so as to get the videos on the latest topics of Android, Kotlin and Firebase. Thank you!

https://youtu.be/wFR-WTtE-tw

YOU MAY BE INTERESTED IN

YOU MAY BE INTERESTED IN

blog
Hi, today I come to you with a quick tip on how to update…
READ MORE
blog
Automation is a key point of Software Testing once it make possible to reproduce…
READ MORE
blog
Drag and Drop reordering in Recyclerview can be achieved with ItemTouchHelper (checkout implementation reference).…
READ MORE
blog
Modern mobile applications are already quite serious enterprise projects that are developed by hundreds…
READ MORE

Leave a Reply

Your email address will not be published.

Fill out this field
Fill out this field
Please enter a valid email address.

Menu