简体   繁体   English

无限滚动的动态高度(反应虚拟化)

[英]Dynamic height with infinite scroll (react-virtualized)

I'm using 'react-virtualized' to render an infinite scrolling list. 我正在使用'react-virtualized'渲染无限滚动列表。

However, I am having trouble rendering the rowHeight dynamically. 但是,我无法动态呈现rowHeight I made an attempt, but it only is relevent for desktop, and feels wrong. 我尝试了一下,但这只是桌面上的事,感觉不对。

I tried following the examples, but had no success. 我尝试按照示例进行操作,但没有成功。

What is the correct way to calculate the true row height? 计算真实行高的正确方法是什么?

It should be responsive to mobile. 它应该对移动响应。

Here is an example: 这是一个例子:

https://codesandbox.io/s/ADARgvlxB https://codesandbox.io/s/ADARgvlxB

class App extends React.Component {

  render() {

    return (
      <div>

        <AutoSizer>
        {({ height, width }) => (
        <List
          height={600}
          width={width}
          rowCount={foo.length}
          rowHeight={({ index }) => {
            const x = foo[index];
            if (x.name.length < 10) { return 20; } 
            else if (x.name.length > 9) { return 40;}
          }}
          rowRenderer={({ index, style }) => {
            const x = foo[index];
            return (
              <div key={index} style={style}>
                {x.name}
              </div>
            );
          }}
        />
        )}
        </AutoSizer>
      </div>
    );
  }
}

What is the correct way to calculate the true row height? 计算真实行高的正确方法是什么?

This is what the react-virtualized CellMeasurer component is for. 这就是反应虚拟化CellMeasurer组件的用途。 You can see a demo of it measuring dynamic heights here . 您可以在此处看到有关测量动态高度演示 The source code for the demo are the *.example.js files here . 该演示的源代码是此处*.example.js文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM