react-native - 在 native react 最好是List或ScrollView吗?

标签 react-native

我正在像应用程序这样的聊天,并且我已经看到了使用ListView和ScrollView的示例。两者的优点是什么?我需要在整个聊天过程中呈现不同外观的项(输入与响应或文本与图像)。一个人能更好地处理这种情况吗?

最佳答案

我认为您的问题是“ScrollView vs FlatList-使用哪个”?
根据React-Native docs:

ScrollView vs FlatList - which one to use?

ScrollView simply renders all its react child components at once. That makes it very easy to understand and use.

On the other hand, this has a performance downside. Imagine you have a very long list of items you want to display, maybe several screens worth of content. Creating JS components and native views for everythign all at once, much of which may not even be shown, will contribute to slow rendering and increased memory usage.

This is where FlatList comes into play. FlatList renders items lazily, just when they are about to appear, and removes items that scroll way off screen to save memory and processing time.

FlatList is also handy if you want to render separators between your items, multiple columns, infinite scroll loading, or any number of other features it supports out of the box.


我会使用FlatList。这就是你所需要的。它更有效,并且仅在需要时才懒加载数据。

关于react-native - 在 native react 最好是List或ScrollView吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44181806/

相关文章:

javascript - React Native - 不变违规 : Element type is invalid: expected string but got: undefiend

react-native - 动画 : Image component cannot contain child even when child component position is absolute

javascript - ReactNative 中的 ScrollView 没有填充剩余空间

android - 任务 ':react-native-background-job:compileDebugJavaWithJavac'的执行失败。在执行react-native-background-job时?

javascript - 如何在 React Native 中更改按钮的颜色?

react-native - React Native 展览地点 : How to make the background location service update more often?

javascript - 与 native 应用程序集成时,React-native 应用程序在每次导航时都会重新启动

javascript - React Native 不识别静态变量

javascript - 推送到 React 状态数组

react-native - react-native-device-info 中的 getUniqueID() 可以改变吗?