typedef struct OH_NativeXComponent_Callback {...} OH_NativeXComponent_Callback Defines OH_NativeXComponent_Callback, which is used to register the Surface lifecycle (creation, change, and destruction) and touch event callbacks of the XComponent component. It applies to scenarios where the surface state changes need to be detected on the native side and user touch interactions need to be handled.
Since: 8
Related module: OH_NativeXComponent Native XComponent
Header file: native_interface_xcomponent.h
| Name | Description |
|---|---|
| void (*OnSurfaceCreated)(OH_NativeXComponent* component, void* window) | Invoked when the surface is created. |
| void (*OnSurfaceChanged)(OH_NativeXComponent* component, void* window) | Invoked when the size of the surface changes. |
| void (*OnSurfaceDestroyed)(OH_NativeXComponent* component, void* window) | Invoked when the surface is destroyed. |
| void (*DispatchTouchEvent)(OH_NativeXComponent* component, void* window) | Invoked when a touch event is dispatched. |
void (*OnSurfaceCreated)(OH_NativeXComponent* component, void* window)
Description
Invoked when the surface is created.
Since: 8
Parameters
| Name | Description |
|---|---|
| OH_NativeXComponent* component | Pointer to the OH_NativeXComponent instance. |
| void* window | NativeWindow handle. The NativeWindow obtained through the XComponent lifecycle is held by the system with a reference count. After the OnSurfaceDestroyed callback is triggered, the reference count is decremented by one. After it reaches zero, the NativeWindow will be released. |
void (*OnSurfaceChanged)(OH_NativeXComponent* component, void* window)
Description
Invoked when the size of the surface changes.
Since: 8
Parameters
| Name | Description |
|---|---|
| OH_NativeXComponent* component | Pointer to the OH_NativeXComponent instance. |
| void* window | NativeWindow handle. This handle is passed in when the surface size or format changes, allowing you to perceive the latest surface state and update the rendering configuration. |
void (*OnSurfaceDestroyed)(OH_NativeXComponent* component, void* window)
Description
Invoked when the surface is destroyed.
Since: 8
Parameters
| Name | Description |
|---|---|
| OH_NativeXComponent* component | Pointer to the OH_NativeXComponent instance. |
| void* window | NativeWindow handle. After this callback is triggered, the reference count of the NativeWindow held by the system is decremented by one. The NativeWindow will be released after it reaches zero. Do not continue to use this window handle after this callback. |
void (*DispatchTouchEvent)(OH_NativeXComponent* component, void* window)
Description
Invoked when a touch event is dispatched. You can obtain touch event data in this callback to implement custom interaction logic, such as gesture recognition and custom drawing.
Since: 8
Parameters
| Name | Description |
|---|---|
| OH_NativeXComponent* component | Pointer to the OH_NativeXComponent instance. |
| void* window | NativeWindow handle. The NativeWindow obtained through the XComponent lifecycle is held by the system with a reference count. After the OnSurfaceDestroyed callback is triggered, the reference count is decremented by one. The NativeWindow will be released after the reference count reaches zero. |