【发布时间】:2016-04-12 16:49:00
【问题描述】:
事情就是这样。 我想呈现一个在 onEndReached 时更新数据的列表视图。
在更新数据时,我想在列表下方呈现一个“正在加载”文本(不删除列表)。像这样:
render() {
var {isFetching} = this.props.query
var loading
if(isFetching){
loading = this.renderLoading()
}
return (
<ListView
dataSource={this.dataSource}
renderRow={this.renderItem}
onEndReached={this.props.fetchNextPage}
onEndReachedThreshold={10}
style={styles.listView} />
{loading}
)
}
renderLoading () {
return (
<View style={styles.loading}>
<ActivityIndicatorIOS
size='large'/>
<Text>
Loading books...
</Text>
</View>
)
}
但很快我就意识到渲染函数必须返回单个元素。所以我尝试了这个:
return (
<View>
<ListView
dataSource={this.dataSource}
renderRow={this.renderItem}
onEndReached={this.props.fetchNextPage}
onEndReachedThreshold={10}
style={styles.listView}/>
{loading}
</View>
)
但是 onEndReached 在安装后一次又一次地触发。甚至在我触摸屏幕之前。
如何在保持“无限滚动”行为的同时实现加载视图?
【问题讨论】: