CardStackView icon indicating copy to clipboard operation
CardStackView copied to clipboard

How to set swipe Direction only one side

Open karanbeer123 opened this issue 5 years ago • 7 comments

karanbeer123 avatar Feb 20 '20 06:02 karanbeer123

This could use some documentation expansion if you'd like to submit a PR to update it.

You can setup the swipeable directions on the CardStackLayoutManager:

cardStackView.layoutManager = CardStackLayoutManager(requireContext(), this).apply {
    setDirections(listOf(Direction.Right))
}

Barryrowe avatar Mar 20 '20 14:03 Barryrowe

this doesn't seem to work. I tried setting Direction.Left but it allows swipe in all directions akin to Direction.FREEDOM.

tangiable avatar Mar 20 '20 18:03 tangiable

Hmm this is working for me. It doesn't limit all motion in the other directions, but will limit which directions result in the card actually swiping away.

Are you looking for a way to prevent any motion at all except for a single direction?

Barryrowe avatar Mar 20 '20 18:03 Barryrowe

@Barryrowe yes, just the way setting setCanScrollHorizontal = true works, just that now I want cards to swipe only in one direction (i.e. Left) while the other direction swipe is blocked.

Any suggestions how this can be achieved?

tangiable avatar Mar 20 '20 18:03 tangiable

I'm not sure with the current API. I think the library would have to be extended to include finer grained options like:

canScrollHorizontalLeft canScrollHorizontalRight canScrollVerticalTop canScrollVerticalBottom

Barryrowe avatar Mar 20 '20 18:03 Barryrowe

actually, I am using CardStack in a Fragment inside of a ViewPager. It is conflicting with swipe right gesture of ViewPager which should open another page.

tangiable avatar Mar 20 '20 18:03 tangiable

That's a much bigger undertaking, and will likely require overriding onInterceptTouchEvent at some point in your view heirarchy. I don't think there's anything on the CardStackView that is intended to support that scenario out of the box.

Barryrowe avatar Mar 20 '20 19:03 Barryrowe