ListView 和 FlatList 有什么区别?

编程入门 行业动态 更新时间:2024-10-23 01:59:09
本文介绍了ListView 和 FlatList 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

根据 Facebook 的文档,

According to Facebook's documentation,

ListView - 一个核心组件,设计用于高效显示垂直滚动的变化数据列表.

ListView - A core component designed for efficient display of vertically scrolling lists of changing data.

FlatList - 用于呈现简单、平面列表的高性能界面.

FlatList - A performant interface for rendering simple, flat lists.

似乎两者都有效.两者取舍时应考虑什么?

It seems both are efficient. What should we consider when choosing one from the other?

推荐答案

FlatList - 与 ListView 相比性能更高.一旦项目数量变大,ListView 渲染就会变慢.FlatList 显着提高了内存使用率和效率(特别是对于大型或复杂的列表),同时还显着简化了 props — 不再需要 dataSource!

FlatList - More performant compared to ListView. ListView rendering can get slow once the number of items grows larger. FlatList significantly improves memory usage and efficiency (especially for large or complex lists) while also significantly simplifying the props — no more dataSource necessary!

功能Flatlist 包含充满功能的新组件,可以处理大多数开箱即用的用例:

Features Flatlist is packed with new components full of features to handle the majority of use cases out of the box:

  • 滚动加载(onEndReached).
  • 拉动刷新(onRefresh/refresh).
  • 可配置的可见度 (VPV) 回调(onViewableItemsChanged/viewabilityConfig).
  • 水平模式(水平).
  • 智能项目和部分分隔符.
  • 多列支持(numColumns)
  • scrollToEnd、scrollToIndex 和 scrollToItem
  • 更好的 Flow 输入.

FlatList 仍然缺少一些功能,例如粘性标题,但它正在快速发展.ListView 将被 弃用.

ListView 现在已弃用,并且扁平列表中的粘性标题现在可以使用

ListView is deprecated now and Sticky Headers in Flat list working now

更好的选择

在平面列表中渲染 5000 多个项目时出现性能问题.寻找其他替代方案并找到 recyclerlistview - React Native 和 Web 的高性能列表视图.与平面列表相比,scrollTo 性能和渲染优化要好得多.

I was getting performance issues while rendering 5000+ items in flat-list. Looked for other alternatives and found recyclerlistview - High performance list-view for React Native and web. Much better scrollTo performance and better rendering optimisations compared to flat-list.

更多推荐

ListView 和 FlatList 有什么区别?

本文发布于:2023-11-03 15:03:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1555422.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有什么区别   ListView   FlatList

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!