Tunous / SwipeActionView

Android swipe-able view, which allows users to perform actions with swipe gestures.
Apache License 2.0
198 stars 17 forks source link

Ability to perform different actions based on swipe distance (More than one action on one side) #19

Closed biniamHaddish closed 12 months ago

Tunous commented 5 years ago

Not sure if I understand correctly but when you add background views in xml code you can use the android:layout_gravity attribute to specify whether they should be displayed on left or right side.

The example from readme adds ImageView for left and right actions which can then be listened to via gesture listeners to see in which direction the user did swipe.

Appearance of these "background" views is entierly up to you. They can be basic ImageViews or custom views. You can customize them in regular ways like findViewById or similar.

biniamHaddish commented 5 years ago

what I mean is when I swipe to right instead of having one action I can have to: for example one for saving and one for posting ...

Tunous commented 5 years ago

I see now. Unfortunately that is currently not possible (but I am open to pull requests 😃).

The closest feature you can get is to place view with few buttons as one of the background views and then return false from gesture listener. This will make it so when users swipe the view it won't be automatically swiped back and they will be able to click on the revealed buttons. You can read about that behavior in Gesture listeners section of the Readme.


Creating a pull request that would add such feature probably wouldn't be that hard. We could add a parameter to gesture listener telling how far the user has swiped, which would then allow us to determine which action to execute. And with the use of custom animations we could make it so the background views correctly update also based on the swipe distance. (Documentation about these animators is currently lacking but you can see how it works by checking ScalableIconAnimator).

If someone would like to create such a pull request feel free to contact me. I can answer any questions and help with ideas.