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

fix(util): UIEventManager should handle touch cancel event #7169

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 22 additions & 16 deletions src/util/ui-event-manager.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import {ElementRef} from '@angular/core';




/**
* @private
*/
export class PointerEvents {
private rmTouchStart: Function = null;
private rmTouchMove: Function = null;
private rmTouchEnd: Function = null;
private rmTouchCancel: Function = null;

private rmMouseStart: Function = null;
private rmMouseMove: Function = null;
Expand All @@ -26,8 +25,8 @@ export class PointerEvents {
private zone: boolean,
private option: any) {

this.rmTouchStart = listenEvent(ele, 'touchstart', zone, option, (ev: any) => this.handleTouchStart(ev));
this.rmMouseStart = listenEvent(ele, 'mousedown', zone, option, (ev: any) => this.handleMouseDown(ev));
this.rmTouchStart = listenEvent(ele, 'touchstart', zone, option, this.handleTouchStart.bind(this));
this.rmMouseStart = listenEvent(ele, 'mousedown', zone, option, this.handleMouseDown.bind(this));
}

private handleTouchStart(ev: any) {
Expand All @@ -38,8 +37,12 @@ export class PointerEvents {
if (!this.rmTouchMove) {
this.rmTouchMove = listenEvent(this.ele, 'touchmove', this.zone, this.option, this.pointerMove);
}
let handleTouchEnd = (ev: any) => this.handleTouchEnd(ev);
if (!this.rmTouchEnd) {
this.rmTouchEnd = listenEvent(this.ele, 'touchend', this.zone, this.option, (ev: any) => this.handleTouchEnd(ev));
this.rmTouchEnd = listenEvent(this.ele, 'touchend', this.zone, this.option, handleTouchEnd);
}
if (!this.rmTouchCancel) {
this.rmTouchCancel = listenEvent(this.ele, 'touchcancel', this.zone, this.option, handleTouchEnd);
}
}

Expand All @@ -60,35 +63,38 @@ export class PointerEvents {
}

private handleTouchEnd(ev: any) {
this.rmTouchMove && this.rmTouchMove();
this.rmTouchMove = null;
this.rmTouchEnd && this.rmTouchEnd();
this.rmTouchEnd = null;

this.stopTouch();
this.pointerUp(ev);
}

private handleMouseUp(ev: any) {
this.rmMouseMove && this.rmMouseMove();
this.rmMouseMove = null;
this.rmMouseUp && this.rmMouseUp();
this.rmMouseUp = null;

this.stopMouse();
this.pointerUp(ev);
}

stop() {
private stopTouch() {
this.rmTouchMove && this.rmTouchMove();
this.rmTouchEnd && this.rmTouchEnd();
this.rmTouchCancel && this.rmTouchCancel();

this.rmTouchMove = null;
this.rmTouchEnd = null;
this.rmTouchCancel = null;
}

private stopMouse() {
this.rmMouseMove && this.rmMouseMove();
this.rmMouseUp && this.rmMouseUp();

this.rmMouseMove = null;
this.rmMouseUp = null;
}

stop() {
this.stopTouch();
this.stopMouse();
}

destroy() {
this.rmTouchStart && this.rmTouchStart();
this.rmTouchStart = null;
Expand Down