Merge pull request #866 from nwind/master

去掉动态根据数据更新宽度,避免不断扩宽问题
This commit is contained in:
liaoxuezhi 2020-08-20 16:29:08 +08:00 committed by GitHub
commit ce9d8879f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 5 deletions

View File

@ -179,6 +179,8 @@ export default class VirtualList extends React.PureComponent<Props, State> {
// 自适应宽度
updateRootWidth() {
const itemsDom = this.rootNode.children[0].children;
const scrollbarWidth =
window.innerWidth - document.documentElement.clientWidth || 15;
const containerWidth = this.rootNode.parentElement!.getBoundingClientRect()
.width;
let maxItemWidth = 0;
@ -188,10 +190,8 @@ export default class VirtualList extends React.PureComponent<Props, State> {
maxItemWidth = itemWidth;
}
}
if (containerWidth >= maxItemWidth) {
this.rootNode.style.width = containerWidth + 'px';
} else {
this.rootNode.style.width = maxItemWidth + 'px';
if (maxItemWidth > containerWidth) {
this.rootNode.style.width = maxItemWidth + scrollbarWidth + 'px';
}
}
@ -253,7 +253,6 @@ export default class VirtualList extends React.PureComponent<Props, State> {
}
componentDidUpdate(_: Props, prevState: State) {
this.updateRootWidth();
const {offset, scrollChangeReason} = this.state;
if (
prevState.offset !== offset &&