Skip to content

Commit

Permalink
Merge pull request #236 from yomotsu/fix-cancel-emits-controlend-twice
Browse files Browse the repository at this point in the history
fix: cancel emits controlend event twice
  • Loading branch information
yomotsu authored Dec 31, 2021
2 parents 22e2b6a + aa11fc6 commit 8063259
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions src/CameraControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,6 @@ export class CameraControls extends EventDispatcher {
const lastDragPosition = new THREE.Vector2() as _THREE.Vector2;
const dollyStart = new THREE.Vector2() as _THREE.Vector2;

const cancelDragging = (): void => {

this._state = ACTION.NONE;
this._activePointers.length = 0;
endDragging();

};

const onPointerDown = ( event: PointerEvent ) => {

if ( ! this._enabled ) return;
Expand Down Expand Up @@ -785,9 +777,9 @@ export class CameraControls extends EventDispatcher {
this._domElement.ownerDocument.removeEventListener( 'touchmove', onTouchMove, { passive: false } as AddEventListenerOptions );
this._domElement.ownerDocument.removeEventListener( 'touchend', onTouchEnd );

}
this.dispatchEvent( { type: 'controlend' } );

this.dispatchEvent( { type: 'controlend' } );
}

};

Expand Down Expand Up @@ -823,9 +815,11 @@ export class CameraControls extends EventDispatcher {

this.cancel = (): void => {

cancelDragging();
if ( this._state === ACTION.NONE ) return;

this.dispatchEvent( { type: 'controlend' } );
this._state = ACTION.NONE;
this._activePointers.length = 0;
endDragging();

};

Expand Down

0 comments on commit 8063259

Please sign in to comment.