-
Notifications
You must be signed in to change notification settings - Fork 123
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
add hold detection functionality #345
Conversation
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.
Small changes are needed.
src/controllers/handlePointerDown.ts
Outdated
|
||
let holdTimeoutId: NodeJS.Timeout; | ||
|
||
if (event.button === 2 || usedTouch) { |
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.
What is it?
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.
If the event is a right-click or a touch event, a timeout is set to trigger. holdTimeoutId
is used to clear the timeout if a pointer up event occurs before 500 ms, so the hold handler function will not be called
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.
Okay. Can you create some sort of constant assertion or simply a normal const that will describe event.button === 2
, so the code will be easier to understand?
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.
Yup, it's a good idea
detectHold function that handles the detection and completion of a hold action for both mouse and touch pointer types.
It includes the following features:
hold detection: this could be a right mouse click or a touch event. It sets up an interval to check the duration of the hold and listens for a pointer up event.
hold completion: when a pointer up event occurs, the function terminates the hold detection process. If the hold duration was 200 milliseconds or more, it resolves a promise to indicate that the hold action has been completed.