yuyakaido / CardStackView

📱Tinder like swipeable card view for Android
Apache License 2.0
2.36k stars 448 forks source link

How to set swipe Direction only one side #308

Open karanbeer123 opened 4 years ago

Barryrowe commented 4 years ago

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))
}
tangiable commented 4 years ago

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

Barryrowe commented 4 years ago

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?

tangiable commented 4 years ago

@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?

Barryrowe commented 4 years ago

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

tangiable commented 4 years ago

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.

Barryrowe commented 4 years ago

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.