openharmony 鸿蒙 ts-universal-attributes-use-effect

2025-06-12 浏览 (1)

Special Effect Drawing Combination

The useEffect attribute is used to combine the drawing of special effects, such as background blur.

NOTE

This attribute is supported since API version 12. Updates will be marked with a superscript to indicate their earliest API version.

useEffect

useEffect(value: boolean)

Specifies whether to combine the drawing of special effects, such as background blur.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

NameTypeMandatoryDescription
valuebooleanYesWhether the component inherits the special effect settings of the EffectComponent component.
The value true means the component inherits the special effect settings of the EffectComponent component, and false means the opposite.
Default value: false

useEffect14+

useEffect(useEffect: boolean, effectType: EffectType)

Specifies whether to apply the effect defined by the parent EffectComponent or the window.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

NameTypeMandatoryDescription
useEffectbooleanYesWhether to apply the effect defined by the parent EffectComponent or the window.
The value true means to apply the effect defined by the parent EffectComponent or the window.
Default value: false
effectTypeEffectTypeYesType of effect to apply to the component, which is defined by the parent EffectComponent or the window.
Default value: EffectType.DEFAULT

useEffect18+

useEffect(useEffect: Optional<boolean>, effectType?: EffectType)

Specifies whether to apply the effect defined by the parent EffectComponent or the window. Compared to useEffect14+, this API supports the undefined type for the useEffect parameter.

Atomic service API: This API can be used in atomic services since API version 18.

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

NameTypeMandatoryDescription
useEffectOptional<boolean>YesWhether to apply the effect defined by the parent EffectComponent or the window.
The value true means to apply the effect defined by the parent EffectComponent or the window.
Default value: false
If useEffect is set to undefined, the previous value is retained.
effectTypeEffectTypeNoType of effect to apply to the component, which is defined by the parent EffectComponent or the window.
Default value: EffectType.DEFAULT

EffectType14+

Enumerates the types of effect templates.

Atomic service API: This API can be used in atomic services since API version 14.

System capability: SystemCapability.ArkUI.ArkUI.Full

NameValueDescription
DEFAULT0Uses the effect template defined by the parent EffectComponent or .
WINDOW_EFFECT1Uses the effect template defined by the window.

Effect Template

Device TypeFuzzy Radius (Unit: px)SaturationBrightnessColor
Mobile device000'#ffffffff'
2-in-1 device: dark mode801.51.0'#e52e3033'
2-in-1 device: light mode801.91.0'#e5ffffff'
Tablet000'#ffffffff'

Example

This example shows how to combine the drawing of special effects, including background blur.

//Index.ets
@Entry
@Component
struct Index {
  @State isUse: boolean = true;

  build() {
    Stack() {
      Image($r("app.media.mountain"))
        .autoResize(true)
      EffectComponent() {
        Column({ space: 20 }) {
           Column() {
           }
           .position({ x: 0, y: 0 })
           .width(150)
           .height(800)
           .useEffect(this.isUse, EffectType.WINDOW_EFFECT)
         
           Column() {
           }
           .position({ x: 200, y: 20 })
           .width(150)
           .height(300)
           .useEffect(this.isUse, EffectType.DEFAULT)

           Column() {
           }
           .position({ x: 400, y: 20 })
           .width(150)
           .height(300)
           .useEffect(this.isUse)
        }
        .width('100%')
        .height('100%')
      }
      .backgroundBlurStyle(BlurStyle.Thin)

       Column() {
       }
        .position({ x: 600, y: 0 })
        .width(150)
        .height(800)
        .useEffect(this.isUse, EffectType.WINDOW_EFFECT)

      Row() {
        Button('useEffect')
        .margin(30)
        .onClick(() => {
          this.isUse = !this.isUse;
        })
      }
      .position({ x: 300, y: 450 })
    }
    .backgroundColor(Color.Black)
    .width('100%')
  }
}

en-us_image_useeffect_effecttype

你可能感兴趣的鸿蒙文章

harmony 鸿蒙ArcButton

harmony 鸿蒙ArcSlider

harmony 鸿蒙Chip

harmony 鸿蒙ChipGroup

harmony 鸿蒙ComposeListItem

harmony 鸿蒙ComposeTitleBar

harmony 鸿蒙advanced.Counter

harmony 鸿蒙Dialog Box (Dialog)

harmony 鸿蒙DialogV2

harmony 鸿蒙DownloadFileButton

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/jFCneE