@@ -101,8 +101,6 @@ export class AppGif {
101101 return ;
102102 }
103103
104- this . paginationNext = tenorResponse . next ;
105-
106104 const gifs : TenorGif [ ] = tenorResponse . results ;
107105
108106 if ( ! gifs || gifs . length <= 0 ) {
@@ -123,6 +121,15 @@ export class AppGif {
123121 this . gifsOdd = [ ...this . gifsOdd , ...gifs . filter ( ( _a , i ) => i % 2 ) ] ;
124122 this . gifsEven = [ ...this . gifsEven , ...gifs . filter ( ( _a , i ) => ! ( i % 2 ) ) ] ;
125123
124+ if ( ! this . paginationNext || this . paginationNext === 0 ) {
125+ // We just put a small delay because of the repaint
126+ setTimeout ( async ( ) => {
127+ await this . autoScrollToTop ( ) ;
128+ } , 100 )
129+ }
130+
131+ this . paginationNext = tenorResponse . next ;
132+
126133 resolve ( ) ;
127134 } ) ;
128135 }
@@ -161,6 +168,21 @@ export class AppGif {
161168 this . searchTerm = ( $event . target as InputTargetEvent ) . value ;
162169 }
163170
171+ private autoScrollToTop ( ) : Promise < void > {
172+ return new Promise < void > ( async ( resolve ) => {
173+ const content : HTMLIonContentElement = this . el . querySelector ( 'ion-content' ) ;
174+
175+ if ( ! content ) {
176+ resolve ( ) ;
177+ return ;
178+ }
179+
180+ await content . scrollToTop ( ) ;
181+
182+ resolve ( ) ;
183+ } ) ;
184+ }
185+
164186 render ( ) {
165187 return [
166188 < ion-header >
@@ -185,7 +207,8 @@ export class AppGif {
185207 </ div >
186208 </ div >
187209
188- < ion-infinite-scroll threshold = "100px" disabled = { this . disableInfiniteScroll } onIonInfinite = { ( e : CustomEvent < void > ) => this . searchNext ( e ) } >
210+ < ion-infinite-scroll threshold = "100px" disabled = { this . disableInfiniteScroll }
211+ onIonInfinite = { ( e : CustomEvent < void > ) => this . searchNext ( e ) } >
189212 < ion-infinite-scroll-content
190213 loadingSpinner = "bubbles"
191214 loadingText = "Loading more data..." >
0 commit comments