Skip to content

Conversation

hemengke1997
Copy link
Contributor

问题描述

由于延迟更新column宽度,导致表头表body宽度更新不同步

相关issuse

ant-design/ant-design#33545

解决方案

移除2帧的延迟

@vercel
Copy link

vercel bot commented Jan 6, 2022

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/react-component/table/57xzRapUus1qL1dSk8ybKJrGaTDM
✅ Preview: https://table-git-fork-hemengke1997-fix-table-resize-react-component.vercel.app

@hemengke1997
Copy link
Contributor Author

@zombieJ 哥,有空看一下 🎈

return () => {
raf.cancel(rafIdRef.current);
};
}, []);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这样会不会造成 #706 提到的性能问题。

cc @curly210102

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里是对连续 resize 的优化,连续拖动的情况较少就先放一边了,主要考虑侧边栏切换动画的场景

可以先看下 Demo:

延迟可以减缓掉帧让 resize 看上去更流畅一点,但整体体验上差异比较细微,考虑到同步性 > 细微优化,个人觉得可以把延迟去掉。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@curly210102 没太明白,是说这个 PR 没问题可合是么?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗯,他的意思是可以合😁

@codecov
Copy link

codecov bot commented Jan 7, 2022

Codecov Report

Merging #731 (9d19722) into master (b973d40) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head 9d19722 differs from pull request most recent head b1e92c3. Consider uploading reports for the commit b1e92c3 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master     #731      +/-   ##
==========================================
- Coverage   99.37%   99.36%   -0.01%     
==========================================
  Files          33       33              
  Lines         964      951      -13     
  Branches      278      277       -1     
==========================================
- Hits          958      945      -13     
  Misses          6        6              
Impacted Files Coverage Δ
src/Body/BodyRow.tsx 97.91% <ø> (ø)
src/Body/index.tsx 100.00% <ø> (ø)
src/Table.tsx 99.17% <ø> (ø)
src/context/ExpandedRowContext.tsx 100.00% <ø> (ø)
src/Body/ExpandedRow.tsx 100.00% <100.00%> (ø)
src/Body/MeasureRow.tsx 100.00% <100.00%> (ø)
src/Cell/index.tsx 98.95% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b973d40...b1e92c3. Read the comment docs.

return () => {
raf.cancel(rafIdRef.current);
};
}, []);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里是对连续 resize 的优化,连续拖动的情况较少就先放一边了,主要考虑侧边栏切换动画的场景

可以先看下 Demo:

延迟可以减缓掉帧让 resize 看上去更流畅一点,但整体体验上差异比较细微,考虑到同步性 > 细微优化,个人觉得可以把延迟去掉。

<ResizeObserver.Collection
onBatchResize={infoList => {
infoList.forEach(({ data: columnKey, size }) => {
resizedColumnsRef.current.set(columnKey, size.offsetWidth);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

去延迟的话,这边应该不需要存到 resizedColumnsRef 了,直接拿 infoList 操作就好

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那我这边改一下哈 @curly210102

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

加了2帧延迟的视觉上看起来更流畅,请问如果把header和body都加上延迟会怎样呢,可以实现既同步又流畅吗 @curly210102

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants