Skip to content

Commit afc4556

Browse files
avpeeryrreussermourner
authored
Fix an iOS15 issue where Safari tab bar interrupts panning (#11084) (#11101)
* Fix an iOS15 issue where Safari tab bar interrupts panning (#11084) (#11089) * fix an iOS15 issue where map stops when panning * fix tests and lint * Test drag pan handler does not end interaction on resize * Move blur event reset into non-touch handlers (#11087) * Move blur event reset into non-touch handlers * Fix linter * Fix/amend unit tests * Flush task queue in rotate test Co-authored-by: Ricky Reusser <ricky.reusser@mapbox.com> Co-authored-by: Ricky Reusser <rreusser@users.noreply.github.com> Co-authored-by: Vladimir Agafonkin <agafonkin@gmail.com> * Removed getBoundingClientRect conflict for unit tests * Added offsetHeight to replace getBoundingClientRect to fix unit tests * add clientWidth and clientHeight to unit tests * container -> map.getContainer() * Replaced offsetWidth with clientWidth * removing change difference in attribution and logo unit tests from v1.13.2 * Change size of container instead of canvas container to trigger resize in unit tests * Added change in height to trigger resize * fix to attribution.test.js * Fixes logo.test.js to pass * removed unneeded changes Co-authored-by: Ricky Reusser <rreusser@users.noreply.github.com> Co-authored-by: Vladimir Agafonkin <agafonkin@gmail.com>
1 parent 50adf1c commit afc4556

12 files changed

Lines changed: 98 additions & 10 deletions

File tree

src/ui/handler/box_zoom.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ class BoxZoomHandler {
142142
}
143143
}
144144

145+
blur() {
146+
this.reset();
147+
}
148+
145149
reset() {
146150
this._active = false;
147151

src/ui/handler/click_zoom.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ export default class ClickZoomHandler {
1616
this._active = false;
1717
}
1818

19+
blur() {
20+
this.reset();
21+
}
22+
1923
dblclick(e: MouseEvent, point: Point) {
2024
e.preventDefault();
2125
return {

src/ui/handler/keyboard.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ class KeyboardHandler {
4141
this._rotationDisabled = false;
4242
}
4343

44+
blur() {
45+
this.reset();
46+
}
47+
4448
reset() {
4549
this._active = false;
4650
}

src/ui/handler/mouse.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ class MouseHandler {
3131
this._clickTolerance = options.clickTolerance || 1;
3232
}
3333

34+
blur() {
35+
this.reset();
36+
}
37+
3438
reset() {
3539
this._active = false;
3640
this._moved = false;

src/ui/handler/scroll_zoom.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,10 @@ class ScrollZoomHandler {
338338
return easing;
339339
}
340340

341+
blur() {
342+
this.reset();
343+
}
344+
341345
reset() {
342346
this._active = false;
343347
}

src/ui/handler_manager.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -291,11 +291,6 @@ class HandlerManager {
291291

292292
handleEvent(e: InputEvent | RenderFrameEvent, eventName?: string) {
293293

294-
if (e.type === 'blur') {
295-
this.stop(true);
296-
return;
297-
}
298-
299294
this._updatingCamera = true;
300295
assert(e.timeStamp !== undefined);
301296

src/ui/map.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -591,17 +591,17 @@ class Map extends Camera {
591591
* if (mapDiv.style.visibility === true) map.resize();
592592
*/
593593
resize(eventData?: Object) {
594-
const dimensions = this._containerDimensions();
595-
const width = dimensions[0];
596-
const height = dimensions[1];
594+
const [width, height] = this._containerDimensions();
595+
596+
// do nothing if container remained the same size
597+
if (width === this.transform.width && height === this.transform.height) return this;
597598

598599
this._resizeCanvas(width, height);
599600
this.transform.resize(width, height);
600601
this.painter.resize(width, height);
601602

602603
const fireMoving = !this._moving;
603604
if (fireMoving) {
604-
this.stop();
605605
this.fire(new Event('movestart', eventData))
606606
.fire(new Event('move', eventData));
607607
}

test/unit/ui/control/attribution.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,15 @@ test('AttributionControl appears in compact mode if compact option is used', (t)
6363
test('AttributionControl appears in compact mode if container is less then 640 pixel wide', (t) => {
6464
const map = createMap(t);
6565
Object.defineProperty(map.getCanvasContainer(), 'offsetWidth', {value: 700, configurable: true});
66+
Object.defineProperty(map.getContainer(), 'clientWidth', {value: 700, configurable: true});
6667
map.addControl(new AttributionControl());
6768

6869
const container = map.getContainer();
6970

7071
t.equal(container.querySelectorAll('.mapboxgl-ctrl-attrib:not(.mapboxgl-compact)').length, 1);
7172

7273
Object.defineProperty(map.getCanvasContainer(), 'offsetWidth', {value: 600, configurable: true});
74+
Object.defineProperty(map.getContainer(), 'clientWidth', {value: 600, configurable: true});
7375
map.resize();
7476

7577
t.equal(container.querySelectorAll('.mapboxgl-ctrl-attrib.mapboxgl-compact').length, 1);

test/unit/ui/control/logo.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,12 @@ test('LogoControl appears in compact mode if container is less then 250 pixel wi
9393
const container = map.getContainer();
9494

9595
Object.defineProperty(map.getCanvasContainer(), 'offsetWidth', {value: 255, configurable: true});
96+
Object.defineProperty(map.getContainer(), 'clientWidth', {value: 255, configurable: true});
9697
map.resize();
9798
t.equal(container.querySelectorAll('.mapboxgl-ctrl-logo:not(.mapboxgl-compact)').length, 1);
9899

99100
Object.defineProperty(map.getCanvasContainer(), 'offsetWidth', {value: 245, configurable: true});
101+
Object.defineProperty(map.getContainer(), 'clientWidth', {value: 245, configurable: true});
100102
map.resize();
101103
t.equal(container.querySelectorAll('.mapboxgl-ctrl-logo.mapboxgl-compact').length, 1);
102104

test/unit/ui/handler/drag_pan.test.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,15 @@ test('DragPanHandler ends a mouse-triggered drag if the window blurs', (t) => {
150150
map._renderTaskQueue.run();
151151

152152
simulate.blur(window);
153+
map._renderTaskQueue.run();
154+
153155
t.equal(dragend.callCount, 1);
154156

155157
map.remove();
156158
t.end();
157159
});
158160

159-
test('DragPanHandler ends a touch-triggered drag if the window blurs', (t) => {
161+
test('DragPanHandler does not end a touch-triggered drag if the window blurs', (t) => {
160162
const map = createMap(t);
161163
const target = map.getCanvas();
162164

@@ -170,7 +172,40 @@ test('DragPanHandler ends a touch-triggered drag if the window blurs', (t) => {
170172
map._renderTaskQueue.run();
171173

172174
simulate.blur(window);
175+
map._renderTaskQueue.run();
176+
177+
t.equal(dragend.callCount, 0);
178+
179+
map.remove();
180+
t.end();
181+
});
182+
183+
test('DragPanHandler does not end a touch-triggered drag if the window resizes', (t) => {
184+
const map = createMap(t);
185+
const target = map.getCanvas();
186+
187+
const dragend = t.spy();
188+
map.on('dragend', dragend);
189+
190+
const drag = t.spy();
191+
map.on('drag', drag);
192+
193+
simulate.touchstart(map.getCanvas(), {touches: [{target, clientX: 0, clientY: 0}]});
194+
map._renderTaskQueue.run();
195+
196+
simulate.touchmove(map.getCanvas(), {touches: [{target, clientX: 10, clientY: 10}]});
197+
map._renderTaskQueue.run();
198+
199+
map.resize();
200+
201+
simulate.touchmove(map.getCanvas(), {touches: [{target, clientX: 20, clientY: 10}]});
202+
map._renderTaskQueue.run();
203+
204+
simulate.touchend(map.getCanvas());
205+
map._renderTaskQueue.run();
206+
173207
t.equal(dragend.callCount, 1);
208+
t.equal(drag.callCount, 2);
174209

175210
map.remove();
176211
t.end();

0 commit comments

Comments
 (0)