Is it possible to add items to the React Native ListView in the onTopReached event, similar to how one adds items to the onEndReached event? Currently, when I add rows to the list, the ListView scrolls up.
Use case: I have an application with a feed that the user can scroll down. When you go from the feed and then go back to it, I want to show the last row seen above. Then the user should be able to scroll either up to see the previous lines that he has scrolled, and, of course, load new lines. Assuming I have already displayed a ListView, starting with the last visible row, a far-fetched example would look something like this:
_onTopReached() { this._unshiftRows(); }, _unshiftRows() { var list = this.props.list;
In the above example, I simply add the first part of the list to the already processed last part with _onTopReached shooting right away, because I'm already at the top. However, this causes the ListView to re-display the first row at the top of the screen, rather than retaining its previous position.
An alternative is to save the y offset of the last visible row and move to the ListView list at that position. However, this method requires that each line be displayed before the current one, which takes a lot of time. I also could not get the correct offset using scrollWithoutAnimationTo or setting contentOffSet . However, it performs the transition to the correct position if I use scrollTo or set a timeout before calling scrollWithoutAnimationTo and allow the first lines to be rendered in average time. But it is not very nice.
All help would be greatly appreciated. Thanks!
source share