@wildebeest/touch
Advanced tools
Comparing version 0.1.0 to 0.2.0
{ | ||
"name": "@wildebeest/touch", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Touch event module", | ||
@@ -8,3 +8,4 @@ "main": "dist/index.js", | ||
"scripts": { | ||
"build": "tsc --declaration" | ||
"build": "tsc --declaration", | ||
"test": "jest" | ||
}, | ||
@@ -16,5 +17,9 @@ "repository": { | ||
"dependencies": { | ||
"@wildebeest/common": "^0.1.0" | ||
"@wildebeest/js-modules": "^0.1.0", | ||
"@wildebeest/common": "^0.2.0" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^24.0.11", | ||
"jest": "^24.7.1", | ||
"ts-jest": "^24.0.2", | ||
"typescript": "^3.4.3" | ||
@@ -21,0 +26,0 @@ }, |
@@ -7,3 +7,3 @@ import { Emitter } from "@wildebeest/common"; | ||
protected emitter: Emitter; | ||
protected touch: any = null; | ||
protected touch: TouchEvent; | ||
@@ -14,3 +14,5 @@ constructor(element: any, emitter: Emitter) | ||
this.emitter = emitter; | ||
this.element.addEventListener('touchstart', this.setTouch.bind(this)); | ||
this.element.addEventListener('touchstart', (event: TouchEvent) => { | ||
this.touch = event; | ||
}); | ||
this.element.addEventListener('touchend', () => { | ||
@@ -27,13 +29,11 @@ this.touch = null; | ||
protected setTouch(event: any): void | ||
protected getFingerPosition(event: TouchEvent): any | ||
{ | ||
this.touch = { | ||
position: { | ||
x: event.changedTouches[0].pageX, | ||
y: event.changedTouches[0].pageY | ||
} | ||
return { | ||
x: event.changedTouches[0].clientX, | ||
y: event.changedTouches[0].clientY | ||
}; | ||
} | ||
protected onMove(event: any): void | ||
protected onMove(event: TouchEvent): void | ||
{ | ||
@@ -44,10 +44,11 @@ if (!this.touch) { | ||
let prevTouch: any = this.touch; | ||
this.setTouch(event); | ||
let lastPosition: any = this.getFingerPosition(this.touch); | ||
let currentPosition: any = this.getFingerPosition(event); | ||
let diff = { | ||
horizontal: prevTouch.position.x - this.touch.position.x, | ||
vertical: prevTouch.position.y - this.touch.position.y, | ||
horizontal: lastPosition.x - currentPosition.x, | ||
vertical: lastPosition.y - currentPosition.y, | ||
} | ||
this.emitter.emit('touchScroll', diff); | ||
this.touch = event; | ||
this.emitter.emit('wbTouchscroll', diff); | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10568
18
213
2
4
+ Added@wildebeest/common@0.2.5(transitive)
- Removed@wildebeest/common@0.1.1(transitive)
Updated@wildebeest/common@^0.2.0