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 (optional) cursor support #6

Closed
nickschot opened this issue Mar 19, 2020 · 5 comments · Fixed by #16
Closed

add (optional) cursor support #6

nickschot opened this issue Mar 19, 2020 · 5 comments · Fixed by #16

Comments

@nickschot
Copy link
Owner

Currently only actual touch events are supported.

@josemarluedke
Copy link

👍 I recently implemented a similar modifier and I had cursor support as requirement. Having it here would be awesome. BTW, great addon!

@nickschot
Copy link
Owner Author

@josemarluedke how did you implement the cursor part? Plain mouse events or through pointer events (or both)? Currently researching what the best way to add support for this would be.

@josemarluedke
Copy link

I used mouse events. It worked well so far.

  setup() {
    // setup touch
    this.element.addEventListener('touchstart', this.handleStart, false);
    this.element.addEventListener('touchmove', this.handleMove, false);
    this.element.addEventListener('touchend', this.handleEnd, false);

    // setup mouse
    this.element.addEventListener('mousedown', this.handleStart, false);
    this.element.addEventListener('mousemove', this.handleMove, false);
    this.element.addEventListener('mouseup', this.handleEnd, false);
  }
  
  /// ....

  @action handleStart(event: TouchEvent | MouseEvent): void {
    if (event instanceof TouchEvent) {
      this.startX = event.changedTouches[0].clientX;
    } else {
      this.startX = event.clientX;
    }
  }
  // etc ... 

@josemarluedke
Copy link

Actually, the check needs to account for TouchEvent not been defined, which occurs in desktop Safari.

function isTouchEvent(event: MouseEvent | TouchEvent): event is TouchEvent {
  return (
    (typeof TouchEvent as never) !== 'undefined' && event instanceof TouchEvent
  );
}

@nickschot
Copy link
Owner Author

So I'm gonna rework the implementation to utilize PointerEvents so we can support all types of input at once (also pencils etc.)

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 a pull request may close this issue.

2 participants