Skip to content

Commit e816f42

Browse files
Fix: Crop overlay jumps during multiple pointers active, but initial pointer is released (#656)
1 parent 71c372b commit e816f42

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

cropper/src/main/kotlin/com/canhub/cropper/CropOverlayView.kt

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ internal class CropOverlayView @JvmOverloads constructor(
110110

111111
private var textLabelPaint: Paint? = null
112112

113+
/**
114+
* Currently moving pointer used to stop movement event
115+
* when initial pointer was released
116+
* (to avoid crop overlay jumps)
117+
*/
118+
private var currentPointerId: Int? = null
119+
113120
/** Used for oval crop window shape or non-straight rotation drawing. */
114121
private val mPath = Path()
115122

@@ -233,7 +240,7 @@ internal class CropOverlayView @JvmOverloads constructor(
233240
* [viewHeight] The bounding image view height.
234241
*/
235242
fun setBounds(boundsPoints: FloatArray?, viewWidth: Int, viewHeight: Int) {
236-
if (boundsPoints == null || !Arrays.equals(mBoundsPoints, boundsPoints)) {
243+
if (boundsPoints == null || !mBoundsPoints.contentEquals(boundsPoints)) {
237244
if (boundsPoints == null) {
238245
Arrays.fill(mBoundsPoints, 0f)
239246
} else {
@@ -1097,18 +1104,25 @@ internal class CropOverlayView @JvmOverloads constructor(
10971104

10981105
when (event.action) {
10991106
MotionEvent.ACTION_DOWN -> {
1107+
currentPointerId = event.getPointerId(0)
11001108
onActionDown(event.x, event.y)
11011109
true
11021110
}
11031111
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
1112+
currentPointerId = event.getPointerId(0)
11041113
parent.requestDisallowInterceptTouchEvent(false)
11051114
onActionUp()
11061115
true
11071116
}
1108-
MotionEvent.ACTION_MOVE -> {
1109-
onActionMove(event.x, event.y)
1110-
parent.requestDisallowInterceptTouchEvent(true)
1111-
true
1117+
MotionEvent.ACTION_MOVE -> when {
1118+
// If we have released the pointer,
1119+
// we should ignore the next event to avoid overlay jumping.
1120+
currentPointerId != event.getPointerId(0) -> false
1121+
else -> {
1122+
onActionMove(event.x, event.y)
1123+
parent.requestDisallowInterceptTouchEvent(true)
1124+
true
1125+
}
11121126
}
11131127
else -> false
11141128
}

0 commit comments

Comments
 (0)