如何将InfiniteLoader与WindowScroller结合起来?

时间:2017-01-27 15:02:37

标签: react-virtualized

如何在窗口滚动条中创建无限滚动列表? (与Facebook时间表相同 - Mock up)?

下面是我尝试过的代码,但它没有按预期工作。它只显示第一项,之后不再显示任何内容。

<div className={styles.WindowScrollerWrapper}>
    <InfiniteLoader
      isRowLoaded={this._isRowLoaded}
      loadMoreRows={this._loadMoreRows}
      rowCount={list.size}
      threshold={10}>
      {({ onRowsRendered, registerChild }) => (
        <WindowScroller>
          {({ height, isScrolling, scrollTop }) => (
            <AutoSizer disableHeight>
              {({ width }) => (

                <List
                  ref={registerChild}
                  className={styles.List}
                  autoHeight
                  height={height}
                  width={width}
                  onRowsRendered={onRowsRendered}
                  rowCount={list.size}
                  rowHeight={30}
                  rowRenderer={this._rowRenderer}
                  scrollToIndex={randomScrollToIndex}
                  />
              )}
            </AutoSizer>
          )}
        </WindowScroller>
      )}
    </InfiniteLoader>
</div>

非常感谢提前。

更新

以下是演示的网址:https://plnkr.co/edit/akyEpZ0cXhfs2jtZgQmN

1 个答案:

答案 0 :(得分:14)

根据your Plnkrcorrected Plnkr显示了它应该如何运作。{{3}} (您忘记将scrollTop param从WindowScroller传递给孩子List。)

你走了:

    <InfiniteLoader
      isRowLoaded={this._isRowLoaded}
      loadMoreRows={this._loadMoreRows}
      rowCount={list.size}
      threshold={10}>
      {({ onRowsRendered, registerChild }) => (
        <WindowScroller>
          {({ height, isScrolling, scrollTop }) => (
            <AutoSizer disableHeight>
              {({ width }) => (
                <List
                  ref={registerChild}
                  className="List"
                  autoHeight
                  height={height}
                  width={width}
                  onRowsRendered={onRowsRendered}
                  rowCount={list.size}
                  rowHeight={30}
                  rowRenderer={this._rowRenderer}
                  scrollTop={scrollTop} />
              )}
            </AutoSizer>
          )}
        </WindowScroller>
      )}
    </InfiniteLoader>