目录

Common Event Callbacks

The initial APIs of this module are supported since API version 12. Newly added APIs will be marked with a superscript to indicate their earliest API version.

UICommonEvent

Implements a common event callback. Passing undefined as the input parameter resets the corresponding event callback.

[h2]setOnClick

setOnClick(callback: Callback<ClickEvent> | undefined): void

Set the callback for the click event.

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

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
callback Callback<ClickEvent> | undefined Yes Callback for the click event.

[h2]setOnTouch

setOnTouch(callback: Callback<TouchEvent> | undefined): void

Sets the callback for the touch event.

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

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
callback Callback<TouchEvent> | undefined Yes Callback for the touch event.

[h2]setOnAppear

setOnAppear(callback: Callback<void> | undefined): void

Sets the callback for the onAppear event.

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

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
callback Callback<void> | undefined Yes Callback invoked when the component appears.

[h2]setOnDisappear

setOnDisappear(callback: Callback<void> | undefined): void

Sets the callback for the onDisAppear event.

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

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
callback Callback<void> | undefined Yes Callback invoked when the component disappears.

[h2]setOnKeyEvent

setOnKeyEvent(callback: Callback<KeyEvent> | undefined): void

Sets the callback for the key event.

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

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
callback Callback<KeyEvent> | undefined Yes Callback for the key event.

[h2]setOnFocus

setOnFocus(callback: Callback<void> | undefined): void

Sets the callback for the onFocus event.

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

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
callback Callback<void> | undefined Yes Callback for the focus event.

[h2]setOnBlur

setOnBlur(callback: Callback<void> | undefined): void

Sets the callback for the onBlur event.

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

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
callback Callback<void> | undefined Yes Callback for the blur event.

[h2]setOnHover

setOnHover(callback: HoverCallback | undefined): void

Sets the callback for the onHover event.

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

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
callback HoverCallback | undefined Yes Callback for the hover event.

[h2]setOnMouse

setOnMouse(callback: Callback<MouseEvent> | undefined): void

Sets the callback for the onMouse event.

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

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
callback Callback<MouseEvent> | undefined Yes Callback for the mouse event.

[h2]setOnSizeChange

setOnSizeChange(callback: SizeChangeCallback | undefined): void

Sets the callback for the onSizeChange event, which is triggered when the component's size changes.

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

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
callback SizeChangeCallback | undefined Yes Callback invoked when the component's size changes.

[h2]setOnVisibleAreaApproximateChange

setOnVisibleAreaApproximateChange(options: VisibleAreaEventOptions, event: VisibleAreaChangeCallback | undefined): void

Sets the callback for the onVisibleAreaChange visible area change event.

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

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
options VisibleAreaEventOptions Yes Configuration options for visible area change detection.
event VisibleAreaChangeCallback | undefined Yes Callback invoked when the ratio of the component's visible area to its total area crosses the threshold specified in options.

Difference from onVisibleAreaChange: onVisibleAreaChange calculates the visible area ratio every frame, which can lead to high power consumption when many nodes are registered. This API reduces the calculation frequency: The interval is controlled by the expectedUpdateInterval parameter in VisibleAreaEventOptions.

By default, the interval threshold of the visible area change callback includes 0. This means that, if the provided threshold is [0.5], the effective threshold will be [0.0, 0.5].

HoverCallback

type HoverCallback = (isHover: boolean, event: HoverEvent)=> void

Defines the callback type for hover events.

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

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
isHover boolean Yes Whether the element is in the hover state. true: yes; false: no.
event HoverEvent Yes Position coordinates of the hovered mouse or stylus.