Unable to maintain the visible area when prepending items in ListView
I am making an Android app (using react-native 0.18.1) that has a ListView full of items with different heights. I want to adjust the scroll position in a way that the currently visible area doesn't change when prepending items (the standart behaviour is just to maintain the scroll position and the visible area is pushed down). I tried to use ListView's onContentSizeChange and find the new scroll position by summing the old one and the difference between the new height and the old height. I am getting the heights with ListView.scrollProperties.contentLength. Then i use scrollResponderScrollWithoutAnimationTo(). The problem is that the transition that should be instant is in fact visible. The visible area is first pushed down and then returned back by the onContentSizeChange's logic.
P.S. I had also tried to make the calculations and scrolling in componentDidUpdate with requestAnimationFrame and using innerScrollView.measure() to find the new height, but the problem still appears.
Hey ayanchevski, thanks for reporting this issue!
React Native, as you've probably heard, is getting really popular and truth is we're getting a bit overwhelmed by the activity surrounding it. There are just too many issues for us to manage properly.
- If you don't know how to do something or something is not working as you expect but not sure it's a bug, please ask on StackOverflow with the tag
react-nativeor for more real time interactions, ask on Discord in the #react-native channel. - If this is a feature request or a bug that you would like to be fixed, please report it on Product Pains. It has a ranking feature that lets us focus on the most important issues the community is experiencing.
- We welcome clear issues and PRs that are ready for in-depth discussion. Please provide screenshots where appropriate and always mention the version of React Native you're using. Thank you for your contributions!
+1
+1
+1
+1
+1
+1
any solutions?
We solved this by writing our own ListView on top of ScrollView. That's one approach you could consider.
@ide So did I, but the result doesn't feel just as smooth as the native behaviour (not even close indeed ^^). Indeed, I have the same problem with a scrollview. Do you have any hint on how you proceeded ?
@ayanchevski This is also a big issue for me. Looks like you already have a draft. I'd Happy to work/help/debug your code. Can you paste it in a Gist?
@JeandeCampredon This is also a big issue for me. Looks like you already have a draft. I'd Happy to work/help/debug your code. Can you paste it in a Gist?
Obviously a bunch of people want this. It's not quite clear to me what the next step is though - might be a total ListView overhaul. I suggest folks upvote https://productpains.com/post/react-native/fix-various-listview-issues to help get that prioritized. For now, I'm going to close this issue.