Reputation: 655
I have a <List>
component. I am building a feature where it:
<List>
. It does by using the scrollToIndex
prop.document.getElementById('myId').scrollIntoView()
.How can I ensure that step (2) occurs after step (1)?
Note: I have already tried the onRowsRendered()
but it looks like that is not always executed after scrollTo
.
Documentation is here, but unfortunately I'm quite stuck.
Edit: In case anyone comes across this question in future, I got kind of an answer over at the GitHub repo:
the
onScroll
prop you pass in is bound to the htmlonscroll
event which is triggered every moment you scroll. ThescrollToIndex
prop is used to calculate thescrollTop
and then is manually set on the html element.
https://github.com/bvaughn/react-virtualized/issues/1077#issuecomment-381438215
Upvotes: 1
Views: 806
Reputation: 2045
See https://stackoverflow.com/a/41111505/5683904
// Keep track of last scroll position
_lastScrollTop;
_cellRangeRenderer(props) {
this._rowSizeAndPositionManager = props.rowSizeAndPositionManager;
if (props.isScrolling === false && this._lastScrollTop !== props.scrollTop) {
// Only call this function if
this._lastScrollTop = props.scrollTop;
this.onAfterScroll();
}
return defaultCellRangeRenderer(props);
}
onAfterScroll(){
//Do what you want to do after scrolling has stopped.
}
In order to scroll to specific div in the DOM (2)
document.getElementById('myId').scrollIntoView()
you have to ensure that the dom has already been rendered.
onNextFrame(callback) {
window.requestAnimationFrame(callback);
}
//And wrap the function that accesses the Dom directly like this
onNextFrame(() => {
let target = document.querySelector(`...`);
...
});
Upvotes: 2