TouchEventManager.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. export class TouchEventManager {
  2. ontouch = null;
  3. onlongtouch = null;
  4. onlongtouchrepeatly = null;
  5. ontouchdown = null;
  6. ontouchup = null;
  7. ontouchmove = null;
  8. constructor(widget) {
  9. this._init(widget);
  10. }
  11. _init(widget) {
  12. let handleClick = true;
  13. let timerLongTap = -1;
  14. widget.addEventListener(hmUI.event.CLICK_UP, (e) => {
  15. if(this.ontouchup) this.ontouchup(e);
  16. if(handleClick && this.ontouch) this.ontouch(e);
  17. handleClick = false;
  18. timer.stopTimer(timerLongTap);
  19. });
  20. widget.addEventListener(hmUI.event.CLICK_DOWN, (e) => {
  21. if(this.ontouchdown) this.ontouchdown(e);
  22. handleClick = true;
  23. timerLongTap = timer.createTimer(750, 150, () => {
  24. if(handleClick && this.onlongtouch) {
  25. this.onlongtouch(e);
  26. handleClick = false;
  27. }
  28. if(this.onlongtouchrepeatly)
  29. this.onlongtouchrepeatly(e);
  30. })
  31. });
  32. widget.addEventListener(hmUI.event.MOVE, (e) => {
  33. if(this.ontouchmove) this.ontouchmove(e);
  34. handleClick = false;
  35. timer.stopTimer(timerLongTap);
  36. })
  37. }
  38. }