Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix buttons getting stuck after scrolling on them #2693

Merged
merged 4 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,21 @@ class NativeViewGestureHandler : GestureHandler<NativeViewGestureHandler>() {
override fun onHandle(event: MotionEvent, sourceEvent: MotionEvent) {
val view = view!!
if (event.actionMasked == MotionEvent.ACTION_UP) {
view.onTouchEvent(event)
if ((state == STATE_UNDETERMINED || state == STATE_BEGAN) && view.isPressed) {
activate()
if (state == STATE_UNDETERMINED && !hook.canBegin(event)) {
cancel()
} else {
view.onTouchEvent(event)
if ((state == STATE_UNDETERMINED || state == STATE_BEGAN) && view.isPressed) {
activate()
}

if (state == STATE_UNDETERMINED) {
cancel()
} else {
end()
}
}
end()

hook.afterGestureEnd(event)
} else if (state == STATE_UNDETERMINED || state == STATE_BEGAN) {
when {
Expand All @@ -104,10 +114,8 @@ class NativeViewGestureHandler : GestureHandler<NativeViewGestureHandler>() {
hook.handleEventBeforeActivation(event)
}
state != STATE_BEGAN -> {
if (hook.canBegin()) {
if (hook.canBegin(event)) {
begin()
} else {
cancel()
}
}
}
Expand Down Expand Up @@ -144,7 +152,7 @@ class NativeViewGestureHandler : GestureHandler<NativeViewGestureHandler>() {
* @return Boolean value signalling whether the handler can transition to the BEGAN state. If false
* the gesture will be cancelled.
*/
fun canBegin() = true
fun canBegin(event: MotionEvent) = true

/**
* Called after the gesture transitions to the END state.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,15 +270,15 @@ class RNGestureHandlerButtonViewManager : ViewGroupManager<ButtonViewGroup>(), R
* [com.swmansion.gesturehandler.NativeViewGestureHandler.onHandle] */
@SuppressLint("ClickableViewAccessibility")
override fun onTouchEvent(event: MotionEvent): Boolean {
val eventTime = event.eventTime
val action = event.action

if (event.action == MotionEvent.ACTION_CANCEL) {
tryFreeingResponder()
return super.onTouchEvent(event)
}

val eventTime = event.eventTime
val action = event.action
// always true when lastEventTime or lastAction have default value (-1)
if (lastEventTime != eventTime || lastAction != action) {
if (lastEventTime != eventTime || lastAction != action || action == MotionEvent.ACTION_CANCEL) {
lastEventTime = eventTime
lastAction = action
return super.onTouchEvent(event)
Expand Down Expand Up @@ -384,7 +384,11 @@ class RNGestureHandlerButtonViewManager : ViewGroupManager<ButtonViewGroup>(), R
}
}

override fun canBegin(): Boolean {
override fun canBegin(event: MotionEvent): Boolean {
if (event.action == MotionEvent.ACTION_CANCEL || event.action == MotionEvent.ACTION_UP || event.actionMasked == MotionEvent.ACTION_POINTER_UP) {
return false
}

val isResponder = tryGrabbingResponder()
if (isResponder) {
isTouched = true
Expand Down
Loading