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

Commit cca4b36

Browse files
author
jaimeagudo
committed
Allow click over cards pass touch event handlers
1 parent dd5a984 commit cca4b36

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

library/src/main/java/link/fls/swipestack/SwipeHelper.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ public class SwipeHelper implements View.OnTouchListener {
3939
private float mOpacityEnd = SwipeStack.DEFAULT_SWIPE_OPACITY;
4040
private int mAnimationDuration = SwipeStack.DEFAULT_ANIMATION_DURATION;
4141

42+
private boolean isClick = true;
43+
44+
4245
public SwipeHelper(SwipeStack swipeStack) {
4346
mSwipeStack = swipeStack;
4447
}
@@ -48,7 +51,9 @@ public boolean onTouch(View v, MotionEvent event) {
4851

4952
switch (event.getAction()) {
5053
case MotionEvent.ACTION_DOWN:
51-
if(!mListenForTouchEvents || !mSwipeStack.isEnabled()) {
54+
isClick = true;
55+
56+
if (!mListenForTouchEvents || !mSwipeStack.isEnabled()) {
5257
return false;
5358
}
5459

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

75+
isClick = Math.abs(dx + dy) < SwipeStack.CLICK_DISTANCE_THRESHOLD;
76+
7077
float newX = mObservedView.getX() + dx;
7178
float newY = mObservedView.getY() + dy;
7279

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

94101
case MotionEvent.ACTION_UP:
102+
if (isClick) {
103+
v.performClick();
104+
}
105+
95106
v.getParent().requestDisallowInterceptTouchEvent(false);
96107
mSwipeStack.onSwipeEnd();
97108
checkViewPosition();
@@ -104,7 +115,7 @@ public boolean onTouch(View v, MotionEvent event) {
104115
}
105116

106117
private void checkViewPosition() {
107-
if(!mSwipeStack.isEnabled()) {
118+
if (!mSwipeStack.isEnabled()) {
108119
resetViewPosition();
109120
return;
110121
}

library/src/main/java/link/fls/swipestack/SwipeStack.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public class SwipeStack extends ViewGroup {
4444
public static final float DEFAULT_SWIPE_OPACITY = 1f;
4545
public static final float DEFAULT_SCALE_FACTOR = 1f;
4646
public static final boolean DEFAULT_DISABLE_HW_ACCELERATION = true;
47+
public static final float CLICK_DISTANCE_THRESHOLD = 6;
4748

4849
private static final String KEY_SUPER_STATE = "superState";
4950
private static final String KEY_CURRENT_INDEX = "currentIndex";

0 commit comments

Comments
 (0)