1

I have a horizontal ListView each item of the ListView occupy the whole width and height and same for the second item and so on ( it's like a horizontal pagination ), after implementing it I want to scroll to the next item programmatically, so I disabled scrolling scrollEnabled={false} now I want to scroll programmatically ( after triggering an event ) to the next item (page), any hint or idea for this one?

UPD

This the error caused by scrollTo : scrollTo is not defined

<Button title="Learn More"
  onPress = {(ev)=>{
     scrollTo(0, 1000)
  }}></Button>
6
  • 1
    scrollTo function would be best possible way to achieve this. Commented May 3, 2017 at 9:06
  • @SagarKhatri I'd did use it inside a function "renderRow()" but I'm getting scrollTo in not defined! Commented May 3, 2017 at 9:15
  • @AbdenaceurLichiheb If you're getting that error (and not only in this case) is better to showing us the code :) Commented May 3, 2017 at 9:37
  • 1
    ok. This is more a javascript related error. scrollTo(0, 1000) is not defined because the context of that call is that arrow function and not the component. So you need a reference to the ListView and then you can do like: listview.scrollTo(0, 1000) Commented May 3, 2017 at 9:44
  • 1
    @AbdenaceurLichiheb Just for reference: developer.mozilla.org/en/docs/Web/JavaScript/Reference/… Commented May 3, 2017 at 10:58

1 Answer 1

2

1. Try to get a reference to the scroll view

This is how I do it:

render(){
  let _listView: ListView;
  return (          
      <ListView ref={(listView) => { _listView = listView; }}
            dataSource={this.state.dataSource}
            renderRow={this._renderRow.bind(this)}
      />
  )
}

2. Using the _listView variable and calling the scrollTo method.

Note that you're using it in an arrow function and in my code above, the _listView variable is inside the render method. So you can create it inside the constructor and then use it as a class property.

Like this:

constructor() {
  this._listView = {};
}

(Note that this is an example initialization, I don't know where you're using that button, so probably this second point is not necessary or even wrong, so everything could be done inside the render method).

Sign up to request clarification or add additional context in comments.

1 Comment

I already fix it I just forgot to add ref="listview" to my listview, thanks :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.