React native Android ScrollView scrollTo not working

前端 未结 4 832
太阳男子
太阳男子 2020-12-15 17:00

I am trying to use a horizontal ScrollView in React Native for Android, where the starting position is in the middle of the scrolling images rather than (0,

4条回答
  •  执笔经年
    2020-12-15 17:07

    I wanted to avoid using delays and timers so after a bit of digging I found that using onLayout works very smooth:

    scrollToInitialPosition = () => {
      this.scrollViewRef.scrollTo({ y: 100 });
    }
    ...
     { this.scrollViewRef = ref; }}
      onLayout={this.scrollToInitialPosition}
    />
    

提交回复
热议问题