Skip to content

Commit 3a239a3

Browse files
committed
feat(android): layoutCompleted event
1 parent 633d6c5 commit 3a239a3

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

packages/collectionview/platforms/android/java/com/nativescript/collectionview/GridLayoutManager.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@
66
import java.util.HashMap;
77

88
public 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) {

src/collectionview/index.android.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ export enum SnapPosition {
128128
}
129129

130130
export 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
}

src/collectionview/typings/android.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff 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);

0 commit comments

Comments
 (0)