Skip to main content

xcomponent_sys/
lib.rs

1// Native XComponent bindings
2//
3// ## When to Use
4//
5// NativeXComponent provides an instance for the <XComponent> at the native layer, which can be
6// used as a bridge for binding with the <XComponent> at the JS layer. The NDK APIs provided by the
7// <XComponent> depend on this instance. The provided APIs include those for obtaining a native
8// window, obtaining the layout or event information of the <XComponent>, registering the lifecycle
9// callbacks of the <XComponent>, and registering the callbacks for the touch, mouse, and key events
10// of the <XComponent>. You can use the provided APIs in the following scenarios:
11//
12//  * Register the lifecycle and event callbacks of the <XComponent>.
13//  * Initialize the environment, obtain the current state, and respond to various events via these callbacks.
14//  * Use the native window and EGL APIs to develop custom drawing content, and apply for and submit buffers to the graphics queue.
15//! Source:
16//!
17//! [English Documentation](https://docs.openharmony.cn/pages/v5.0/en/application-dev/ui/napi-xcomponent-guidelines.md)
18//! [Chinese Documentation](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/ui/napi-xcomponent-guidelines.md)
19//!
20//! ## Feature flags
21#![cfg_attr(
22    feature = "document-features",
23    cfg_attr(doc, doc = ::document_features::document_features!())
24)]
25#![cfg_attr(docsrs, feature(doc_cfg))]
26
27#[cfg(target_env = "ohos")]
28#[link(name = "ace_ndk.z")]
29extern "C" {}
30
31mod xcomponent_ffi;
32pub use xcomponent_ffi::*;
33
34#[cfg(feature = "arkui")]
35mod xcomponent_arkui_ffi;
36#[cfg(feature = "arkui")]
37pub use xcomponent_arkui_ffi::*;
38
39mod xcomponent_result_ffi;
40
41/// Enumerates the API access states.
42///
43/// Available since API 8.
44#[repr(transparent)]
45pub struct XcomponentResult(pub std::ffi::c_int);
46
47impl XcomponentResult {
48    pub const SUCCESS: Self = Self(0);
49    pub const FAILED: Self = Self(-1);
50    pub const BAD_PARAMETER: Self = Self(-2);
51}
52
53// assert that our handwritten binding matches the size of the generated binding.
54// needs to be updated when regenerating the bindings, since the bindgen type name
55// may change.
56#[allow(dead_code)]
57const ASSERT_SIZE_OK: () =
58    assert!(size_of::<XcomponentResult>() == size_of::<xcomponent_result_ffi::_bindgen_ty_14>());
59
60#[cfg(feature = "keyboard-types")]
61#[cfg_attr(docsrs, doc(cfg(feature = "keyboard-types")))]
62pub mod keyboard_types_compat;