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

Prevent bearing snap ease interfering with new ease #9884

Merged
merged 1 commit into from
Aug 4, 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
2 changes: 1 addition & 1 deletion src/ui/camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@ class Camera extends Evented {
}
if (!allowGestures) {
const handlers = (this: any).handlers;
if (handlers) handlers.stop();
if (handlers) handlers.stop(false);
}
return this;
}
Expand Down
20 changes: 8 additions & 12 deletions src/ui/handler_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ class HandlerManager {
_updatingCamera: boolean;
_changes: Array<[HandlerResult, Object, any]>;
_previousActiveHandlers: { [string]: Handler };
_bearingChanged: boolean;
_listeners: Array<[HTMLElement, string, void | {passive?: boolean, capture?: boolean}]>;

constructor(map: Map, options: { interactive: boolean, pitchWithRotate: boolean, clickTolerance: number, bearingSnap: number}) {
Expand Down Expand Up @@ -235,15 +234,15 @@ class HandlerManager {
this._handlersById[handlerName] = handler;
}

stop() {
stop(allowEndAnimation: boolean) {
// do nothing if this method was triggered by a gesture update
if (this._updatingCamera) return;

for (const {handler} of this._handlers) {
handler.reset();
}
this._inertia.clear();
this._fireEvents({}, {});
this._fireEvents({}, {}, allowEndAnimation);
this._changes = [];
}

Expand Down Expand Up @@ -293,7 +292,7 @@ class HandlerManager {
handleEvent(e: InputEvent | RenderFrameEvent, eventName?: string) {

if (e.type === 'blur') {
this.stop();
this.stop(true);
return;
}

Expand Down Expand Up @@ -358,7 +357,7 @@ class HandlerManager {
const {cameraAnimation} = mergedHandlerResult;
if (cameraAnimation) {
this._inertia.clear();
this._fireEvents({}, {});
this._fireEvents({}, {}, true);
this._changes = [];
cameraAnimation(this._map);
}
Expand Down Expand Up @@ -416,7 +415,7 @@ class HandlerManager {
const tr = map.transform;

if (!hasChange(combinedResult)) {
return this._fireEvents(combinedEventsInProgress, deactivatedHandlers);
return this._fireEvents(combinedEventsInProgress, deactivatedHandlers, true);
}

let {panDelta, zoomDelta, bearingDelta, pitchDelta, around, pinchAround} = combinedResult;
Expand All @@ -437,11 +436,11 @@ class HandlerManager {

this._map._update();
if (!combinedResult.noInertia) this._inertia.record(combinedResult);
this._fireEvents(combinedEventsInProgress, deactivatedHandlers);
this._fireEvents(combinedEventsInProgress, deactivatedHandlers, true);

}

_fireEvents(newEventsInProgress: { [string]: Object }, deactivatedHandlers: Object) {
_fireEvents(newEventsInProgress: { [string]: Object }, deactivatedHandlers: Object, allowEndAnimation: boolean) {

const wasMoving = isMoving(this._eventsInProgress);
const nowMoving = isMoving(newEventsInProgress);
Expand All @@ -465,8 +464,6 @@ class HandlerManager {
this._fireEvent(name, startEvents[name]);
}

if (newEventsInProgress.rotate) this._bearingChanged = true;

if (nowMoving) {
this._fireEvent('move', nowMoving.originalEvent);
}
Expand All @@ -493,7 +490,7 @@ class HandlerManager {
}

const stillMoving = isMoving(this._eventsInProgress);
if ((wasMoving || nowMoving) && !stillMoving) {
if (allowEndAnimation && (wasMoving || nowMoving) && !stillMoving) {
this._updatingCamera = true;
const inertialEase = this._inertia._onMoveEnd(this._map.dragPan._inertiaOptions);

Expand All @@ -510,7 +507,6 @@ class HandlerManager {
this._map.resetNorth();
}
}
this._bearingChanged = false;
this._updatingCamera = false;
}

Expand Down