简体   繁体   English

如何在原生反应中滚动平面列表中的特定项目?

[英]How to scroll specific no of items in a flatlist in react native?

I have a flatlist that shows list of items.我有一个显示项目列表的平面列表。 I want to control its scrolling nature.我想控制它的滚动性质。 I want that when the user scroll it only sees the next 5 items.我希望当用户滚动时它只能看到接下来的 5 个项目。 How can i overwrite the on scroll behaviour of flatlist in react native.如何在 react native 中覆盖 flatlist 的滚动行为。 Is there is any way to handle it.有什么办法可以处理。 Please suggest it out.请提出建议。

Suppose there is a horizontal flatlist in which i have 1000 items.假设有一个水平平面列表,其中我有 1000 个项目。 Initally i show 10 items to the user.最初我向用户展示了 10 个项目。 Now i want that when the user scrolls in the right direction then i show only the next 10 items to user.After these 10 items are show if user scrolls again then i show next 10 items.现在我希望当用户向正确的方向滚动时,我只向用户显示接下来的 10 个项目。在显示这 10 个项目之后,如果用户再次滚动,那么我将显示接下来的 10 个项目。 In current scenerio i am unable to control the amount of scrolling.在当前场景中,我无法控制滚动量。

Same condition for scrolling in left direction.向左滚动的条件相同。 When the user scrolls in the left direction is should only see the previous 10 items当用户向左滚动时应该只看到前 10 项

You didn't explain your question precisely so i just provide info that may help you.您没有准确解释您的问题,所以我只是提供可能对您有帮助的信息。

Full docs in: https://reactnative.dev/docs/flatlist完整文档在: https://reactnative.dev/docs/flatlist

You can set initial number of item to show with initialNumToRender prop.您可以使用initialNumToRender设置要显示的项目的初始数量。

flatlist renders the items you pass it with data prop so when you change that value the data is there to load when you scroll further, you can fetch 5 number of items each time you reach at its end with onEndReached and have a infinite scroll. flatlist 使用data属性呈现您传递的项目,因此当您更改该值时,当您进一步滚动时,数据会在那里加载,每次您使用onEndReached到达其末尾时,您可以获取 5 个项目并进行无限滚动。

or if you want user to do something before you show the next 5 items without just scrolling down, eg put a button and fetch next 5 items and add to prop data each time user presses that.或者,如果您希望用户在显示接下来的 5 个项目之前执行某些操作,而无需向下滚动,例如,放置一个按钮并获取接下来的 5 个项目,并在每次用户按下它时添加到道具data

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM