fix: Fixed the problem of scrolling the message list while updating t… #2451
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
…he message stream, and the message list would unexpectedly scroll to the bottom
中文模板 / Chinese Template
What kind of change does this PR introduce? (check at least one)
PR description
Fixes #
在发送消息/接受消息,以及消息流式更新等场景中,无需显示滚动条,并且在内容更新时候,需要自动滚动到最底部;
但是在使用鼠标/触控板拖动等用户触发的滚动行为时,需要显示滚动条,此时如果同时存在消息流式更新场景,不应该将滚动条滚动到最底部来显示最新消息。
问题表现:
用户滚动聊天框后,消息流式更新,会导致聊天框滚动到最底部显示最新信息,不符合预期。
问题原因:
wheel 事件的 target 是鼠标/触控板滚动行为发生的元素。
预期是在 wheel 事件中检测用户是否执行滚动行为。但是判断的依据错误(wheel 事件的 event.target 和 event.currentTarget)
问题解决方案:
实际发生滚动的元素可以通过聊天内容 container 中的 scroll 事件的 target 进行获取。在 scroll 事件中保存事件的target(scrollTarget),在container 的 wheel 事件中判断 scrollTarget 是否为 container(wheel 的 event.currentTarget),即可判断是否是用户触发了 container 的滚动,以此决定是否显示滚动条以及在回复的消息流式更新时候,是否需要滚动到最底部
Changelog
🇨🇳 Chinese
🇺🇸 English
Checklist
Other
Additional information