React native null is not an object (evaluating '_scrollView.scrollTo') on Android
componentDidMount() {
let scrollValue = 0;
setInterval(function(){
scrollValue = scrollValue + width; // width = screen width
_scrollView.scrollTo({x: scrollValue})
}, 3000);
}
<ScrollView
ref={(scrollView) => { _scrollView = scrollView; }}
horizontal={true} pagingEnabled={true} >
{items}
</ScrollView>
it's work auto slide content but when I'm going back from another page it's return error null is not an object (evaluating '_scrollView.scrollTo') I don't know about that
you have to check if _scrollView not null
if(this._scrollView != null){
scrollValue = scrollValue + width;
this._scrollView.scrollTo({x: scrollValue})
}
render() {
// ...
return (
<ScrollView
ref={scrollView => this._scrollView = scrollView}
horizontal={true}
pagingEnabled={true}
>
{items}
</ScrollView>
)
}
I hope it will work as I resolved my issue like that way..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With