【问题标题】:Shoutem ListView - onLoadMore does not stop loadingShoutem ListView - onLoadMore 不会停止加载
【发布时间】:2017-04-23 04:42:37
【问题描述】:

根据documentation,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);
        })
      }
}

【问题讨论】:

    标签: react-native shoutem


    【解决方案1】:

    如果您的 ListView 位于 ScrollView 中,请将其移出。在这种情况下,这是 RN 的 onEndReached 回调的一个已知问题。

    【讨论】:

    • 这解决了我的问题。我在 ScrollView 中有 ListView
    猜你喜欢
    • 2023-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多