【发布时间】:2015-11-20 09:58:40
【问题描述】:
我正在尝试使用拉动刷新功能实现无限滚动。
我得到了新数据,通过concat 附加它,它渲染得很好。问题是它用它渲染了整个列表。如果我有超过 500 件物品,那将是一场噩梦。
onRefresh() {
var posts = this.state.posts;
var firstPost = posts[0].m._id;
server.getStream('', firstPost, 4000)
.then(res => {
posts = res.concat(posts);
this.setState({
dataSource: this.ds.cloneWithRows(posts),
posts
});
this.swipeRefreshLayout && this.swipeRefreshLayout.finishRefresh();
})
}
有没有办法告诉 RN 只呈现新行?可能是某种key 道具?
谢谢
更新
DatSource 中的 rowHasChanged 比较器不会触发。我认为我构建组件的方式可能与它有关。
renderRow(post) {
if(post === 'loader') {
return (
<ProgressBarAndroid
styleAttr="Large"
style={styles.spinnerBottom}/>
)
}
let hasLoader = post.m._id === lastPostId;
let loader = hasLoader ?
<ProgressBarAndroid
styleAttr="Large"
style={styles.spinnerBottom}/> : null;
return (
<View>
<Post
post={post}
isLoadingTop={isLoadingTop}/>
{loader}
</View>
)
}
render() {
var stream = <ListView
dataSource={this.state.dataSource}
renderRow={this.renderRow.bind(this)}
onEndReached={this.onEndReached.bind(this)}
onEndReachedThreshold={1}
pageSize={15} />
return (
<View style={styles.mainContainer}>
<View style={styles.header}>
<Text style={styles.headerText}>Header</Text>
</View>
<SwipeRefreshLayoutAndroid
ref={(c) => {
this.swipeRefreshLayout = c;
}}
onRefresh={this.onRefresh.bind(this)}>
{stream}
</SwipeRefreshLayoutAndroid>
</View>
);
有什么想法吗?
【问题讨论】:
标签: react-native