RefreshControl 下拉刷新
通过触发,立刻重新加载内容。规则
一般多运用在 List 和 ListView 中。
可考虑定期自动刷新,eg:登录 app 后,自动刷新首页 List。
代码演示
下拉刷新
import { RefreshControl, List } from 'antd-mobile';
let count = 1;
const App = React.createClass({
getInitialState() {
return {
items: null,
};
},
loadingFunction() {
return new Promise((resolve, reject) => {
setTimeout(() => {
if (this.addItem()) {
resolve();
} else {
reject();
}
}, 500);
});
},
addItem() {
const newItems = this.state.items ? [...this.state.items] : [];
newItems.unshift(
<List.Item key={`item-${count}`} extra="horizontal,箭头向右" arrow="horizontal">标题文字 {count++}</List.Item>
);
this.setState({
items: newItems,
});
return true;
},
render() {
return (
<RefreshControl
loadingFunction={this.loadingFunction}
resistance={1}
className="am-refresh-control-demo1"
style={{
textAlign: 'center',
}}
>
<List title="下拉刷新">
<List.Body>
{this.state.items}
<List.Item extra="horizontal,箭头向右" arrow="horizontal">标题文字</List.Item>
<List.Item extra="down,箭头向下" arrow="down">标题文字</List.Item>
<List.Item extra="up,箭头向上" arrow="up">标题文字</List.Item>
</List.Body>
</List>
</RefreshControl>
);
},
});
ReactDOM.render(<App />, mountNode);
.demo {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient:vertical;
-webkit-box-direction:normal;
-ms-flex-direction:column;
flex-direction:column;
}
.demo-preview-item {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient:vertical;
-webkit-box-direction:normal;
-ms-flex-direction:column;
flex-direction:column;
-webkit-box-flex: 1;
-ms-flex: 1;
flex: 1;
}
.am-refresh-control-demo1 {
-webkit-box-flex:1;
-ms-flex:1;
flex:1;
}
API (web)
成员 | 说明 | 类型 | 默认值 |
---|---|---|---|
children | 内容 | any | 无 |
className | 容器className | String | - |
style | 容器style | object | - |
icon | 刷新指示icon | React element | … |
loading | 加载指示器 | React element | anticon-loading |
distanceToRefresh | 刷新距离 | number | 50 |
loadingFunction | 刷新回调函数 | function, required | - |