鸿蒙OpenHarmony Native API【Native XComponent】

Native XComponent

Overview

Description:

Describes the surface and touch event held by the ArkUI XComponent, which can be used for the EGL/OpenGLES and media data input and displayed on the ArkUI XComponent.

Since:

8

Version:

1.0

Summary

Files

File Name Description
native_interface_xcomponent.h Declares APIs for accessing a Native XComponent.

Classes

Classe Name Description
OH_NativeXComponent_TouchPoint
OH_NativeXComponent_TouchEvent
OH_NativeXComponent_Callback Registers the surface lifecycle and touch event callbacks.

Macros

Macro Name and Value Description
OH_NATIVE_XCOMPONENT_OBJ ("NATIVE_XCOMPONENT_OBJ")

Typedefs

Typedef Name Description
OH_NativeXComponent typedef struct OH_NativeXComponent Provides an encapsulated OH_NativeXComponent instance.
OH_NativeXComponent_Callback typedef struct OH_NativeXComponent_Callback Registers the surface lifecycle and touch event callbacks.

Enumerations

Enumeration Name Description
{ OH_NATIVEXCOMPONENT_RESULT_SUCCESS = 0, OH_NATIVEXCOMPONENT_RESULT_FAILED = -1, OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER = -2 } Enumerates the API access states.
OH_NativeXComponent_TouchEventType { OH_NATIVEXCOMPONENT_DOWN = 0, OH_NATIVEXCOMPONENT_UP, OH_NATIVEXCOMPONENT_MOVE, OH_NATIVEXCOMPONENT_CANCEL, OH_NATIVEXCOMPONENT_UNKNOWN }

Functions

Function Description
OH_NativeXComponent_GetXComponentId (OH_NativeXComponent *component, char *id, uint64_t *size) int32_t Obtains the ID of the ArkUI XComponent.
OH_NativeXComponent_GetXComponentSize (OH_NativeXComponent *component, const void *window, uint64_t *width, uint64_t *height) int32_t Obtains the size of the surface held by the ArkUI XComponent.
OH_NativeXComponent_GetXComponentOffset (OH_NativeXComponent *component, const void *window, double *x, double *y) int32_t Obtains the offset of the surface held by the ArkUI XComponent.
OH_NativeXComponent_GetTouchEvent (OH_NativeXComponent *component, const void *window, OH_NativeXComponent_TouchEvent *touchEvent) int32_t Obtains the touch event dispatched by the ArkUI XComponent.
OH_NativeXComponent_RegisterCallback (OH_NativeXComponent *component, OH_NativeXComponent_Callback *callback) int32_t Registers a callback for this OH_NativeXComponent instance.

Details

Typedef

OH_NativeXComponent

复制代码
typedef struct OH_NativeXComponent OH_NativeXComponent

Description:

Provides an encapsulated OH_NativeXComponent instance.

OH_NativeXComponent_Callback

复制代码
typedef struct OH_NativeXComponent_Callback OH_NativeXComponent_Callback

Description:

Registers the surface lifecycle and touch event callbacks.

Enumeration Type

anonymous enum

复制代码
anonymous enum

Description:

Enumerates the API access states.

Enumerator Description
OH_NATIVEXCOMPONENT_RESULT_SUCCESS Success result.
OH_NATIVEXCOMPONENT_RESULT_FAILED Failed result.
OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER Invalid parameters.

OH_NativeXComponent_TouchEventType

复制代码
enum OH_NativeXComponent_TouchEventType
Enumerator Description
OH_NATIVEXCOMPONENT_DOWN Trigger a touch event when a finger is pressed.
OH_NATIVEXCOMPONENT_UP Trigger a touch event when a finger is lifted.
OH_NATIVEXCOMPONENT_MOVE Trigger a touch event when a finger moves on the screen in pressed state.
OH_NATIVEXCOMPONENT_CANCEL Trigger an event when a touch event is canceled.
OH_NATIVEXCOMPONENT_UNKNOWN Invalid touch type.

Function

OH_NativeXComponent_GetTouchEvent()

复制代码
int32_t OH_NativeXComponent_GetTouchEvent (OH_NativeXComponent * component, const void * window, OH_NativeXComponent_TouchEvent * touchEvent )

Description:

Obtains the touch event dispatched by the ArkUI XComponent.

Parameters:

Name Description
component Indicates the pointer to this OH_NativeXComponent instance.
window Indicates the native window handler.
touchEvent Indicates the pointer to the current touch event.

Returns:

Returns the status code of the execution.

OH_NativeXComponent_GetXComponentId()

复制代码
int32_t OH_NativeXComponent_GetXComponentId (OH_NativeXComponent * component, char * id, uint64_t * size )

Description:

Obtains the ID of the ArkUI XComponent.

Parameters:

Name Description
component Indicates the pointer to this OH_NativeXComponent instance.
id Indicates the char buffer to keep the ID of this OH_NativeXComponent instance. Note that a null-terminator will be appended to the char buffer, so the size of the char buffer should be at least as large as the size of the real id length plus 1. It is recommended that the size of the char buffer be OH_XCOMPONENT_ID_LEN_MAX + 1.
size Indicates the pointer to the length of id, which you can set and receive.

Returns:

Returns the status code of the execution.

OH_NativeXComponent_GetXComponentOffset()

复制代码
int32_t OH_NativeXComponent_GetXComponentOffset (OH_NativeXComponent * component, const void * window, double * x, double * y )

Description:

Obtains the offset of the surface held by the ArkUI XComponent.

Parameters:

Name Description
component Indicates the pointer to this OH_NativeXComponent instance.
window Indicates the native window handler.
x Indicates the pointer to the x coordinate of the current surface.
y Indicates the pointer to the y coordinate of the current surface.

Returns:

Returns the status code of the execution.

OH_NativeXComponent_GetXComponentSize()

复制代码
int32_t OH_NativeXComponent_GetXComponentSize (OH_NativeXComponent * component, const void * window, uint64_t * width, uint64_t * height )

Description:

Obtains the size of the surface held by the ArkUI XComponent.

Parameters:

Name Description
component Indicates the pointer to this OH_NativeXComponent instance.
window Indicates the native window handler.
width Indicates the pointer to the width of the current surface.
height Indicates the pointer to the height of the current surface.

Returns:

Returns the status code of the execution.

OH_NativeXComponent_RegisterCallback()

复制代码
int32_t OH_NativeXComponent_RegisterCallback (OH_NativeXComponent * component, OH_NativeXComponent_Callback * callback )

Description:

Registers a callback for this OH_NativeXComponent instance.

Parameters:

Name Description
component Indicates the pointer to this OH_NativeXComponent instance.
callback Indicates the pointer to a surface lifecycle and touch event callback.

Returns:

Returns the status code of the execution.

Variable

deviceId

复制代码
int64_t OH_NativeXComponent_TouchEvent::deviceId = 0

Description:

ID of the device where the current touch event is generated.

DispatchTouchEvent

复制代码
void(* OH_NativeXComponent_Callback::DispatchTouchEvent) (OH_NativeXComponent *component, void *window)

Description:

Called when a touch event is triggered.

force 1/2

复制代码
float OH_NativeXComponent_TouchPoint::force = 0.0

Description:

Pressure of the current touch event.

force 2/2

复制代码
float OH_NativeXComponent_TouchEvent::force = 0.0

Description:

Pressure of the current touch event.

id 1/2

复制代码
int32_t OH_NativeXComponent_TouchPoint::id = 0

Description:

Unique identifier of a finger.

id 2/2

复制代码
int32_t OH_NativeXComponent_TouchEvent::id = 0

Description:

Unique identifier of a finger.

isPressed

复制代码
bool OH_NativeXComponent_TouchPoint::isPressed = false

Description:

Whether the current point is pressed.

numPoints

复制代码
uint32_t OH_NativeXComponent_TouchEvent::numPoints = 0

Description:

Number of current touch points.

OnSurfaceChanged

复制代码
void(* OH_NativeXComponent_Callback::OnSurfaceChanged) (OH_NativeXComponent *component, void *window)

Description:

Called when the surface is changed. This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.

OnSurfaceCreated

复制代码
void(* OH_NativeXComponent_Callback::OnSurfaceCreated) (OH_NativeXComponent *component, void *window)

Description:

Called when the surface is created.

OnSurfaceDestroyed

复制代码
void(* OH_NativeXComponent_Callback::OnSurfaceDestroyed) (OH_NativeXComponent *component, void *window)

Description:

Called when the surface is destroyed.

screenX 1/2

复制代码
float OH_NativeXComponent_TouchPoint::screenX = 0.0

Description:

X coordinate of the touch point relative to the left edge of the screen.

screenX 2/2

复制代码
float OH_NativeXComponent_TouchEvent::screenX = 0.0

Description:

X coordinate of the touch point relative to the left edge of the screen.

screenY 1/2

复制代码
float OH_NativeXComponent_TouchPoint::screenY = 0.0

Description:

Y coordinate of the touch point relative to the upper edge of the screen.

screenY 2/2

复制代码
float OH_NativeXComponent_TouchEvent::screenY = 0.0

Description:

Y coordinate of the touch point relative to the upper edge of the screen.

size 1/2

复制代码
double OH_NativeXComponent_TouchPoint::size = 0.0

Description:

Contact area between the finger pad and the screen.

size 2/2

复制代码
double OH_NativeXComponent_TouchEvent::size = 0.0

Description:

Contact area between the finger pad and the screen.

timeStamp 1/2

复制代码
long long OH_NativeXComponent_TouchPoint::timeStamp = 0

Description:

Timestamp of the current touch event.

timeStamp 2/2

复制代码
long long OH_NativeXComponent_TouchEvent::timeStamp = 0

Description:

Timestamp of the current touch event.

touchPoints

复制代码
OH_NativeXComponent_TouchPoint OH_NativeXComponent_TouchEvent::touchPoints[OH_MAX_TOUCH_POINTS_NUMBER]

Description:

Array of the current touch points.

type 1/2

复制代码
OH_NativeXComponent_TouchEventType OH_NativeXComponent_TouchPoint::type = OH_NativeXComponent_TouchEventType::OH_NATIVEXCOMPONENT_UNKNOWN

Description:

Touch type of the touch event.

type 2/2

复制代码
OH_NativeXComponent_TouchEventType OH_NativeXComponent_TouchEvent::type = OH_NativeXComponent_TouchEventType::OH_NATIVEXCOMPONENT_UNKNOWN

Description:

Touch type of the touch event.

x 1/2

复制代码
float OH_NativeXComponent_TouchPoint::x = 0.0

Description:

X coordinate of the touch point relative to the left edge of the element to touch.

x 2/2

复制代码
float OH_NativeXComponent_TouchEvent::x = 0.0

Description:

X coordinate of the touch point relative to the left edge of the element to touch.

y 1/2

复制代码
float OH_NativeXComponent_TouchPoint::y = 0.0

Description:

Y coordinate of the touch point relative to the upper edge of the element to touch.

y 2/2

复制代码
float OH_NativeXComponent_TouchEvent::y = 0.0

鸿蒙更多技术,结尾扫

Description:

Y coordinate of the touch point relative to the upper edge of the element to touch.

相关推荐
大锅盖127 分钟前
围绕夜航深蓝与霓虹青的跨境画卷构建 HarmonyOS ArkUI 出境旅行向导平台
华为·harmonyos
星核0penstarry9 小时前
试一试用gr.Workflow把AI多步骤串联变成可视化画布
人工智能·python·ai作画·api·ai编程·工作流·api聚合平台
骐骥19 小时前
学习:使用postMessage()建立应用侧与前端页面的数据通道
harmonyos·鸿蒙·jsbridge·postmessage·数据通道
VIP_CQCRE11 小时前
用 Ace Data Cloud 开启 AI 能力商业化:推广平台,或打造自己的白标 AI 平台
ai·api·mcp·ace data cloud·白标平台
HwJack2016 小时前
鸿蒙开发ArkData 全景与选型决策:三种存储到底用哪个
华为·harmonyos
czhm5717 小时前
基于 HarmonyOS ArkTS API 24,工具函数抽离业务计算逻辑,状态颜色判断解耦组件代码
harmonyos·arkts
lilian23317 小时前
HarmonyOS 7 新特性(九)|碰一碰精准分享与互动卡片
华为·harmonyos
lilian23317 小时前
HarmonyOS 7 新特性(十)|DevEco Code 与 DevEco CLI AI 开发提效
人工智能·华为·harmonyos
袁震18 小时前
HarmonyOS 应用包体积优化与上架自检实战:从 76.2MB 到 3.6MB
java·华为·性能优化·harmonyos
2501_9197490319 小时前
华为鸿蒙免费美食APP—小羊美食
华为·harmonyos·美食