Skip to content

Commit 6ea6d72

Browse files
committed
Fix behaviors for setShouldPassTouchEventToAnchor
1 parent 3714144 commit 6ea6d72

File tree

1 file changed

+18
-3
lines changed
  • balloon/src/main/kotlin/com/skydoves/balloon

1 file changed

+18
-3
lines changed

balloon/src/main/kotlin/com/skydoves/balloon/Balloon.kt

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1827,16 +1827,31 @@ public class Balloon private constructor(
18271827
)
18281828
}
18291829

1830+
/** remembers the last pressed action event to pass it after move the touch-up points. */
1831+
private var passedEventActionDownEvent: Pair<MotionEvent, Boolean>? = null
1832+
18301833
private fun passTouchEventToAnchor(anchor: View) {
18311834
if (!this.builder.passTouchEventToAnchor) return
18321835
setOnBalloonOverlayTouchListener { view, event ->
18331836
view.performClick()
18341837
val rect = Rect()
18351838
anchor.getGlobalVisibleRect(rect)
1836-
if (event.action == MotionEvent.ACTION_UP || event.action == MotionEvent.ACTION_MOVE) {
1837-
anchor.rootView.dispatchTouchEvent(event)
1839+
1840+
if (event.action == MotionEvent.ACTION_DOWN) {
1841+
passedEventActionDownEvent = event to rect.contains(
1842+
event.rawX.toInt(),
1843+
event.rawY.toInt(),
1844+
)
1845+
}
1846+
1847+
val passedEventActionDownEvents = passedEventActionDownEvent?.first
1848+
val passedEventActionDownInvokable = passedEventActionDownEvent?.second ?: false
1849+
1850+
if (passedEventActionDownInvokable && (event.action == MotionEvent.ACTION_UP)
1851+
) {
1852+
anchor.rootView.dispatchTouchEvent(passedEventActionDownEvents!!)
18381853
true
1839-
} else if (rect.contains(event.rawX.toInt(), event.rawY.toInt())) {
1854+
} else if (passedEventActionDownInvokable) {
18401855
anchor.rootView.dispatchTouchEvent(event)
18411856
true
18421857
} else {

0 commit comments

Comments
 (0)