React native Android ScrollView scrollTo not working

I had the same issue, and wasted several hours no it:

  • 1: in android, ScrollView can scroll only when its size < content’s size

  • 2: in react native android, if you call ScrollView.scrollTo() in componentDidMount, it won’t work, because ScrollView has a layout animation when create, you can find it in ReactScrollView.java

protected void onLayout(boolean changed, int l, int t, int r, int b) {
    // Call with the present values in order to re-layout if necessary
    scrollTo(getScrollX(), getScrollY());
}

so, you must delay it after the animation

componentDidMount() {
    InteractionManager.runAfterInteractions(() => {
      this.myScroll.scrollTo(100);
        console.log("called DidMount");
    })  
}

Leave a Comment