Skip to content

Commit

Permalink
Fix touch event (#16893)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
minggo authored Apr 12, 2024
1 parent 24f3f65 commit 72c8487
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cocos/2d/event/pointer-event-dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ class PointerEventDispatcher implements IEventDispatcher {
pointerEventProcessor._handleEventTouch(eventTouch);
if (eventTouch.type === InputEventType.TOUCH_END || eventTouch.type === InputEventType.TOUCH_CANCEL) {

Check failure on line 154 in cocos/2d/event/pointer-event-dispatcher.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

The two values in this comparison do not have a shared enum type

Check failure on line 154 in cocos/2d/event/pointer-event-dispatcher.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

The two values in this comparison do not have a shared enum type
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) {
Expand All @@ -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;
Expand Down

0 comments on commit 72c8487

Please sign in to comment.