• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Native XComponent
2
3
4## **Overview**
5
6**Description:**
7
8Describes 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.
9
10**Since:**
11
128
13
14**Version:**
15
161.0
17
18
19## **Summary**
20
21
22### Files
23
24  | File Name | Description |
25| -------- | -------- |
26| [native_interface_xcomponent.h](native__interface__xcomponent_8h.md) | Declares APIs for accessing a Native XComponent. |
27
28
29### Classes
30
31  | Classe Name | Description |
32| -------- | -------- |
33| [OH_NativeXComponent_TouchPoint](_o_h___native_x_component___touch_point.md) |  |
34| [OH_NativeXComponent_TouchEvent](_o_h___native_x_component___touch_event.md) |  |
35| [OH_NativeXComponent_Callback](_o_h___native_x_component___callback.md) | Registers the surface lifecycle and touch event callbacks. |
36
37
38### Macros
39
40  | Macro Name and Value | Description |
41| -------- | -------- |
42| **OH_NATIVE_XCOMPONENT_OBJ**   ("__NATIVE_XCOMPONENT_OBJ__") |  |
43
44
45### Typedefs
46
47  | Typedef Name | Description |
48| -------- | -------- |
49| OH_NativeXComponent | typedef&nbsp;struct&nbsp;OH_NativeXComponent<br/>Provides&nbsp;an&nbsp;encapsulated&nbsp;**OH_NativeXComponent**&nbsp;instance. |
50| OH_NativeXComponent_Callback | typedef&nbsp;struct&nbsp;OH_NativeXComponent_Callback<br/>Registers&nbsp;the&nbsp;surface&nbsp;lifecycle&nbsp;and&nbsp;touch&nbsp;event&nbsp;callbacks. |
51
52
53### Enumerations
54
55  | Enumeration&nbsp;Name | Description |
56| -------- | -------- |
57| {&nbsp;OH_NATIVEXCOMPONENT_RESULT_SUCCESS&nbsp;=&nbsp;0,&nbsp;OH_NATIVEXCOMPONENT_RESULT_FAILED&nbsp;=&nbsp;-1,&nbsp;OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER&nbsp;=&nbsp;-2&nbsp;} | Enumerates&nbsp;the&nbsp;API&nbsp;access&nbsp;states. |
58| OH_NativeXComponent_TouchEventType&nbsp;{&nbsp;&nbsp;&nbsp;OH_NATIVEXCOMPONENT_DOWN&nbsp;=&nbsp;0,&nbsp;OH_NATIVEXCOMPONENT_UP,&nbsp;OH_NATIVEXCOMPONENT_MOVE,&nbsp;OH_NATIVEXCOMPONENT_CANCEL,&nbsp;&nbsp;&nbsp;OH_NATIVEXCOMPONENT_UNKNOWN&nbsp;} |  |
59
60
61### Functions
62
63  | Function | Description |
64| -------- | -------- |
65| OH_NativeXComponent_GetXComponentId&nbsp;(OH_NativeXComponent&nbsp;\*component,&nbsp;char&nbsp;\*id,&nbsp;uint64_t&nbsp;\*size) | int32_t<br/>Obtains&nbsp;the&nbsp;ID&nbsp;of&nbsp;the&nbsp;ArkUI&nbsp;XComponent. |
66| OH_NativeXComponent_GetXComponentSize&nbsp;(OH_NativeXComponent&nbsp;\*component,&nbsp;const&nbsp;void&nbsp;\*window,&nbsp;uint64_t&nbsp;\*width,&nbsp;uint64_t&nbsp;\*height) | int32_t<br/>Obtains&nbsp;the&nbsp;size&nbsp;of&nbsp;the&nbsp;surface&nbsp;held&nbsp;by&nbsp;the&nbsp;ArkUI&nbsp;XComponent. |
67| OH_NativeXComponent_GetXComponentOffset&nbsp;(OH_NativeXComponent&nbsp;\*component,&nbsp;const&nbsp;void&nbsp;\*window,&nbsp;double&nbsp;\*x,&nbsp;double&nbsp;\*y) | int32_t<br/>Obtains&nbsp;the&nbsp;offset&nbsp;of&nbsp;the&nbsp;surface&nbsp;held&nbsp;by&nbsp;the&nbsp;ArkUI&nbsp;XComponent. |
68| OH_NativeXComponent_GetTouchEvent&nbsp;(OH_NativeXComponent&nbsp;\*component,&nbsp;const&nbsp;void&nbsp;\*window,&nbsp;OH_NativeXComponent_TouchEvent&nbsp;\*touchEvent) | int32_t<br/>Obtains&nbsp;the&nbsp;touch&nbsp;event&nbsp;dispatched&nbsp;by&nbsp;the&nbsp;ArkUI&nbsp;XComponent. |
69| OH_NativeXComponent_RegisterCallback&nbsp;(OH_NativeXComponent&nbsp;\*component,&nbsp;OH_NativeXComponent_Callback&nbsp;\*callback) | int32_t<br/>Registers&nbsp;a&nbsp;callback&nbsp;for&nbsp;this&nbsp;**OH_NativeXComponent**&nbsp;instance. |
70
71
72## **Details**
73
74
75## **Typedef**
76
77
78### OH_NativeXComponent
79
80
81```
82typedef struct OH_NativeXComponent OH_NativeXComponent
83```
84
85**Description:**
86
87Provides an encapsulated **OH_NativeXComponent** instance.
88
89
90### OH_NativeXComponent_Callback
91
92
93```
94typedef struct OH_NativeXComponent_Callback OH_NativeXComponent_Callback
95```
96
97**Description:**
98
99Registers the surface lifecycle and touch event callbacks.
100
101
102## **Enumeration Type**
103
104
105### anonymous enum
106
107
108```
109anonymous enum
110```
111
112**Description:**
113
114Enumerates the API access states.
115
116  | Enumerator | Description |
117| -------- | -------- |
118| OH_NATIVEXCOMPONENT_RESULT_SUCCESS | Success&nbsp;result. |
119| OH_NATIVEXCOMPONENT_RESULT_FAILED | Failed&nbsp;result. |
120| OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER | Invalid&nbsp;parameters. |
121
122
123### OH_NativeXComponent_TouchEventType
124
125
126```
127enum OH_NativeXComponent_TouchEventType
128```
129
130  | Enumerator | Description |
131| -------- | -------- |
132| OH_NATIVEXCOMPONENT_DOWN | Trigger&nbsp;a&nbsp;touch&nbsp;event&nbsp;when&nbsp;a&nbsp;finger&nbsp;is&nbsp;pressed. |
133| OH_NATIVEXCOMPONENT_UP | Trigger&nbsp;a&nbsp;touch&nbsp;event&nbsp;when&nbsp;a&nbsp;finger&nbsp;is&nbsp;lifted. |
134| OH_NATIVEXCOMPONENT_MOVE | Trigger&nbsp;a&nbsp;touch&nbsp;event&nbsp;when&nbsp;a&nbsp;finger&nbsp;moves&nbsp;on&nbsp;the&nbsp;screen&nbsp;in&nbsp;pressed&nbsp;state. |
135| OH_NATIVEXCOMPONENT_CANCEL | Trigger&nbsp;an&nbsp;event&nbsp;when&nbsp;a&nbsp;touch&nbsp;event&nbsp;is&nbsp;canceled. |
136| OH_NATIVEXCOMPONENT_UNKNOWN | Invalid&nbsp;touch&nbsp;type. |
137
138
139## **Function**
140
141
142### OH_NativeXComponent_GetTouchEvent()
143
144
145```
146int32_t OH_NativeXComponent_GetTouchEvent (OH_NativeXComponent * component, const void * window, OH_NativeXComponent_TouchEvent * touchEvent )
147```
148
149**Description:**
150
151Obtains the touch event dispatched by the ArkUI XComponent.
152
153**Parameters:**
154
155  | Name | Description |
156| -------- | -------- |
157| component | Indicates&nbsp;the&nbsp;pointer&nbsp;to&nbsp;this&nbsp;**OH_NativeXComponent**&nbsp;instance. |
158| window | Indicates&nbsp;the&nbsp;native&nbsp;window&nbsp;handler. |
159| touchEvent | Indicates&nbsp;the&nbsp;pointer&nbsp;to&nbsp;the&nbsp;current&nbsp;touch&nbsp;event. |
160
161**Returns:**
162
163Returns the status code of the execution.
164
165
166### OH_NativeXComponent_GetXComponentId()
167
168
169```
170int32_t OH_NativeXComponent_GetXComponentId (OH_NativeXComponent * component, char * id, uint64_t * size )
171```
172
173**Description:**
174
175Obtains the ID of the ArkUI XComponent.
176
177**Parameters:**
178
179  | Name | Description |
180| -------- | -------- |
181| component | Indicates&nbsp;the&nbsp;pointer&nbsp;to&nbsp;this&nbsp;**OH_NativeXComponent**&nbsp;instance. |
182| id | Indicates&nbsp;the&nbsp;char&nbsp;buffer&nbsp;to&nbsp;keep&nbsp;the&nbsp;ID&nbsp;of&nbsp;this&nbsp;**OH_NativeXComponent**&nbsp;instance.&nbsp;Note&nbsp;that&nbsp;a&nbsp;null-terminator&nbsp;will&nbsp;be&nbsp;appended&nbsp;to&nbsp;the&nbsp;char&nbsp;buffer,&nbsp;so&nbsp;the&nbsp;size&nbsp;of&nbsp;the&nbsp;char&nbsp;buffer&nbsp;should&nbsp;be&nbsp;at&nbsp;least&nbsp;as&nbsp;large&nbsp;as&nbsp;the&nbsp;size&nbsp;of&nbsp;the&nbsp;real&nbsp;id&nbsp;length&nbsp;plus&nbsp;1.&nbsp;It&nbsp;is&nbsp;recommended&nbsp;that&nbsp;the&nbsp;size&nbsp;of&nbsp;the&nbsp;char&nbsp;buffer&nbsp;be&nbsp;[OH_XCOMPONENT_ID_LEN_MAX&nbsp;+&nbsp;1]. |
183| size | Indicates&nbsp;the&nbsp;pointer&nbsp;to&nbsp;the&nbsp;length&nbsp;of&nbsp;**id**,&nbsp;which&nbsp;you&nbsp;can&nbsp;set&nbsp;and&nbsp;receive. |
184
185**Returns:**
186
187Returns the status code of the execution.
188
189
190### OH_NativeXComponent_GetXComponentOffset()
191
192
193```
194int32_t OH_NativeXComponent_GetXComponentOffset (OH_NativeXComponent * component, const void * window, double * x, double * y )
195```
196
197**Description:**
198
199Obtains the offset of the surface held by the ArkUI XComponent.
200
201**Parameters:**
202
203  | Name | Description |
204| -------- | -------- |
205| component | Indicates&nbsp;the&nbsp;pointer&nbsp;to&nbsp;this&nbsp;**OH_NativeXComponent**&nbsp;instance. |
206| window | Indicates&nbsp;the&nbsp;native&nbsp;window&nbsp;handler. |
207| x | Indicates&nbsp;the&nbsp;pointer&nbsp;to&nbsp;the&nbsp;x&nbsp;coordinate&nbsp;of&nbsp;the&nbsp;current&nbsp;surface. |
208| y | Indicates&nbsp;the&nbsp;pointer&nbsp;to&nbsp;the&nbsp;y&nbsp;coordinate&nbsp;of&nbsp;the&nbsp;current&nbsp;surface. |
209
210**Returns:**
211
212Returns the status code of the execution.
213
214
215### OH_NativeXComponent_GetXComponentSize()
216
217
218```
219int32_t OH_NativeXComponent_GetXComponentSize (OH_NativeXComponent * component, const void * window, uint64_t * width, uint64_t * height )
220```
221
222**Description:**
223
224Obtains the size of the surface held by the ArkUI XComponent.
225
226**Parameters:**
227
228  | Name | Description |
229| -------- | -------- |
230| component | Indicates&nbsp;the&nbsp;pointer&nbsp;to&nbsp;this&nbsp;**OH_NativeXComponent**&nbsp;instance. |
231| window | Indicates&nbsp;the&nbsp;native&nbsp;window&nbsp;handler. |
232| width | Indicates&nbsp;the&nbsp;pointer&nbsp;to&nbsp;the&nbsp;width&nbsp;of&nbsp;the&nbsp;current&nbsp;surface. |
233| height | Indicates&nbsp;the&nbsp;pointer&nbsp;to&nbsp;the&nbsp;height&nbsp;of&nbsp;the&nbsp;current&nbsp;surface. |
234
235**Returns:**
236
237Returns the status code of the execution.
238
239
240### OH_NativeXComponent_RegisterCallback()
241
242
243```
244int32_t OH_NativeXComponent_RegisterCallback (OH_NativeXComponent * component, OH_NativeXComponent_Callback * callback )
245```
246
247**Description:**
248
249Registers a callback for this **OH_NativeXComponent** instance.
250
251**Parameters:**
252
253  | Name | Description |
254| -------- | -------- |
255| component | Indicates&nbsp;the&nbsp;pointer&nbsp;to&nbsp;this&nbsp;**OH_NativeXComponent**&nbsp;instance. |
256| callback | Indicates&nbsp;the&nbsp;pointer&nbsp;to&nbsp;a&nbsp;surface&nbsp;lifecycle&nbsp;and&nbsp;touch&nbsp;event&nbsp;callback. |
257
258**Returns:**
259
260Returns the status code of the execution.
261
262
263## **Variable**
264
265
266### deviceId
267
268
269```
270int64_t OH_NativeXComponent_TouchEvent::deviceId = 0
271```
272
273**Description:**
274
275ID of the device where the current touch event is generated.
276
277
278### DispatchTouchEvent
279
280
281```
282void(* OH_NativeXComponent_Callback::DispatchTouchEvent) (OH_NativeXComponent *component, void *window)
283```
284
285**Description:**
286
287Called when a touch event is triggered.
288
289
290### force [1/2]
291
292
293```
294float OH_NativeXComponent_TouchPoint::force = 0.0
295```
296
297**Description:**
298
299Pressure of the current touch event.
300
301
302### force [2/2]
303
304
305```
306float OH_NativeXComponent_TouchEvent::force = 0.0
307```
308
309**Description:**
310
311Pressure of the current touch event.
312
313
314### id [1/2]
315
316
317```
318int32_t OH_NativeXComponent_TouchPoint::id = 0
319```
320
321**Description:**
322
323Unique identifier of a finger.
324
325
326### id [2/2]
327
328
329```
330int32_t OH_NativeXComponent_TouchEvent::id = 0
331```
332
333**Description:**
334
335Unique identifier of a finger.
336
337
338### isPressed
339
340
341```
342bool OH_NativeXComponent_TouchPoint::isPressed = false
343```
344
345**Description:**
346
347Whether the current point is pressed.
348
349
350### numPoints
351
352
353```
354uint32_t OH_NativeXComponent_TouchEvent::numPoints = 0
355```
356
357**Description:**
358
359Number of current touch points.
360
361
362### OnSurfaceChanged
363
364
365```
366void(* OH_NativeXComponent_Callback::OnSurfaceChanged) (OH_NativeXComponent *component, void *window)
367```
368
369**Description:**
370
371Called 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.
372
373
374### OnSurfaceCreated
375
376
377```
378void(* OH_NativeXComponent_Callback::OnSurfaceCreated) (OH_NativeXComponent *component, void *window)
379```
380
381**Description:**
382
383Called when the surface is created.
384
385
386### OnSurfaceDestroyed
387
388
389```
390void(* OH_NativeXComponent_Callback::OnSurfaceDestroyed) (OH_NativeXComponent *component, void *window)
391```
392
393**Description:**
394
395Called when the surface is destroyed.
396
397
398### screenX [1/2]
399
400
401```
402float OH_NativeXComponent_TouchPoint::screenX = 0.0
403```
404
405**Description:**
406
407X coordinate of the touch point relative to the left edge of the screen.
408
409
410### screenX [2/2]
411
412
413```
414float OH_NativeXComponent_TouchEvent::screenX = 0.0
415```
416
417**Description:**
418
419X coordinate of the touch point relative to the left edge of the screen.
420
421
422### screenY [1/2]
423
424
425```
426float OH_NativeXComponent_TouchPoint::screenY = 0.0
427```
428
429**Description:**
430
431Y coordinate of the touch point relative to the upper edge of the screen.
432
433
434### screenY [2/2]
435
436
437```
438float OH_NativeXComponent_TouchEvent::screenY = 0.0
439```
440
441**Description:**
442
443Y coordinate of the touch point relative to the upper edge of the screen.
444
445
446### size [1/2]
447
448
449```
450double OH_NativeXComponent_TouchPoint::size = 0.0
451```
452
453**Description:**
454
455Contact area between the finger pad and the screen.
456
457
458### size [2/2]
459
460
461```
462double OH_NativeXComponent_TouchEvent::size = 0.0
463```
464
465**Description:**
466
467Contact area between the finger pad and the screen.
468
469
470### timeStamp [1/2]
471
472
473```
474long long OH_NativeXComponent_TouchPoint::timeStamp = 0
475```
476
477**Description:**
478
479Timestamp of the current touch event.
480
481
482### timeStamp [2/2]
483
484
485```
486long long OH_NativeXComponent_TouchEvent::timeStamp = 0
487```
488
489**Description:**
490
491Timestamp of the current touch event.
492
493
494### touchPoints
495
496
497```
498OH_NativeXComponent_TouchPoint OH_NativeXComponent_TouchEvent::touchPoints[OH_MAX_TOUCH_POINTS_NUMBER]
499```
500
501**Description:**
502
503Array of the current touch points.
504
505
506### type [1/2]
507
508
509```
510OH_NativeXComponent_TouchEventType OH_NativeXComponent_TouchPoint::type = OH_NativeXComponent_TouchEventType::OH_NATIVEXCOMPONENT_UNKNOWN
511```
512
513**Description:**
514
515Touch type of the touch event.
516
517
518### type [2/2]
519
520
521```
522OH_NativeXComponent_TouchEventType OH_NativeXComponent_TouchEvent::type = OH_NativeXComponent_TouchEventType::OH_NATIVEXCOMPONENT_UNKNOWN
523```
524
525**Description:**
526
527Touch type of the touch event.
528
529
530### x [1/2]
531
532
533```
534float OH_NativeXComponent_TouchPoint::x = 0.0
535```
536
537**Description:**
538
539X coordinate of the touch point relative to the left edge of the element to touch.
540
541
542### x [2/2]
543
544
545```
546float OH_NativeXComponent_TouchEvent::x = 0.0
547```
548
549**Description:**
550
551X coordinate of the touch point relative to the left edge of the element to touch.
552
553
554### y [1/2]
555
556
557```
558float OH_NativeXComponent_TouchPoint::y = 0.0
559```
560
561**Description:**
562
563Y coordinate of the touch point relative to the upper edge of the element to touch.
564
565
566### y [2/2]
567
568
569```
570float OH_NativeXComponent_TouchEvent::y = 0.0
571```
572
573**Description:**
574
575Y coordinate of the touch point relative to the upper edge of the element to touch.
576