-
Notifications
You must be signed in to change notification settings - Fork 431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix scroll position for dynamic contents #127
Comments
You shouldn't be creating a new instance of the DataProvider. Just use the existing one.
Note that if you add items to the top of the list the scroll position won't be maintained though. You could try to do that imperatively. |
Remember |
@abdallamohamed I test your approach and see that is not working as I expected When the scroll reaches at top I add items to the top of the list and if before loading items you see 100th item I want scroll show 100th item after scrolling , but it show top item Can you show me an example code? |
@sm2017 I'm doing an ugly workaround right but at least it preserves the scroll position. Before setting the state with the new dataProvider. I get a reference to the top row in the list. Then I set the state, and afterwards, I calculate the index of the top row and then I call
|
@abdallamohamed your approach don't works as I expected @naqvitalha I will send a working expo demo asap |
@sm2017 I think what you're describing is the same issue that I struggled with before. Check out this snack and let me know if it helps. https://snack.expo.io/@abdallamohamed/preserving-scroll-position-with-recyclerlistview |
@abdallamohamed your expo code preserves scroll position (but not accuracy in pixel) |
@sm2017 Yeah, it's a compromise I had to accept. I'd love to see what @naqvitalha has to say. |
Try this https://snack.expo.io/S1zKr6tPf. Even though it's a hack (uses private api) but it certainly proves that it is possible. Also, note none of these solutions work in between a scroll. Maybe we can transform the whole list instead to correct the offset. Post the animation work we will be introducing stableIds which will improve this further and the flicker will go away automatically without increasing |
@naqvitalha I cannot understand why |
It removed the flicker, the reason for it was that items are moved to that location post the manual scroll request. Since this is async there is one frame where there are no items. In the the |
To remove the flicker you generate 10 items each time and set Can |
@naqvitalha is there any tricks for |
@naqvitalha Help please |
@naqvitalha 😭 help needed! |
@sm2017 if you can cache layouts yourself it might work. The same solution will work only if you know exact heights. Why don't you start caching them externally? |
@naqvitalha How exactly?? At first time how can I read from cache as there is no cache?? Must I render items outside view? And mount again inside?? It is expensive |
@naqvitalha I just tested your snack code but in a web project. It seemd not to be working as native. What I saw debugging it is that the scrollcomponent does not have a ref here when calling the scrollToOffset |
@tafelito Try |
@naqvitalha Awesome that worked and I like it works with react-native-web too because right now that wasn't working either. regarding @sm2017 request, I'm also thinking on how to make it work even if using inverted for a chat app. Not every message in a chat has the same height. So how do you now the renderAheadOffset value beforehand? Or if you have a feed like twitter's Also regarding the inverted prop, I gotta finish what I started before you moved everything to Typescript if you are not working internally. |
@naqvitalha I need for chat app but inverted prop is not solution because , I have both up/down direction infinite scrolling You can scroll up to we history |
You can fetch new messages on coming down and smoothly insert using animations. Wouldn't that help? See I do have a solution for this but that is still quite far away. I'm thinking to transform entire list to lock scroll positions. I'm sure that will work but I can't start doing that because I need to do sticky headers and stableId work before that. You can experiment around it though. |
@naqvitalha Can you share more details about transform entire list to lock scroll positions |
@naqvitalha I'm loving what you guys are doing with this library! Just out of curiosity, how do you intend to implement sticky headers? |
@naqvitalha Have you plan to implement |
@naqvitalha Reply please |
@sm2017 Let's say my first visible index was 5, I can compute it's offset from top and after inserting items I can transform the whole list such that the position of the same item from top stays the same. This will work in the middle of a scroll as well. Now as soon as the scroll stops I can fix the offset by removing the transform and calling |
@naqvitalha why when I append data to data provider just some items are rendered but when I prepend whole items are renered |
@naqvitalha I just saw that on the February release of RN, the ScrollView now includes a property |
I was just going to comment with a link to that commit, @tafelito |
@tafelito @abdallamohamed Doing it in native makes sense, however an acceptable implementation should be possible in JS too. Plus this can never work on |
@tafelito it looks like the same logic |
@naqvitalha I think right now yes it only works for iOS but I read they are also working on the Android version so they might change that in the future. But as you said, it'd definitely make more sense doint it in JS whenever is possible so it works for both web and native |
Hello, |
@naqvitalha were you able to take a look at this? I'm still trying to find a smoother way to lock scroll position when loading dynamic content but everything I tried seems like a hack |
Version 2.0.13-alpha.1 If i understand the issue, I'm having the same problems with a list of fixed size items. It's a grid of pictures. That's the only issue so far, the performance is really great even with thousands of pictures. |
@immortalx i fixed that issue by making a custom scroll view and removing the scroll to method on it . It seems to be embedded into the recycler list out of the box |
hey @nikolas7892 , thanks for your answer. |
@GSManganneau Despite my fixes I've had so many issues with this project its better to just stick with Facebooks RN Flatlist and just optimize your cell items. I've done weeks of research on the best solution and that's it..... This native solution is great in concept but it has no where the same community around it like Facebook to actively fix bugs for production application.. I recommend using why did you render to see which parts of your applications are causing rerenders (for sure its a ton...) and use React.memo with areEqual to determine when to rerender the cell.. https://github.com/welldone-software/why-did-you-render Let me know if you still need the example, i can spin one up for you. |
Can you provide an example for the above approach that you have recommended using |
@afrinsulthana1 docs = https://reactjs.org/docs/react-api.html#reactmemo
|
I want to create an infinite scroll view using recyclerlistview in both direction (up and down)
When I load more contents , the following code executed
Here the scroll offset will reset to zero and scroll go to the top
I use
scrollToOffset
to change the offset togetCurrentScrollOffset()+heightOfNewContents
when scrolling to up direction ,scrollToOffset
works accuracy well but I see a small view refresh , the view become blank for a fraction of secondI find that changing
dataProvider
is not the cause ,scrollToOffset
is the reason because If I don't change data and just callscrollToOffset
I see the view become blank for fraction of second , I test with a simplePureComponent
and I'm surescrollToOffset
is problem not theCellContainer
view itselfThe text was updated successfully, but these errors were encountered: