mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 08:02:39 +08:00
Fix touch event (#16893)
* only one event processor can handle the corresponding touch end/cancel event when touch end/cancel event is handled, other event processor that waiting to handle the touch event should be canceld.
This commit is contained in:
@@ -153,6 +153,8 @@ class PointerEventDispatcher implements IEventDispatcher {
|
||||
pointerEventProcessor._handleEventTouch(eventTouch);
|
||||
if (eventTouch.type === InputEventType.TOUCH_END || eventTouch.type === InputEventType.TOUCH_CANCEL) {
|
||||
js.array.removeAt(pointerEventProcessor.claimedTouchIdList, index);
|
||||
// The event is handled, so should remove other EventProcessor's claimedTouchIdList.
|
||||
this._removeClaimedTouch(i + 1, index);
|
||||
}
|
||||
dispatchToNextEventDispatcher = false;
|
||||
if (!eventTouch.preventSwallow) {
|
||||
@@ -170,6 +172,18 @@ class PointerEventDispatcher implements IEventDispatcher {
|
||||
return dispatchToNextEventDispatcher;
|
||||
}
|
||||
|
||||
private _removeClaimedTouch (eventProcessorIndex: number, touchID: number): void {
|
||||
const pointerEventProcessorList = this._pointerEventProcessorList;
|
||||
const length = pointerEventProcessorList.length;
|
||||
for (let i = eventProcessorIndex; i < length; ++i) {
|
||||
const pointerEventProcessor = pointerEventProcessorList[i];
|
||||
const touchIndex = pointerEventProcessor.claimedTouchIdList.indexOf(touchID);
|
||||
if (touchIndex !== -1) {
|
||||
js.array.removeAt(pointerEventProcessor.claimedTouchIdList, touchIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private _updatePointerEventProcessorList (): void {
|
||||
const listToAdd = this._processorListToAdd;
|
||||
const addLength = listToAdd.length;
|
||||
|
||||
Reference in New Issue
Block a user