yuyakaido / CardStackView

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

Even when just on Automatic mode, cards can be dragged after the swipe begins #243

Open samwaxman opened 5 years ago

samwaxman commented 5 years ago

I've set manager.setSwipeableMethod(SwipeableMethod.Automatic) and it works, but it fails when an automatic swipe begins. There's a gif below. The expected behavior is that I shouldn't be able to start dragging it.

swipeBug

yuyakaido commented 5 years ago

@samwaxman Thank you for report.

I already know this issue and try to resolve. But it is difficult because we can't identify manual swipe or automatic swipe in CardStackLayoutManager especially in scrollHorizontallyBy and scrollVerticallyBy. So we can't block manual swipe while running automatic swipe.

Do you have any idea to resolve this issue? And your contribution is welcome!

yueban commented 5 years ago

@samwaxman there's a hack way to solve this issue temporarily. you can add another view to cover on the cardStackView. And then add a scrollListener for cardStackView, when it comes to scrolling, show the cover view to intercept touch event.

cardStackView.addOnScrollListener(new RecyclerView.OnScrollListener() {
    @Override
    public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
        super.onScrollStateChanged(recyclerView, newState);
        if (newState == RecyclerView.SCROLL_STATE_IDLE) {
            coverView.setVisibility(View.GONE);
        } else {
            coverView.setVisibility(View.VISIBLE);
        }
    }
});

make sure your cover view is transparent and can handle touch event:

android:background="@android:color/transparent"
android:clickable="true"
android:focusable="true"