Skip to content

Commit

Permalink
fix(MessagesList): prevent scroll position changes based on messages …
Browse files Browse the repository at this point in the history
…height when user is scrolling down.

Signed-off-by: DorraJaouad <[email protected]>
  • Loading branch information
DorraJaouad committed Sep 9, 2024
1 parent c632327 commit e6ac43b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/components/MessagesList/MessagesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ export default {
dateSeparatorLabels: {},
endScrollTimeout: () => {},
isScrollingToBottom: false,
}
},
Expand Down Expand Up @@ -939,6 +941,10 @@ export default {
endScroll() {
this.isScrolling = false
// set timeout to avoid flickering
setTimeout(() => {
this.isScrollingToBottom = false
}, 500)
clearTimeout(this.endScrollTimeout)
},
Expand Down Expand Up @@ -1103,6 +1109,7 @@ export default {
let newTop
if (options?.force) {
newTop = this.$refs.scroller.scrollHeight
this.isScrollingToBottom = true
this.setChatScrolledToBottom(true)
} else if (!this.isSticky) {
// Reading old messages
Expand Down Expand Up @@ -1273,6 +1280,11 @@ export default {
},
onMessageHeightChanged({ heightDiff }) {
if (this.isScrollingToBottom || heightDiff <= 0) {
// Don't scroll while the user is scrolling
// or if the height difference is negative (e.g. when a message is deleted)
return
}
// scroll down by the height difference
this.$refs.scroller.scrollTop += heightDiff
},
Expand Down

0 comments on commit e6ac43b

Please sign in to comment.