SwipeActionView icon indicating copy to clipboard operation
SwipeActionView copied to clipboard

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

Open biniamHaddish opened this issue 5 years ago • 3 comments

biniamHaddish avatar Apr 13 '19 11:04 biniamHaddish

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.

Tunous avatar Apr 13 '19 12:04 Tunous

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

biniamHaddish avatar Apr 13 '19 13:04 biniamHaddish

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.

Tunous avatar Apr 13 '19 18:04 Tunous