• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# NDK API Overview
2
3
4The ArkUI framework offers NDK APIs for building UIs with C/C++, including component creation, UI tree control, attribute configuration, and event handling. While ArkTS and the ArkUI declarative framework are recommended for most UI development, use the ArkUI NDK APIs when:
5
6
7- You need to dynamically create and mount UI components for bridging to your own UI framework.
8
9- You want to enhance UI performance by finely controlling component creation and attributes to reduce latency and handle high loads.
10
11- You aim to reuse C or C++ UI libraries developed by yourself or others.
12
13
14The ArkUI NDK APIs provide the following capabilities:
15
16
17- **Layout**
18
19  Layout defines the size and position of components on the UI. The ArkUI NDK APIs offer linear, stacking, flexbox, relative layouts, and scrollable and carousel containers.
20
21- **Component**
22
23  Components are essential for UI, shaping the appearance on the screen. They include both built-in components and custom components with user-defined layout and drawing behaviors. Built-in components, such as buttons, radio buttons, images, and text, can be quickly created and have their attributes and events set using the ArkUI NDK APIs. Customization capabilities for UI components encompass layout measurement and drawing, enabling the construction of distinctive UI components.
24
25- **Dialog box**
26
27  Dialog boxes are vital for UI interactions. ArkUI NDK APIs enable the creation and display of custom dialog boxes with user-defined content.
28
29- **Animation**
30
31  Animations are one of the key elements of UI. The ArkUI NDK provides explicit animation APIs for crafting property animations that enhance the user experience with efficient and sophisticated effects.
32
33- **Interaction event**
34
35  Interaction events are important for interactions between the UI and users. The ArkUI NDK allows users to interact with your application UI, with support for various universal events and gesture events. Universal events include touch events, mouse events, and focus events. Gesture events accept single gestures (tap, long press, pan, pinch, rotation, and swipe), and a combination of gestures.
36
37
38## Overall Architecture
39
40**Figure 1** Relationship between NDK APIs and the ArkTS declarative UI
41
42![en-us_image_0000001923986433](figures/en-us_image_0000001923986433.png)
43
44**Figure 2** Schematic diagram of component mounting through NDK APIs
45
46![NDK Access](figures/ndk_access.png)
47
48- The ArkTS declarative UI frontend and the NDK APIs both expose ArkUI's underlying capabilities. Compared with the ArkTS declarative UI frontend, NDK APIs not only strip away the declarative UI syntax such as state management but also streamline component capabilities, encapsulating the core functions of ArkUI components through C APIs.
49
50- NDK-created UI components must be mounted through ArkTS placeholder components. Once mounted, they coexist with ArkTS components on the same UI tree, following uniform layout and event-handling rules.
51
52
53## How to Develop
54
55Using the NDK for UI development involves the following tasks.
56
57
58| Task| Description|
59| -------- | -------- |
60| [Getting Started with the NDK](../napi/ndk-development-overview.md)| Introduces the suitable scenarios and essential knowledge for the NDK.|
61| [Integrating with ArkTS Pages](ndk-access-the-arkts-page.md)| Explains how to mount the NDK-developed UI onto ArkTS pages for rendering and display.|
62| [Listening for Component Events](ndk-listen-to-component-events.md)| Describes how to register event listeners for components and add gesture interactions.|
63| [Using Animations](ndk-use-animation.md)| Introduces how to add animations on the native side.|
64| [Building Layouts](ndk-loading-long-list.md) | Describes how to use container components to build layouts on the native side.|
65| [Building Dialog Boxes](ndk-build-pop-up-window.md)| Introduces how to build dialog boxes.|
66| [Building Custom Components](ndk-build-custom-components.md)| Describes how to build custom components with the NDK to achieve unique UI elements.|
67| [Embedding ArkTS Components](ndk-embed-arkts-components.md)| Explains how to build pages on the native side that include ArkTS components.|
68| [Integrating Accessibility Through XComponent](ndk-accessibility-xcomponent.md)| Describes how to connect third-party systems to the UI platform through **XComponent**.|
69| [Implementing Custom Drawing](arkts-user-defined-draw.md)| Describes how to use custom drawing capabilities to render custom content.|
70| [Querying and Operating Custom Nodes](ndk-node-query-operate.md) | Introduces how to query and operate custom nodes.|
71| [Launching EmbeddedUIExtensionAbility with EmbeddedComponent](ndk-embedded-component.md) | Introduces how to launch **EmbeddedUIExtensionAbility** with **EmbeddedComponent** on the native side. This is mainly used in modular development scenarios with process isolation requirements.|
72| [Using Text](ndk-styled-string.md) | Describes how to render styled text using the **Text** component and how to listen for text box events.|
73| [Ensuring Functionality in Multi-Instance Scenarios](ndk-scope-task.md) | Introduces how to ensure the normal functionality of API calls in NDK multi-threaded scenarios.|
74
75
76## Precautions
77
78When using NDK APIs to develop UIs, ensure that all UI API calls are made on the application's main thread to prevent multi-threading issues, which can lead to crashes.
79<!--no_check-->