Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React native null is not an object (evaluating '_scrollView.scrollTo') on Android

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

like image 813
Wee Avatar asked Jul 24 '26 07:07

Wee


1 Answers

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..

like image 51
Sk Sunny Avatar answered Jul 26 '26 23:07

Sk Sunny



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!