Skip to content

Commit

Permalink
combine duplicated callback, phetsims/buoyancy#150
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Kauzmann <[email protected]>
  • Loading branch information
zepumph committed May 9, 2024
1 parent c951bae commit 278ffe8
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions js/buoyancy/view/BuoyancyLabScreenView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import DerivedProperty from '../../../../axon/js/DerivedProperty.js';
import Vector2 from '../../../../dot/js/Vector2.js';
import { combineOptions } from '../../../../phet-core/js/optionize.js';
import { AlignBox, HBox, ManualConstraint, Node, RichText, VBox } from '../../../../scenery/js/imports.js';
import { AlignBox, HBox, LayoutProxy, ManualConstraint, Node, RichText, VBox } from '../../../../scenery/js/imports.js';
import Panel from '../../../../sun/js/Panel.js';
import DensityBuoyancyCommonConstants from '../../common/DensityBuoyancyCommonConstants.js';
import Material from '../../common/model/Material.js';
Expand Down Expand Up @@ -102,19 +102,17 @@ export default class BuoyancyLabScreenView extends DensityBuoyancyScreenView<Buo
} );
this.addChild( leftSideContent );

const positionLeftSideContent = () => {
leftSideContent.bottom = this.visibleBoundsProperty.value.bottom - DESIRED_LEFT_SIDE_MARGIN;
leftSideContent.left = this.visibleBoundsProperty.value.left + DESIRED_LEFT_SIDE_MARGIN;
const positionLeftSideContent = ( nodelLike: LayoutProxy | Node ) => {
nodelLike.bottom = this.visibleBoundsProperty.value.bottom - DESIRED_LEFT_SIDE_MARGIN;
nodelLike.left = this.visibleBoundsProperty.value.left + DESIRED_LEFT_SIDE_MARGIN;
};

// Reflow when the entire accordion box is hidden in phet-io studio.
// TODO: https://github.com/phetsims/buoyancy/issues/150 this layout is duplicated with the above. Is there a way to listen to visibleBoundsProperty in a ManualConstraint?
ManualConstraint.create( this, [ leftSideContent ], leftSideContentProxy => {
leftSideContentProxy.bottom = this.visibleBoundsProperty.value.bottom - DESIRED_LEFT_SIDE_MARGIN;
leftSideContentProxy.left = this.visibleBoundsProperty.value.left + DESIRED_LEFT_SIDE_MARGIN;
} );
ManualConstraint.create( this, [ leftSideContent ], positionLeftSideContent );

this.visibleBoundsProperty.link( positionLeftSideContent );
this.visibleBoundsProperty.link( () => {
positionLeftSideContent( leftSideContent );
} );

const displayedMysteryMaterials = [
Material.DENSITY_A,
Expand Down

0 comments on commit 278ffe8

Please sign in to comment.