From 6ea6d72c9645726cdbafa80dbd2fb1521a007404 Mon Sep 17 00:00:00 2001 From: skydoves Date: Sat, 2 Nov 2024 10:53:07 +0900 Subject: [PATCH] Fix behaviors for setShouldPassTouchEventToAnchor --- .../kotlin/com/skydoves/balloon/Balloon.kt | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/balloon/src/main/kotlin/com/skydoves/balloon/Balloon.kt b/balloon/src/main/kotlin/com/skydoves/balloon/Balloon.kt index 45771169..5a2b77ba 100644 --- a/balloon/src/main/kotlin/com/skydoves/balloon/Balloon.kt +++ b/balloon/src/main/kotlin/com/skydoves/balloon/Balloon.kt @@ -1827,16 +1827,31 @@ public class Balloon private constructor( ) } + /** remembers the last pressed action event to pass it after move the touch-up points. */ + private var passedEventActionDownEvent: Pair? = null + private fun passTouchEventToAnchor(anchor: View) { if (!this.builder.passTouchEventToAnchor) return setOnBalloonOverlayTouchListener { view, event -> view.performClick() val rect = Rect() anchor.getGlobalVisibleRect(rect) - if (event.action == MotionEvent.ACTION_UP || event.action == MotionEvent.ACTION_MOVE) { - anchor.rootView.dispatchTouchEvent(event) + + if (event.action == MotionEvent.ACTION_DOWN) { + passedEventActionDownEvent = event to rect.contains( + event.rawX.toInt(), + event.rawY.toInt(), + ) + } + + val passedEventActionDownEvents = passedEventActionDownEvent?.first + val passedEventActionDownInvokable = passedEventActionDownEvent?.second ?: false + + if (passedEventActionDownInvokable && (event.action == MotionEvent.ACTION_UP) + ) { + anchor.rootView.dispatchTouchEvent(passedEventActionDownEvents!!) true - } else if (rect.contains(event.rawX.toInt(), event.rawY.toInt())) { + } else if (passedEventActionDownInvokable) { anchor.rootView.dispatchTouchEvent(event) true } else {