Skip to content

Commit 7425e3c

Browse files
author
Peter Cai
committed
SwipeLayout: Allow childs to deny swipe gesture
When used with ScorllView(or horizontal) inside SwipeLayout, the swipe gesture may conflict with the scroll action. If use requestDisallowInterceptTouchEvent, the scroll action will be back but the parent ListView's scroll action may be disallowed too. This patch solved this problem by introducing a "SwipeDenier" interface whose implementation should return if this swipe event should be denied. When onInterceptTouchEvent is called, SwipeLayout will call all SwipeDenier and if one of them returns true, the event will not be intercepted and passed to child views. Tested in app: https://github.com/PaperAirplane-Dev-Team/BlackLight which requires HorizontalScrollView inside SwipeLayout Signed-off-by: Peter Cai <[email protected]>
1 parent 7d7752b commit 7425e3c

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

library/src/main/java/com/daimajia/swipe/SwipeLayout.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public class SwipeLayout extends FrameLayout {
2828
private ShowMode mShowMode;
2929

3030
private List<SwipeListener> mSwipeListeners = new ArrayList<SwipeListener>();
31+
private List<SwipeDenier> mSwipeDeniers = new ArrayList<SwipeDenier>();
3132
private Map<View, ArrayList<OnRevealListener>> mRevealListeners = new HashMap<View, ArrayList<OnRevealListener>>();
3233
private Map<View, Boolean> mShowEntirely = new HashMap<View, Boolean>();
3334

@@ -82,6 +83,31 @@ public void removeAllSwipeListener(){
8283
mSwipeListeners.clear();
8384
}
8485

86+
public static interface SwipeDenier {
87+
/*
88+
* Called in onInterceptTouchEvent
89+
* Determines if this swipe event should be denied
90+
* Implement this interface if you are using views with swipe gestures
91+
* As a child of SwipeLayout
92+
*
93+
* @return true deny
94+
* false allow
95+
*/
96+
public boolean shouldDenySwipe(MotionEvent ev);
97+
}
98+
99+
public void addSwipeDenier(SwipeDenier denier) {
100+
mSwipeDeniers.add(denier);
101+
}
102+
103+
public void removeSwipeDenier(SwipeDenier denier) {
104+
mSwipeDeniers.remove(denier);
105+
}
106+
107+
public void removeAllSwipeDeniers() {
108+
mSwipeDeniers.clear();
109+
}
110+
85111
public interface OnRevealListener {
86112
public void onReveal(View child, DragEdge edge, float fraction, int distance);
87113
}
@@ -615,6 +641,12 @@ public boolean dispatchTouchEvent(MotionEvent ev) {
615641

616642
@Override
617643
public boolean onInterceptTouchEvent(MotionEvent ev) {
644+
for (SwipeDenier denier : mSwipeDeniers) {
645+
if (denier != null && denier.shouldDenySwipe(ev)) {
646+
return false;
647+
}
648+
}
649+
618650
return mDragHelper.shouldInterceptTouchEvent(ev);
619651
}
620652

0 commit comments

Comments
 (0)