mirror of
https://github.com/billsonnn/nitro-react.git
synced 2024-11-23 06:40:50 +01:00
Touch event fixes
This commit is contained in:
parent
6a6d7f6947
commit
2b9f6b5634
@ -4,38 +4,9 @@ import { GetRoomEngine } from './GetRoomEngine';
|
|||||||
let didMouseMove = false;
|
let didMouseMove = false;
|
||||||
let lastClick = 0;
|
let lastClick = 0;
|
||||||
let clickCount = 0;
|
let clickCount = 0;
|
||||||
let touchTimer: ReturnType<typeof setTimeout> = null;
|
|
||||||
|
|
||||||
export const DispatchTouchEvent = (event: TouchEvent, canvasId: number = 1, longTouch: boolean = false, altKey: boolean = false, ctrlKey: boolean = false, shiftKey: boolean = false) =>
|
export const DispatchTouchEvent = (event: TouchEvent, canvasId: number = 1, longTouch: boolean = false, altKey: boolean = false, ctrlKey: boolean = false, shiftKey: boolean = false) =>
|
||||||
{
|
{
|
||||||
let eventType = event.type;
|
|
||||||
|
|
||||||
if(longTouch) eventType = TouchEventType.TOUCH_LONG;
|
|
||||||
|
|
||||||
if(eventType === TouchEventType.TOUCH_END && !didMouseMove)
|
|
||||||
{
|
|
||||||
eventType = MouseEventType.MOUSE_CLICK;
|
|
||||||
|
|
||||||
if(lastClick)
|
|
||||||
{
|
|
||||||
clickCount = 1;
|
|
||||||
|
|
||||||
if(lastClick >= (Date.now() - 300)) clickCount++;
|
|
||||||
}
|
|
||||||
|
|
||||||
lastClick = Date.now();
|
|
||||||
|
|
||||||
if(clickCount === 2)
|
|
||||||
{
|
|
||||||
eventType = MouseEventType.DOUBLE_CLICK;
|
|
||||||
|
|
||||||
clickCount = 0;
|
|
||||||
lastClick = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(touchTimer) clearTimeout(touchTimer);
|
|
||||||
|
|
||||||
let x = 0;
|
let x = 0;
|
||||||
let y = 0;
|
let y = 0;
|
||||||
|
|
||||||
@ -51,6 +22,32 @@ export const DispatchTouchEvent = (event: TouchEvent, canvasId: number = 1, long
|
|||||||
y = event.changedTouches[0].clientY;
|
y = event.changedTouches[0].clientY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let eventType = event.type;
|
||||||
|
|
||||||
|
if(longTouch) eventType = TouchEventType.TOUCH_LONG;
|
||||||
|
|
||||||
|
if(eventType === MouseEventType.MOUSE_CLICK || eventType === TouchEventType.TOUCH_END)
|
||||||
|
{
|
||||||
|
eventType = MouseEventType.MOUSE_CLICK;
|
||||||
|
|
||||||
|
if(lastClick)
|
||||||
|
{
|
||||||
|
clickCount = 1;
|
||||||
|
|
||||||
|
if(lastClick >= (Date.now() - 300)) clickCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
lastClick = Date.now();
|
||||||
|
|
||||||
|
if(clickCount === 2)
|
||||||
|
{
|
||||||
|
if(!didMouseMove) eventType = MouseEventType.DOUBLE_CLICK;
|
||||||
|
|
||||||
|
clickCount = 0;
|
||||||
|
lastClick = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch(eventType)
|
switch(eventType)
|
||||||
{
|
{
|
||||||
case MouseEventType.MOUSE_CLICK:
|
case MouseEventType.MOUSE_CLICK:
|
||||||
@ -58,13 +55,6 @@ export const DispatchTouchEvent = (event: TouchEvent, canvasId: number = 1, long
|
|||||||
case MouseEventType.DOUBLE_CLICK:
|
case MouseEventType.DOUBLE_CLICK:
|
||||||
break;
|
break;
|
||||||
case TouchEventType.TOUCH_START:
|
case TouchEventType.TOUCH_START:
|
||||||
touchTimer = setTimeout(() =>
|
|
||||||
{
|
|
||||||
if(didMouseMove) return;
|
|
||||||
|
|
||||||
DispatchTouchEvent(event, canvasId, true);
|
|
||||||
}, 300);
|
|
||||||
|
|
||||||
eventType = MouseEventType.MOUSE_DOWN;
|
eventType = MouseEventType.MOUSE_DOWN;
|
||||||
|
|
||||||
didMouseMove = false;
|
didMouseMove = false;
|
||||||
@ -83,5 +73,10 @@ export const DispatchTouchEvent = (event: TouchEvent, canvasId: number = 1, long
|
|||||||
default: return;
|
default: return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (eventType === TouchEventType.TOUCH_START)
|
||||||
|
{
|
||||||
|
GetRoomEngine().dispatchMouseEvent(canvasId, x, y, eventType, altKey, ctrlKey, shiftKey, false);
|
||||||
|
}
|
||||||
|
|
||||||
GetRoomEngine().dispatchMouseEvent(canvasId, x, y, eventType, altKey, ctrlKey, shiftKey, false);
|
GetRoomEngine().dispatchMouseEvent(canvasId, x, y, eventType, altKey, ctrlKey, shiftKey, false);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user