要在ListView上实现无限滚动,您可以使用ListView组件中的onEndReached和renderFooter.它看起来像这样(你只需触发onEndReached时的renderFooter)
onEndReached() { if (!this.state.waiting) { this.setState({waiting: true}); this.fetchData() // fetching new data,ended with this.setState({waiting: false}); } } renderFooter() { if (this.state.waiting) { return <ActivityIndicator />; } else { return <Text>~</Text>; } } render() { return ( <ListView dataSource={this.state.dataSource} renderRow={this.renderRow} renderFooter={this.renderFooter} onEndReached={this.onEndReached} />); }
另一种方法是使用一些库:
> https://github.com/exponentjs/react-native-infinite-scroll-view
> https://github.com/FaridSafi/react-native-gifted-listview
我尝试使用remobile,但它已被弃用(而且太复杂了,你必须实现大约4-5方法来满足这个组件).我使用了FaridSafi,没关系,但刷新是点击,而不是拉.