question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

scrollToIndex and dynamic size

See original GitHub issue

I have a dynamic height list and want to scroll to end https://codesandbox.io/s/exciting-kate-h555x?file=/src/index.js

When I press Scroll To end it sometimes goes to the end and sometime to the Row 9993 Please open the list and press Scroll To end , If you goes to end refresh the page and retry again

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:13

github_iconTop GitHub Comments

2reactions
piecykcommented, Nov 24, 2021

Just want to ask Is it ok to have 4 requestAnimationFrame?

It’s definitely a code smell and would not recommend it, but if it solve the issue 99% of times 🙈

Don’t know exactly what is your use case, but there is also an option to pre-render the last n elements of list, just make it render once before scrolling. It can be done via rangeExtractor, for example pre rendering 25 last items https://codesandbox.io/s/toend-forked-mvow4?file=/src/index.js

0reactions
Recognizedcommented, Jul 1, 2022

I guess the only real way to solve this issue is to use scroll “anchoring” instead of one “scrollToIndex” call. You should maintain scroll position and automatically readjust it in case items or parent container resize. But it is not that easy anyway. Using timeouts or 2+ requestAnimationFrame to wait for something is just unreliable. Some users would report you issues with scroll and you wouldn’t be able to reproduce it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

scrollToIndex and dynamic size · Issue #216 · TanStack/virtual
I have a dynamic height list and want to scroll to end https://codesandbox.io/s/exciting-kate-h555x?file=/src/index.js When I press Scroll ...
Read more >
Dynamic size item scroll inside FlatList : r/reactnative - Reddit
React Native scrollToIndex - Dynamic size item scroll inside FlatList : r/reactnative.
Read more >
Efficient way to scroll to certain index in FlatList with variable ...
My solution was to get each item's size when rendered by using onLayout and map them with their index. I can then use...
Read more >
React Native FlatList scrollToIndex with Fixed or Variable Row ...
It is easier to use scrollToIndex with items of a fixed size, but you are not out of luck if your items are...
Read more >
Virtualizer | TanStack Table Docs
This function is passed the index of each item and should return the actual size (or estimated size if you will be dynamically...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found