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">icon without text</p>
  24. <div className="loading-example">
  25. <ActivityIndicator animating />
  26. </div>
  27. <WhiteSpace size="xl" />
  28. <p className="sub-title">icon with text</p>
  29. <div className="loading-example">
  30. <ActivityIndicator
  31. text="Loading..."
  32. />
  33. </div>
  34. <WhiteSpace size="xl" />
  35. <p className="sub-title">icon with large size and customized text style</p>
  36. <div className="loading-example">
  37. <div className="align">
  38. <ActivityIndicator size="large" />
  39. <span style={{ marginTop: 8 }}>Loading...</span>
  40. </div>
  41. </div>
  42. </div>
  43. <div className="toast-container">
  44. <WhiteSpace size="xl" />
  45. <Button onClick={this.showToast}>Click to show Toast</Button>
  46. <div className="toast-example">
  47. <ActivityIndicator
  48. toast
  49. text="Loading..."
  50. animating={this.state.animating}
  51. />
  52. </div>
  53. </div>
  54. </WingBlank>
  55. </div>
  56. );
  57. }
  58. }
  59. 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: .28rem;
  12. padding: 30px 0 18px 0;
  13. }

ActivityIndicator活动指示器 - 图1

API

适用平台:WEB、React-Native
  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-
color (RN only)spinner颜色stringgray