React native 获取平面列表的当前滚动位置
我有以下代码:React native 获取平面列表的当前滚动位置,react-native,React Native,我有以下代码: <FlatList ref={(x) => (this.flatList = x)} data={players} style={this.props.style} /> (this.flatList=x)} 数据={players} style={this.props.style} /> 我需要的是在用户离开时保存FlatList的当前滚动位置 类似于this.flatList.getCurrentScrollPosition()
<FlatList
ref={(x) => (this.flatList = x)}
data={players}
style={this.props.style}
/>
(this.flatList=x)}
数据={players}
style={this.props.style}
/>
我需要的是在用户离开时保存FlatList
的当前滚动位置
类似于this.flatList.getCurrentScrollPosition()
有这样的东西吗?
FlatList
继承了所有的ScrollView
道具。因此,您可以使用onScroll
onScroll = (event) => {
const scrollOffset = event.nativeEvent.contentOffset.y
}
谢谢我在考虑一个与HTML中的
element.scrollTop
等价的东西,它只会查询元素的当前位置。让onScroll
事件在每个滚动事件中触发远远超出了我的需要。您可以使用scrollEventThrottle
道具来限制触发次数