簡體   English   中英

React Native ListView scrollToEnd 它不起作用

[英]React Native ListView scrollToEnd it doesn't work

我使用 ListView 的scrollToEnd ,但它不起作用,但它適用於scrollTo 我該怎么做才能處理它。

在此處輸入圖片說明

在此處輸入圖片說明

有一個解決方法,將其包裝在setTimeout如下所示:

componentDidMount() {
  setTimeout(() => {
    this.refs.dateList.scrollToEnd();
  }, 50);
}

嘗試這個:

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

文檔

渲染需要時間,因此在滾動到結束之前 setTimeout() 將起作用。 但是,您可以使用 onLayout() 方法。

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'
           ...
      />
   }
 }

注意:ListView 現在已棄用。

這對我有用。

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

這允許您使用 scrollToPosition(0) 函數,如

this.contentComponent._root.scrollToPosition(0);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM