[react-native]是否仍然知道flatList的渲染何时完成

时间:2018-10-19 02:50:05

标签: android react-native react-native-flatlist

我有一个flatList视图,我希望它在数据更新后(从服务器获取数据)为scrollToEnd或scrollToIndex,我在comoponentDidUpdate中进行操作,但它不起作用。现在渲染完成后,listView总是滚动到顶部,我看不到最新加载的数据。因此,有一种方法可以在渲染完成后捕获事件。

代码:

...
fetchData(){
    fetch(url)
    .then((res)=>{
        this.setData({data:[...this.state.data, res.data]})
    })
}
componentDidUpdate(){
    this.refs.listView.scrollToEnd({animated:true})
}
render(){
    return <FlatList ref='listView' data={this.state.data} onEndReached={()=>this.fetchData()}.../>
}

0 个答案:

没有答案