Skip to content
This repository has been archived by the owner on Jul 22, 2019. It is now read-only.

Commit

Permalink
Allow click over cards pass touch event handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
jaimeagudo committed Jun 9, 2017
1 parent dd5a984 commit b358671
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
15 changes: 13 additions & 2 deletions library/src/main/java/link/fls/swipestack/SwipeHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public class SwipeHelper implements View.OnTouchListener {
private float mOpacityEnd = SwipeStack.DEFAULT_SWIPE_OPACITY;
private int mAnimationDuration = SwipeStack.DEFAULT_ANIMATION_DURATION;

private boolean isClick = true;


public SwipeHelper(SwipeStack swipeStack) {
mSwipeStack = swipeStack;
}
Expand All @@ -48,7 +51,9 @@ public boolean onTouch(View v, MotionEvent event) {

switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
if(!mListenForTouchEvents || !mSwipeStack.isEnabled()) {
isClick = true;

if (!mListenForTouchEvents || !mSwipeStack.isEnabled()) {
return false;
}

Expand All @@ -67,6 +72,8 @@ public boolean onTouch(View v, MotionEvent event) {
float dx = event.getX(pointerIndex) - mDownX;
float dy = event.getY(pointerIndex) - mDownY;

isClick = Math.abs(dx + dy) < SwipeStack.CLICK_DISTANCE_THRESHOLD;

float newX = mObservedView.getX() + dx;
float newY = mObservedView.getY() + dy;

Expand All @@ -92,6 +99,10 @@ public boolean onTouch(View v, MotionEvent event) {
return true;

case MotionEvent.ACTION_UP:
if (isClick) {
v.performClick();
}

v.getParent().requestDisallowInterceptTouchEvent(false);
mSwipeStack.onSwipeEnd();
checkViewPosition();
Expand All @@ -104,7 +115,7 @@ public boolean onTouch(View v, MotionEvent event) {
}

private void checkViewPosition() {
if(!mSwipeStack.isEnabled()) {
if (!mSwipeStack.isEnabled()) {
resetViewPosition();
return;
}
Expand Down
1 change: 1 addition & 0 deletions library/src/main/java/link/fls/swipestack/SwipeStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class SwipeStack extends ViewGroup {
public static final float DEFAULT_SWIPE_OPACITY = 1f;
public static final float DEFAULT_SCALE_FACTOR = 1f;
public static final boolean DEFAULT_DISABLE_HW_ACCELERATION = true;
public static final boolean CLICK_DISTANCE_THRESHOLD = 6;

private static final String KEY_SUPER_STATE = "superState";
private static final String KEY_CURRENT_INDEX = "currentIndex";
Expand Down

0 comments on commit b358671

Please sign in to comment.