diff --git a/js/common/model/Mass.ts b/js/common/model/Mass.ts index f1356eb9..10399f1c 100644 --- a/js/common/model/Mass.ts +++ b/js/common/model/Mass.ts @@ -175,6 +175,14 @@ export default abstract class Mass extends PhetioObject { public readonly resetEmitter = new Emitter(); + // MassViews and their GrabDragInteractions are recreated, the mass stores relevant information from one instantiation to + // another. These quantities do not need to be PhET-iO stateful, because they are related to usability and + // accessibility, and when studio launches a Standard PhET-iO Wrapper, these values should be zeroed out, not preserved + // in the state. These values are internal, and should not be read. Instead, get the most up-to-date info from the + // view's GrabDragInteraction itself. + public numberOfKeyboardGrabs = 0; + public numberOfGrabs = 0; + protected constructor( engine: PhysicsEngine, providedOptions: MassOptions ) { const options = optionize()( { @@ -582,6 +590,9 @@ export default abstract class Mass extends PhetioObject { this.resetPosition(); + this.numberOfGrabs = 0; + this.numberOfKeyboardGrabs = 0; + this.resetEmitter.emit(); } diff --git a/js/common/view/MassView.ts b/js/common/view/MassView.ts index bca9bf57..78763a5c 100644 --- a/js/common/view/MassView.ts +++ b/js/common/view/MassView.ts @@ -157,10 +157,11 @@ export default abstract class MassView extends Disposable { onRelease() { endKeyboardInteraction(); }, - tandem: Tandem.OPT_OUT + tandem: Tandem.OPT_OUT, + numberOfKeyboardGrabs: mass.numberOfKeyboardGrabs, + numberOfGrabs: mass.numberOfGrabs } ); - const myListener = () => { if ( this.focusablePath && this.grabDragInteraction && !this.focusablePath.isDisposed ) { @@ -205,6 +206,11 @@ export default abstract class MassView extends Disposable { mass.transformedEmitter.addListener( myListener ); this.disposeEmitter.addListener( () => { + + // Keep in sync for the next time this mass will create a new view + mass.numberOfKeyboardGrabs = this.grabDragInteraction!.numberOfKeyboardGrabs; + mass.numberOfGrabs = this.grabDragInteraction!.numberOfGrabs; + this.grabDragInteraction!.dispose(); keyboardDragListener.dispose(); this.focusablePath!.dispose();