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.

Animating .scrollTo() / .scrollToIndex() ❓

See original GitHub issue

Hi there 😃

Thanks for this great lib!

I’m experimenting with it and I wondered whether it’s somehow possible to animate the scrolling behavior (“smooth scroll”) when using scrollTo() / scrollToIndex()?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

11reactions
petrsuhin-alcommented, May 7, 2021

Just add to your global or component styles:

.List {scroll-behavior: smooth;}

IMHO, the simplest and most elegant solution, I don’t understand why no one suggested it

10reactions
gauthamchandracommented, Oct 10, 2019

This is easier to do with the outerRef prop which gives you a reference to the scrollable div.

You could then use that in combination with the standard Element.scrollTo() API.

So it would something along the lines of this:

export default VirtualizedList extends React.Component {
   constructor() {
     this.listRef = React.createRef();
     this.scrollableContainerRef = React.createRef();
   }

  scrollTo(scrollOffset) {
    // note that my list is vertical which is why I am feeding this to the "top" prop.
    this.scrollableContainerRef.current.scrollTo({ 
      left: 0, 
      top: scrollOffset,
      behavior: 'smooth',
    });
  }

  render() {
    <List 
      ref={this.listRef}
      outerRef={this.scrollableContainerRef}
      layout="vertical"
      ...
  }
}

NOTE: I removed all the extraneous code and props above to keep things brief.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Native scrollToIndex - Dynamic size item scroll inside ...
In this video tutorial you will learn about React Native scrollToIndex and how to scroll to an item inside a FlatList, ListView, ScrollView, ......
Read more >
RN Animated.FlatList ScrollToIndex(0) causes Flashing ...
I'm trying to create a carousel with infinite looping on finite set of data using FlatList and am using ScrollToIndex to scroll to...
Read more >
scrollToItem(at:at:animated:) | Apple Developer Documentation
Instance Method. scrollToItem(at:at:animated:) Scrolls the collection view contents until the specified item is visible. iOS 6.0+ iPadOS 6.0+ Mac Catalyst ...
Read more >
scrollTo | React Native Reanimated - Software Mansion
Provides synchronous scroll on the UI thread to a given offset using an animated ref to a scroll view. This allows performing smooth...
Read more >
FlatList scrollToIndex practical example. - Expo Snack
FlatList scrollToIndex practical example. No description. Open with Expo Go. Open in editor. Need Expo? Don't have the Expo Go? Download the app...
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