ActivityIndicator 活动指示器

活动指示器。表明某个任务正在进行中。

规则

  • 不要让活动指示器静止,用户会以为该任务停滞了。

  • 在某些特定场景下,提供有意义的文案,帮助用户明白哪个任务正在进行中,eg:正在上传照片。

  • 如果能知道用户的等待时间,可以使用组件 Progress 来替代。

代码演示

基本

Basic usage

  1. import { ActivityIndicator, WingBlank, WhiteSpace, Button } from 'antd-mobile';
  2. class App extends React.Component {
  3. constructor(props) {
  4. super(props);
  5. this.state = {
  6. animating: false,
  7. };
  8. }
  9. componentWillUnmount() {
  10. clearTimeout(this.closeTimer);
  11. }
  12. showToast = () => {
  13. this.setState({ animating: !this.state.animating });
  14. this.closeTimer = setTimeout(() => {
  15. this.setState({ animating: !this.state.animating });
  16. }, 1000);
  17. }
  18. render() {
  19. return (
  20. <div>
  21. <WingBlank>
  22. <div className="loading-container">
  23. <p className="sub-title">Without text</p>
  24. <div className="loading-example">
  25. <ActivityIndicator animating />
  26. </div>
  27. <p className="sub-title">With text</p>
  28. <div className="loading-example">
  29. <ActivityIndicator
  30. text="Loading..."
  31. />
  32. </div>
  33. <p className="sub-title">With large size and customized text style</p>
  34. <div className="loading-example">
  35. <div className="align">
  36. <ActivityIndicator size="large" />
  37. <span style={{ marginTop: 8 }}>Loading...</span>
  38. </div>
  39. </div>
  40. </div>
  41. <div className="toast-container">
  42. <WhiteSpace size="xl" />
  43. <Button onClick={this.showToast}>click to show Toast</Button>
  44. <div className="toast-example">
  45. <ActivityIndicator
  46. toast
  47. text="Loading..."
  48. animating={this.state.animating}
  49. />
  50. </div>
  51. </div>
  52. </WingBlank>
  53. </div>
  54. );
  55. }
  56. }
  57. ReactDOM.render(<App />, mountNode);
  1. .loading-example {
  2. display: flex;
  3. justify-content: flex-start;
  4. }
  5. .align {
  6. display: flex;
  7. flex-direction: column;
  8. }
  9. .sub-title {
  10. color: #888;
  11. font-size: 14px;
  12. padding: 30px 0 18px 0;
  13. }

ActivityIndicator活动指示器 - 图1

API

  1. <ActivityIndicator />
  2. <ActivityIndicator color="white" />
  3. <ActivityIndicator size="large" />
  4. <ActivityIndicator text="正在加载" />
  5. <ActivityIndicator toast />
  6. <ActivityIndicator toast text="正在加载" />

ActivityIndicator

属性说明类型默认值
animating显隐状态booleantrue
sizespinner大小,可选small/largestringsmall
toastloading样式类型booleanfalse
textloading文本string-