1e41f4b71Sopenharmony_ci# LoadingProgress 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe **\<LoadingProgress>** component is used to create a loading animation. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **NOTE** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> This component is supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version. 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci## Child Components 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ciNot supported 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci## APIs 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ciLoadingProgress() 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ciCreates a **\<LoadingProgress>** component. 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9. 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci## Attributes 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ciIn addition to the [universal attributes](ts-universal-attributes-size.md), the following attributes are supported. 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ci### color 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_cicolor(value: ResourceColor) 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ciSets the foreground color for the **\<LoadingProgress>** component. 34e41f4b71Sopenharmony_ci 35e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9. 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci**Parameters** 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 44e41f4b71Sopenharmony_ci| ------ | ------------------------------------------ | ---- | ------------------------------------------------------------ | 45e41f4b71Sopenharmony_ci| value | [ResourceColor](ts-types.md#resourcecolor) | Yes | Foreground color of the **\<LoadingProgress>** component.<br>Default value:<br>API version 10 or earlier: **'#99666666'**<br>API version 11 or later: **'#ff666666'** | 46e41f4b71Sopenharmony_ci 47e41f4b71Sopenharmony_ci### enableLoading<sup>10+</sup> 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_cienableLoading(value: boolean) 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ciSets whether to show the loading animation. The component still takes up space in the layout when the loading animation is not shown. The universal attribute [Visibility.Hidden](ts-universal-attributes-visibility.md#visibility) hides the entire component area, including the borders and paddings. In contrast, **enableLoading=false** only hides the loading animation itself and does not affect the borders or other elements. 52e41f4b71Sopenharmony_ci 53e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9. 54e41f4b71Sopenharmony_ci 55e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 56e41f4b71Sopenharmony_ci 57e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 58e41f4b71Sopenharmony_ci 59e41f4b71Sopenharmony_ci**Parameters** 60e41f4b71Sopenharmony_ci 61e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 62e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ---------------------------------------------- | 63e41f4b71Sopenharmony_ci| value | boolean | Yes | Whether to show the loading animation.<br>Default value: **true** | 64e41f4b71Sopenharmony_ci 65e41f4b71Sopenharmony_ci### contentModifier<sup>12+</sup> 66e41f4b71Sopenharmony_ci 67e41f4b71Sopenharmony_cicontentModifier(modifier: ContentModifier\<LoadingProgressConfiguration>) 68e41f4b71Sopenharmony_ci 69e41f4b71Sopenharmony_ciCreates a content modifier. 70e41f4b71Sopenharmony_ci 71e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 72e41f4b71Sopenharmony_ci 73e41f4b71Sopenharmony_ci**Parameters** 74e41f4b71Sopenharmony_ci 75e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 76e41f4b71Sopenharmony_ci| ------ | --------------------------------------------- | ---- | ------------------------------------------------ | 77e41f4b71Sopenharmony_ci| modifier | [ContentModifier\<LoadingProgressConfiguration>](#loadingprogressconfiguration12) | Yes | Content modifier to apply to the current component.<br>**modifier**: content modifier. You need a custom class to implement the **ContentModifier** API. | 78e41f4b71Sopenharmony_ci 79e41f4b71Sopenharmony_ci## Events 80e41f4b71Sopenharmony_ci 81e41f4b71Sopenharmony_ciThe [universal events](ts-universal-events-click.md) are supported. 82e41f4b71Sopenharmony_ci 83e41f4b71Sopenharmony_ci## LoadingProgressConfiguration<sup>12+</sup> 84e41f4b71Sopenharmony_ci 85e41f4b71Sopenharmony_ciYou need a custom class to implement the **ContentModifier** API. 86e41f4b71Sopenharmony_ci 87e41f4b71Sopenharmony_ci| Name | Type | Default Value | Description | 88e41f4b71Sopenharmony_ci| ------ | ------ | ------ |-------------------------------- | 89e41f4b71Sopenharmony_ci| enableloading | boolean | true |Whether to show the loading animation.<br>Default value: **true** | 90e41f4b71Sopenharmony_ci 91e41f4b71Sopenharmony_ci## Example 92e41f4b71Sopenharmony_ci 93e41f4b71Sopenharmony_ci### Example 1 94e41f4b71Sopenharmony_ci 95e41f4b71Sopenharmony_ci```ts 96e41f4b71Sopenharmony_ci// xxx.ets 97e41f4b71Sopenharmony_ci@Entry 98e41f4b71Sopenharmony_ci@Component 99e41f4b71Sopenharmony_cistruct LoadingProgressExample { 100e41f4b71Sopenharmony_ci build() { 101e41f4b71Sopenharmony_ci Column({ space: 5 }) { 102e41f4b71Sopenharmony_ci Text('Orbital LoadingProgress ').fontSize(9).fontColor(0xCCCCCC).width('90%') 103e41f4b71Sopenharmony_ci LoadingProgress() 104e41f4b71Sopenharmony_ci .color(Color.Blue) 105e41f4b71Sopenharmony_ci .layoutWeight(1) 106e41f4b71Sopenharmony_ci }.width('100%').margin({ top: 5 }) 107e41f4b71Sopenharmony_ci } 108e41f4b71Sopenharmony_ci} 109e41f4b71Sopenharmony_ci``` 110e41f4b71Sopenharmony_ci 111e41f4b71Sopenharmony_ci 112e41f4b71Sopenharmony_ci 113e41f4b71Sopenharmony_ci### Example 2 114e41f4b71Sopenharmony_ci 115e41f4b71Sopenharmony_ci```ts 116e41f4b71Sopenharmony_ci// This example implements a custom <LoadingProgress> component, enabling the component's visibility to be switched through a button. When the button is clicked, config.enableLoading is switched to false, and the component is not displayed. 117e41f4b71Sopenharmony_ci// xxx.ets 118e41f4b71Sopenharmony_ciimport { hilog } from '@kit.PerformanceAnalysisKit' 119e41f4b71Sopenharmony_ciimport { promptAction } from '@kit.ArkUI' 120e41f4b71Sopenharmony_ci 121e41f4b71Sopenharmony_ciclass MyLoadingProgressStyle implements ContentModifier<LoadingProgressConfiguration> { 122e41f4b71Sopenharmony_ci enableLoading: boolean = false 123e41f4b71Sopenharmony_ci 124e41f4b71Sopenharmony_ci constructor(enableLoading: boolean) { 125e41f4b71Sopenharmony_ci this.enableLoading = enableLoading 126e41f4b71Sopenharmony_ci } 127e41f4b71Sopenharmony_ci 128e41f4b71Sopenharmony_ci applyContent(): WrappedBuilder<[LoadingProgressConfiguration]> { 129e41f4b71Sopenharmony_ci return wrapBuilder(buildLoadingProgress) 130e41f4b71Sopenharmony_ci } 131e41f4b71Sopenharmony_ci} 132e41f4b71Sopenharmony_ci 133e41f4b71Sopenharmony_cilet arr1: string[] = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"] 134e41f4b71Sopenharmony_cilet arr2: string[] = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"] 135e41f4b71Sopenharmony_ci 136e41f4b71Sopenharmony_ci@Builder 137e41f4b71Sopenharmony_cifunction buildLoadingProgress(config: LoadingProgressConfiguration) { 138e41f4b71Sopenharmony_ci Column({ space: 8 }) { 139e41f4b71Sopenharmony_ci Row() { 140e41f4b71Sopenharmony_ci Column() { 141e41f4b71Sopenharmony_ci Circle({ 142e41f4b71Sopenharmony_ci width: ((config.contentModifier as MyLoadingProgressStyle).enableLoading) ? 100 : 80, 143e41f4b71Sopenharmony_ci height: ((config.contentModifier as MyLoadingProgressStyle).enableLoading) ? 100 : 80 144e41f4b71Sopenharmony_ci }) 145e41f4b71Sopenharmony_ci .fill(((config.contentModifier as MyLoadingProgressStyle).enableLoading) ? Color.Grey : 0x2577e3) 146e41f4b71Sopenharmony_ci }.width('50%') 147e41f4b71Sopenharmony_ci 148e41f4b71Sopenharmony_ci Column() { 149e41f4b71Sopenharmony_ci Button('' + ((config.contentModifier as MyLoadingProgressStyle).enableLoading)) 150e41f4b71Sopenharmony_ci .onClick((event: ClickEvent) => { 151e41f4b71Sopenharmony_ci promptAction.showToast({ 152e41f4b71Sopenharmony_ci message: ((config.contentModifier as MyLoadingProgressStyle).enableLoading) + '' 153e41f4b71Sopenharmony_ci }) 154e41f4b71Sopenharmony_ci }) 155e41f4b71Sopenharmony_ci .fontColor(Color.White) 156e41f4b71Sopenharmony_ci .backgroundColor(((config.contentModifier as MyLoadingProgressStyle).enableLoading) ? Color.Grey : 0x2577e3) 157e41f4b71Sopenharmony_ci }.width('50%') 158e41f4b71Sopenharmony_ci 159e41f4b71Sopenharmony_ci } 160e41f4b71Sopenharmony_ci 161e41f4b71Sopenharmony_ci Row() { 162e41f4b71Sopenharmony_ci Column() { 163e41f4b71Sopenharmony_ci Gauge({ 164e41f4b71Sopenharmony_ci value: (config.contentModifier as MyLoadingProgressStyle).enableLoading?50:30, min: 11, max: 100 165e41f4b71Sopenharmony_ci }) { 166e41f4b71Sopenharmony_ci Column() { 167e41f4b71Sopenharmony_ci Text('60') 168e41f4b71Sopenharmony_ci .maxFontSize("180sp") 169e41f4b71Sopenharmony_ci .minFontSize("160.0vp") 170e41f4b71Sopenharmony_ci .fontWeight(FontWeight.Medium) 171e41f4b71Sopenharmony_ci .fontColor("#ff182431") 172e41f4b71Sopenharmony_ci .width('40%') 173e41f4b71Sopenharmony_ci .height('30%') 174e41f4b71Sopenharmony_ci .textAlign(TextAlign.Center) 175e41f4b71Sopenharmony_ci .margin({ top: '22.2%' }) 176e41f4b71Sopenharmony_ci .textOverflow({ overflow: TextOverflow.Ellipsis }) 177e41f4b71Sopenharmony_ci .maxLines(1) 178e41f4b71Sopenharmony_ci }.width('100%').height('100%') 179e41f4b71Sopenharmony_ci } 180e41f4b71Sopenharmony_ci 181e41f4b71Sopenharmony_ci .colors(((config.contentModifier as MyLoadingProgressStyle).enableLoading) ? Color.Grey : 0x2577e3) 182e41f4b71Sopenharmony_ci .width(200) 183e41f4b71Sopenharmony_ci .strokeWidth(18) 184e41f4b71Sopenharmony_ci .padding(5) 185e41f4b71Sopenharmony_ci .trackShadow({ radius: 7, offsetX: 7, offsetY: 7 }) 186e41f4b71Sopenharmony_ci .height(200) 187e41f4b71Sopenharmony_ci }.width('100%') 188e41f4b71Sopenharmony_ci 189e41f4b71Sopenharmony_ci } 190e41f4b71Sopenharmony_ci 191e41f4b71Sopenharmony_ci Column() { 192e41f4b71Sopenharmony_ci List({ space: 20, initialIndex: 0 }) { 193e41f4b71Sopenharmony_ci ForEach(arr2, (item: string) => { 194e41f4b71Sopenharmony_ci ListItem() { 195e41f4b71Sopenharmony_ci Text((config.contentModifier as MyLoadingProgressStyle).enableLoading ? '' + item : Number(item) * 2 + '') 196e41f4b71Sopenharmony_ci .width('100%') 197e41f4b71Sopenharmony_ci .height('100%') 198e41f4b71Sopenharmony_ci .fontColor((config.contentModifier as MyLoadingProgressStyle).enableLoading ? Color.White : Color.Orange) 199e41f4b71Sopenharmony_ci .fontSize((config.contentModifier as MyLoadingProgressStyle).enableLoading ? 16 : 20) 200e41f4b71Sopenharmony_ci .textAlign(TextAlign.Center) 201e41f4b71Sopenharmony_ci .backgroundColor((config.contentModifier as MyLoadingProgressStyle).enableLoading ? Color.Grey : 0x2577e3) 202e41f4b71Sopenharmony_ci } 203e41f4b71Sopenharmony_ci .height(110) 204e41f4b71Sopenharmony_ci .border({ 205e41f4b71Sopenharmony_ci width: 2, 206e41f4b71Sopenharmony_ci color: Color.White 207e41f4b71Sopenharmony_ci }) 208e41f4b71Sopenharmony_ci }, (item: string) => item) 209e41f4b71Sopenharmony_ci } 210e41f4b71Sopenharmony_ci .height(200) 211e41f4b71Sopenharmony_ci .width('100%') 212e41f4b71Sopenharmony_ci .friction(0.6) 213e41f4b71Sopenharmony_ci 214e41f4b71Sopenharmony_ci .lanes({ minLength: (config.contentModifier as MyLoadingProgressStyle).enableLoading?40:80, maxLength: (config.contentModifier as MyLoadingProgressStyle).enableLoading?40:80 }) 215e41f4b71Sopenharmony_ci .scrollBar(BarState.Off) 216e41f4b71Sopenharmony_ci } 217e41f4b71Sopenharmony_ci 218e41f4b71Sopenharmony_ci }.width("100%").padding(10) 219e41f4b71Sopenharmony_ci} 220e41f4b71Sopenharmony_ci 221e41f4b71Sopenharmony_ci 222e41f4b71Sopenharmony_ci@Entry 223e41f4b71Sopenharmony_ci@Component 224e41f4b71Sopenharmony_cistruct LoadingProgressDemoExample { 225e41f4b71Sopenharmony_ci @State loadingProgressList: (boolean | undefined | null)[] = [undefined, true, null, false] 226e41f4b71Sopenharmony_ci @State widthList: (number | string)[] = ['110%', 220, '40%', 80] 227e41f4b71Sopenharmony_ci @State loadingProgressIndex: number = 0 228e41f4b71Sopenharmony_ci @State clickFlag: number = 0 229e41f4b71Sopenharmony_ci scroller: Scroller = new Scroller() 230e41f4b71Sopenharmony_ci 231e41f4b71Sopenharmony_ci build() { 232e41f4b71Sopenharmony_ci Column() { 233e41f4b71Sopenharmony_ci Scroll(this.scroller) { 234e41f4b71Sopenharmony_ci Column({ space: 5 }) { 235e41f4b71Sopenharmony_ci Column() { 236e41f4b71Sopenharmony_ci LoadingProgress() 237e41f4b71Sopenharmony_ci .color('#106836') 238e41f4b71Sopenharmony_ci .size({ width: '100%' }) 239e41f4b71Sopenharmony_ci .contentModifier(new MyLoadingProgressStyle(this.loadingProgressList[this.loadingProgressIndex])) 240e41f4b71Sopenharmony_ci }.width('100%').backgroundColor(0xdcdcdc) 241e41f4b71Sopenharmony_ci }.width('100%').margin({ top: 5 }) 242e41f4b71Sopenharmony_ci }.height('85%') 243e41f4b71Sopenharmony_ci 244e41f4b71Sopenharmony_ci Button ('Switch config.enableloading').onClick(() => { 245e41f4b71Sopenharmony_ci this.clickFlag++ 246e41f4b71Sopenharmony_ci this.loadingProgressIndex = (this.loadingProgressIndex + 1) % this.loadingProgressList.length 247e41f4b71Sopenharmony_ci console.log('enableLoading:' + this.loadingProgressList[this.loadingProgressIndex]) 248e41f4b71Sopenharmony_ci }).margin(20) 249e41f4b71Sopenharmony_ci } 250e41f4b71Sopenharmony_ci 251e41f4b71Sopenharmony_ci } 252e41f4b71Sopenharmony_ci} 253e41f4b71Sopenharmony_ci``` 254e41f4b71Sopenharmony_ci 255