HarmonyOS/OpenHarmony应用开发--ArkTS组件区域变化事件

一、事件

组件区域变化事件指组件显示的尺寸、位置等发生变化时触发的事件。api8开始支持

名称

支持冒泡

功能描述

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

组件区域变化时触发该回调。

二、示例

 

代码:

@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 })
  }
}

网站代码地址:HarmonyOSAPP开发相关组件: 深圳市蛟龙腾飞网络科技有限公司 - Gitee.com 

猜你喜欢

转载自blog.csdn.net/weixin_69135651/article/details/129703095