@@ -281,7 +281,7 @@ export class CollectionView extends CollectionViewBase {
281281 // colWidthProperty.coerce(this);
282282 // rowHeightProperty.coerce(this);
283283 }
284- _getSpanSize : ( position : number ) => number ;
284+ _getSpanSize : ( item , index ) => number ;
285285 public getViewForItemAtIndex ( index : number ) : View {
286286 let result : View ;
287287 this . _viewHolders . some ( function ( cellItemView , key ) {
@@ -295,7 +295,7 @@ export class CollectionView extends CollectionViewBase {
295295 return result ;
296296 }
297297 //@ts -ignore
298- set spanSize ( inter : ( position : number ) => number ) {
298+ set spanSize ( inter : ( item , index ) => number ) {
299299 if ( ! ( typeof inter === 'function' ) ) {
300300 return ;
301301 }
@@ -306,7 +306,10 @@ export class CollectionView extends CollectionViewBase {
306306 inter
307307 ? new com . nativescript . collectionview . SpanSizeLookup (
308308 new com . nativescript . collectionview . SpanSizeLookup . Interface ( {
309- getSpanSize : inter
309+ getSpanSize : ( position ) => {
310+ const dataItem = this . getItemAtIndex ( position ) ;
311+ return inter ( dataItem , position ) ;
312+ }
310313 } )
311314 )
312315 : null
@@ -665,6 +668,19 @@ export class CollectionView extends CollectionViewBase {
665668 this . nativeViewProtected . addOnLayoutChangeListener ( this . layoutChangeListener ) ;
666669 }
667670 }
671+ _updateSpanCount ( ) {
672+ if ( this . isLayoutValid && this . layoutManager && this . layoutManager [ 'setSpanCount' ] ) {
673+ this . layoutManager [ 'setSpanCount' ] ( this . computeSpanCount ( ) ) ;
674+ }
675+ }
676+ _onColWidthPropertyChanged ( oldValue : CoreTypes . PercentLengthType , newValue : CoreTypes . PercentLengthType ) {
677+ this . _updateSpanCount ( ) ;
678+ super . _onColWidthPropertyChanged ( oldValue , newValue ) ;
679+ }
680+ _onRowHeightPropertyChanged ( oldValue : CoreTypes . PercentLengthType , newValue : CoreTypes . PercentLengthType ) {
681+ this . _updateSpanCount ( ) ;
682+ super . _onRowHeightPropertyChanged ( oldValue , newValue ) ;
683+ }
668684 public onLayout ( left : number , top : number , right : number , bottom : number ) {
669685 super . onLayout ( left , top , right , bottom ) ;
670686 const p = CollectionViewBase . plugins [ this . layoutStyle ] ;
@@ -675,9 +691,7 @@ export class CollectionView extends CollectionViewBase {
675691 const p = CollectionViewBase . plugins [ k ] ;
676692 p . onLayout && p . onLayout ( this , left , top , right , bottom ) ;
677693 } ) ;
678- if ( this . layoutManager && this . layoutManager [ 'setSpanCount' ] ) {
679- this . layoutManager [ 'setSpanCount' ] ( this . computeSpanCount ( ) ) ;
680- }
694+ this . _updateSpanCount ( ) ;
681695 // there is no need to call refresh if it was triggered before with same size.
682696 // this refresh is just to handle size change
683697 const layoutKey = this . _innerWidth + '_' + this . _innerHeight ;
@@ -794,7 +808,7 @@ export class CollectionView extends CollectionViewBase {
794808 return ;
795809 }
796810 const view = this . nativeViewProtected ;
797- if ( ! this . isLoaded ) {
811+ if ( ! this . isLoaded || ! this . isLayoutValid ) {
798812 this . _isDataDirty = true ;
799813 return ;
800814 }
@@ -1020,7 +1034,7 @@ export class CollectionView extends CollectionViewBase {
10201034 let width = this . _effectiveColWidth ;
10211035 let height = this . _effectiveRowHeight ;
10221036 if ( this . _getSpanSize ) {
1023- const spanSize = this . _getSpanSize ( position ) ;
1037+ const spanSize = this . _getSpanSize ( bindingContext , position ) ;
10241038 const horizontal = this . isHorizontal ( ) ;
10251039 if ( horizontal ) {
10261040 height *= spanSize ;
0 commit comments