Add scroll to bottom btn in chat conversation

This commit is contained in:
tiago.kayaya
2021-09-24 15:38:50 +01:00
parent 36baa00fc6
commit 0a8331db05
+18 -4
View File
@@ -50,6 +50,8 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
private scrollChangeCallback: () => void;
currentPosition: any;
startPosition: number;
mesageItemDropdownOptions: boolean = false;
scrollToBottomBtn = false;
constructor(
public popoverController: PopoverController,
@@ -122,6 +124,13 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
} catch(err) { }
}
scrollToBottomClicked(): void {
try {
this.myScrollContainer.nativeElement.scrollTop = this.myScrollContainer.nativeElement.scrollHeight;
//this.scrollingOnce = false;
} catch(err) { }
}
ngAfterViewInit() {
this.scrollChangeCallback = () => this.onContentScrolled(event);
window.addEventListener('scroll', this.scrollChangeCallback, true);
@@ -130,17 +139,22 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
onContentScrolled(e) {
this.startPosition = e.srcElement.scrollTop;
let scroll = e.srcElement.scrollTop;
let windowHeight = e.srcElement.scrollHeight;
let containerHeight = windowHeight - 454.199951171875;
if (scroll > this.currentPosition) {
//this.showButton = false;
//alert('BOTTOM');
} else {
//this.showButton = true;
//alert('UP');
this.scrollingOnce = false;
}
if((containerHeight - 100) > scroll){
this.scrollToBottomBtn = true;
}
else{
this.scrollToBottomBtn = false;
}
this.currentPosition = scroll;
/* console.log(this.currentPosition);
console.log(this.scrollingOnce); */
}
ngOnDestroy() {