Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #9676, fire touchmove event while handlers are active #9685

Merged
merged 1 commit into from
May 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/ui/handler/map_event.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ export class MapEventHandler {
return this._firePreventable(new MapTouchEvent(e.type, this._map, e));
}

touchmove(e: TouchEvent) {
this._map.fire(new MapTouchEvent(e.type, this._map, e));
}

touchend(e: TouchEvent) {
this._map.fire(new MapTouchEvent(e.type, this._map, e));
}
Expand Down Expand Up @@ -114,11 +118,6 @@ export class BlockableMapEventHandler {
this._map.fire(new MapMouseEvent(e.type, this._map, e));
}

touchmove(e: TouchEvent) {
// touchmove map events should not be fired when interaction handlers (pan, rotate, etc) are active
this._map.fire(new MapTouchEvent(e.type, this._map, e));
}

mousedown() {
this._delayContextMenu = true;
}
Expand Down
45 changes: 44 additions & 1 deletion test/unit/ui/handler/map_event.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ test('MapEvent handler fires touch events with correct values', (t) => {
t.deepEqual(touchstart.getCall(0).args[0].point, {x: 0, y: 50});
t.equal(touchmove.callCount, 0);
t.equal(touchend.callCount, 0);
console.log(touchstart);

simulate.touchmove(map.getCanvas(), {touches: touchesMove, targetTouches: touchesMove});
t.equal(touchstart.callCount, 1);
Expand All @@ -46,3 +45,47 @@ test('MapEvent handler fires touch events with correct values', (t) => {
map.remove();
t.end();
});

test('MapEvent handler fires touchmove even while drag handler is active', (t) => {
const map = createMap(t);
const target = map.getCanvas();
map.dragPan.enable();

const touchstart = t.spy();
const touchmove = t.spy();
const touchend = t.spy();
const drag = t.spy();

map.on('touchstart', touchstart);
map.on('touchmove', touchmove);
map.on('touchend', touchend);
map.on('drag', drag);

const touchesStart = [{target, identifier: 1, clientX: 0, clientY: 50}];
const touchesMove = [{target, identifier: 1, clientX: 0, clientY: 60}];
const touchesEnd = [{target, identifier: 1, clientX: 0, clientY: 60}];

simulate.touchstart(map.getCanvas(), {touches: touchesStart, targetTouches: touchesStart});
t.equal(touchstart.callCount, 1);
t.deepEqual(touchstart.getCall(0).args[0].point, {x: 0, y: 50});
t.equal(touchmove.callCount, 0);
t.equal(touchend.callCount, 0);

simulate.touchmove(map.getCanvas(), {touches: touchesMove, targetTouches: touchesMove});
t.equal(touchstart.callCount, 1);
t.equal(touchmove.callCount, 1);
t.deepEqual(touchmove.getCall(0).args[0].point, {x: 0, y: 60});
t.equal(touchend.callCount, 0);

simulate.touchend(map.getCanvas(), {touches: [], targetTouches: [], changedTouches: touchesEnd});
t.equal(touchstart.callCount, 1);
t.equal(touchmove.callCount, 1);
t.equal(touchend.callCount, 1);
t.deepEqual(touchend.getCall(0).args[0].point, {x: 0, y: 60});

map._renderTaskQueue.run();
t.equal(drag.callCount, 1);

map.remove();
t.end();
});