Skip to content

Commit 32a1907

Browse files
committed
Fix buttons getting stuck in scroll views
1 parent 48b8d00 commit 32a1907

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

android/src/main/java/com/swmansion/gesturehandler/core/GestureHandler.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,7 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
657657

658658
fun fail() {
659659
if (state == STATE_ACTIVE || state == STATE_UNDETERMINED || state == STATE_BEGAN) {
660+
onFail()
660661
moveToState(STATE_FAILED)
661662
}
662663
}
@@ -710,6 +711,7 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
710711
protected open fun onStateChange(newState: Int, previousState: Int) {}
711712
protected open fun onReset() {}
712713
protected open fun onCancel() {}
714+
protected open fun onFail() {}
713715

714716
private fun isButtonInConfig(clickedButton: Int): Boolean {
715717
if (mouseButton == 0) {

android/src/main/java/com/swmansion/gesturehandler/core/NativeViewGestureHandler.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class NativeViewGestureHandler : GestureHandler<NativeViewGestureHandler>() {
148148
}
149149
}
150150

151-
override fun onCancel() {
151+
private fun dispatchCancelEventToView() {
152152
val time = SystemClock.uptimeMillis()
153153
val event = MotionEvent.obtain(time, time, MotionEvent.ACTION_CANCEL, 0f, 0f, 0).apply {
154154
action = MotionEvent.ACTION_CANCEL
@@ -157,6 +157,10 @@ class NativeViewGestureHandler : GestureHandler<NativeViewGestureHandler>() {
157157
event.recycle()
158158
}
159159

160+
override fun onCancel() = dispatchCancelEventToView()
161+
162+
override fun onFail() = dispatchCancelEventToView()
163+
160164
override fun onReset() {
161165
this.hook = defaultHook
162166
}

0 commit comments

Comments
 (0)