根据文档,ListView的onLoadMore()回调只能在“ListView一直滚动到第一页底部”时触发。
我确实有以下实现,问题是,即使没有向下滚动页面,ListView也不会停止调用onLoadMore回调。这不是一个可接受的解决方案,因为当视图打开一段时间时,它只是加载了大量数据,从而导致响应迟钝。
代码如下所示:
<ListView
data={this.state.posts}
renderRow={this.renderRow}
loading={this.state.loading}
onLoadMore={this.onFeedLoadMore}
/>..。
onFeedLoadMore() {
console.log("onFeedLoadMore called");
this.setState({loading: true});
if (_.has(this.state.paging, 'next')) {
fetch(this.state.paging.next, {
method: 'GET',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
}
}).then((response) => response.json()).then((responseJson) => {
this.setState({loading: false});
console.log(responseJson);
this.setState({paging: responseJson.paging});
this.setState({posts: this.state.posts.concat(responseJson.data)})
}).catch((error) => {
this.setState({loading: false});
console.log("error fetching paged fb newsfeed: ", error);
})
}
}发布于 2017-04-22 20:42:37
如果您的ListView在ScrollView中,请将其移出。这是RN在这个场景中的onEndReached回调中的一个已知问题。
https://stackoverflow.com/questions/43564021
复制相似问题