@@ -85,7 +85,6 @@ export class InfiniteScroll implements ComponentInterface {
85
85
* If `true`, the infinite scroll will preserve the scroll position
86
86
* when the content is re-rendered. This is useful when the content is
87
87
* re-rendered with new keys, and the scroll position should be preserved.
88
- * @internal
89
88
*/
90
89
@Prop ( ) preserveRerenderScrollPosition : boolean = false ;
91
90
@@ -143,15 +142,18 @@ export class InfiniteScroll implements ComponentInterface {
143
142
144
143
if ( distanceFromInfinite < 0 ) {
145
144
if ( ! this . didFire ) {
145
+ this . isLoading = true ;
146
+ this . didFire = true ;
147
+
146
148
if ( this . preserveRerenderScrollPosition ) {
147
149
// Lock the min height of the siblings of the infinite scroll
148
150
// if we are preserving the rerender scroll position
149
- this . lockSiblingMinHeight ( true ) ;
151
+ this . lockSiblingMinHeight ( true ) . then ( ( ) => {
152
+ this . ionInfinite . emit ( ) ;
153
+ } ) ;
154
+ } else {
155
+ this . ionInfinite . emit ( ) ;
150
156
}
151
-
152
- this . isLoading = true ;
153
- this . didFire = true ;
154
- this . ionInfinite . emit ( ) ;
155
157
return 3 ;
156
158
}
157
159
}
@@ -168,32 +170,44 @@ export class InfiniteScroll implements ComponentInterface {
168
170
* We preserve existing min-height values, if they're set, so we don't erase what
169
171
* has been previously set by the user when we restore after complete is called.
170
172
*/
171
- private lockSiblingMinHeight ( lock : boolean ) {
172
- const siblings = this . el . parentElement ?. children || [ ] ;
173
- for ( const sibling of siblings ) {
174
- // Loop through all the siblings of the infinite scroll, but ignore ourself
175
- if ( sibling !== this . el && sibling instanceof HTMLElement ) {
176
- if ( lock ) {
177
- const elementHeight = sibling . getBoundingClientRect ( ) . height ;
178
- if ( this . minHeightLocked ) {
179
- // The previous min height is from us locking it before, so we can disregard it
180
- // We still need to lock the min height if we're already locked, though, because
181
- // the user could have triggered a new load before we've finished the previous one.
182
- const previousMinHeight = sibling . style . minHeight ;
183
- if ( previousMinHeight ) {
184
- sibling . style . setProperty ( '--ion-previous-min-height' , previousMinHeight ) ;
185
- }
173
+ private lockSiblingMinHeight ( lock : boolean ) : Promise < void > {
174
+ return new Promise ( ( resolve ) => {
175
+ const siblings = this . el . parentElement ?. children || [ ] ;
176
+ const writes : ( ( ) => void ) [ ] = [ ] ;
177
+
178
+ for ( const sibling of siblings ) {
179
+ // Loop through all the siblings of the infinite scroll, but ignore ourself
180
+ if ( sibling !== this . el && sibling instanceof HTMLElement ) {
181
+ if ( lock ) {
182
+ const elementHeight = sibling . getBoundingClientRect ( ) . height ;
183
+ writes . push ( ( ) => {
184
+ if ( this . minHeightLocked ) {
185
+ // The previous min height is from us locking it before, so we can disregard it
186
+ // We still need to lock the min height if we're already locked, though, because
187
+ // the user could have triggered a new load before we've finished the previous one.
188
+ const previousMinHeight = sibling . style . minHeight ;
189
+ if ( previousMinHeight ) {
190
+ sibling . style . setProperty ( '--ion-previous-min-height' , previousMinHeight ) ;
191
+ }
192
+ }
193
+ sibling . style . minHeight = `${ elementHeight } px` ;
194
+ } ) ;
195
+ } else {
196
+ writes . push ( ( ) => {
197
+ const previousMinHeight = sibling . style . getPropertyValue ( '--ion-previous-min-height' ) ;
198
+ sibling . style . minHeight = previousMinHeight || 'auto' ;
199
+ sibling . style . removeProperty ( '--ion-previous-min-height' ) ;
200
+ } ) ;
186
201
}
187
- sibling . style . minHeight = `${ elementHeight } px` ;
188
- } else {
189
- const previousMinHeight = sibling . style . getPropertyValue ( '--ion-previous-min-height' ) ;
190
- sibling . style . minHeight = previousMinHeight || 'auto' ;
191
- sibling . style . removeProperty ( '--ion-previous-min-height' ) ;
192
202
}
193
203
}
194
- }
195
204
196
- this . minHeightLocked = lock ;
205
+ writeTask ( ( ) => {
206
+ writes . forEach ( ( w ) => w ( ) ) ;
207
+ this . minHeightLocked = lock ;
208
+ resolve ( ) ;
209
+ } ) ;
210
+ } ) ;
197
211
}
198
212
199
213
/**
@@ -264,8 +278,8 @@ export class InfiniteScroll implements ComponentInterface {
264
278
// Unlock the min height of the siblings of the infinite scroll
265
279
// if we are preserving the rerender scroll position
266
280
if ( this . preserveRerenderScrollPosition ) {
267
- setTimeout ( ( ) => {
268
- this . lockSiblingMinHeight ( false ) ;
281
+ setTimeout ( async ( ) => {
282
+ await this . lockSiblingMinHeight ( false ) ;
269
283
} , 100 ) ;
270
284
}
271
285
}
0 commit comments