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