-
Notifications
You must be signed in to change notification settings - Fork 1.6k
fix: cancel useLongPress when a second touch begins #10535
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
Open
giaBaoJS
wants to merge
1
commit into
adobe:main
Choose a base branch
from
giaBaoJS:fix/long-press-cancel-multitouch
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+263
−3
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't longpress end have already happened by here? it's canceled on pointerDown
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, and the pre-fix behavior is what makes it look like it should.
onLongPressEndis emitted from one place only:usePress'sonPressEnd(useLongPress.ts:150-160). In the uninterrupted path it arrives before pointerup because the timer callback dispatches a syntheticpointercancel(useLongPress.ts:95), which runsusePress'scancel(usePress.ts:309-315) and fires press end. That is whyshould perform a long presssees longpressstart, longpressend, longpress.The cancel path does not dispatch
pointercancel. It only clears the timer (useLongPress.ts:126-129), so the press is still live and nothing fires press end. The secondpointerdownitself produces no event at all, becauseusePress.ts:560skips the entire block whenstate.isPressedis already true.I instrumented the element with both
usePressanduseLongPresshandlers to confirm the order:So at that line only longpressstart has fired, and longpressend arrives on lift, which the second assertion at the end of the test covers. Restoring the pre-fix source and keeping the tests turns exactly that assertion red, receiving longpressstart, longpressend, longpress, which is the sequence you have in mind.
One decision this exposes, though: since the press is left untouched, lifting the finger still fires
onPress, so a three-finger tap on a menu item cancels the long press but still activates the item. Dispatchingpointercancelon the second touch instead of just clearing the timer would both give you longpressend at that point and suppress the press. I kept the scope narrow deliberately, but I am happy to make that change if you prefer it.