简体   繁体   English

React-Native:Flatlist ScrollToPosition不会滚动到实际位置

[英]React-Native: Flatlist ScrollToPosition doesn't scroll to actual position

With flatList and rendering about 100 items or so. 使用flatList并渲染大约100个项目。 Once we use scrollToOffset that are outside the rendered zone, the scrollToIndex function will only bring you the last frame of the initially rendered items. 一旦我们使用位于渲染区域之外的scrollToOffset,scrollToIndex函数将只为您带来初始渲染项目的最后一帧。 Is this a limitation, or am I doing something wrong. 这是一个限制,还是我做错了什么。

This can be fixed but setting the initialNumToRender to a very large number supporting 100+ items, but in this case the performance will suffer. 可以解决此问题,但是将initialNumToRender设置为支持100多个项目的非常大的数目,但是在这种情况下,性能会受到影响。

Current situation: We render 100 objects to place in the flatList. 现状:我们渲染100个对象放置在flatList中。 They are dynamic in size so using getItemLayout/ scrollToIndex is out of the question. 它们的大小是动态的,因此不可能使用getItemLayout / scrollToIndex。 When the user moves out of the page, and then comes back, we want the position to be maintained. 当用户移出页面,然后返回时,我们希望保持该位置。 But on Android, if it is an item very far down on the list, it won't maintain that position, and will put us at the end of the initial rendered position. 但是在Android上,如果它是列表中的最后一个项目,它将不会保持该位置,并且会将我们置于初始渲染位置的末尾。

Version: React-native: 0.44 React: 16.0.0-alpha.6 版本:React-native:0.44 React:16.0.0-alpha.6

I read that the only way to get this to work is to also use the getItemLayout prop. 我读到, getItemLayout起作用的唯一方法是也使用getItemLayout This will also improve perf for the flatlist. 这也将改善单位列表的性能。 One thing to note, however, is that the rows need to have the same height in order for this to work. 但是要注意的一件事是,行必须具有相同的高度才能使此行有效。

https://facebook.github.io/react-native/docs/flatlist.html#getitemlayout https://facebook.github.io/react-native/docs/flatlist.html#getitemlayout

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

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