ts-universal-component-area-change-event.md 1.5 KB
Newer Older
Z
zengyawen 已提交
1 2
# Component Area Change Event

E
ester.zhou 已提交
3
The area change event is triggered when the component's size, position, or any other attribute that may affect its display area changes.
Z
zengyawen 已提交
4

E
ester.zhou 已提交
5
>  **NOTE**
E
ester.zhou 已提交
6
>
E
ester.zhou 已提交
7
>  The APIs of this module are supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.
Z
zengyawen 已提交
8 9 10 11


## Events

E
ester.zhou 已提交
12 13
| Name                                      | Bubbling Supported| Description                                    |
| ---------------------------------------- | ---- | ---------------------------------------- |
E
esterzhou 已提交
14
| onAreaChange(event: (oldValue: [Area](ts-types.md#area8), newValue: [Area](ts-types.md#area8)) => void) | No   | Triggered when the component area changes.|
Z
zengyawen 已提交
15 16 17 18


## Example

E
ester.zhou 已提交
19 20
```ts
// xxx.ets
Z
zengyawen 已提交
21 22 23 24
@Entry
@Component
struct AreaExample {
  @State value: string = 'Text'
E
esterzhou 已提交
25
  @State sizeValue: string = ''
Z
zengyawen 已提交
26 27 28 29 30 31 32 33 34 35

  build() {
    Column() {
      Text(this.value)
        .backgroundColor(Color.Green).margin(30).fontSize(20)
        .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)}`)
E
esterzhou 已提交
36
          this.sizeValue = JSON.stringify(newValue)
Z
zengyawen 已提交
37
        })
E
esterzhou 已提交
38
      Text('new area is: \n' + this.sizeValue).margin({ right: 30, left: 30 })
Z
zengyawen 已提交
39 40 41 42 43 44
    }
    .width('100%').height('100%').margin({ top: 30 })
  }
}
```

E
ester.zhou 已提交
45
![en-us_image_0000001189634870](figures/en-us_image_0000001189634870.gif)