React Native ListView scrollToEnd not working

I am using ListView scrollToEnd but it does not work, but it worked for scrollTo . What should I do to handle this.

enter image description here

enter image description here

+11
javascript listview react-native
source share
3 answers

There is a workaround, wrap it in setTimeout as follows:

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

Try this:

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

document

+8
source share

Rendering takes time, so setTimeout () will work before scrolling to the end. However, you can 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 deprecated.

0
source share

All Articles