使用RefreshControl实现下拉刷新,这一组件可以用在 ScrollView 或 FlatList 内部,为其添加下拉刷新的功能。
import React from 'react';
import { ScrollView, RefreshControl } from 'react-native'
export default class Component extends React.Component {
state = {
refreshing: false
}
// 在这里刷新页面
onRefresh = () => {
this.setState({ refreshing: true });
this.props.pageFreshen()
.then(() => {
this.setState({ refreshing: false });
});
}
render() {
return (
<ScrollView
refreshControl={
<RefreshControl
// 是否正在刷新
refreshing={this.state.refreshing}
// 刷新函数
onRefresh={this.onRefresh}
/>
}
>
{
this.props.children
}
</ScrollView>
)
}
}