RefreshControl 下拉刷新

通过触发,立刻重新加载内容。

规则

  • 一般多运用在 List 和 ListView 中。

  • 可考虑定期自动刷新,eg:登录 app 后,自动刷新首页 List。

代码演示

基本

下拉刷新

  1. import { RefreshControl, List } from 'antd-mobile';
  2. let count = 1;
  3. const App = React.createClass({
  4. getInitialState() {
  5. return {
  6. items: null,
  7. };
  8. },
  9. loadingFunction() {
  10. return new Promise((resolve, reject) => {
  11. setTimeout(() => {
  12. if (this.addItem()) {
  13. resolve();
  14. } else {
  15. reject();
  16. }
  17. }, 500);
  18. });
  19. },
  20. addItem() {
  21. const newItems = this.state.items ? [...this.state.items] : [];
  22. newItems.unshift(
  23. <List.Item key={`item-${count}`} extra="horizontal,箭头向右" arrow="horizontal">标题文字 {count++}</List.Item>
  24. );
  25. this.setState({
  26. items: newItems,
  27. });
  28. return true;
  29. },
  30. render() {
  31. return (
  32. <RefreshControl
  33. loadingFunction={this.loadingFunction}
  34. resistance={1}
  35. className="am-refresh-control-demo1"
  36. style={{
  37. textAlign: 'center',
  38. }}
  39. >
  40. <List title="下拉刷新">
  41. <List.Body>
  42. {this.state.items}
  43. <List.Item extra="horizontal,箭头向右" arrow="horizontal">标题文字</List.Item>
  44. <List.Item extra="down,箭头向下" arrow="down">标题文字</List.Item>
  45. <List.Item extra="up,箭头向上" arrow="up">标题文字</List.Item>
  46. </List.Body>
  47. </List>
  48. </RefreshControl>
  49. );
  50. },
  51. });
  52. ReactDOM.render(<App />, mountNode);
  1. .demo {
  2. display: -webkit-box;
  3. display: -ms-flexbox;
  4. display: flex;
  5. -webkit-box-orient:vertical;
  6. -webkit-box-direction:normal;
  7. -ms-flex-direction:column;
  8. flex-direction:column;
  9. }
  10. .demo-preview-item {
  11. display: -webkit-box;
  12. display: -ms-flexbox;
  13. display: flex;
  14. -webkit-box-orient:vertical;
  15. -webkit-box-direction:normal;
  16. -ms-flex-direction:column;
  17. flex-direction:column;
  18. -webkit-box-flex: 1;
  19. -ms-flex: 1;
  20. flex: 1;
  21. }
  22. .am-refresh-control-demo1 {
  23. -webkit-box-flex:1;
  24. -ms-flex:1;
  25. flex:1;
  26. }

RefreshControl下拉刷新 - 图1

API (web)

成员说明类型默认值
children内容any
className容器classNameString-
style容器styleobject-
icon刷新指示iconReact element
loading加载指示器React elementanticon-loading
distanceToRefresh刷新距离number50
loadingFunction刷新回调函数function, required-

API (ios/android)

见此:https://facebook.github.io/react-native/docs/refreshcontrol.html#props