Skip to content

Commit

Permalink
Merge pull request #216 from gavine99/fix_gesture_motionevent_recycle…
Browse files Browse the repository at this point in the history
…_race_cond

bug fix for motion events being used after recycled
  • Loading branch information
octoshrimpy authored Jan 16, 2025
2 parents 5c9ad98 + 67a59dd commit cb11999
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ fun View.forwardTouches(parent: View) {
parent.onTouchEvent(e)
if (lastUpEvent !== null) {
parent.onTouchEvent(lastUpEvent)
lastUpEvent?.recycle()
lastUpEvent = null
}

return true
}

override fun onSingleTapUp(e: MotionEvent): Boolean {
onTouchEvent(e)
lastUpEvent = e
lastUpEvent = MotionEvent.obtain(e)
return true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
message.setOnTouchListener(object : OnTouchListener {
private val gestureDetector =
GestureDetector(this@ComposeActivity, object : SimpleOnGestureListener() {
private var lastUpEvent: MotionEvent? = null

override fun onDoubleTap(e: MotionEvent): Boolean {
val speechRecognizerIntent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
.putExtra(
Expand All @@ -195,11 +197,16 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
}

override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
message.showKeyboard()
if (lastUpEvent !== null) {
message.onTouchEvent(lastUpEvent)
lastUpEvent?.recycle()
lastUpEvent = null
}
return true
}

override fun onSingleTapUp(e: MotionEvent): Boolean {
lastUpEvent = MotionEvent.obtain(e)
return true // don't show soft keyboard on this event
}
})
Expand Down

0 comments on commit cb11999

Please sign in to comment.