Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/collectionview/index-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ export abstract class CollectionViewBase extends View implements CollectionViewD
public abstract refreshVisibleItems();
public abstract isItemAtIndexVisible(index: number);
public abstract findFirstVisibleItemIndex(): number;
public abstract findLastVisibleItemIndex(): number;
public abstract scrollToIndex(index: number, animated: boolean);
public abstract scrollToOffset(value: number, animated?: boolean): any;

Expand Down
11 changes: 11 additions & 0 deletions src/collectionview/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,17 @@ export class CollectionView extends CollectionViewBase {
}
return -1;
}
public findLastVisibleItemIndex() {
const view = this.nativeViewProtected;
if (!view) {
return -1;
}
const layoutManager = this.layoutManager as androidx.recyclerview.widget.LinearLayoutManager;
if (layoutManager['findLastVisibleItemPosition']) {
return layoutManager.findLastVisibleItemPosition();
}
return -1;
}

_layedOut = false;
@profile
Expand Down
1 change: 1 addition & 0 deletions src/collectionview/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class CollectionView extends CollectionViewBase {
public refreshVisibleItems();
public isItemAtIndexVisible(index: number): boolean;
public findFirstVisibleItemIndex(): number;
public findLastVisibleItemIndex(): number;
public scrollToIndex(index: number, animated?: boolean, snap?: SnapPosition = SnapPosition.START);
public scrollToOffset(value: number, animation?: boolean);
public getViewForItemAtIndex(index: number): View;
Expand Down
18 changes: 15 additions & 3 deletions src/collectionview/index.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -679,11 +679,23 @@ export class CollectionView extends CollectionViewBase {
if (!view) {
return -1;
}
const indexes = Array.from<NSIndexPath>(view.indexPathsForVisibleItems)

return this.getRowIndexPath(view)[0] ?? -1;
}
public findLastVisibleItemIndex() {
const view = this.nativeViewProtected;
if (!view) {
return -1;
}
return this.getRowIndexPath(view).at(-1) ?? -1;
}

private getRowIndexPath(view: UICollectionView){
return Array.from<NSIndexPath>(view.indexPathsForVisibleItems)
.map((e) => e.row)
.sort();
return indexes[0] ?? -1;
.sort((a, b) => a - b);
}

@profile
public refresh() {
if (!this.isLoaded || !this.nativeView) {
Expand Down