From 3a7d29279c25aadd021449d39375e87c063d1401 Mon Sep 17 00:00:00 2001 From: Justin Covell Date: Tue, 28 Feb 2023 17:54:09 -0800 Subject: [PATCH] Fire pointerup for each pointer/add test for event order --- src/Stage.ts | 14 ++++++++------ test/unit/TouchEvents-test.ts | 15 ++++++++++++++- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/Stage.ts b/src/Stage.ts index d4caa514..2bc84960 100644 --- a/src/Stage.ts +++ b/src/Stage.ts @@ -732,12 +732,14 @@ export class Stage extends Container { }); if (!triggeredOnShape) { - this._fire(events.pointerup, { - evt: evt, - target: this, - currentTarget: this, - pointerId: this._changedPointerPositions[0].id, - }); + for (const pointer of this._changedPointerPositions) { + this._fire(events.pointerup, { + evt: evt, + target: this, + currentTarget: this, + pointerId: pointer.id, + }) + } stageClickEvents.forEach(([e, evt]) => this._fire(e, evt)) } diff --git a/test/unit/TouchEvents-test.ts b/test/unit/TouchEvents-test.ts index 292aee21..b1b4400e 100644 --- a/test/unit/TouchEvents-test.ts +++ b/test/unit/TouchEvents-test.ts @@ -343,6 +343,8 @@ describe('TouchEvents', function () { var stageTouchStart = 0; var stageTouchMove = 0; var stageTouchEnd = 0; + var stageTap = 0; + var stageEventStack: string[] = []; stage.on('touchstart', function () { stageTouchStart++; }); @@ -351,7 +353,12 @@ describe('TouchEvents', function () { }); stage.on('touchend', function () { stageTouchEnd++; + stageEventStack.push('touchend'); }); + stage.on('tap', function () { + stageTap++; + stageEventStack.push('tap'); + }) // start with one touch simulateTouchStart( @@ -452,6 +459,11 @@ describe('TouchEvents', function () { ); assert.equal(touchEnd, 1); assert.equal(stageTouchEnd, 1); + assert.equal(stageTap, 1); + // Check that tap fires after touchend + // (remember stacks are reverse event order) + assert.equal(stageEventStack.pop(), 'tap', 'should fire tap after touchend') + assert.equal(stageEventStack.pop(), 'touchend', 'should fire tap after touchend') // try two touch ends on both shapes simulateTouchEnd( @@ -465,8 +477,9 @@ describe('TouchEvents', function () { assert.equal(touchEnd, 2); assert.equal(touchEnd2, 1); - // TODO: it should be 2, not 3 assert.equal(stageTouchEnd, 3); + assert.equal(stageTap, 1) + // Don't need to check event stack here, the pointers moved so no tap is fired }); it.skip('letting go of two fingers quickly should not fire dbltap', function () {