Diolor / Swipecards

A Tinder-like Android library to create the swipe cards effect. You can swipe left or right to like or dislike the content.
Apache License 2.0
2.34k stars 583 forks source link

Consuming TouchEvents on childviews fucks up the library, but by not consuming them, you only ever get ACTION_DOWN #163

Closed SennaGehenna closed 8 years ago

SennaGehenna commented 8 years ago

I'm working on an app where users are portrayed on cards, which can be flung around. You ought to be able to both drag the card around and click the profile image.

I tried to use a simple onClickListener before, but that disables the drag-ability, I figured, I could simply do the swipe-detection logic myself by using an onTouchListener and listen to the motionEvents.

Problem is, I only ever get ACTION_DOWN, which defeats my idea, because I never know when the user raises their finger.

I'm hoping that this is merely a bug

the code, just in case you can make use of that

    public boolean onTouch(View view, MotionEvent motionEvent) {
        int action = motionEvent.getAction();
        Log.d(TAG, translateMotionEvent(action));
        if (action == MotionEvent.ACTION_DOWN) {
            oldX = motionEvent.getX();
            oldY = motionEvent.getY();
        }
        if (action == MotionEvent.ACTION_UP) {
            doSomething();
        }
        //this is where the trouble starts, return true and you can't drag anymore 
        //(because the parentview doesn't receive the touchevent, return false 
        //and only ACTION_DOWN is called
        return true;
    }```
SennaGehenna commented 8 years ago

For those wondering how to implement this, since the dev doesn't seem to answer, you can implement an ItemClickListener and not bind any click events on childViews at all. Might require a redesign, depending on how your app works in the first place, or you could implement the whole thing yourself