FlatList方案
推荐使用该方案
FlatList 有个 scrollToIndex(params),可以直接实现该功能。
参数params:
类型object,包含以下 key
- ‘animated’ (boolean) - Whether the list should do an animation while scrolling. Defaults to
true
. - ‘index’ (number) - The index to scroll to. Required.
- ‘viewOffset’ (number) - A fixed number of pixels to offset the final target position.
- ‘viewPosition’ (number) - A value of
0
places the item specified by index at the top,1
at the bottom, and0.5
centered in the middle.
scrollView 实现方案
scrollView 实现该功能的思路为 计算要滚动的距离 + scrollTo( )来实现
1 | import React, { Component } from 'react'; |