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.

Feature request

I have a list with a button that scrolls to the top of the list. The user can press the button any time, and when he does, the list should scroll to the top. The button may be pressed multiple times, the user may scroll in between. Each time, the list should scroll to the top.

The current workaround is to use the scrollToRow prop, and set it to 0 when the button is pressed. You then have to spy on the scroll position, and change the scrollToRow prop to undefined when the component has reached the correct scroll position.

I’m suggesting having a scrollToRow method instead, which would allow the following use case :

class Weeks extends Component {
  constructor(props) {
    super(props)
    auto_bind(this)
  }

  scroll_to_top() {
    this.list.scrollToRow(0)
  }

  render_week({key, index, style}) {
    return (
      <div key={key} style={style}>
        <Week week={index}/>
      </div>
    )
  }

  render() {
    return (
      <List
        height={height}
        width={width}
        ref={(list) => {
          this.list = list
        }}
        rowCount={100}
        rowHeight={row_height}
        rowRenderer={this.render_week}
        />
    )
  }
}

This is the same strategy as the React Native ScrollView component : https://facebook.github.io/react-native/docs/scrollview.html#scrollview

I can implement it if you give me the go-ahead.

(This issue is linked to this stack overflow question : http://stackoverflow.com/questions/41122140/how-to-scroll-to-index-in-infinite-list-with-react-virtualized/41126137?noredirect=1#comment69546597_41126137)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

14reactions
kelly-tockcommented, Jan 14, 2019

is there a way to scroll a specific row by index number to the top of the scrollable area?

3reactions
codeclowncommented, Sep 26, 2020

@kelly-tock Yes (docs):

<List
  scrollToIndex={index}
  scrollToAlignment="start"
  ...
/>
Read more comments on GitHub >

github_iconTop Results From Across the Web

scroll_to_index | Flutter Package - Pub.dev
scroll-to-index #. This package provides the scroll to index mechanism for fixed/variable row height for Flutter scrollable widget.
Read more >
flutter ListView scroll to index not available - Stack Overflow
I want to scroll a list by some index, how can i do that. What I know: scrollToIndex should start from n index,...
Read more >
Scroll to Index - React Virtuoso
The Virtuoso component exposes an imperative scrollToIndex method, which scrolls the item at the specified index into view.
Read more >
Scroll to Index ListView - GitHub Gist
Calculates the offset of a widget at [index]. If you scroll to that. /// index, that item will be at the top of...
Read more >
Flutter: How to scroll to a specific position in ListView? - Medium
There is always a problem with scrolling in ListView inside Flutter, so here I am coming with an example where we can scroll...
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