React Native ListView不会重新呈现大数据

编程入门 行业动态 更新时间:2024-10-13 20:20:40
本文介绍了React Native ListView不会重新呈现大数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如果列表具有较大的数据源,则在调用this.setState之后,React Native ListView将不会重新渲染其行,即如果我的行数很少(1到9),则一切正常,但是如果我添加更多的数据,则re -渲染不会发生.

React Native ListView won't re-render its rows after calling this.setState if list has large data source i.e. everything works correctly if I have few rows (1 to 9), but if I add more data, then the re-rendering won't happen.

关于此主题也有类似的帖子,但是我找不到能解决此问题的任何帖子.

There are similar posts about this topic, but I didn't find any that tackled exactly this problem.

这是一些简化的示例代码:

Here is some simplified sample code:

render() { return ( <View style={Styles.listContainer}> <ListView dataSource={this.state.triggerDataSource} enableEmptySections={true} renderRow={(data) => this._renderListRow(data)} renderHeader={() => this._renderListHeader()}/> </View> ); } ... _renderListRow(data) { return ( <View style={Styles.listRow}> {this._renderX(data)} <View style={Styles.listItem}> <Text style={Styles.listLabel}>{data.symbol}</Text> </View> </View> ); } ... _renderX(data) { if (this.state.isShowing) { return ( <Button> Some button </Button> ); } else { return null; } }

如果ListView数据源相对较小,则调用this.setState({isShowing: true});将触发重新渲染,并且每行现在都将包含Button,但是当我添加更多数据时,更改状态不会执行任何操作.

If the ListView datasource is relatively small, then calling this.setState({isShowing: true}); will trigger re-render and each of the rows will now contain the Button, but when I add more data, then changing state does nothing.

我的解决方案部分有效(例如,用于较小的数据大小)-我想知道如果数据大小增加,ListView功能为何以及如何更改.建议的答案不能完全回答这个问题.如果行数达到10,我的代码将停止工作.如果低于10,则一切正常.

My solution is partially working (i.e. for small data size) - I would like to know why and how the ListView functionality changes if the data size increases. Suggested answers don't answer exactly this question. My code stops working if the row count reaches 10. If it's below then everything works just fine.

推荐答案

使用以下方法找到解决方案:

Find the way to solve it with this:

ReactNative ListView组件使用initialListSize属性计算在初始组件安装时要呈现的行数.默认情况下,initialListSize设置为10.

ReactNative ListView component calculates how many rows to render on initial component mount using initialListSize property. By default the initialListSize is set to 10.

作为参考,请参见ReactNative ListView源代码中的以下函数,

For reference, See the below function from ReactNative ListView source code,

var DEFAULT_INITIAL_ROWS = 10; getDefaultProps: function() { return { initialListSize: DEFAULT_INITIAL_ROWS, pageSize: DEFAULT_PAGE_SIZE, renderScrollComponent: props => <ScrollView {...props} />, scrollRenderAheadDistance: DEFAULT_SCROLL_RENDER_AHEAD, onEndReachedThreshold: DEFAULT_END_REACHED_THRESHOLD, stickyHeaderIndices: [], }; }

更多推荐

React Native ListView不会重新呈现大数据

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

发布评论

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

>www.elefans.com

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