Merge pull request #2843 from NoelDeMartin/MOBILE-3320
MOBILE-3320 UX: Trigger long press on down eventmain
commit
c9796eb3c2
|
@ -25,9 +25,11 @@ import { GestureController } from '@singletons';
|
||||||
})
|
})
|
||||||
export class CoreLongPressDirective implements OnInit, OnDestroy {
|
export class CoreLongPressDirective implements OnInit, OnDestroy {
|
||||||
|
|
||||||
|
readonly HOLD_DURATION = 500;
|
||||||
|
|
||||||
element: HTMLElement;
|
element: HTMLElement;
|
||||||
pressGesture?: Gesture;
|
pressGesture?: Gesture;
|
||||||
protected moved = false;
|
timeout?: NodeJS.Timeout;
|
||||||
|
|
||||||
@Output() longPress = new EventEmitter();
|
@Output() longPress = new EventEmitter();
|
||||||
|
|
||||||
|
@ -45,9 +47,15 @@ export class CoreLongPressDirective implements OnInit, OnDestroy {
|
||||||
threshold: 0,
|
threshold: 0,
|
||||||
disableScroll: true,
|
disableScroll: true,
|
||||||
gestureName: 'longpress',
|
gestureName: 'longpress',
|
||||||
onStart: () => this.moved = false,
|
onStart: (event) => {
|
||||||
onMove: () => this.moved = true,
|
this.timeout = setTimeout(() => {
|
||||||
onEnd: ev => !this.moved && this.longPress.emit(ev.event),
|
this.longPress.emit(event);
|
||||||
|
|
||||||
|
delete this.timeout;
|
||||||
|
}, this.HOLD_DURATION);
|
||||||
|
},
|
||||||
|
onMove: () => this.clearTimeout(),
|
||||||
|
onEnd: () => this.clearTimeout(),
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
this.pressGesture.enable();
|
this.pressGesture.enable();
|
||||||
|
@ -58,6 +66,16 @@ export class CoreLongPressDirective implements OnInit, OnDestroy {
|
||||||
*/
|
*/
|
||||||
ngOnDestroy(): void {
|
ngOnDestroy(): void {
|
||||||
this.pressGesture?.destroy();
|
this.pressGesture?.destroy();
|
||||||
|
this.clearTimeout();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected clearTimeout(): void {
|
||||||
|
if (!this.timeout) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
clearTimeout(this.timeout);
|
||||||
|
delete this.timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue