Skip to content

Commit 9d6acc3

Browse files
committed
fix(infinite-scroll): prevent locking sibling min height while it's already locked, prevent useless setTimeout from being set up while preserve rerender scroll property isn't set
1 parent f9e7dcd commit 9d6acc3

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

core/src/components/infinite-scroll/infinite-scroll.tsx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export class InfiniteScroll implements ComponentInterface {
1616
private thrPx = 0;
1717
private thrPc = 0;
1818
private scrollEl?: HTMLElement;
19+
private minHeightLocked = false;
1920

2021
/**
2122
* didFire exists so that ionInfinite
@@ -141,13 +142,14 @@ export class InfiniteScroll implements ComponentInterface {
141142

142143
if (distanceFromInfinite < 0) {
143144
if (!this.didFire) {
145+
if (this.preserveRerenderScrollPosition) {
146+
// Lock the min height of the siblings of the infinite scroll
147+
// if we are preserving the rerender scroll position
148+
this.lockSiblingMinHeight(true);
149+
}
150+
144151
this.isLoading = true;
145152
this.didFire = true;
146-
147-
// Lock the min height of the siblings of the infinite scroll
148-
// if we are preserving the rerender scroll position
149-
this.lockSiblingMinHeight(true);
150-
151153
this.ionInfinite.emit();
152154
return 3;
153155
}
@@ -166,9 +168,10 @@ export class InfiniteScroll implements ComponentInterface {
166168
* has been previously set by the user when we restore after complete is called.
167169
*/
168170
private lockSiblingMinHeight(lock: boolean) {
169-
if (!this.preserveRerenderScrollPosition) {
171+
if (this.minHeightLocked === lock) {
170172
return;
171173
}
174+
this.minHeightLocked = lock;
172175

173176
// Loop through all the siblings of the infinite scroll, but ignore the infinite scroll itself
174177
const siblings = this.el.parentElement?.children || [];
@@ -257,9 +260,11 @@ export class InfiniteScroll implements ComponentInterface {
257260

258261
// Unlock the min height of the siblings of the infinite scroll
259262
// if we are preserving the rerender scroll position
260-
setTimeout(() => {
261-
this.lockSiblingMinHeight(false);
262-
}, 100);
263+
if (this.preserveRerenderScrollPosition) {
264+
setTimeout(() => {
265+
this.lockSiblingMinHeight(false);
266+
}, 100);
267+
}
263268
}
264269

265270
private canStart(): boolean {

0 commit comments

Comments
 (0)