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

add hold detection functionality #345

Merged
merged 4 commits into from
Feb 14, 2024
Merged

Conversation

webloopbox
Copy link
Contributor

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.

Copy link
Contributor

@Michota Michota left a 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/types/Behavior.ts Outdated Show resolved Hide resolved

let holdTimeoutId: NodeJS.Timeout;

if (event.button === 2 || usedTouch) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is it?

Copy link
Contributor Author

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

Copy link
Contributor

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?

Copy link
Contributor Author

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

@Michota Michota merged commit d6e2784 into v5-dev Feb 14, 2024
@MichaelMatejko MichaelMatejko deleted the v5-feat/hold-event-handlers branch May 8, 2024 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants