[英]React Native ListView scrollToEnd it doesn't work
有一個解決方法,將其包裝在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.