From 938679e239c2e10659ec0d7e999338147c7a6b72 Mon Sep 17 00:00:00 2001 From: Caij <271945881@qq.com> Date: Wed, 22 Dec 2021 22:01:10 +0800 Subject: [PATCH] when image scaled, fix edge top horizontal scroll --- .../chrisbanes/photoview/PhotoViewAttacher.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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 55965b81..165c9fa3 100644 --- a/photoview/src/main/java/com/github/chrisbanes/photoview/PhotoViewAttacher.java +++ b/photoview/src/main/java/com/github/chrisbanes/photoview/PhotoViewAttacher.java @@ -118,11 +118,15 @@ public void onDrag(float dx, float dy) { */ ViewParent parent = mImageView.getParent(); if (mAllowParentInterceptOnEdge && !mScaleDragDetector.isScaling() && !mBlockParentIntercept) { + float positiveDx = dx < 0 ? -dx : dx; + float positiveDy = dy < 0 ? -dy : dx; + boolean dragHorizontal = positiveDx > positiveDy * 0.65; + boolean dragVertical = positiveDy > positiveDx * 0.65; if (mHorizontalScrollEdge == HORIZONTAL_EDGE_BOTH - || (mHorizontalScrollEdge == HORIZONTAL_EDGE_LEFT && dx >= 1f) - || (mHorizontalScrollEdge == HORIZONTAL_EDGE_RIGHT && dx <= -1f) - || (mVerticalScrollEdge == VERTICAL_EDGE_TOP && dy >= 1f) - || (mVerticalScrollEdge == VERTICAL_EDGE_BOTTOM && dy <= -1f)) { + || (mHorizontalScrollEdge == HORIZONTAL_EDGE_LEFT && dx >= 1f && dragHorizontal) + || (mHorizontalScrollEdge == HORIZONTAL_EDGE_RIGHT && dx <= -1f && dragHorizontal) + || (mVerticalScrollEdge == VERTICAL_EDGE_TOP && dy >= 1f && dragVertical) + || (mVerticalScrollEdge == VERTICAL_EDGE_BOTTOM && dy <= -1f && dragVertical)) { if (parent != null) { parent.requestDisallowInterceptTouchEvent(false); }