文档管理中心

双边边缘流光

场景介绍

从6.0.0(20)版本开始,新增支持双边边缘流光

通过双边边缘流光接口可以设置组件的边缘发光效果,并且可以设置两条边的起始、终止位置和边缘颜色效果,常用于胶囊组件、屏幕边缘发光等。

开发步骤

  1. 导入模块。

    收起
    自动换行
    深色代码主题
    复制
    1. import { hdsEffect } from '@kit.UIDesignKit';
  2. 设置双边边缘流光效果。

    收起
    自动换行
    深色代码主题
    复制
    1. @Entry
    2. @Component
    3. struct Index {
    4. @State controller: hdsEffect.ShaderEffectController = new hdsEffect.ShaderEffectController();
    5. build() {
    6. Column() {
    7. Stack() {
    8. }
    9. .visualEffect(new hdsEffect.HdsEffectBuilder()
    10. .shaderEffect({
    11. effectType: hdsEffect.EffectType.DUAL_EDGE_FLOW_LIGHT,
    12. animation: {
    13. duration: 4000,
    14. iterations: -1,
    15. autoPlay: true,
    16. onFinish: () => {
    17. console.info('Succeeded in finishing');
    18. }
    19. },
    20. controller: this.controller,
    21. params: {
    22. firstEdgeFlowLight: {
    23. startPos: 0,
    24. endPos: 1.0,
    25. color: '#1AD0F1',
    26. },
    27. secondEdgeFlowLight: {
    28. startPos: 0.5,
    29. endPos: 1.5,
    30. color: '#FFA4E5',
    31. }
    32. }
    33. })
    34. .buildEffect())
    35. .width(200)
    36. .borderRadius('50%')
    37. .clip(true)
    38. .height(200)
    39. .backgroundColor('#383838')
    40. }
    41. .justifyContent(FlexAlign.Center)
    42. .backgroundColor(Color.Black)
    43. .width('100%')
    44. .height('100%')
    45. }
    46. }