-
-
Notifications
You must be signed in to change notification settings - Fork 980
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
Don't cancel long press after activation on Android #574
base: main
Are you sure you want to change the base?
Conversation
Makes long presses more consistent with iOS, which doesn’t cancel the gesture due to maxDist if it’s already in the `ACTIVE` state. This is also more consistent with TapGestureHandler, whose docs specifically say that maxDist fails if the “handler hasn't yet activated”.
Hi @lnikkila thanks for PR. how to reproduce this issue? |
We have a LongPressHandler that uses onHandlerStateChange and onGestureEvent together to first wait for a long press, and then observe drag touch events (XY-coordinates) until the user lets go. This handler also has a max distance limit so that the activating long press needs to be stationary. On iOS, once the long press handler activates, you can then keep dragging arbitrary distances without the max distance limit interrupting the gesture. This makes sense since the long press has already activated. On Android, the max distance limit terminates the gesture even after it has activated, and you can’t drag after the long press. This patch changes behaviour on Android to be consistent with iOS, and makes a “long press and drag” gesture possible without adding additional handlers like PanGestureHandler. If you need a repro sample to review this, I can write one later this week. |
@lnikkila |
I'm finding this happens on Android even when the |
Sorry about the wait, I've been super busy. Here's some pseudocode that should repro this issue, the expected behaviour is for the long press to not deactivate after it's first been activated even if you keep dragging, this allows observing drag events after the initial long press: const onHandlerStateChange = ({ nativeEvent }) => {
const { state } = nativeEvent;
if (state === State.ACTIVE) {
console.log('ACTIVE');
} else if (state === State.END) {
console.log('END');
} else if (state === State.CANCELLED) {
console.log('CANCELLED');
}
};
const onGestureEvent = ({ nativeEvent }) => {
// You should be able to observe these touch events after long pressing and
// then dragging more than `maxDist` after the initial activation.
console.log(nativeEvent);
};
const Component = () => {
return (
<LongPressGestureHandler
onGestureEvent={onGestureEvent}
onHandlerStateChange={onHandlerStateChange}
>
<View style={{ flex: 1, backgroundColor: 'red' }} />
</LongPressGestureHandler>
);
} At the time I wrote this patch this worked as expected on iOS, but emitted the |
I have confirmed the behavior described by @lnikkila on the current version as well. Regarding my earlier comment, I realized that setting |
Makes long presses more consistent with iOS, which doesn’t cancel the gesture due to maxDist if it’s already in the
ACTIVE
state. This is also more consistent with TapGestureHandler, whose docs specifically say that maxDist fails if the “handler hasn't yet activated”.