@@ -85,7 +85,6 @@ export class InfiniteScroll implements ComponentInterface {
8585 * If `true`, the infinite scroll will preserve the scroll position
8686 * when the content is re-rendered. This is useful when the content is
8787 * re-rendered with new keys, and the scroll position should be preserved.
88- * @internal
8988 */
9089 @Prop ( ) preserveRerenderScrollPosition : boolean = false ;
9190
@@ -143,15 +142,18 @@ export class InfiniteScroll implements ComponentInterface {
143142
144143 if ( distanceFromInfinite < 0 ) {
145144 if ( ! this . didFire ) {
145+ this . isLoading = true ;
146+ this . didFire = true ;
147+
146148 if ( this . preserveRerenderScrollPosition ) {
147149 // Lock the min height of the siblings of the infinite scroll
148150 // 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 ( ) ;
150156 }
151-
152- this . isLoading = true ;
153- this . didFire = true ;
154- this . ionInfinite . emit ( ) ;
155157 return 3 ;
156158 }
157159 }
@@ -168,32 +170,44 @@ export class InfiniteScroll implements ComponentInterface {
168170 * We preserve existing min-height values, if they're set, so we don't erase what
169171 * has been previously set by the user when we restore after complete is called.
170172 */
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+ } ) ;
186201 }
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' ) ;
192202 }
193203 }
194- }
195204
196- this . minHeightLocked = lock ;
205+ writeTask ( ( ) => {
206+ writes . forEach ( ( w ) => w ( ) ) ;
207+ this . minHeightLocked = lock ;
208+ resolve ( ) ;
209+ } ) ;
210+ } ) ;
197211 }
198212
199213 /**
@@ -264,8 +278,8 @@ export class InfiniteScroll implements ComponentInterface {
264278 // Unlock the min height of the siblings of the infinite scroll
265279 // if we are preserving the rerender scroll position
266280 if ( this . preserveRerenderScrollPosition ) {
267- setTimeout ( ( ) => {
268- this . lockSiblingMinHeight ( false ) ;
281+ setTimeout ( async ( ) => {
282+ await this . lockSiblingMinHeight ( false ) ;
269283 } , 100 ) ;
270284 }
271285 }
0 commit comments