Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

164
Visualizações
Scroll virtual list to specified row

Struggle to make virtualized list scrolled to a particular row after content refresh. Scenario: there are few rows, user scrolls to somewhere in the list, and then triggers an event (e.g. presses a button in the app) that modifies the content of the list items. Ideally the user must see the same row at the top of the scroll view that was before the event occurred.

Here is the snippet from my code where I try to make it work with no success.

class MyList extends React.Component {
  state = {
    newScrollToIndex: undefined
  }

  // function triggered from outsided events
  onCellContentChanged() {
    const index = this.listRowIndex

    // Don't know really which one to call exactlty
    // Just called everything
    this.cellMeasurerCache.clearAll()
    this.listView.recomputeRowHeights()
    this.listView.measureAllRows()

    /*
     * Tried this did not work at all.
     * const off = this.listView.getOffsetForRow({ index })
     * this.listView.scrollToPosition(off)
     */

    // This two seem to work equivalently with 50% chance to work correctly.
    // this.listView.scrollToRow(index)
    this.setState({ newScrollToIndex: index })
  }

  renderInfiniteList({ height, width }) {
    return (
      <InfiniteLoader
        isRowLoaded={this.isRowLoaded}
        loadMoreRows={this.loadMoreRows}
        rowCount={this.rowCount}
      >
        {({ onRowsRendered, registerChild }) => {
          return (
            <List
              style={{ outline: 'none' }}
              noRowsRenderer={() => (
                <NoRows
                  loading={
                    this.state.loadingMoreRows || this.state.loadingFields
                  }
                />
              )}
              height={height}
              width={width}
              overscanRowCount={2}
              rowCount={this.listViewRowCount}
              rowHeight={this.cellMeasurerCache.rowHeight}
              deferredMeasurementCache={this.cellMeasurerCache}
              rowRenderer={this.rowRenderer}
              scrollToIndex={this.state.newScrollToIndex}
              onRowsRendered={(o) => {
                onRowsRendered(o)
                this.listRowIndex = o.startIndex
              }}
              ref={(listView) => {
                registerChild(listView)
                this.listView = listView
              }}
            />
          )
        }}
      </InfiniteLoader>
    )
  }
}

Any clarification on what is the proper way to make of this scenario to work is appreciated.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda