File
Description
HOW TO USE:
Index
Properties
|
|
Inputs
|
|
Outputs
|
|
HostListeners
|
|
longPressTimeout
|
Type : number
|
Default value : 500
|
|
Outputs
appLongPressDo
|
Type : EventEmitter<number>
|
|
HostListeners
mousedown
|
Arguments : '$event'
|
|
mouseleave
|
Arguments : '$event'
|
|
mousemove
|
Arguments : '$event'
|
|
mouseup
|
Arguments : '$event'
|
|
touchcancel
|
Arguments : '$event'
|
|
touchend
|
Arguments : '$event'
|
|
touchmove
|
Arguments : '$event'
|
|
touchstart
|
Arguments : '$event'
|
|
Private
Readonly
handle
|
Default value : new Subject()
|
|
onExit
|
Default value : () => {...}
|
Decorators :
@HostListener('touchend', ['$event']) @HostListener('touchcancel', ['$event']) @HostListener('touchmove', ['$event']) @HostListener('mouseup', ['$event']) @HostListener('mouseleave', ['$event']) @HostListener('mousemove', ['$event'])
|
|
startHold
|
Default value : () => {...}
|
Decorators :
@HostListener('mousedown', ['$event']) @HostListener('touchstart', ['$event'])
|
|
import {
Directive,
HostListener,
EventEmitter,
Output,
Input,
} from '@angular/core';
import { interval, Subject } from 'rxjs';
import { take, takeUntil } from 'rxjs/operators';
/**
* HOW TO USE:
* <div appLongPress [holdTime]="500" (appLongPressDo)="holdHandler(anything)"></div>
*
* @param longPressTime (Optional). Will `emit()` every 100ms by default.
*/
@Directive({
selector: '[appLongPress]',
standalone: true,
})
export class LongPressDirective {
@Input() longPressTimeout = 500;
@Output() appLongPressDo: EventEmitter<number> = new EventEmitter();
private readonly handle = new Subject();
@HostListener('touchend', ['$event'])
@HostListener('touchcancel', ['$event'])
@HostListener('touchmove', ['$event'])
@HostListener('mouseup', ['$event'])
@HostListener('mouseleave', ['$event'])
@HostListener('mousemove', ['$event'])
onExit = () => this.handle.next(false);
@HostListener('mousedown', ['$event'])
@HostListener('touchstart', ['$event'])
startHold = ($event: any) =>
interval(this.longPressTimeout)
.pipe(take(1), takeUntil(this.handle))
.subscribe(() => this.appLongPressDo.emit($event));
}