我想从RxJS中的touch事件中重新创建contextmenu事件,因为iOS does not support是touch上的contextmenu事件.
用通俗易懂的语言,当出现以下情况时,应发出此可见光:
- 发生touchstart事件
- 2000ms(基本上为长压)
- 接touchend
在以下情况下不应发出:
- touch 端在2000毫秒内发生
- touchstart事件之后是touchmove事件
如果touchend出现得更早,或者touchstart后面跟着touchmove,我不知道如何跳过.这就是我目前所做的:
const touchStart$ = fromEvent<TouchEvent>(this.el.nativeElement, "touchstart");
const touchEnd$ = fromEvent<TouchEvent>(this.el.nativeElement, "touchend");
const touchMove$ = fromEvent<TouchEvent>(this.el.nativeElement, "touchmove");
const contextmenu$ = touchStart$.pipe(
switchMap(event => touchEnd$.pipe(mapTo(event))),
switchMap(event => timer(2000).pipe(mapTo(event), takeUntil(merge(touchEnd$, touchMove$))))
);
contextmenu$.subscribe($event => {
console.log("CONTEXTMENU EVENT HAPPENED");
});