【问题标题】:React-virtualized, List is Flickkering/lagging when scrolling反应虚拟化,列表在滚动时闪烁/滞后
【发布时间】:2017-09-27 19:06:32
【问题描述】:

我在滚动列表时遇到了一些问题。 还要注意底部的巨大空间。 看视频:https://vimeo.com/215349521

据我所知,我没有犯任何重大错误。 但我相信问题出在 CellMeasurer 上。

Chrome 版本:58.0.3029.81

class PromotionList extends Component {

constructor(props) {
    super(props);

    this.cache = new CellMeasurerCache({
        defaultHeight: 100,
        fixedWidth: true,
    });

    this.rowRenderer = this.rowRenderer.bind(this);
}

componentWillMount() {
    this.props.fetchPromotionsIfNeeded();
}

rowRenderer({ index, parent }) {
    const { promotions } = this.props;
    const data = promotions.list[index];

    return (
      <CellMeasurer
        cache={this.cache}
        columnIndex={0}
        key={uuid.v1()}
        parent={parent}
        rowIndex={index}
      >
        <BlobItem
          key={uuid.v1()}
          type={BlobTypes.promotion}
          data={data}
          onClick={this.props.onItemClick}
          index={index}
        />
      </CellMeasurer>
    );
}


render() {
    const { promotions, previewSize } = this.props;

    return (
      <List
        height={300}
        width={previewSize.width}
        rowCount={promotions.list.length}
        deferredMeasurementCache={this.cache}
        rowHeight={this.cache.rowHeight}
        rowRenderer={this.rowRenderer}
        className="blobList"
      />
    );
}
}

【问题讨论】:

  • 嗯。这种闪烁乍一看有点像浏览器错误。也许类似于此评论中显示的那个? github.com/bvaughn/react-virtualized/issues/…
  • @brianvaughn 它看起来不一样安静,即使我停止滚动,我的也会四处弹跳。但它不是舒尔的 CellMeasurer,删除它仍然是一样的。但我同意,这可能是浏览器错误,或者您提供的链接中建议的列表组件

标签: reactjs react-virtualized


【解决方案1】:

阅读文档后找到了解决方案。 只需在“rowRender”方法中添加样式即可:

rowRenderer({ index, parent, style }) {
  const { promotions } = this.props;
  const data = promotions.list[index];

  return (
    <CellMeasurer
      cache={this.cache}
      columnIndex={0}
      key={uuid.v1()}
      parent={parent}
      rowIndex={index}
    >
      <BlobItem
        key={uuid.v1()}
        type={BlobTypes.promotion}
        data={data}
        onClick={this.props.onItemClick}
        index={index}
        style={style}
      />
    </CellMeasurer>
  );
}

【讨论】:

  • 感谢您抽出宝贵时间回答您自己的问题!
  • 魔法。我想我是根据文档得到的(将静态定位切换为相对)。如果这是原因,您介意更新我们的答案/解释为什么会这样吗?
  • 这个答案也对我有用。我只是在它周围扔了一个封闭的
    @azium 我相信这必须以这种方式工作,因为我想虚拟化库是做时髦的绝对定位事情来推动屏幕周围的细胞。没有样式,所有东西都会变得杂乱无章。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-22
  • 1970-01-01
  • 2018-06-20
相关资源
最近更新 更多