Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: 加载更多消息后,虚拟列表定位到加载时的那条消息位置有误差。 #55

Closed
xyqfei opened this issue Jun 13, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@xyqfei
Copy link
Contributor

xyqfei commented Jun 13, 2023

BUG 描述
加载更多消息后,定位到加载时的那条消息位置有误差。

预期效果
加载更多消息完成后,消息准确定位到加载时的那条消息

信息

  • 系统: [iOS]
  • 系统版本: [iOS 12.1]
  • 浏览器: [chrome 114.0.5735.106(正式版本) (arm64)]

bug视频
https://github.com/Evansy/MallChatWeb/assets/23380976/8deff4f1-e0bb-4494-af7b-3c2c9c2df548

问题初步分析:

// 到顶部时触发函数 记录旧的滚动高度,加载更多消息后滚动回加载时那条消息的位置
const onTotop = throttle(async () => {
const oldScrollTop = virtualListRef.value.getScrollSize()
await chatStore.loadMore()
nextTick(() => {
const newScrollTop = virtualListRef.value.getScrollSize() - oldScrollTop
virtualListRef.value.scrollToOffset(newScrollTop)
})
}, 1600)

当触顶事件onToTop事件内计算得出的newScrollTop都没有问题,但是

virtualListRef.value.scrollToOffset(newScrollTop)

会导致虚拟列表scrollHeight改变,从而使定位出现误差。

以下是验证代码

const onTotop = throttle(async () => {
  const oldScrollTop = virtualListRef.value.getScrollSize()
  await chatStore.loadMore()
  nextTick(() => {
    const scrollHeight1 = virtualListRef.value.getScrollSize()
    console.log(scrollHeight1)
    const newScrollTop = virtualListRef.value.getScrollSize() - oldScrollTop
    virtualListRef.value.scrollToOffset(newScrollTop)
  }).then(() => {
    nextTick(() => {
      setTimeout(() => {
        const scrollHeight2 = virtualListRef.value.getScrollSize()
        console.log(scrollHeight2)
      }, 1000)
    })
  })
}, 1600)```

结果发现 scrollHeight1  scrollHeight2 并不相等。


@Evansy
Copy link
Owner

Evansy commented Jun 17, 2023

#58 已修复

@Evansy Evansy closed this as completed Jun 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants