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

鸿蒙时代
发布于 2023-3-21 10:50
浏览
0收藏

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

名称 支持冒泡 功能描述
onAreaChange(event: (oldValue: Area, newValue: Area) => void) 组件区域变化时触发该回调。

二、示例
HarmonyOS/OpenHarmony应用开发--ArkTS组件区域变化事件-鸿蒙开发者社区HarmonyOS/OpenHarmony应用开发--ArkTS组件区域变化事件-鸿蒙开发者社区

代码:

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

网站代码地址:https://gitee.com/jltfcloudcn/jump_to/tree/master/AreaChange

标签
HarmonyOSOpenHarmony应用开发--ArkTS组件.docx 71.82K 17次下载
收藏
回复
举报
回复
    相关推荐