Scroll up issues with cell measure
What is the current behavior?
When table element has scrollToIndex and image measure, then scroll up jumps to scrolltoindex position.
What is the expected behavior?
Scroll up should work without jump like scroll down
Example Repo
https://codepen.io/muthu32/pen/pmygmR
What is the current behavior?
The same issue as above but with a list element. When a scrollToIndex has been specified and is no longer visible, the scroll will jump. In the example above, it happens for scrolling both up and down, which is the same as what I'm experiencing.
What is the expected behavior?
It seems that scrollToIndex will force you to go back to specified index if it isn't visible. I would like the behavior to be like the example here, list element demo. In that list, you can specify an index to be scrolled to, but then interact with the list normally.
To add on, it seems like this is related to the cached row height. When I manually input a value, the list seems to work as expected. In the demo, it looks like the row height isn't being calculated.
There is a problem with image measure that force you to jump up. When I analysed the source code following lines are found to be responsible for jump to scroll to index position.
https://github.com/bvaughn/react-virtualized/blob/bc5ae2fa084e20323b445b31fd72acee90e0ab5f/source/CellMeasurer/CellMeasurer.js#L141-L144
https://github.com/bvaughn/react-virtualized/blob/bc5ae2fa084e20323b445b31fd72acee90e0ab5f/source/Grid/Grid.js#L554-L558
When I removed those specified lines from Grid.js, it works fine.
Facing the same issue - is there a way to know once ScrollToIndex is applied, so it can be set to undefined for any subsequent scroll event.
I found that using the this.list.scrollToRow(row) on the componentDidMount works better than the scrollToIndex on the component
I just added an onScroll handler that ended up setting my scrollToIndex back to undefined, tiny workaround
This is addressed in react-virtualized 10 (upcoming). Table's scrollToIndex prop is replaced by tableRef.current.scrollToRow({ index }), which is a one-time scroll, so images measured while scrolling up no longer make it jump back.