Skip to content

Commit

Permalink
add an observable for whether the AnimatedPanZoomListener is currentl…
Browse files Browse the repository at this point in the history
  • Loading branch information
jessegreenberg committed Sep 25, 2023
1 parent 753e302 commit 8bd8324
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions js/listeners/AnimatedPanZoomListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import PhetioAction from '../../../tandem/js/PhetioAction.js';
import { EventIO, Focus, FocusManager, globalKeyStateTracker, Intent, KeyboardDragListener, KeyboardUtils, KeyboardZoomUtils, KeyStateTracker, Mouse, MultiListenerPress, Node, PanZoomListener, PanZoomListenerOptions, PDOMPointer, PDOMUtils, Pointer, PressListener, scenery, SceneryEvent, Trail, TransformTracker } from '../imports.js';
import optionize, { EmptySelfOptions } from '../../../phet-core/js/optionize.js';
import Tandem from '../../../tandem/js/Tandem.js';
import BooleanProperty from '../../../axon/js/BooleanProperty.js';

// constants
const MOVE_CURSOR = 'all-scroll';
Expand Down Expand Up @@ -102,6 +103,10 @@ class AnimatedPanZoomListener extends PanZoomListener {
// to scale the target Node
private trackpadGestureStartScale = 1;

// True when the listener is actively panning or zooming to the destination position and scale. Updated in the
// animation frame.
private readonly animatingProperty = new BooleanProperty( false );

// A TransformTracker that will watch for changes to the targetNode's global transformation matrix, used to keep
// the targetNode in view during animation.
private _transformTracker: TransformTracker | null = null;
Expand Down Expand Up @@ -223,6 +228,8 @@ class AnimatedPanZoomListener extends PanZoomListener {
// @ts-expect-error - Event type for this Safari specific event isn't available yet
boundGestureChangeListener && window.removeEventListener( 'gestureChange', boundGestureChangeListener );

this.animatingProperty.dispose();

if ( this._transformTracker ) {
this._transformTracker.dispose();
}
Expand Down Expand Up @@ -965,6 +972,8 @@ class AnimatedPanZoomListener extends PanZoomListener {
const positionDirty = !destinationPosition.equalsEpsilon( sourcePosition, 0.1 );
const scaleDirty = !Utils.equalsEpsilon( this.sourceScale, this.destinationScale, 0.001 );

this.animatingProperty.value = positionDirty || scaleDirty;

// Only a MiddlePress can support animation while down
if ( this._presses.length === 0 || this.middlePress !== null ) {
if ( positionDirty ) {
Expand Down

0 comments on commit 8bd8324

Please sign in to comment.