ts-basic-components-progress.md 7.0 KB
Newer Older
Z
zengyawen 已提交
1
# Progress
Z
zengyawen 已提交
2

E
ester.zhou 已提交
3
The **\<Progress>** component is used to provide a progress indicator that displays the progress of content loading or an operation.
Z
zengyawen 已提交
4

5
>  **NOTE**
E
ester.zhou 已提交
6
>
7
>  This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
Z
zengyawen 已提交
8 9 10


## Child Components
Z
zengyawen 已提交
11

E
ester.zhou 已提交
12
Not supported
Z
zengyawen 已提交
13 14


Z
zengyawen 已提交
15 16
## APIs

E
ester.zhou 已提交
17
Progress(options: {value: number, total?: number, type?: ProgressType})
Z
zengyawen 已提交
18

E
ester.zhou 已提交
19
Creates a progress indicator.
Z
zengyawen 已提交
20

E
ester.zhou 已提交
21 22
Since API version 9, this API is supported in ArkTS widgets.

E
ester.zhou 已提交
23
**Parameters**
Z
zengyawen 已提交
24

E
ester.zhou 已提交
25 26
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
27 28 29
| value | number | Yes| Current progress. If the value is less than 0, the value **0** is used. If the value is greater than that of **total**, the value of **total** is used.<br>Since API version 9, this API is supported in ArkTS widgets.|
| total | number | No| Total progress.<br>Default value: **100**<br>Since API version 9, this API is supported in ArkTS widgets.|
| type<sup>8+</sup> | [ProgressType](#progresstype) | No| Style the progress indicator.<br>Default value: **ProgressType.Linear**<br>Since API version 9, this API is supported in ArkTS widgets.|
E
esterzhou 已提交
30
| style<sup>deprecated</sup> | [ProgressStyle](#progressstyle) | No| Type of the progress indicator.<br>This parameter is deprecated since API version 8. You are advised to use **type** instead.<br>Default value: **ProgressStyle.Linear**|
E
ester.zhou 已提交
31 32 33

## ProgressType

E
ester.zhou 已提交
34 35
Since API version 9, this API is supported in ArkTS widgets.

E
ester.zhou 已提交
36 37
| Name| Description|
| -------- | -------- |
E
esterzhou 已提交
38
| Linear | Linear type. Since API version 9, the progress indicator adaptively switches to vertical layout if the height is greater than the width.|
E
ester.zhou 已提交
39 40
| Ring<sup>8+</sup> | Indeterminate ring type. The ring fills up as the progress increases.|
| Eclipse<sup>8+</sup> | Eclipse type, which visualizes the progress in a way similar to the moon waxing from new to full.|
E
esterzhou 已提交
41 42
| ScaleRing<sup>8+</sup> | Determinate ring type, which is similar to the clock scale. Since API version 9, when the outer circles of scales overlap, the progress indicator is automatically converted to the **Ring** type.|
| Capsule<sup>8+</sup> | Capsule type. At both ends, the progress indicator works in a same manner as the eclipse type. In the middle part of the capsule, the progress indicator works in a same manner as the linear type. If the height is greater than the width, the progress indicator adaptively switches to vertical layout.|
E
ester.zhou 已提交
43 44 45

##  ProgressStyle

E
ester.zhou 已提交
46 47
Since API version 9, this API is supported in ArkTS widgets.

E
ester.zhou 已提交
48 49
| Name     | Description                                                        |
| --------- | ------------------------------------------------------------ |
E
esterzhou 已提交
50 51
| Linear    | Linear type.|
| Ring      | Indeterminate ring type. The ring fills up as the progress increases.|
E
ester.zhou 已提交
52
| Eclipse   | Eclipse type, which visualizes the progress in a way similar to the moon waxing from new to full.|
E
esterzhou 已提交
53 54
| ScaleRing | Determinate ring type, which is similar to the clock scale.|
| Capsule   | Capsule type. At both ends, the progress indicator works in a same manner as the eclipse type. In the middle part of the capsule, the progress indicator works in a same manner as the linear type. If the height is greater than the width, the progress indicator adaptively switches to vertical layout.|
Z
zengyawen 已提交
55 56 57

## Attributes

E
ester.zhou 已提交
58 59
| Name| Type| Description|
| -------- | -------- | -------- |
E
ester.zhou 已提交
60 61 62 63
| value | number | Current progress. If the value is less than 0, the value **0** is used. If the value is greater than that of **total**, the value of **total** is used. Invalid values do not take effect.<br>Since API version 9, this API is supported in ArkTS widgets.|
| color | [ResourceColor](ts-types.md#resourcecolor) | Background color of the progress indicator.<br>Since API version 9, this API is supported in ArkTS widgets.|
| backgroundColor | [ResourceColor](ts-types.md#resourcecolor) | Background color of the progress indicator.<br>Since API version 9, this API is supported in ArkTS widgets.|
| style<sup>8+</sup> | {<br>strokeWidth?: [Length](ts-types.md#length),<br>scaleCount?: number,<br>scaleWidth?: [Length](ts-types.md#length)<br>} | Component style.<br>- **strokeWidth**: stroke width of the progress indicator. It cannot be set in percentage. Since API version 9, if the stroke width of the ring progress bar is greater than or equal to the radius, the width is changed to half of the radius.<br>Default value: **4.0Vp**<br>- **scaleCount**: number of divisions on the determinate ring-type process indicator.<br>Default value: **120**<br>- **scaleWidth**: scale width of the ring progress bar. It cannot be set in percentage. If it is greater than the value of **strokeWidth**, the default scale width is used.<br>Default value: **2.0Vp**<br>Since API version 9, this API is supported in ArkTS widgets.|
Z
zengyawen 已提交
64 65 66 67


## Example

E
ester.zhou 已提交
68 69
```ts
// xxx.ets
Z
zengyawen 已提交
70 71 72 73
@Entry
@Component
struct ProgressExample {
  build() {
Z
zengyawen 已提交
74
    Column({ space: 15 }) {
Z
zengyawen 已提交
75
      Text('Linear Progress').fontSize(9).fontColor(0xCCCCCC).width('90%')
E
esterzhou 已提交
76 77
      Progress({ value: 10, type: ProgressType.Linear }).width(200)
      Progress({ value: 20, total: 150, type: ProgressType.Linear }).color(Color.Grey).value(50).width(200)
Z
zengyawen 已提交
78

E
esterzhou 已提交
79

Z
zengyawen 已提交
80 81
      Text('Eclipse Progress').fontSize(9).fontColor(0xCCCCCC).width('90%')
      Row({ space: 40 }) {
E
esterzhou 已提交
82 83
        Progress({ value: 10, type: ProgressType.Eclipse }).width(100)
        Progress({ value: 20, total: 150, type: ProgressType.Eclipse }).color(Color.Grey).value(50).width(100)
Z
zengyawen 已提交
84 85 86 87
      }

      Text('ScaleRing Progress').fontSize(9).fontColor(0xCCCCCC).width('90%')
      Row({ space: 40 }) {
E
esterzhou 已提交
88 89
        Progress({ value: 10, type: ProgressType.ScaleRing }).width(100)
        Progress({ value: 20, total: 150, type: ProgressType.ScaleRing })
Z
zengyawen 已提交
90 91 92 93
          .color(Color.Grey).value(50).width(100)
          .style({ strokeWidth: 15, scaleCount: 15, scaleWidth: 5 })
      }

E
esterzhou 已提交
94 95 96 97 98 99 100 101 102 103
      // scaleCount vs. scaleWidth
      Row({ space: 40 }) {
        Progress({ value: 20, total: 150, type: ProgressType.ScaleRing })
          .color(Color.Grey).value(50).width(100)
          .style({ strokeWidth: 20, scaleCount: 20, scaleWidth: 5 })
        Progress({ value: 20, total: 150, type: ProgressType.ScaleRing })
          .color(Color.Grey).value(50).width(100)
          .style({ strokeWidth: 20, scaleCount: 30, scaleWidth: 3 })
      }

Z
zengyawen 已提交
104 105
      Text('Ring Progress').fontSize(9).fontColor(0xCCCCCC).width('90%')
      Row({ space: 40 }) {
E
esterzhou 已提交
106 107
        Progress({ value: 10, type: ProgressType.Ring }).width(100)
        Progress({ value: 20, total: 150, type: ProgressType.Ring })
Z
zengyawen 已提交
108 109 110 111 112 113
          .color(Color.Grey).value(50).width(100)
          .style({ strokeWidth: 20, scaleCount: 30, scaleWidth: 20 })
      }

      Text('Capsule Progress').fontSize(9).fontColor(0xCCCCCC).width('90%')
      Row({ space: 40 }) {
E
ester.zhou 已提交
114
        Progress({ value: 10, type: ProgressType.Capsule }).width(100).height(50)
E
ester.zhou 已提交
115 116 117 118 119
        Progress({ value: 20, total: 150, type: ProgressType.Capsule })
          .color(Color.Grey)
          .value(50)
          .width(100)
          .height(50)
Z
zengyawen 已提交
120 121
      }
    }.width('100%').margin({ top: 30 })
Z
zengyawen 已提交
122 123 124 125
  }
}
```

E
esterzhou 已提交
126
![progress](figures/progress.png)