Prevent panning before quick scale

This commit is contained in:
ajp_anton
2026-07-27 21:23:27 +00:00
parent 1145713584
commit 2584aa77be
@@ -27,6 +27,7 @@ class ZoomImageView @JvmOverloads constructor(
private var lastFocusX = 0f private var lastFocusX = 0f
private var lastFocusY = 0f private var lastFocusY = 0f
private var pointerCount = 0 private var pointerCount = 0
private var quickScaleGesture = false
private val scaleDetector = ScaleGestureDetector(context, object : ScaleGestureDetector.SimpleOnScaleGestureListener() { private val scaleDetector = ScaleGestureDetector(context, object : ScaleGestureDetector.SimpleOnScaleGestureListener() {
override fun onScaleBegin(detector: ScaleGestureDetector): Boolean { override fun onScaleBegin(detector: ScaleGestureDetector): Boolean {
lastFocusX = detector.focusX lastFocusX = detector.focusX
@@ -54,6 +55,18 @@ class ZoomImageView @JvmOverloads constructor(
return true return true
} }
override fun onDoubleTap(event: MotionEvent): Boolean {
quickScaleGesture = true
return true
}
override fun onDoubleTapEvent(event: MotionEvent): Boolean {
if (event.actionMasked == MotionEvent.ACTION_UP || event.actionMasked == MotionEvent.ACTION_CANCEL) {
quickScaleGesture = false
}
return true
}
}) })
init { init {
@@ -81,7 +94,7 @@ class ZoomImageView @JvmOverloads constructor(
lastY = event.y lastY = event.y
dragging = false dragging = false
} }
MotionEvent.ACTION_MOVE -> if (event.pointerCount == 1 && !scaleDetector.isInProgress) { MotionEvent.ACTION_MOVE -> if (event.pointerCount == 1 && !scaleDetector.isInProgress && !quickScaleGesture) {
val dx = event.x - lastX val dx = event.x - lastX
val dy = event.y - lastY val dy = event.y - lastY
if (dx != 0f || dy != 0f) { if (dx != 0f || dy != 0f) {