aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/Touchable.tsx
diff options
context:
space:
mode:
authorStanley Yip <stanley_yip@brown.edu>2019-11-23 17:29:18 -0500
committerStanley Yip <stanley_yip@brown.edu>2019-11-23 17:29:18 -0500
commit22472e278c5616ba86c75ed29cd5846d0cf35ff5 (patch)
treed4be5e18814c8491161caf5d858f8879fcfc2798 /src/client/views/Touchable.tsx
parent92491285a0b394f433a018810606bc6a543e7e93 (diff)
auto pen !
Diffstat (limited to 'src/client/views/Touchable.tsx')
-rw-r--r--src/client/views/Touchable.tsx34
1 files changed, 20 insertions, 14 deletions
diff --git a/src/client/views/Touchable.tsx b/src/client/views/Touchable.tsx
index 326e8e578..dbadc27ea 100644
--- a/src/client/views/Touchable.tsx
+++ b/src/client/views/Touchable.tsx
@@ -17,22 +17,28 @@ export abstract class Touchable<T = {}> extends React.Component<T> {
@action
protected onTouchStart = (e: React.TouchEvent): void => {
for (let i = 0; i < e.targetTouches.length; i++) {
- let pt = e.targetTouches.item(i);
- this.prevPoints.set(pt.identifier, pt);
+ let pt: any = e.targetTouches.item(i);
+ // pen is also a touch, but with a radius of 0.5 (at least with the surface pens). i doubt anyone's fingers are 2 pixels wide,
+ // and this seems to be the only way of differentiating pen and touch on touch events
+ if (pt.radiusX > 2 && pt.radiusY > 2) {
+ this.prevPoints.set(pt.identifier, pt);
+ }
}
- switch (e.targetTouches.length) {
- case 1:
- this.handle1PointerDown(e);
- break;
- case 2:
- this.handle2PointersDown(e);
- }
+ if (this.prevPoints.size) {
+ switch (e.targetTouches.length) {
+ case 1:
+ this.handle1PointerDown(e);
+ break;
+ case 2:
+ this.handle2PointersDown(e);
+ }
- document.removeEventListener("touchmove", this.onTouch);
- document.addEventListener("touchmove", this.onTouch);
- document.removeEventListener("touchend", this.onTouchEnd);
- document.addEventListener("touchend", this.onTouchEnd);
+ document.removeEventListener("touchmove", this.onTouch);
+ document.addEventListener("touchmove", this.onTouch);
+ document.removeEventListener("touchend", this.onTouchEnd);
+ document.addEventListener("touchend", this.onTouchEnd);
+ }
}
/**
@@ -45,7 +51,7 @@ export abstract class Touchable<T = {}> extends React.Component<T> {
this._touchDrag = true;
switch (e.targetTouches.length) {
case 1:
- this.handle1PointerMove(e)
+ this.handle1PointerMove(e);
break;
case 2:
this.handle2PointersMove(e);