有没有人有过使用FlatList(或任何其他组件)进行双向无限滚动的经验?
我的用例是我有一个日历月视图,我希望能够左右滑动以获取下个月和上个月。
FlatList与onEndReached和onEndReachedThreshold对于一个方向来说效果很好,但一开始就没有类似的东西。有什么建议么?
您可以使用onScrollFlatlist 上的道具:https://reactnative.dev/docs/scrollview#onscroll
onScroll={({
nativeEvent: {
contentInset: { bottom, left, right, top },
contentOffset: { x, y },
contentSize: { height: contentHeight, width: contentWidth },
layoutMeasurement: { height, width },
zoomScale,
},
}) => {
if ( y <= your_start_threshold) {
// Do what you need to do on start reached
}
}}
Run Code Online (Sandbox Code Playgroud)
唯一的问题是 React Native 不支持FlatListAndroid 上的双向。这意味着当您将项目添加到列表的开头时,它将跳到顶部,而不是保留当前项目在视图中(https://github.com/facebook/react-native/issues/25239)。
(iOs确实有一个maintainVisibleContentPosition道具)
| 归档时间: |
|
| 查看次数: |
2432 次 |
| 最近记录: |