这一组件可以用在ScrollView或ListView内部,为其添加下拉刷新的功能。当ScrollView处于竖直方向的起点位置(scrollY: 0),此时下拉会触发一个onRefresh事件。
import React, {Component} from 'react';
import
{
StyleSheet,
Text,
View,
RefreshControl,
ScrollView,
} from 'react-native';
type Props = {};
export default class App extends Component<Props>
{
constructor(props)
{
super(props);
this.state = {isRefreshing: false,};
}
_onRefresh()
{
this.setState({isRefreshing: true});
setTimeout(()=>
{
this.setState({isRefreshing: false});
//加载数据
},2000)
}
render()
{
return
(
<View style={styles.contain}>
<ScrollView
refreshControl={
<RefreshControl
refreshing={this.state.isRefreshing}
onRefresh={this._onRefresh.bind(this)}
tintColor="#ff0000"
title="Loading..."
titleColor="#00ff00"
colors={['#ff0000', '#00ff00', '#0000ff']}
progressBackgroundColor="#ffff00"/>
}>
<Text>显示数据</Text>
</ScrollView>
</View>
);
}
}
const styles = StyleSheet.create(
{
contain: {flex: 1,},
});
参考:Github下载