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

🐛: useVirtualList flicker #2049

Closed
kaitoukid-1412 opened this issue Feb 7, 2023 · 12 comments
Closed

🐛: useVirtualList flicker #2049

kaitoukid-1412 opened this issue Feb 7, 2023 · 12 comments
Assignees
Labels
bug Something isn't working

Comments

@kaitoukid-1412
Copy link

screen-capture.webm
@luo3house
Copy link
Contributor

#2040
#2033
#1940

@crazylxr
Copy link
Collaborator

v3.7.5 已修复

@xiangdongbu
Copy link

v3.7.5 已修复

使用 3.7.8 的版本 依然会有滑动过程中闪烁的问题

@liuyib
Copy link
Collaborator

liuyib commented Aug 8, 2023

使用 3.7.8 的版本 依然会有滑动过程中闪烁的问题

是必现的吗?麻烦来个可复现的在线 demo,感谢 @xiangdongbu

@xiangdongbu
Copy link

使用 3.7.8 的版本 依然会有滑动过程中闪烁的问题

是必现的吗?麻烦来个可复现的在线 demo,感谢 @xiangdongbu

是必现的,比如list里的每一条都可以点击展开 默认是全部收起的,但是我点击了某一条后,这一条会展开 这一条的总高度也会变高,这时候再去滑动 ,会影响后面。

@liuyib
Copy link
Collaborator

liuyib commented Aug 8, 2023

比如list里的每一条都可以点击展开 默认是全部收起的

是像 antd Collapse 组件这样折叠展开吗?可否来个在线 demo?

@xiangdongbu
Copy link

比如list里的每一条都可以点击展开 默认是全部收起的

是像 antd Collapse 组件这样折叠展开吗?可否来个在线 demo?

是的 跟antd Collapse 组件 一样

@xiangdongbu
Copy link

xiangdongbu commented Aug 9, 2023

比如list里的每一条都可以点击展开 默认是全部收起的

是像 antd Collapse 组件这样折叠展开吗?可否来个在线 demo?

demo
有两个问题:

  1. 展开以后,往下滑动的时候,会出现跳动;
  2. 展开以后,展开状态会丢失,比如第一个展开 往下滑动,等再次划回来的时候,已经是收起的状态。

@luo3house
Copy link
Contributor

钩子会把窗口+缓存范围以外的 Item 卸载。由于 demo 给出 itemHeight 是固定的,钩子不会知道 Item 改变了高度,Item 卸载时就会跳

尝试基于 index 计算动态高度:

const [list, scrollTo] = useVirtualList(originalList, {
containerTarget: containerRef,
wrapperTarget: wrapperRef,
itemHeight: (i) => (i % 2 === 0 ? 42 + 8 : 84 + 8),
overscan: 10,
});

@liuyib
Copy link
Collaborator

liuyib commented Aug 11, 2023

demo 有两个问题:

  1. 展开以后,往下滑动的时候,会出现跳动;
  2. 展开以后,展开状态会丢失,比如第一个展开 往下滑动,等再次划回来的时候,已经是收起的状态。

useVirtualList 并不会真的渲染所有 N 个项,而是复用 DOM。前面展开的项,其 DOM 会被后面的项复用,复用其实就是重新计算为新的项,旧的展开状态自然就没了,所以没法做到第二点。

第一点,我这里看你给的在线 demo,没复现。

@luo3house 的思路应该可以解决第一点,试试呢 @xiangdongbu

钩子会把窗口+缓存范围以外的 Item 卸载。由于 demo 给出 itemHeight 是固定的,钩子不会知道 Item 改变了高度,Item 卸载时就会跳

尝试基于 index 计算动态高度:

const [list, scrollTo] = useVirtualList(originalList, {
containerTarget: containerRef,
wrapperTarget: wrapperRef,
itemHeight: (i) => (i % 2 === 0 ? 42 + 8 : 84 + 8),
overscan: 10,
});

@liuyib
Copy link
Collaborator

liuyib commented Aug 11, 2023

  1. 展开以后,展开状态会丢失,比如第一个展开 往下滑动,等再次划回来的时候,已经是收起的状态。

@xiangdongbu 我写了个 demo,自己缓存状态,可以解决第二点状态被重置的问题:
https://codesandbox.io/s/ahooks-issue-2049-d6w6cz?file=/App.tsx

  1. 展开以后,往下滑动的时候,会出现跳动;

第一点我怎么都复现不了,来个复现的录屏看下呢 @xiangdongbu

@xiangdongbu
Copy link

  1. 展开以后,展开状态会丢失,比如第一个展开 往下滑动,等再次划回来的时候,已经是收起的状态。

@xiangdongbu 我写了个 demo,自己缓存状态,可以解决第二点状态被重置的问题: https://codesandbox.io/s/ahooks-issue-2049-d6w6cz?file=/App.tsx

  1. 展开以后,往下滑动的时候,会出现跳动;

第一点我怎么都复现不了,来个复现的录屏看下呢 @xiangdongbu

好的 👌🏻

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

6 participants