React Native ListView scrollToEnd it doesn't work

前端 未结 4 1514
半阙折子戏
半阙折子戏 2021-01-04 05:40

I use the ListView\'s scrollToEnd, but it doesn\'t work, but it worked for scrollTo. What should I do to deal with it.

相关标签:
4条回答
  • 2021-01-04 05:43

    This this worked for me.

    <Content ref={c => (this.contentComponent = c)}>
    ....Any code
    </Content >
    

    This allows you to to use the scrollToPosition(0) function like

    this.contentComponent._root.scrollToPosition(0);
    
    0 讨论(0)
  • 2021-01-04 05:48

    Rendering takes time so setTimeout() before scrolling to end will work. You can, however, use the onLayout() method.

    export default MyComponent extends React.Component {
      constructor(props) {
        super(props)
    
        this.scrollToBottom = this.scrollToBottom.bind(this)
      }
    
      scrollToBottom() {
        this.refs.myView.scrollToEnd()
      }
    
      render() {
        return {
          <ListView
               onLayout={this.scrollToBottom}
               ref='myView'
               ...
          />
       }
     }
    

    Note: ListView is now deprecated.

    0 讨论(0)
  • 2021-01-04 06:00

    Try this:

    <ListView
        ref={ ( ref ) => this.scrollView = ref }
        onContentSizeChange={ () => {        
            this.scrollView.scrollToEnd( { animated: false } )
        } } >
    </ListView>
    

    document

    0 讨论(0)
  • 2021-01-04 06:01

    There is a workaround, wrap it in a setTimeout like so:

    componentDidMount() {
      setTimeout(() => {
        this.refs.dateList.scrollToEnd();
      }, 50);
    }
    
    0 讨论(0)
提交回复
热议问题