From b1f9d00350de4d24052e9de061f7d7b889a1d473 Mon Sep 17 00:00:00 2001 From: BojanK Date: Wed, 12 Feb 2020 10:04:02 +0100 Subject: [PATCH 1/3] Allow parent to intercept touch events in case vertical scroll edge flag is set to both --- .../java/com/github/chrisbanes/photoview/PhotoViewAttacher.java | 1 + 1 file changed, 1 insertion(+) diff --git a/photoview/src/main/java/com/github/chrisbanes/photoview/PhotoViewAttacher.java b/photoview/src/main/java/com/github/chrisbanes/photoview/PhotoViewAttacher.java index f8494d41..3d1a1c3e 100644 --- a/photoview/src/main/java/com/github/chrisbanes/photoview/PhotoViewAttacher.java +++ b/photoview/src/main/java/com/github/chrisbanes/photoview/PhotoViewAttacher.java @@ -121,6 +121,7 @@ public void onDrag(float dx, float dy) { if (mHorizontalScrollEdge == HORIZONTAL_EDGE_BOTH || (mHorizontalScrollEdge == HORIZONTAL_EDGE_LEFT && dx >= 1f) || (mHorizontalScrollEdge == HORIZONTAL_EDGE_RIGHT && dx <= -1f) + || (mVerticalScrollEdge == VERTICAL_EDGE_BOTH) || (mVerticalScrollEdge == VERTICAL_EDGE_TOP && dy >= 1f) || (mVerticalScrollEdge == VERTICAL_EDGE_BOTTOM && dy <= -1f)) { if (parent != null) { From fd3e50069e622402262934a73d5de9d97dddd30e Mon Sep 17 00:00:00 2001 From: Bojank Date: Fri, 14 Feb 2020 08:06:20 +0100 Subject: [PATCH 2/3] Make parent scroll direction configurable --- .../chrisbanes/photoview/ParentScrollDirection.java | 6 ++++++ .../java/com/github/chrisbanes/photoview/PhotoView.java | 4 ++++ .../github/chrisbanes/photoview/PhotoViewAttacher.java | 9 +++++++-- 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 photoview/src/main/java/com/github/chrisbanes/photoview/ParentScrollDirection.java diff --git a/photoview/src/main/java/com/github/chrisbanes/photoview/ParentScrollDirection.java b/photoview/src/main/java/com/github/chrisbanes/photoview/ParentScrollDirection.java new file mode 100644 index 00000000..d6a64f58 --- /dev/null +++ b/photoview/src/main/java/com/github/chrisbanes/photoview/ParentScrollDirection.java @@ -0,0 +1,6 @@ +package com.github.chrisbanes.photoview; + +public @interface ParentScrollDirection { + int HORIZONTAL = 0; + int VERTICAL = 1; +} \ No newline at end of file diff --git a/photoview/src/main/java/com/github/chrisbanes/photoview/PhotoView.java b/photoview/src/main/java/com/github/chrisbanes/photoview/PhotoView.java index 8a8ba0a7..e0615361 100644 --- a/photoview/src/main/java/com/github/chrisbanes/photoview/PhotoView.java +++ b/photoview/src/main/java/com/github/chrisbanes/photoview/PhotoView.java @@ -253,4 +253,8 @@ public void setOnScaleChangeListener(OnScaleChangedListener onScaleChangedListen public void setOnSingleFlingListener(OnSingleFlingListener onSingleFlingListener) { attacher.setOnSingleFlingListener(onSingleFlingListener); } + + public void setParentScrollDirection(@ParentScrollDirection int scrollDirection) { + attacher.setParentScrollDirection(scrollDirection); + } } diff --git a/photoview/src/main/java/com/github/chrisbanes/photoview/PhotoViewAttacher.java b/photoview/src/main/java/com/github/chrisbanes/photoview/PhotoViewAttacher.java index 3d1a1c3e..39abd509 100644 --- a/photoview/src/main/java/com/github/chrisbanes/photoview/PhotoViewAttacher.java +++ b/photoview/src/main/java/com/github/chrisbanes/photoview/PhotoViewAttacher.java @@ -90,6 +90,7 @@ public class PhotoViewAttacher implements View.OnTouchListener, private FlingRunnable mCurrentFlingRunnable; private int mHorizontalScrollEdge = HORIZONTAL_EDGE_BOTH; private int mVerticalScrollEdge = VERTICAL_EDGE_BOTH; + private int mParentScrollDirection = ParentScrollDirection.HORIZONTAL; private float mBaseRotation; private boolean mZoomEnabled = true; @@ -118,10 +119,10 @@ public void onDrag(float dx, float dy) { */ ViewParent parent = mImageView.getParent(); if (mAllowParentInterceptOnEdge && !mScaleDragDetector.isScaling() && !mBlockParentIntercept) { - if (mHorizontalScrollEdge == HORIZONTAL_EDGE_BOTH + if ((mHorizontalScrollEdge == HORIZONTAL_EDGE_BOTH && mParentScrollDirection == ParentScrollDirection.HORIZONTAL) || (mHorizontalScrollEdge == HORIZONTAL_EDGE_LEFT && dx >= 1f) || (mHorizontalScrollEdge == HORIZONTAL_EDGE_RIGHT && dx <= -1f) - || (mVerticalScrollEdge == VERTICAL_EDGE_BOTH) + || (mVerticalScrollEdge == VERTICAL_EDGE_BOTH && mParentScrollDirection == ParentScrollDirection.VERTICAL) || (mVerticalScrollEdge == VERTICAL_EDGE_TOP && dy >= 1f) || (mVerticalScrollEdge == VERTICAL_EDGE_BOTTOM && dy <= -1f)) { if (parent != null) { @@ -261,6 +262,10 @@ public void setOnSingleFlingListener(OnSingleFlingListener onSingleFlingListener this.mSingleFlingListener = onSingleFlingListener; } + public void setParentScrollDirection(@ParentScrollDirection int scrollDirection) { + + } + @Deprecated public boolean isZoomEnabled() { return mZoomEnabled; From 6b90aaf6a469ce3588e3e0e1bd800c90e5cf08fc Mon Sep 17 00:00:00 2001 From: Bojank Date: Fri, 14 Feb 2020 08:08:25 +0100 Subject: [PATCH 3/3] Set the variable when set is invoked --- .../java/com/github/chrisbanes/photoview/PhotoViewAttacher.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/photoview/src/main/java/com/github/chrisbanes/photoview/PhotoViewAttacher.java b/photoview/src/main/java/com/github/chrisbanes/photoview/PhotoViewAttacher.java index 39abd509..9f55916f 100644 --- a/photoview/src/main/java/com/github/chrisbanes/photoview/PhotoViewAttacher.java +++ b/photoview/src/main/java/com/github/chrisbanes/photoview/PhotoViewAttacher.java @@ -263,7 +263,7 @@ public void setOnSingleFlingListener(OnSingleFlingListener onSingleFlingListener } public void setParentScrollDirection(@ParentScrollDirection int scrollDirection) { - + this.mParentScrollDirection = scrollDirection; } @Deprecated