Prevent panning before quick scale
This commit is contained in:
@@ -27,6 +27,7 @@ class ZoomImageView @JvmOverloads constructor(
|
||||
private var lastFocusX = 0f
|
||||
private var lastFocusY = 0f
|
||||
private var pointerCount = 0
|
||||
private var quickScaleGesture = false
|
||||
private val scaleDetector = ScaleGestureDetector(context, object : ScaleGestureDetector.SimpleOnScaleGestureListener() {
|
||||
override fun onScaleBegin(detector: ScaleGestureDetector): Boolean {
|
||||
lastFocusX = detector.focusX
|
||||
@@ -54,6 +55,18 @@ class ZoomImageView @JvmOverloads constructor(
|
||||
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 {
|
||||
@@ -81,7 +94,7 @@ class ZoomImageView @JvmOverloads constructor(
|
||||
lastY = event.y
|
||||
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 dy = event.y - lastY
|
||||
if (dx != 0f || dy != 0f) {
|
||||
|
||||
Reference in New Issue
Block a user