From 91cc673d806fe7bf010a23d6e77f02a398841efa Mon Sep 17 00:00:00 2001 From: richard-loafle <44828666+richard-loafle@users.noreply.github.com> Date: Thu, 6 Feb 2020 16:00:56 +0900 Subject: [PATCH] bug of search is fixed --- .../src/lib/components/messages.component.ts | 64 ++++++++++++------- 1 file changed, 40 insertions(+), 24 deletions(-) diff --git a/projects/ucap-webmessenger-ui-chat/src/lib/components/messages.component.ts b/projects/ucap-webmessenger-ui-chat/src/lib/components/messages.component.ts index c9c1b5d7..6511a7f3 100644 --- a/projects/ucap-webmessenger-ui-chat/src/lib/components/messages.component.ts +++ b/projects/ucap-webmessenger-ui-chat/src/lib/components/messages.component.ts @@ -425,29 +425,39 @@ export class MessagesComponent implements OnInit, OnDestroy { useSwap: boolean, addtionalOffset?: number ) { - this.preSwapScroll(useHide, useSwap); - if (!!preCallback) { - preCallback(); - } - - this.virtualScroller.scrollInto( - to, - true, - undefined !== this.storedScrollItemOffsetTop - ? -this.storedScrollItemOffsetTop - : undefined !== addtionalOffset - ? -addtionalOffset - : 0, - 0, - () => { - setTimeout(() => { - if (!!postCallback) { - postCallback(); - } - this.postSwapScroll(useHide, useSwap); - }); + if (!!to) { + this.preSwapScroll(useHide, useSwap); + if (!!preCallback) { + preCallback(); } - ); + + this.virtualScroller.scrollInto( + to, + true, + undefined !== this.storedScrollItemOffsetTop + ? -this.storedScrollItemOffsetTop + : undefined !== addtionalOffset + ? -addtionalOffset + : 0, + 0, + () => { + setTimeout(() => { + if (!!postCallback) { + postCallback(); + } + this.postSwapScroll(useHide, useSwap); + }); + } + ); + } else { + if (!!preCallback) { + preCallback(); + } + + if (!!postCallback) { + postCallback(); + } + } } preSwapScroll(useHide: boolean, useSwap: boolean) { @@ -526,6 +536,10 @@ export class MessagesComponent implements OnInit, OnDestroy { false ); } else { + if (!this.eventList || 0 === this.eventList.length) { + return; + } + const lastEvent = !!this.eventList && 0 < this.eventList.length ? this.eventList[this.eventList.length - 1] @@ -536,7 +550,9 @@ export class MessagesComponent implements OnInit, OnDestroy { } const isInViewPortItems = this.isInViewPortItems(lastEvent.seq); this.swapScrollTo( - this.eventList[this.eventList.length - 1], + !!this.gotoEventSeq + ? undefined + : this.eventList[this.eventList.length - 1], () => {}, () => { this.initalized = true; @@ -547,7 +563,7 @@ export class MessagesComponent implements OnInit, OnDestroy { }, -1 === this.virtualScroller.viewPortInfo.endIndex || !isInViewPortItems, - !isInViewPortItems + !isInViewPortItems || !!this.gotoEventSeq ); } }