1e41f4b71Sopenharmony_ci# Shape Clipping 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciShape clipping changes the visible portion of a component through clipping or masking. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **NOTE** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> The APIs of this module are supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version. 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci## clip<sup>12+</sup> 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ciclip(value: boolean) 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ciSets whether to clip the areas of child components that extend beyond this component's boundaries, that is, whether to perform clipping based on the edge contour of the parent container 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 12. 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci**Parameters** 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 24e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 25e41f4b71Sopenharmony_ci| value | boolean | Yes | Whether to perform clipping based on the edge contour of the parent container.<br>Default value: **false**| 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci## clip<sup>(deprecated)</sup> 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ciclip(value: boolean | CircleAttribute | EllipseAttribute | PathAttribute | RectAttribute) 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ciSets whether to clip this component based on the given shape. 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ci> **NOTE** 34e41f4b71Sopenharmony_ci> 35e41f4b71Sopenharmony_ci> This API is supported since API version 7 and deprecated since API version 12. You are advised to use [clip](#clip12) and [clipShape](#clipshape12) instead. 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9. 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 | boolean \| [CircleAttribute](ts-drawing-components-circle.md) \| [EllipseAttribute](ts-drawing-components-ellipse.md) \| [PathAttribute](ts-drawing-components-path.md) \| [RectAttribute](ts-drawing-components-rect.md) | Yes | Clip mode. If the value is a shape, the component is clipped based on the specified shape. If the value is of the Boolean type, it specifies whether to clip the component based on the edge contour of the parent container.<br>Default value: **false**| 46e41f4b71Sopenharmony_ci 47e41f4b71Sopenharmony_ci## clipShape<sup>12+</sup> 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_ciclipShape(value: CircleShape | EllipseShape | PathShape | RectShape) 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ciClips this component based on the given shape. 52e41f4b71Sopenharmony_ci 53e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 54e41f4b71Sopenharmony_ci 55e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 12. 56e41f4b71Sopenharmony_ci 57e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 58e41f4b71Sopenharmony_ci 59e41f4b71Sopenharmony_ci**Parameters** 60e41f4b71Sopenharmony_ci 61e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 62e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 63e41f4b71Sopenharmony_ci| value | [CircleShape](../js-apis-arkui-shape.md#circleshape) \| [EllipseShape](../js-apis-arkui-shape.md#ellipseshape) \| [PathShape](../js-apis-arkui-shape.md#pathshape) \| [RectShape](../js-apis-arkui-shape.md#rectshape) | Yes | Shape that the component to be clipped into.| 64e41f4b71Sopenharmony_ci 65e41f4b71Sopenharmony_ci## mask<sup>12+</sup> 66e41f4b71Sopenharmony_ci 67e41f4b71Sopenharmony_cimask(value: ProgressMask) 68e41f4b71Sopenharmony_ci 69e41f4b71Sopenharmony_ciAdds a mask of the specified shape to the component. 70e41f4b71Sopenharmony_ci 71e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 72e41f4b71Sopenharmony_ci 73e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 74e41f4b71Sopenharmony_ci 75e41f4b71Sopenharmony_ci**Parameters** 76e41f4b71Sopenharmony_ci 77e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 78e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | -------------------------------- | 79e41f4b71Sopenharmony_ci| value | [ProgressMask](#progressmask10) | Yes | Mask to add to the component, which allows for dynamic adjustment of progress, maximum value, and color settings.| 80e41f4b71Sopenharmony_ci 81e41f4b71Sopenharmony_ci## mask<sup>(deprecated)</sup> 82e41f4b71Sopenharmony_ci 83e41f4b71Sopenharmony_cimask(value: CircleAttribute | EllipseAttribute | PathAttribute | RectAttribute | ProgressMask) 84e41f4b71Sopenharmony_ci 85e41f4b71Sopenharmony_ciAdds a mask of the specified shape to the component. 86e41f4b71Sopenharmony_ci 87e41f4b71Sopenharmony_ci> **NOTE** 88e41f4b71Sopenharmony_ci> 89e41f4b71Sopenharmony_ci> This API is supported since API version 7 and deprecated since API version 12. You are advised to use [mask](#mask12) and [maskShape](#maskshape12) instead. 90e41f4b71Sopenharmony_ci 91e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9. 92e41f4b71Sopenharmony_ci 93e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 94e41f4b71Sopenharmony_ci 95e41f4b71Sopenharmony_ci**Parameters** 96e41f4b71Sopenharmony_ci 97e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 98e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | -------------------------------- | 99e41f4b71Sopenharmony_ci| value | [CircleAttribute](ts-drawing-components-circle.md) \| [EllipseAttribute](ts-drawing-components-ellipse.md) \| [PathAttribute](ts-drawing-components-path.md) \| [RectAttribute](ts-drawing-components-rect.md) \| [ProgressMask](#progressmask10)<sup>10+</sup> | Yes | Mask of the specified shape to add to the component.| 100e41f4b71Sopenharmony_ci 101e41f4b71Sopenharmony_ci## maskShape<sup>12+</sup> 102e41f4b71Sopenharmony_ci 103e41f4b71Sopenharmony_cimaskShape(value: CircleShape | EllipseShape | PathShape | RectShape) 104e41f4b71Sopenharmony_ci 105e41f4b71Sopenharmony_ciAdds a mask of the specified shape to the component. 106e41f4b71Sopenharmony_ci 107e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 108e41f4b71Sopenharmony_ci 109e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 12. 110e41f4b71Sopenharmony_ci 111e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 112e41f4b71Sopenharmony_ci 113e41f4b71Sopenharmony_ci**Parameters** 114e41f4b71Sopenharmony_ci 115e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 116e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | -------------------------------- | 117e41f4b71Sopenharmony_ci| value | [CircleShape](../js-apis-arkui-shape.md#circleshape) \| [EllipseShape](../js-apis-arkui-shape.md#ellipseshape) \| [PathShape](../js-apis-arkui-shape.md#pathshape) \| [RectShape](../js-apis-arkui-shape.md#rectshape) | Yes | Mask of the specified shape to add to the component.| 118e41f4b71Sopenharmony_ci 119e41f4b71Sopenharmony_ci## ProgressMask<sup>10+</sup> 120e41f4b71Sopenharmony_ci 121e41f4b71Sopenharmony_ciImplements a **ProgressMask** object to set the progress, maximum value, and color of the mask. 122e41f4b71Sopenharmony_ci 123e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 124e41f4b71Sopenharmony_ci 125e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 126e41f4b71Sopenharmony_ci 127e41f4b71Sopenharmony_ci### constructor<sup>10+</sup> 128e41f4b71Sopenharmony_ci 129e41f4b71Sopenharmony_ciconstructor(value: number, total: number, color: ResourceColor) 130e41f4b71Sopenharmony_ci 131e41f4b71Sopenharmony_ciConstructs a **ProgressMask** object. 132e41f4b71Sopenharmony_ci 133e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 134e41f4b71Sopenharmony_ci 135e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 136e41f4b71Sopenharmony_ci 137e41f4b71Sopenharmony_ci**Parameters** 138e41f4b71Sopenharmony_ci 139e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 140e41f4b71Sopenharmony_ci| ------ | ------------------------------------------ | ---- | ------------------ | 141e41f4b71Sopenharmony_ci| value | number | Yes | Current value of the progress mask.| 142e41f4b71Sopenharmony_ci| total | number | Yes | Maximum value of the progress mask.| 143e41f4b71Sopenharmony_ci| color | [ResourceColor](ts-types.md#resourcecolor) | Yes | Color of the progress mask. | 144e41f4b71Sopenharmony_ci 145e41f4b71Sopenharmony_ci### updateProgress<sup>10+</sup> 146e41f4b71Sopenharmony_ci 147e41f4b71Sopenharmony_ciupdateProgress(value: number): void 148e41f4b71Sopenharmony_ci 149e41f4b71Sopenharmony_ciUpdates the progress value of the progress mask. 150e41f4b71Sopenharmony_ci 151e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 152e41f4b71Sopenharmony_ci 153e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 154e41f4b71Sopenharmony_ci 155e41f4b71Sopenharmony_ci**Parameters** 156e41f4b71Sopenharmony_ci 157e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description | 158e41f4b71Sopenharmony_ci| ------ | -------- | ---- | ------------------ | 159e41f4b71Sopenharmony_ci| value | number | Yes | Current value of the progress mask.| 160e41f4b71Sopenharmony_ci 161e41f4b71Sopenharmony_ci### updateColor<sup>10+</sup> 162e41f4b71Sopenharmony_ci 163e41f4b71Sopenharmony_ciupdateColor(value: ResourceColor): void 164e41f4b71Sopenharmony_ci 165e41f4b71Sopenharmony_ciUpdates the color of the progress mask. 166e41f4b71Sopenharmony_ci 167e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 168e41f4b71Sopenharmony_ci 169e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 170e41f4b71Sopenharmony_ci 171e41f4b71Sopenharmony_ci**Parameters** 172e41f4b71Sopenharmony_ci 173e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 174e41f4b71Sopenharmony_ci| ------ | ------------------------------------------ | ---- | ---------------- | 175e41f4b71Sopenharmony_ci| value | [ResourceColor](ts-types.md#resourcecolor) | Yes | Color of the progress mask.| 176e41f4b71Sopenharmony_ci 177e41f4b71Sopenharmony_ci### enableBreathingAnimation<sup>12+</sup> 178e41f4b71Sopenharmony_ci 179e41f4b71Sopenharmony_cienableBreathingAnimation(value: boolean): void 180e41f4b71Sopenharmony_ci 181e41f4b71Sopenharmony_ciSets whether to enable the breathing animation when the progress indicator is full. By default, the breathing animation is disabled. 182e41f4b71Sopenharmony_ci 183e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 184e41f4b71Sopenharmony_ci 185e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 186e41f4b71Sopenharmony_ci 187e41f4b71Sopenharmony_ci**Parameters** 188e41f4b71Sopenharmony_ci 189e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 190e41f4b71Sopenharmony_ci| ------ | ------------------------------------------ | ---- | ---------------- | 191e41f4b71Sopenharmony_ci| value | boolean | Yes | Whether to enable the breathing animation. The value **true** means to enable the breathing animation, and **false** means the opposite. Default value: **false**| 192e41f4b71Sopenharmony_ci 193e41f4b71Sopenharmony_ci 194e41f4b71Sopenharmony_ci## Example 195e41f4b71Sopenharmony_ci 196e41f4b71Sopenharmony_ci### Example 1 197e41f4b71Sopenharmony_ci 198e41f4b71Sopenharmony_ci```ts 199e41f4b71Sopenharmony_ci// xxx.ets 200e41f4b71Sopenharmony_ci@Entry 201e41f4b71Sopenharmony_ci@Component 202e41f4b71Sopenharmony_cistruct ClipAndMaskExample { 203e41f4b71Sopenharmony_ci build() { 204e41f4b71Sopenharmony_ci Column({ space: 15 }) { 205e41f4b71Sopenharmony_ci Text('clip').fontSize(12).width('75%').fontColor('#DCDCDC') 206e41f4b71Sopenharmony_ci Row() { 207e41f4b71Sopenharmony_ci Image($r('app.media.testImg')).width('500px').height('280px') 208e41f4b71Sopenharmony_ci } 209e41f4b71Sopenharmony_ci .clip(true) // If clip is not set to true, the image is not confined by the rounded corners of the <Row> component and may extend beyond the <Row> component. 210e41f4b71Sopenharmony_ci .borderRadius(20) 211e41f4b71Sopenharmony_ci // Clip the image based on a circle with a diameter of 280 px. 212e41f4b71Sopenharmony_ci Image($r('app.media.testImg')) 213e41f4b71Sopenharmony_ci .clipShape(new Circle({ width: '280px', height: '280px' })) 214e41f4b71Sopenharmony_ci .width('500px').height('280px') 215e41f4b71Sopenharmony_ci 216e41f4b71Sopenharmony_ci Text('mask').fontSize(12).width('75%').fontColor('#DCDCDC') 217e41f4b71Sopenharmony_ci // Add a 500 px x 280 px square mask to the image. 218e41f4b71Sopenharmony_ci Image($r('app.media.testImg')) 219e41f4b71Sopenharmony_ci .maskShape(new Rect({ width: '500px', height: '280px' }).fill(Color.Gray)) 220e41f4b71Sopenharmony_ci .width('500px').height('280px') 221e41f4b71Sopenharmony_ci 222e41f4b71Sopenharmony_ci // Add a 280 px x 280 px circular mask to the image. 223e41f4b71Sopenharmony_ci Image($r('app.media.testImg')) 224e41f4b71Sopenharmony_ci .maskShape(new Circle({ width: '280px', height: '280px' }).fill(Color.Gray)) 225e41f4b71Sopenharmony_ci .width('500px').height('280px') 226e41f4b71Sopenharmony_ci } 227e41f4b71Sopenharmony_ci .width('100%') 228e41f4b71Sopenharmony_ci .margin({ top: 15 }) 229e41f4b71Sopenharmony_ci } 230e41f4b71Sopenharmony_ci} 231e41f4b71Sopenharmony_ci``` 232e41f4b71Sopenharmony_ci 233e41f4b71Sopenharmony_ci 234e41f4b71Sopenharmony_ci 235e41f4b71Sopenharmony_ci### Example 2 236e41f4b71Sopenharmony_ci 237e41f4b71Sopenharmony_ci```ts 238e41f4b71Sopenharmony_ci@Entry 239e41f4b71Sopenharmony_ci@Component 240e41f4b71Sopenharmony_cistruct ProgressMaskExample { 241e41f4b71Sopenharmony_ci @State progressflag1: boolean = true; 242e41f4b71Sopenharmony_ci @State color: Color = 0x01006CDE; 243e41f4b71Sopenharmony_ci @State value: number = 10.0; 244e41f4b71Sopenharmony_ci @State enableBreathingAnimation: boolean = false; 245e41f4b71Sopenharmony_ci @State progress: ProgressMask = new ProgressMask(10.0, 100.0, Color.Gray); 246e41f4b71Sopenharmony_ci build() { 247e41f4b71Sopenharmony_ci Column({ space: 15 }) { 248e41f4b71Sopenharmony_ci Text('progress mask').fontSize(12).width('75%').fontColor('#DCDCDC') 249e41f4b71Sopenharmony_ci // Add a 280px x 280px progress mask to the image. 250e41f4b71Sopenharmony_ci Image($r('app.media.testImg')) 251e41f4b71Sopenharmony_ci .width('500px').height('280px') 252e41f4b71Sopenharmony_ci .mask(this.progress) 253e41f4b71Sopenharmony_ci .animation({ 254e41f4b71Sopenharmony_ci duration: 2000, // Animation duration. 255e41f4b71Sopenharmony_ci .curve(Curve.Linear) // Animation curve. 256e41f4b71Sopenharmony_ci delay: 0, // Animation delay. 257e41f4b71Sopenharmony_ci iterations: 1, // Number of playback times. 258e41f4b71Sopenharmony_ci playMode: PlayMode.Normal // Animation playback mode. 259e41f4b71Sopenharmony_ci }) // Animation configuration for the width and height attributes of the <Button> component. 260e41f4b71Sopenharmony_ci 261e41f4b71Sopenharmony_ci // Update the progress value of the progress mask. 262e41f4b71Sopenharmony_ci Button('updateProgress') 263e41f4b71Sopenharmony_ci .onClick((event?: ClickEvent) => { 264e41f4b71Sopenharmony_ci this.value += 10; 265e41f4b71Sopenharmony_ci this.progress.updateProgress(this.value); 266e41f4b71Sopenharmony_ci }).width(200).height(50).margin(20) 267e41f4b71Sopenharmony_ci 268e41f4b71Sopenharmony_ci // Update the color of the progress mask. 269e41f4b71Sopenharmony_ci Button('updateColor') 270e41f4b71Sopenharmony_ci .onClick((event?: ClickEvent) => { 271e41f4b71Sopenharmony_ci if (this.progressflag1) { 272e41f4b71Sopenharmony_ci this.progress.updateColor(0x9fff0000); 273e41f4b71Sopenharmony_ci } else { 274e41f4b71Sopenharmony_ci this.progress.updateColor(0x9f0000ff); 275e41f4b71Sopenharmony_ci } 276e41f4b71Sopenharmony_ci this.progressflag1 = !this.progressflag1 277e41f4b71Sopenharmony_ci }).width(200).height(50).margin(20) 278e41f4b71Sopenharmony_ci 279e41f4b71Sopenharmony_ci // Enable or disable the breathing animation. 280e41f4b71Sopenharmony_ci Button('enableBreathingAnimation:' + this.enableBreathingAnimation) 281e41f4b71Sopenharmony_ci .onClick((event?: ClickEvent) => { 282e41f4b71Sopenharmony_ci this.enableBreathingAnimation = !this.enableBreathingAnimation 283e41f4b71Sopenharmony_ci this.progress.enableBreathingAnimation(this.enableBreathingAnimation); 284e41f4b71Sopenharmony_ci }).width(200).height(50).margin(20) 285e41f4b71Sopenharmony_ci 286e41f4b71Sopenharmony_ci // Restore the progress mask. 287e41f4b71Sopenharmony_ci Button('click reset!') 288e41f4b71Sopenharmony_ci .onClick((event?: ClickEvent) => { 289e41f4b71Sopenharmony_ci this.value = 0; 290e41f4b71Sopenharmony_ci this.progress.updateProgress(this.value); 291e41f4b71Sopenharmony_ci }).width(200).height(50).margin(20) 292e41f4b71Sopenharmony_ci } 293e41f4b71Sopenharmony_ci .width('100%') 294e41f4b71Sopenharmony_ci .margin({ top: 15 }) 295e41f4b71Sopenharmony_ci } 296e41f4b71Sopenharmony_ci} 297e41f4b71Sopenharmony_ci``` 298e41f4b71Sopenharmony_ci 299e41f4b71Sopenharmony_ci 300