HarmonyOS/OpenHarmony application development--ArkTS component area change event

1. Events

The component area change event refers to the event triggered when the size and position of the component display change. ( api8 starts to support )

name

Support bubbling

Functional description

onAreaChange(event: (oldValue: Area, newValue: Area) => void)

no

This callback is triggered when the component area changes.

Two, example

 

 

code:

@Entry
@Component
struct AreaExample {
  @State value: string = 'Text'
  @State sizeValue: string = ''

  build() {
    Column() {
      Text(this.value)
        .backgroundColor(Color.Gray).margin(30).fontSize(20).padding(4)
        .onClick(() => {
          this.value = this.value + ' | Text'
        })
        .onAreaChange((oldValue: Area, newValue: Area) => {
          console.info(`Ace: on area change, oldValue is ${JSON.stringify(oldValue)} value is ${JSON.stringify(newValue)}`)
          this.sizeValue = JSON.stringify(newValue)
        })
      Text('new area is: \n' + this.sizeValue).margin({ right: 30, left: 30 })
    }
    .width('100%').height('100%').margin({ top: 30 })
  }
}

Website code address: HarmonyOSAPP development related components: Shenzhen Jiaolong Tengfei Network Technology Co., Ltd. - Gitee.com 

Guess you like

Origin blog.csdn.net/weixin_69135651/article/details/129703095