Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Crop overlay jumps during multiple pointers active, but initial pointer is released #656

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions cropper/src/main/kotlin/com/canhub/cropper/CropOverlayView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ internal class CropOverlayView @JvmOverloads constructor(

private var textLabelPaint: Paint? = null

/**
* Currently moving pointer used to stop movement event
* when initial pointer was released
* (to avoid crop overlay jumps)
*/
private var currentPointerId: Int? = null

/** Used for oval crop window shape or non-straight rotation drawing. */
private val mPath = Path()

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

when (event.action) {
MotionEvent.ACTION_DOWN -> {
currentPointerId = event.getPointerId(0)
onActionDown(event.x, event.y)
true
}
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
currentPointerId = event.getPointerId(0)
parent.requestDisallowInterceptTouchEvent(false)
onActionUp()
true
}
MotionEvent.ACTION_MOVE -> {
onActionMove(event.x, event.y)
parent.requestDisallowInterceptTouchEvent(true)
true
MotionEvent.ACTION_MOVE -> when {
// If we have released the pointer,
// we should ignore the next event to avoid overlay jumping.
currentPointerId != event.getPointerId(0) -> false
else -> {
onActionMove(event.x, event.y)
parent.requestDisallowInterceptTouchEvent(true)
true
}
}
else -> false
}
Expand Down