@@ -29,6 +29,7 @@ import {
2929 scrollBarIndicatorVisibleProperty
3030} from '.' ;
3131import { CLog , CLogTypes , CollectionViewBase , ListViewViewTypes , isScrollEnabledProperty , orientationProperty } from './index-common' ;
32+ import { TypedArray , createArrayBuffer } from '@nativescript-community/arraybuffers' ;
3233
3334export * from './index-common' ;
3435
@@ -337,11 +338,11 @@ export class CollectionView extends CollectionViewBase {
337338 // super.onUnloaded();
338339 // this.detachScrollListenerIfNecessary();
339340 // }
340-
341- _getSpanSize : ( item , index ) => number ;
342341 public getViewForItemAtIndex ( index : number ) : View {
343342 return this . enumerateViewHolders < View > ( ( v ) => ( v . getAdapterPosition ( ) === index ? v . view : undefined ) ) ;
344343 }
344+
345+ _getSpanSize : ( item , index ) => number ;
345346 //@ts -ignore
346347 set spanSize ( inter : ( item , index ) => number ) {
347348 if ( ! ( typeof inter === 'function' ) ) {
@@ -370,6 +371,42 @@ export class CollectionView extends CollectionViewBase {
370371 return this . _getSpanSize ;
371372 }
372373
374+ decorator : com . nativescript . collectionview . OverlapDecoration ;
375+ decoratorBuffer : TypedArray ;
376+ decoratorListener : com . nativescript . collectionview . OverlapDecoration . OverlapDecorationListener ;
377+
378+ nativeGetItemOverlap ( position : number ) {
379+ const item = this . getItemAtIndex ( position ) ;
380+ const result = this . itemOverlap ( item , position ) ;
381+
382+ this . decoratorBuffer [ 0 ] = Length . toDevicePixels ( result [ 0 ] , 0 ) ;
383+ this . decoratorBuffer [ 1 ] = Length . toDevicePixels ( result [ 1 ] , 0 ) ;
384+ this . decoratorBuffer [ 2 ] = Length . toDevicePixels ( result [ 2 ] , 0 ) ;
385+ this . decoratorBuffer [ 3 ] = Length . toDevicePixels ( result [ 3 ] , 0 ) ;
386+ return this . decoratorBuffer ;
387+ }
388+
389+ [ itemOverlapProperty . setNative ] ( value ) {
390+ if ( typeof value === 'function' ) {
391+ if ( ! this . decorator ) {
392+ this . decoratorListener = new com . nativescript . collectionview . OverlapDecoration . OverlapDecorationListener ( {
393+ getItemOverlap : this . nativeGetItemOverlap . bind ( this )
394+ } ) ;
395+ this . decorator = new com . nativescript . collectionview . OverlapDecoration ( this . decoratorListener ) ;
396+ this . nativeViewProtected . addItemDecoration ( this . decorator ) ;
397+ }
398+ if ( ! this . decoratorBuffer ) {
399+ this . decoratorBuffer = createArrayBuffer ( 4 , false , true ) ;
400+ }
401+ } else {
402+ if ( this . decorator ) {
403+ this . nativeViewProtected . removeItemDecoration ( this . decorator ) ;
404+ this . decorator = null ;
405+ }
406+ this . decoratorListener = null ;
407+ }
408+ }
409+
373410 private attachScrollListenerIfNecessary ( ) {
374411 const nativeView = this . nativeViewProtected ;
375412 if ( this . _scrollOrLoadMoreChangeCount > 0 && nativeView && ! nativeView . scrollListener ) {
@@ -560,25 +597,6 @@ export class CollectionView extends CollectionViewBase {
560597 [ paddingLeftProperty . setNative ] ( value : CoreTypes . LengthType ) {
561598 this . _setPadding ( { left : this . effectivePaddingLeft } ) ;
562599 }
563- decorator : com . nativescript . collectionview . OverlapDecoration ;
564- [ itemOverlapProperty . setNative ] ( value : CoreTypes . LengthType [ ] ) {
565- if ( ! value ) {
566- if ( this . decorator ) {
567- this . nativeViewProtected . removeItemDecoration ( this . decorator ) ;
568- this . decorator = null ;
569- }
570- } else {
571- if ( ! this . decorator ) {
572- this . decorator = new com . nativescript . collectionview . OverlapDecoration ( ) ;
573- this . nativeViewProtected . addItemDecoration ( this . decorator ) ;
574- }
575- this . decorator . top = Length . toDevicePixels ( value [ 0 ] , 0 ) ;
576- this . decorator . right = Length . toDevicePixels ( value [ 1 ] , 0 ) ;
577- this . decorator . bottom = Length . toDevicePixels ( value [ 2 ] , 0 ) ;
578- this . decorator . left = Length . toDevicePixels ( value [ 3 ] , 0 ) ;
579- }
580- }
581-
582600 public [ orientationProperty . getDefault ] ( ) : Orientation {
583601 return 'vertical' ;
584602 }
0 commit comments