File tree Expand file tree Collapse file tree 3 files changed +25
-0
lines changed
packages/collectionview/platforms/android/java/com/nativescript/collectionview Expand file tree Collapse file tree 3 files changed +25
-0
lines changed Original file line number Diff line number Diff line change 66import java .util .HashMap ;
77
88public class GridLayoutManager extends androidx .recyclerview .widget .GridLayoutManager {
9+
910 private HashMap <Integer , Integer > childSizesMap = new HashMap ();
1011 public boolean isScrollEnabled = true ;
12+ public LayoutCompletedListener layoutCompletedListener ;
13+
14+ public interface LayoutCompletedListener {
15+ public void onLayoutCompleted ();
16+ }
1117
1218 public GridLayoutManager (Context context , int spanCount ) {
1319 super (context , spanCount );
@@ -20,6 +26,9 @@ public void onLayoutCompleted(RecyclerView.State state) {
2026 View child = getChildAt (i );
2127 childSizesMap .put (getPosition (child ), child .getHeight ());
2228 }
29+ if (layoutCompletedListener != null ) {
30+ layoutCompletedListener .onLayoutCompleted ();
31+ }
2332 }
2433
2534 public int computeVerticalScrollOffset (RecyclerView .State state ) {
Original file line number Diff line number Diff line change @@ -128,6 +128,7 @@ export enum SnapPosition {
128128}
129129
130130export class CollectionView extends CollectionViewBase {
131+ public static layoutCompletedEvent = 'layoutCompleted' ;
131132 public static DEFAULT_TEMPLATE_VIEW_TYPE = 0 ;
132133 public static CUSTOM_TEMPLATE_ITEM_TYPE = 1 ;
133134 public nativeViewProtected : CollectionViewRecyclerView & {
@@ -260,6 +261,13 @@ export class CollectionView extends CollectionViewBase {
260261 layoutManager = CollectionViewBase . layoutStyles [ this . layoutStyle ] . createLayout ( this ) ;
261262 } else {
262263 layoutManager = new com . nativescript . collectionview . PreCachingGridLayoutManager ( this . _context , 1 ) ;
264+ if ( this . hasListeners ( CollectionView . layoutCompletedEvent ) ) {
265+ ( layoutManager as com . nativescript . collectionview . GridLayoutManager ) . layoutCompletedListener = new com . nativescript . collectionview . GridLayoutManager . LayoutCompletedListener ( {
266+ onLayoutCompleted :( ) => {
267+ this . notify ( { eventName :CollectionView . layoutCompletedEvent } )
268+ }
269+ } )
270+ }
263271 // layoutManager = new PreCachingGridLayoutManager(this._context, 1);
264272 // (layoutManager as any).owner = new WeakRef(this);
265273 }
Original file line number Diff line number Diff line change @@ -10,6 +10,14 @@ declare namespace com {
1010 }
1111 export class GridLayoutManager extends androidx . recyclerview . widget . GridLayoutManager {
1212 isScrollEnabled : boolean ;
13+ layoutCompletedListener : LayoutCompletedListener ;
14+ }
15+ export namespace GridLayoutManager {
16+
17+ export class LayoutCompletedListener {
18+ onLayoutCompleted ( ) ;
19+ constructor ( implementation ?: { onLayoutCompleted ( ) } ) ;
20+ }
1321 }
1422 export class PreCachingGridLayoutManager extends GridLayoutManager {
1523 setExtraLayoutSpace ( space : number ) ;
You can’t perform that action at this time.
0 commit comments