Skip to content

Commit 23cbb33

Browse files
authored
Merge pull request #857 from hansonchris/hansonchris/horizontalScrollFix
In SlidingUpPanelLayout.dispatchTouchEvent(), ignore horizontal scrolls
2 parents 23f58d2 + 41fadaa commit 23cbb33

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

library/src/main/java/com/sothree/slidinguppanel/SlidingUpPanelLayout.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ public enum PanelState {
207207
*/
208208
private boolean mIsTouchEnabled;
209209

210+
private float mPrevMotionX;
210211
private float mPrevMotionY;
211212
private float mInitialMotionX;
212213
private float mInitialMotionY;
@@ -961,15 +962,24 @@ public boolean dispatchTouchEvent(MotionEvent ev) {
961962
return super.dispatchTouchEvent(ev);
962963
}
963964

965+
final float x = ev.getX();
964966
final float y = ev.getY();
965967

966968
if (action == MotionEvent.ACTION_DOWN) {
967969
mIsScrollableViewHandlingTouch = false;
970+
mPrevMotionX = x;
968971
mPrevMotionY = y;
969972
} else if (action == MotionEvent.ACTION_MOVE) {
973+
float dx = x - mPrevMotionX;
970974
float dy = y - mPrevMotionY;
975+
mPrevMotionX = x;
971976
mPrevMotionY = y;
972977

978+
if (Math.abs(dx) > Math.abs(dy)) {
979+
// Scrolling horizontally, so ignore
980+
return super.dispatchTouchEvent(ev);
981+
}
982+
973983
// If the scroll view isn't under the touch, pass the
974984
// event along to the dragView.
975985
if (!isViewUnder(mScrollableView, (int) mInitialMotionX, (int) mInitialMotionY)) {

0 commit comments

Comments
 (0)