FlatList 无限循环 - React Native
我正在尝试制作一个在两个方向上无限滚动的平面列表。
已经有一个小的实施概要(https://snack.expo.dev/@ slam_ua/flatlist-loop),但我似乎无法做一些事情:
- 无缝列表。当数据更新时滚动停止。
- 无限向上滚动不起作用。
- 将初始坐标 (00) 置于中心(从带有示例的图片中可以清楚地看出我的意思)。
下面我展示了我想要实现的结果的示例:
I'm trying to make a Flatlist with infinite scrolling in both directions.
There is already a small outline of the implementation (https://snack.expo.dev/@slam_ua/flatlist-loop), but I can't seem to do a few things:
- Seamless list. Scrolling stops when data is updated.
- Infinite scroll up not working.
- Centering the initial coordinate (00) in the center (from the picture with an example it will be clear what I mean).
Below I have shown an example of the result I want to achieve:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我们可以调整 react-native-circular-wheel-picker 来实现这。
我们按如下方式使用它。
上述产生以下结果。
We can tweak react-native-circular-wheel-picker to achieve this.
We use it as follows.
The above yields to the following result.
您可以通过在 React Native 中使用简单的选择器库来实现这一点。
你想要的视图/UI,你必须为它们创建组件。
你可以使用这个库:
react-native-picker
npm i react-native-picker
或
react-native-wheel-picker
https://www.npmjs.com/package/react-native-wheel-picker
编辑后:
如果有人需要的话,请不要删除上面的库。
对于无限滚动,您可以使用和调整此库:
https://www.npmjs.com/package/react-native-无限循环滚动
这是演示链接:
https://drive.google.com/uc?id=1re6VhBZ8NZIsPYvN5DMhgveA7ei87N9U
工作演示,可能是因为吃零食而有点懒惰。

但有效:
You can achieve this by using simple picker libraries in React Native.
The View/UI You want, you have to create components for them.
you can use this library:
react-native-picker
npm i react-native-picker
Or
react-native-wheel-picker
https://www.npmjs.com/package/react-native-wheel-picker
After Edit:
Not Removing Above libraries, if someone needs it ever.
For infinite scroll, you can use and tweak this library:
https://www.npmjs.com/package/react-native-infinite-looping-scroll
Here's the link of demo:
https://drive.google.com/uc?id=1re6VhBZ8NZIsPYvN5DMhgveA7ei87N9U
Working Demo, might be bit laggy because running on snack.

But works:
onEndReached={()=>flatListRef.current.scrollToOffset({offset: 0,animated: true})}
onEndReached={()=>flatListRef.current.scrollToOffset({offset: 0, animated: true})}
修复 David Scholz 答案中的错误。
还有你这样称呼它~
Fixing the bugs in David Scholz's answer.
And you call it like this~