Skip to content

Commit

Permalink
Merge pull request #748 from skydoves/fix/touch-pass-event
Browse files Browse the repository at this point in the history
Fix behaviors for setShouldPassTouchEventToAnchor
  • Loading branch information
skydoves authored Nov 2, 2024
2 parents 3714144 + 6ea6d72 commit fa451ff
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions balloon/src/main/kotlin/com/skydoves/balloon/Balloon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<MotionEvent, Boolean>? = 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 {
Expand Down

0 comments on commit fa451ff

Please sign in to comment.