@@ -441,7 +441,43 @@ export class ListLayout<T, O extends ListLayoutOptions = ListLayoutOptions> exte
441441 }
442442
443443 protected buildSectionHeader ( node : Node < T > , x : number , y : number ) : LayoutNode {
444- return this . buildItem ( node , x , y ) ;
444+ let widthProperty = this . orientation === 'horizontal' ? 'height' : 'width' ;
445+ let heightProperty = this . orientation === 'horizontal' ? 'width' : 'height' ;
446+ let width = this . virtualizer ! . visibleRect [ widthProperty ] - this . padding - ( this . orientation === 'horizontal' ? y : x ) ;
447+ let rectHeight = this . headingHeight ;
448+ let isEstimated = false ;
449+
450+ // If no explicit height is available, use an estimated height.
451+ if ( rectHeight == null ) {
452+ // If a previous version of this layout info exists, reuse its height.
453+ // Mark as estimated if the size of the overall virtualizer changed,
454+ // or the content of the item changed.
455+ let previousLayoutNode = this . layoutNodes . get ( node . key ) ;
456+ let previousLayoutInfo = previousLayoutNode ?. layoutInfo ;
457+ if ( previousLayoutInfo ) {
458+ let curNode = this . virtualizer ! . collection . getItem ( node . key ) ;
459+ let lastNode = this . lastCollection ? this . lastCollection . getItem ( node . key ) : null ;
460+ rectHeight = previousLayoutNode ! . layoutInfo . rect [ heightProperty ] ;
461+ isEstimated = width !== previousLayoutInfo . rect [ widthProperty ] || curNode !== lastNode || previousLayoutInfo . estimatedSize ;
462+ } else {
463+ rectHeight = ( node . rendered ? this . estimatedHeadingHeight : 0 ) ;
464+ isEstimated = true ;
465+ }
466+ }
467+
468+ if ( rectHeight == null ) {
469+ rectHeight = DEFAULT_HEIGHT ;
470+ }
471+
472+ let headerRect = this . orientation === 'horizontal' ? new Rect ( x , y , rectHeight , width - y ) : new Rect ( x , y , width - x , rectHeight ) ;
473+ let header = new LayoutInfo ( 'header' , node . key , headerRect ) ;
474+ header . estimatedSize = isEstimated ;
475+ return {
476+ layoutInfo : header ,
477+ children : [ ] ,
478+ validRect : header . rect . intersection ( this . requestedRect ) ,
479+ node
480+ } ;
445481 }
446482
447483 protected buildItem ( node : Node < T > , x : number , y : number ) : LayoutNode {
@@ -462,7 +498,7 @@ export class ListLayout<T, O extends ListLayoutOptions = ListLayoutOptions> exte
462498 rectHeight = previousLayoutNode . layoutInfo . rect [ heightProperty ] ;
463499 isEstimated = width !== previousLayoutNode . layoutInfo . rect [ widthProperty ] || node !== previousLayoutNode . node || previousLayoutNode . layoutInfo . estimatedSize ;
464500 } else {
465- rectHeight = node . type === 'item' || node . rendered ? this . estimatedRowHeight : 0 ;
501+ rectHeight = this . estimatedRowHeight ;
466502 isEstimated = true ;
467503 }
468504 }
@@ -601,7 +637,7 @@ export class ListLayout<T, O extends ListLayoutOptions = ListLayoutOptions> exte
601637 let layoutInfo = this . getLayoutInfo ( target . key ) ! ;
602638 let rect : Rect ;
603639 if ( target . dropPosition === 'before' ) {
604- rect = this . orientation === 'horizontal' ?
640+ rect = this . orientation === 'horizontal' ?
605641 new Rect ( Math . max ( 0 , layoutInfo . rect . x - this . dropIndicatorThickness / 2 ) , layoutInfo . rect . y , this . dropIndicatorThickness , layoutInfo . rect . height )
606642 : new Rect ( layoutInfo . rect . x , Math . max ( 0 , layoutInfo . rect . y - this . dropIndicatorThickness / 2 ) , layoutInfo . rect . width , this . dropIndicatorThickness ) ;
607643 } else if ( target . dropPosition === 'after' ) {
@@ -621,7 +657,7 @@ export class ListLayout<T, O extends ListLayoutOptions = ListLayoutOptions> exte
621657 currentKey = this . collection . getKeyAfter ( currentKey ) ;
622658 }
623659 }
624- rect = this . orientation === 'horizontal' ?
660+ rect = this . orientation === 'horizontal' ?
625661 new Rect ( layoutInfo . rect . maxX - this . dropIndicatorThickness / 2 , layoutInfo . rect . y , this . dropIndicatorThickness , layoutInfo . rect . height )
626662 : new Rect ( layoutInfo . rect . x , layoutInfo . rect . maxY - this . dropIndicatorThickness / 2 , layoutInfo . rect . width , this . dropIndicatorThickness ) ;
627663 } else {
0 commit comments