Skip to content

Commit c23f701

Browse files
committed
The Touch Manager, Input Manager and Pointer classes all now handle the touchcancel event, such as triggered on iOS when activating an out of browser UI gesture, or in Facebook Instant Games when displaying an overlay ad. This should prevent issues with touch input becoming locked on iOS specifically. Fix phaserjs#3756
1 parent dab510f commit c23f701

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

src/input/InputManager.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,10 @@ var InputManager = new Class({
493493
this.stopPointer(event, time);
494494
break;
495495

496+
case CONST.TOUCH_CANCEL:
497+
this.cancelPointer(event, time);
498+
break;
499+
496500
case CONST.POINTER_LOCK_CHANGE:
497501
this.events.emit('pointerlockchange', event, this.mouse.locked);
498502
break;
@@ -698,6 +702,37 @@ var InputManager = new Class({
698702
}
699703
},
700704

705+
/**
706+
* Called by the main update loop when a Touch Cancel Event is received.
707+
*
708+
* @method Phaser.Input.InputManager#cancelPointer
709+
* @private
710+
* @since 3.15.0
711+
*
712+
* @param {TouchEvent} event - The native DOM event to be processed.
713+
* @param {number} time - The time stamp value of this game step.
714+
*/
715+
cancelPointer: function (event, time)
716+
{
717+
var pointers = this.pointers;
718+
719+
for (var c = 0; c < event.changedTouches.length; c++)
720+
{
721+
var changedTouch = event.changedTouches[c];
722+
723+
for (var i = 1; i < this.pointersTotal; i++)
724+
{
725+
var pointer = pointers[i];
726+
727+
if (pointer.active && pointer.identifier === changedTouch.identifier)
728+
{
729+
pointer.touchend(changedTouch, time);
730+
break;
731+
}
732+
}
733+
}
734+
},
735+
701736
/**
702737
* Adds new Pointer objects to the Input Manager.
703738
*
@@ -841,6 +876,21 @@ var InputManager = new Class({
841876
}
842877
},
843878

879+
/**
880+
* Queues a touch cancel event, as passed in by the TouchManager.
881+
* Also dispatches any DOM callbacks for this event.
882+
*
883+
* @method Phaser.Input.InputManager#queueTouchCancel
884+
* @private
885+
* @since 3.15.0
886+
*
887+
* @param {TouchEvent} event - The native DOM Touch event.
888+
*/
889+
queueTouchCancel: function (event)
890+
{
891+
this.queue.push(CONST.TOUCH_CANCEL, event);
892+
},
893+
844894
/**
845895
* Queues a mouse down event, as passed in by the MouseManager.
846896
* Also dispatches any DOM callbacks for this event.

0 commit comments

Comments
 (0)