🚸 Improve auto scroll behavior

Now only based on bottom of last element if it is in view
This commit is contained in:
Baptiste Arnaud
2024-04-24 17:40:27 +02:00
parent 873ba0bfda
commit a7fc41316c
13 changed files with 22 additions and 18 deletions

View File

@@ -234,17 +234,15 @@ export const ConversationContainer = (props: Props) => {
}
const lastElementRect = lastElement.getBoundingClientRect()
const containerRect = chatContainer.getBoundingClientRect()
const lastElementTopRelative =
lastElementRect.top - containerRect.top + chatContainer.scrollTop
const isLastElementInVisibleArea =
lastElementTopRelative < chatContainer.scrollTop + containerRect.height &&
lastElementTopRelative + lastElementRect.height > chatContainer.scrollTop
const isBottomOfLastElementInView =
lastElementRect.top + lastElementRect.height < containerRect.height
if (isLastElementInVisibleArea)
if (isBottomOfLastElementInView) {
setTimeout(() => {
chatContainer?.scrollTo(0, lastElement.offsetTop - offset)
}, 50)
}
}
const handleAllBubblesDisplayed = async () => {