2017-04-22 73 views
0

根據documentation ListView的onLoadMore()回調應該只觸發,當「ListView滾動到第一頁的底部」。Shoutem ListView - onLoadMore不停止加載

我確實有下面的實現,問題是即使沒有向下滾動頁面,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); 
     }) 
     } 
} 

回答

1

如果你有一個滾動型內你的ListView,將其移出。在這種情況下,這是RN的onEndReached回調的已知問題。

+0

這解決了我的問題。我有一個ScrollView內的ListView –