Skip to content

Commit 31cbb77

Browse files
committed
feat: refreshVisibleItems
1 parent 4bd28b4 commit 31cbb77

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

src/collectionview-common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ export abstract class CollectionViewBase extends View implements CollectionViewD
169169
}
170170

171171
public abstract refresh();
172+
public abstract refreshVisibleItems();
172173
public abstract scrollToIndex(index: number, animated: boolean);
173174
public onLayout(left: number, top: number, right: number, bottom: number) {
174175
super.onLayout(left, top, right, bottom);

src/collectionview.android.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,20 @@ export class CollectionView extends CollectionViewBase {
709709
this._listViewAdapter.notifyDataSetChanged();
710710
}
711711

712+
refreshVisibleItems() {
713+
const view = this.nativeViewProtected;
714+
if (!view) {
715+
return;
716+
}
717+
const layoutManager = this.layoutManager as androidx.recyclerview.widget.LinearLayoutManager;
718+
if (layoutManager['findFirstVisibleItemPosition']) {
719+
const first = layoutManager.findFirstVisibleItemPosition();
720+
const last = layoutManager.findLastVisibleItemPosition();
721+
this._listViewAdapter.notifyItemRangeChanged(first, last - first);
722+
723+
}
724+
}
725+
712726
@profile
713727
public refresh() {
714728
if (!this.nativeViewProtected) {

src/collectionview.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export type Orientation = 'horizontal' | 'vertical';
77

88
export class CollectionView extends CollectionViewBase {
99
public refresh();
10+
public refreshVisibleItems();
1011
public scrollToIndex(index: number, animated: boolean);
1112
public getViewForItemAtIndex(index: number): View;
1213
// on iOS a view is dragged from its center by default

src/collectionview.ios.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,21 @@ export class CollectionView extends CollectionViewBase {
453453
}
454454
}, this);
455455
}
456+
457+
refreshVisibleItems() {
458+
const view = this.nativeViewProtected;
459+
if (!view) {
460+
return;
461+
}
462+
const visibles = view.indexPathsForVisibleItems;
463+
UIView.performWithoutAnimation(()=>{
464+
view.performBatchUpdatesCompletion(() => {
465+
view.reloadItemsAtIndexPaths(visibles);
466+
}, null);
467+
});
468+
}
469+
470+
456471
@profile
457472
public refresh() {
458473
if (!this.isLoaded || !this.nativeView) {

0 commit comments

Comments
 (0)