去掉动态根据数据更新宽度,避免不断扩宽问题

This commit is contained in:
wuduoyi 2020-08-20 16:21:09 +08:00
parent 903f043c07
commit 93eb715d0b
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 &&