RefreshControl 下拉刷新

定义/Definition

用于需要下拉刷新的场景

规则 / Rule

用于需要下拉刷新的场景

代码演示

基本

下拉刷新

  1. import { RefreshControl } from 'antd-mobile';
  2. let count = 1;
  3. const App = React.createClass({
  4. getInitialState() {
  5. return {
  6. items: [
  7. <div key={`item-${count}`} style={{ height: 70 }}>条目 {count++}</div>,
  8. ],
  9. };
  10. },
  11. loadingFunction() {
  12. return new Promise((resolve, reject) => {
  13. setTimeout(() => {
  14. if (this.addItem()) {
  15. resolve();
  16. } else {
  17. reject();
  18. }
  19. }, 500);
  20. });
  21. },
  22. addItem() {
  23. this.state.items.push(<div key={`item-${count}`} style={{ height: 70 }}>条目 {count++}</div>);
  24. this.setState({
  25. items: this.state.items,
  26. });
  27. return true;
  28. },
  29. render() {
  30. return (
  31. <RefreshControl
  32. loadingFunction={this.loadingFunction}
  33. distanceToRefresh={60}
  34. resistance={1}
  35. style={{
  36. position: 'relative',
  37. paddingTop: 20,
  38. textAlign: 'center',
  39. }}
  40. hammerOptions={{
  41. touchAction: 'auto',
  42. recognizers: {
  43. pan: {
  44. threshold: 10,
  45. },
  46. },
  47. }}
  48. >
  49. <h3>下拉刷新</h3>
  50. <div style={{ minHeight: 300 }}>
  51. {this.state.items}
  52. </div>
  53. </RefreshControl>
  54. );
  55. },
  56. });
  57. ReactDOM.render(<App />, mountNode);

RefreshControl下拉刷新 - 图1

API (web)

成员说明类型默认值
children内容any
contentClassName内容容器classNameString-
contentStyle内容容器styleobject-
icon刷新指示iconReact element
loading加载指示器React elementanticon-loading
distanceToRefresh刷新距离number70
resistance阻力系数number2.5
loadingFunction刷新回调函数function, required-
hammerOptions参考 react-hammerjs ,用于配置 Hammer manager,将被合并到默认配置中object-

API (ios/android)

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