react-virtualized: scrollToRow on List with dynamic heights and CellMeasurer doesn't always scroll to the proper location
On a List with many items, all of dynamic height that are measured using a CellMeasurer, sometimes, jumping to a smaller row index n from larger row m index fails. This more frequently happens when m is much larger than n.
Here’s a plunkr to reproduce this behavior: https://plnkr.co/edit/B1463DyuByuIlmWTynRn
Steps:
- Enter a number between 600-800 in the box, and hit “Jump to row…”
- Enter a number between 200-400 in the box, and hit “Jump to row…”. Check whether the row is visible.
- Repeat steps 1 and 2, using a different number in the ranges each time, until you notice that the row in step 2 isn’t visible after the jump.
It usually takes anywhere from 1-5 repetitions for it to first occur. I’ve also noticed the error occurs with decreasing frequency the more jumps are done.
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 23
- Comments: 16 (1 by maintainers)
I have solution
You should do scroll until row index is >= startIndex and <= stopIndex scrollTop can be found by List#getOffsetForRow
I have the same issue, my workaround is to call
scrollToRowagain in thesetStatecallback, like:Are there any other workarounds or solutions ?
BTW @oliverodaa, calling this.ref.measureAllRows() not solving for me
I was having same problem in
Listsolved it by using hack of setting anestimatedRowSizeparameter to average row size value. StackOverflow AnswerA final comment:
You could actually get
measureAllCells()to give correct truly measured data if you setdefaultHeight: 0within the cache - after which you would not need the doublescrollToRow.Of course, depending on your product, this is either not feasible, or totally feasible. Tread lightly.
Okay I have revisited this after a year to try to get a better solution. Here’s what I came up with:
So we basically just try twice and then resolve the promise after the second try.