Skip to content

Commit 6155132

Browse files
committed
Add infiniteScroll feature to search.component
1 parent 16ec0c7 commit 6155132

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

src/app/home/home.page.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
</ion-header>
6969
<ion-content
7070
[scrollEvents]="true"
71-
(ionScrollEnd)="onScrollEnd()"
71+
(ionScroll)="onScroll($event)"
7272
padding>
7373
<section class="book-list">
7474
<app-book-list [_bookList]="bookList"

src/app/home/home.page.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export class HomePage implements OnInit, AfterViewInit {
111111

112112
this.message.getMessage().subscribe((_: IMessage) => {
113113
if(_.event === 'book-list-updated') this.bookList = (_.data as Book[]).slice();
114-
114+
115115
this.cdr.detectChanges();
116116
});
117117

@@ -198,10 +198,20 @@ export class HomePage implements OnInit, AfterViewInit {
198198
});
199199
}
200200

201-
onScrollEnd = () => {
202-
const msg: IMessage = {
203-
event: 'scrolled-to-end'
201+
onScroll = async ($event) => {
202+
if($event.target.localName !== 'ion-content') { return; }
203+
204+
const scrollElement = await $event.target.getScrollElement();
205+
const scrollHeight = scrollElement.scrollHeight - scrollElement.clientHeight;
206+
207+
const currentScrollDepth = $event.detail.scrollTop;
208+
209+
if(currentScrollDepth === scrollHeight){
210+
const msg: IMessage = {
211+
event: 'scrolled-to-end'
212+
}
213+
if(this.search) this.message.sendMessage(msg);
214+
204215
}
205-
if(this.search) this.message.sendMessage(msg);
206216
}
207217
}

0 commit comments

Comments
 (0)