Skip to content

Commit

Permalink
feat: refreshVisibleItems
Browse files Browse the repository at this point in the history
  • Loading branch information
farfromrefug committed Jan 26, 2021
1 parent 4bd28b4 commit 31cbb77
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/collectionview-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ export abstract class CollectionViewBase extends View implements CollectionViewD
}

public abstract refresh();
public abstract refreshVisibleItems();
public abstract scrollToIndex(index: number, animated: boolean);
public onLayout(left: number, top: number, right: number, bottom: number) {
super.onLayout(left, top, right, bottom);
Expand Down
14 changes: 14 additions & 0 deletions src/collectionview.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,20 @@ export class CollectionView extends CollectionViewBase {
this._listViewAdapter.notifyDataSetChanged();
}

refreshVisibleItems() {
const view = this.nativeViewProtected;
if (!view) {
return;
}
const layoutManager = this.layoutManager as androidx.recyclerview.widget.LinearLayoutManager;
if (layoutManager['findFirstVisibleItemPosition']) {
const first = layoutManager.findFirstVisibleItemPosition();
const last = layoutManager.findLastVisibleItemPosition();
this._listViewAdapter.notifyItemRangeChanged(first, last - first);

}
}

@profile
public refresh() {
if (!this.nativeViewProtected) {
Expand Down
1 change: 1 addition & 0 deletions src/collectionview.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export type Orientation = 'horizontal' | 'vertical';

export class CollectionView extends CollectionViewBase {
public refresh();
public refreshVisibleItems();
public scrollToIndex(index: number, animated: boolean);
public getViewForItemAtIndex(index: number): View;
// on iOS a view is dragged from its center by default
Expand Down
15 changes: 15 additions & 0 deletions src/collectionview.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,21 @@ export class CollectionView extends CollectionViewBase {
}
}, this);
}

refreshVisibleItems() {
const view = this.nativeViewProtected;
if (!view) {
return;
}
const visibles = view.indexPathsForVisibleItems;
UIView.performWithoutAnimation(()=>{
view.performBatchUpdatesCompletion(() => {
view.reloadItemsAtIndexPaths(visibles);
}, null);
});
}


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

0 comments on commit 31cbb77

Please sign in to comment.