Skip to content

Commit

Permalink
Replace ComboBoxListItemNode highlight rectangle layout with ManualCo…
Browse files Browse the repository at this point in the history
…nstraint, to resolve reentrancy layout issues caused by the Property-based method, see phetsims/gas-properties#237
  • Loading branch information
jonathanolson committed May 10, 2024
1 parent 1b3d9f6 commit 70a7bed
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions js/ComboBoxListItemNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import { Shape } from '../../kite/js/imports.js';
import StrictOmit from '../../phet-core/js/types/StrictOmit.js';
import optionize from '../../phet-core/js/optionize.js';
import { IndexedNodeIO, Node, NodeOptions, PressListener, Rectangle, TPaint, Voicing, VoicingOptions } from '../../scenery/js/imports.js';
import { IndexedNodeIO, ManualConstraint, Node, NodeOptions, PressListener, Rectangle, TPaint, Voicing, VoicingOptions } from '../../scenery/js/imports.js';
import Tandem from '../../tandem/js/Tandem.js';
import sun from './sun.js';
import SunConstants from './SunConstants.js';
Expand Down Expand Up @@ -123,27 +123,25 @@ export default class ComboBoxListItemNode<T> extends Voicing( Node ) {
};
highlightHeightProperty.link( highlightHeightListener );

options.children = [ highlightRectangle, itemNodeWrapper ];

super( options );
this._supplyOpenResponseOnNextFocus = false;

// Assume that item.node may change (as in ComboBoxDisplay) and adjust layout dynamically.
// See https://github.com/phetsims/scenery-phet/issues/482
const updateItemLayout = () => {
ManualConstraint.create( this, [ highlightRectangle, itemNodeWrapper ], ( highlightProxy, itemProxy ) => {
if ( options.align === 'left' ) {
itemNodeWrapper.left = highlightRectangle.left + options.xMargin;
itemProxy.left = highlightProxy.left + options.xMargin;
}
else if ( options.align === 'right' ) {
itemNodeWrapper.right = highlightRectangle.right - options.xMargin;
itemProxy.right = highlightProxy.right - options.xMargin;
}
else {
itemNodeWrapper.centerX = highlightRectangle.centerX;
itemProxy.centerX = highlightProxy.centerX;
}
itemNodeWrapper.centerY = highlightRectangle.centerY;
};
itemNodeWrapper.boundsProperty.lazyLink( updateItemLayout );
updateItemLayout();

options.children = [ highlightRectangle, itemNodeWrapper ];

super( options );
this._supplyOpenResponseOnNextFocus = false;
itemProxy.centerY = highlightProxy.centerY;
} );

const emptyA11yNameProperty = new DerivedProperty( [ a11yNameProperty ], ( a11yName: string | null ) => {
return a11yName ? a11yName : '';
Expand Down

0 comments on commit 70a7bed

Please sign in to comment.