1# LoadingProgress
2
3用于显示加载动效的组件。
4
5加载动效在组件不可见时停止,组件的可见状态基于[onVisibleAreaChange](./ts-universal-component-visible-area-change-event.md#onvisibleareachange)处理,可见阈值ratios大于0即视为可见状态。
6
7>  **说明:**
8>
9> 该组件从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
10
11
12## 子组件
13
1415
16
17## 接口
18
19LoadingProgress()
20
21创建加载进展组件。
22
23**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。
24
25**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
26
27**系统能力:** SystemCapability.ArkUI.ArkUI.Full
28
29## 属性
30
31除支持[通用属性](ts-universal-attributes-size.md)外,还支持以下属性:
32
33### color
34
35color(value: ResourceColor)
36
37设置加载进度条前景色。
38
39**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。
40
41**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
42
43**系统能力:** SystemCapability.ArkUI.ArkUI.Full
44
45**参数:** 
46
47| 参数名 | 类型                                       | 必填 | 说明                                                         |
48| ------ | ------------------------------------------ | ---- | ------------------------------------------------------------ |
49| value  | [ResourceColor](ts-types.md#resourcecolor) | 是   | 加载进度条的前景色。<br/>默认值:<br/>API version 10及以下:'#99666666'<br/>API version 11及以上:'#ff666666' |
50
51### enableLoading<sup>10+</sup>
52
53enableLoading(value: boolean)
54
55设置LoadingProgress动画显示或者不显示。LoadingProgress动画不显示时,该组件依旧占位。通用属性[Visibility.Hidden](ts-universal-attributes-visibility.md#visibility)隐藏的是包括[border](ts-universal-attributes-border.md#border)、[padding](ts-universal-attributes-size.md#padding)等整个组件范围,而enableLoading=false只隐藏LoadingProgress本身动画内容,不包括border等。
56
57
58**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
59
60**系统能力:** SystemCapability.ArkUI.ArkUI.Full
61
62**参数:** 
63
64| 参数名 | 类型    | 必填 | 说明                                           |
65| ------ | ------- | ---- | ---------------------------------------------- |
66| value  | boolean | 是   | LoadingProgress动画是否显示。<br/>默认值:true |
67
68### contentModifier<sup>12+</sup>
69
70contentModifier(modifier: ContentModifier\<LoadingProgressConfiguration>)
71
72定制LoadingProgress内容区的方法。
73
74**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
75
76**系统能力:** SystemCapability.ArkUI.ArkUI.Full
77
78**参数:**
79
80| 参数名 | 类型                                          | 必填 | 说明                                             |
81| ------ | --------------------------------------------- | ---- | ------------------------------------------------ |
82| modifier  | [ContentModifier\<LoadingProgressConfiguration>](#loadingprogressconfiguration12对象说明) | 是   | 在LoadingProgress组件上,定制内容区的方法。<br/>modifier: 内容修改器,开发者需要自定义class实现ContentModifier接口。 |
83
84## 事件
85
86支持[通用事件](ts-universal-events-click.md)。
87
88## LoadingProgressConfiguration<sup>12+</sup>对象说明
89
90开发者需要自定义class实现ContentModifier接口。
91
92**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
93
94**系统能力:** SystemCapability.ArkUI.ArkUI.Full
95
96| 名称  | 类型    |    只读    |    可选    |  说明              |
97| ------ | ------ | ------ |-------------------------------- |-------------------------------- |
98| enableloading | boolean | 否 | 否 |LoadingProgress动画是否显示。<br/>默认值:true |
99
100## 示例
101
102### 示例1
103
104```ts
105// xxx.ets
106@Entry
107@Component
108struct LoadingProgressExample {
109  build() {
110    Column({ space: 5 }) {
111      Text('Orbital LoadingProgress ').fontSize(9).fontColor(0xCCCCCC).width('90%')
112      LoadingProgress()
113        .color(Color.Blue)
114        .layoutWeight(1)
115    }.width('100%').margin({ top: 5 })
116  }
117}
118```
119
120![LoadingProgress](figures/LoadingProgress.gif)
121
122### 示例2
123
124```ts
125//该示例实现了自定义LoadingProgress的功能,实现了通过按钮切换是否显示LoadingProgress。点击按钮,config.enableLoading切换为false, 不显示LoadingProgress。
126// xxx.ets
127import { hilog } from '@kit.PerformanceAnalysisKit'
128import { promptAction } from '@kit.ArkUI'
129
130class MyLoadingProgressStyle implements ContentModifier<LoadingProgressConfiguration> {
131  enableLoading: boolean = false
132
133  constructor(enableLoading: boolean) {
134    this.enableLoading = enableLoading
135  }
136
137  applyContent(): WrappedBuilder<[LoadingProgressConfiguration]> {
138    return wrapBuilder(buildLoadingProgress)
139  }
140}
141
142let arr1: string[] = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"]
143let arr2: string[] = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
144
145@Builder
146function buildLoadingProgress(config: LoadingProgressConfiguration) {
147  Column({ space: 8 }) {
148    Row() {
149      Column() {
150        Circle({
151          width: ((config.contentModifier as MyLoadingProgressStyle).enableLoading) ? 100 : 80,
152          height: ((config.contentModifier as MyLoadingProgressStyle).enableLoading) ? 100 : 80
153        })
154          .fill(((config.contentModifier as MyLoadingProgressStyle).enableLoading) ? Color.Grey : 0x2577e3)
155      }.width('50%')
156
157      Column() {
158        Button('' + ((config.contentModifier as MyLoadingProgressStyle).enableLoading))
159          .onClick((event: ClickEvent) => {
160            promptAction.showToast({
161              message: ((config.contentModifier as MyLoadingProgressStyle).enableLoading) + ''
162            })
163          })
164          .fontColor(Color.White)
165          .backgroundColor(((config.contentModifier as MyLoadingProgressStyle).enableLoading) ? Color.Grey : 0x2577e3)
166      }.width('50%')
167
168    }
169
170    Row() {
171      Column() {
172        Gauge({
173          value: (config.contentModifier as MyLoadingProgressStyle).enableLoading?50:30, min: 11, max: 100
174        }) {
175          Column() {
176            Text('60')
177              .maxFontSize("180sp")
178              .minFontSize("160.0vp")
179              .fontWeight(FontWeight.Medium)
180              .fontColor("#ff182431")
181              .width('40%')
182              .height('30%')
183              .textAlign(TextAlign.Center)
184              .margin({ top: '22.2%' })
185              .textOverflow({ overflow: TextOverflow.Ellipsis })
186              .maxLines(1)
187          }.width('100%').height('100%')
188        }
189
190        .colors(((config.contentModifier as MyLoadingProgressStyle).enableLoading) ? Color.Grey : 0x2577e3)
191        .width(200)
192        .strokeWidth(18)
193        .padding(5)
194        .trackShadow({ radius: 7, offsetX: 7, offsetY: 7 })
195        .height(200)
196      }.width('100%')
197
198    }
199
200    Column() {
201      List({ space: 20, initialIndex: 0 }) {
202        ForEach(arr2, (item: string) => {
203          ListItem() {
204            Text((config.contentModifier as MyLoadingProgressStyle).enableLoading ? '' + item : Number(item) * 2 + '')
205              .width('100%')
206              .height('100%')
207              .fontColor((config.contentModifier as MyLoadingProgressStyle).enableLoading ? Color.White : Color.Orange)
208              .fontSize((config.contentModifier as MyLoadingProgressStyle).enableLoading ? 16 : 20)
209              .textAlign(TextAlign.Center)
210              .backgroundColor((config.contentModifier as MyLoadingProgressStyle).enableLoading ? Color.Grey : 0x2577e3)
211          }
212          .height(110)
213          .border({
214            width: 2,
215            color: Color.White
216          })
217        }, (item: string) => item)
218      }
219      .height(200)
220      .width('100%')
221      .friction(0.6)
222
223      .lanes({ minLength: (config.contentModifier as MyLoadingProgressStyle).enableLoading?40:80, maxLength: (config.contentModifier as MyLoadingProgressStyle).enableLoading?40:80 })
224      .scrollBar(BarState.Off)
225    }
226
227  }.width("100%").padding(10)
228}
229
230
231@Entry
232@Component
233struct LoadingProgressDemoExample {
234  @State loadingProgressList: (boolean | undefined | null)[] = [undefined, true, null, false]
235  @State widthList: (number | string)[] = ['110%', 220, '40%', 80]
236  @State loadingProgressIndex: number = 0
237  @State clickFlag: number = 0
238  scroller: Scroller = new Scroller()
239
240  build() {
241    Column() {
242      Scroll(this.scroller) {
243        Column({ space: 5 }) {
244          Column() {
245            LoadingProgress()
246              .color('#106836')
247              .size({ width: '100%' })
248              .contentModifier(new MyLoadingProgressStyle(this.loadingProgressList[this.loadingProgressIndex]))
249          }.width('100%').backgroundColor(0xdcdcdc)
250        }.width('100%').margin({ top: 5 })
251      }.height('85%')
252
253      Button('点击切换config.enableloading').onClick(() => {
254        this.clickFlag++
255        this.loadingProgressIndex = (this.loadingProgressIndex + 1) % this.loadingProgressList.length
256        console.log('enableLoading:' + this.loadingProgressList[this.loadingProgressIndex])
257      }).margin(20)
258    }
259
260  }
261}
262```
263![LoadingProgress_builder](figures/LoadingProgress_builder.gif)