bug fixed

This commit is contained in:
richard-loafle 2020-01-31 13:46:23 +09:00
parent 011015c275
commit ba07dc585e
2 changed files with 27 additions and 16 deletions

View File

@ -112,24 +112,23 @@ export class MessageBoxComponent implements OnInit, AfterViewInit {
} }
constructor( constructor(
private elementRef: ElementRef<HTMLElement>,
private changeDetectorRef: ChangeDetectorRef, private changeDetectorRef: ChangeDetectorRef,
private logger: NGXLogger private logger: NGXLogger
) {} ) {}
ngOnInit() { ngOnInit() {
// this.mbContainer.nativeElement.classList.add('hide'); this.mbContainer.nativeElement.classList.add('hide');
} }
ngAfterViewInit(): void { ngAfterViewInit(): void {
// this.logger.debug( this.logger.debug(
// 'offsetHeight' + this.message.seq, 'offsetHeight' + this.message.seq,
// this.mbContainer.nativeElement.offsetHeight this.mbContainer.nativeElement.offsetHeight
// ); );
// this.elementRef.nativeElement.style.height = `${this.mbContainer this.elementRef.nativeElement.style.height = `${this.mbContainer.nativeElement.offsetHeight}px`;
// .nativeElement.offsetHeight + 20}px`; this.elementRef.nativeElement.style.maxHeight = `${this.mbContainer.nativeElement.offsetHeight}px`;
// this.elementRef.nativeElement.style.maxHeight = `${this.mbContainer this.mbContainer.nativeElement.classList.remove('hide');
// .nativeElement.offsetHeight + 20}px`;
// this.mbContainer.nativeElement.classList.remove('hide');
} }
/** /**

View File

@ -31,6 +31,7 @@ import { TranslateService } from '@ngx-translate/core';
import { Observable, Subscription } from 'rxjs'; import { Observable, Subscription } from 'rxjs';
import { VirtualScrollerComponent, IPageInfo } from 'ngx-virtual-scroller'; import { VirtualScrollerComponent, IPageInfo } from 'ngx-virtual-scroller';
import { MessageBoxComponent } from './message-box.component'; import { MessageBoxComponent } from './message-box.component';
import { PerfectScrollbarDirective } from 'ngx-perfect-scrollbar';
@Component({ @Component({
selector: 'ucap-chat-messages', selector: 'ucap-chat-messages',
@ -403,7 +404,9 @@ export class MessagesComponent implements OnInit, OnDestroy {
this.eventList[this.virtualScroller.viewPortInfo.startIndex].seq this.eventList[this.virtualScroller.viewPortInfo.startIndex].seq
); );
if (!!chatMessageBox) { if (!!chatMessageBox) {
this.storedScrollItemOffsetTop = chatMessageBox.offsetTop; this.storedScrollItemOffsetTop =
chatMessageBox.offsetTop -
this.virtualScroller.viewPortInfo.scrollStartPosition;
} else { } else {
this.storedScrollItemOffsetTop = 0; this.storedScrollItemOffsetTop = 0;
} }
@ -414,7 +417,8 @@ export class MessagesComponent implements OnInit, OnDestroy {
preCallback: () => void, preCallback: () => void,
postCallback: () => void, postCallback: () => void,
useHide: boolean, useHide: boolean,
useSwap: boolean useSwap: boolean,
addtionalOffset?: number
) { ) {
this.preSwapScroll(useHide, useSwap); this.preSwapScroll(useHide, useSwap);
if (!!preCallback) { if (!!preCallback) {
@ -426,6 +430,8 @@ export class MessagesComponent implements OnInit, OnDestroy {
true, true,
undefined !== this.storedScrollItemOffsetTop undefined !== this.storedScrollItemOffsetTop
? -this.storedScrollItemOffsetTop ? -this.storedScrollItemOffsetTop
: undefined !== addtionalOffset
? -addtionalOffset
: 0, : 0,
0, 0,
() => { () => {
@ -549,6 +555,10 @@ export class MessagesComponent implements OnInit, OnDestroy {
clear() {} clear() {}
gotoPosition(eventSeq: number) { gotoPosition(eventSeq: number) {
const viewPortItemIndex = this.virtualScroller.viewPortItems.findIndex(
v => v.seq === eventSeq
);
if (!!this.virtualScroller) { if (!!this.virtualScroller) {
const e = this.eventList.find(v => v.seq === eventSeq); const e = this.eventList.find(v => v.seq === eventSeq);
this.swapScrollTo( this.swapScrollTo(
@ -562,8 +572,9 @@ export class MessagesComponent implements OnInit, OnDestroy {
chatMessageBox.shake(); chatMessageBox.shake();
} }
}, },
true, -1 === viewPortItemIndex,
true -1 === viewPortItemIndex,
50
); );
} }
} }
@ -577,13 +588,14 @@ export class MessagesComponent implements OnInit, OnDestroy {
event.stopPropagation(); event.stopPropagation();
if (this.scrollUpInitalized && this.eventRemained) { if (this.scrollUpInitalized && this.eventRemained) {
this.virtualScroller.scrollToPosition(0);
this.virtualScroller.invalidateCachedMeasurementAtIndex(0);
this.storeScrollPosition(); this.storeScrollPosition();
this.preSwapScroll(true, true); this.preSwapScroll(true, true);
this.moreEvent.emit(this.eventList[0].seq); this.moreEvent.emit(this.eventList[0].seq);
this.virtualScroller.invalidateCachedMeasurementAtIndex(0);
} }
} }