react native中flatlist的scrollToIndex等方法使用

1.设置ref

<FlatList
  ref={this._getRef}
  data={data}
  refreshing={this.state.refreshing}
  onRefresh={this._freshData}
  getItemLayout={(param, index) => ({ length: 64, offset: 64 * index, index })} //设置优化滚轮滑动效率  64为每个item高度
/>
 
 

_getRef = (flatList) => {

this._flatList = flatList; const reObj = this._flatList; return reObj; }

2.使用方法

this._flatList.scrollToIndex({ viewPosition: 0, index: 0 });

猜你喜欢

转载自blog.csdn.net/ky1in93/article/details/80364438