OGeek|极客世界-中国程序员成长平台

标题: ios - React Native ListView 回收 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 15:55
标题: ios - React Native ListView 回收

我正在使用 React Native 并试图使用用户可以滚动浏览的 ListView 组件创建一长串卡片(非常类似于 Facebook 当前的应用程序)。我注意到的是,当我创建大量卡片时,应用程序的内存占用量随着它们的滚动而继续增长。除非我滚动,否则它不会增长。

我对此的解释是 ListView 仅在 View 变得可见之前呈现 View ,这正是它应该做的。然而,我没有看到的是,一旦 View 从屏幕上滚出不可见,它就会释放 View 。是否需要设置一些属性才能启用此功能?如何在 React Native 中管理长列表的内存?



Best Answer-推荐答案


ListView 保留它的所有行组件,因为它们可能是有状态的(即具有 this.state),但您可以使用 removeClippedSubviews< 告诉它释放底层原生 View Prop :

This is a special performance property exposed by RCTView and is useful for scrolling content when there are many subviews, most of which are offscreen. For this property to be effective, it must be applied to a view that contains many subviews that extend outside its bound. The subviews must also have overflow: hidden, as should the containing view (or one of its superviews).

https://facebook.github.io/react-native/docs/view.html#removeclippedsubviews .

关于ios - React Native ListView 回收,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31666961/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4