Skip to content

Commit 3457cc1

Browse files
committed
fix(android): try to prevent unecessary requestLayout
1 parent b870dce commit 3457cc1

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/collectionview/index.android.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ export class CollectionView extends CollectionViewBase {
736736
}
737737

738738
@profile
739-
updateSpanCount() {
739+
updateSpanCount(requestLayout = true) {
740740
if (this.mInPropertiesSet) {
741741
this.mShouldUpdateSpanCount = true;
742742
return;
@@ -747,9 +747,13 @@ export class CollectionView extends CollectionViewBase {
747747
const newValue = (this.currentSpanCount = this.computeSpanCount());
748748
if (newValue !== layoutManager['getSpanCount']()) {
749749
layoutManager['setSpanCount'](newValue);
750-
layoutManager.requestLayout();
750+
if (requestLayout) {
751+
layoutManager.requestLayout();
752+
}
753+
return true;
751754
}
752755
}
756+
return false;
753757
}
754758

755759
@profile
@@ -791,7 +795,7 @@ export class CollectionView extends CollectionViewBase {
791795
// this refresh is just to handle size change
792796
const layoutKey = this._innerWidth + '_' + this._innerHeight;
793797
if (this._isDataDirty || (this._lastLayoutKey && this._lastLayoutKey !== layoutKey)) {
794-
setTimeout(() => this.refresh(), 0);
798+
setTimeout(() => this.refresh(false), 0);
795799
}
796800
this._lastLayoutKey = layoutKey;
797801
}
@@ -900,7 +904,7 @@ export class CollectionView extends CollectionViewBase {
900904

901905
_layedOut = false;
902906
@profile
903-
public refresh() {
907+
public refresh(updateSpanCountRequestsLayout = true) {
904908
if (this.mInPropertiesSet) {
905909
this.mShouldRefresh = true;
906910
return;
@@ -926,9 +930,7 @@ export class CollectionView extends CollectionViewBase {
926930
} else if (!view.getAdapter()) {
927931
view.setAdapter(adapter);
928932
}
929-
930-
this.updateSpanCount();
931-
933+
this.updateSpanCount(updateSpanCountRequestsLayout);
932934
adapter.notifyDataSetChanged();
933935
this.notify({ eventName: CollectionViewBase.dataPopulatedEvent });
934936
}

0 commit comments

Comments
 (0)