Lucha para hacer que la lista virtualizada se desplace a una fila en particular después de actualizar el contenido. Escenario: hay pocas filas, el usuario se desplaza a algún lugar de la lista y luego activa un evento (por ejemplo, presiona un botón en la aplicación) que modifica el contenido de los elementos de la lista. Idealmente, el usuario debe ver la misma fila en la parte superior de la vista de desplazamiento que estaba antes de que ocurriera el evento.
Aquí está el fragmento de mi código donde intento que funcione sin éxito.
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> ) } }Se agradece cualquier aclaración sobre cuál es la forma correcta de hacer que este escenario funcione.