Shoutem ListView - onLoadMore 不停止加载
Shoutem ListView - onLoadMore does not stop loading
根据 documentation,ListView 的 onLoadMore() 回调只应在 "the ListView is scrolled all the way to the bottom of the first page".
时触发
我确实有以下实现,问题是即使不向下滚动页面,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);
})
}
}
如果您的 ListView 位于 ScrollView 中,请将其移出。在这种情况下,这是 RN 的 onEndReached 回调的一个已知问题。
根据 documentation,ListView 的 onLoadMore() 回调只应在 "the ListView is scrolled all the way to the bottom of the first page".
时触发我确实有以下实现,问题是即使不向下滚动页面,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);
})
}
}
如果您的 ListView 位于 ScrollView 中,请将其移出。在这种情况下,这是 RN 的 onEndReached 回调的一个已知问题。