目录

Custom Node Overview

Custom nodes in the ArkUI framework are node objects that provide basic capabilities of underlying entity nodes through APIs, and can be mixed and displayed with built-in components. The attachment and display of custom nodes depend on custom placeholder nodes. There are three types of custom nodes: FrameNode, RenderNode, and BuilderNode. The FrameNode represents a single custom component node, the RenderNode represents a streamlined render node, and the BuilderNode provides the capability to create and update built-in components and component trees.

Basic Concepts

Constraints

Custom Placeholder Nodes

Custom placeholder nodes, acting as built-in components, provide anchors for custom nodes in the built-in component tree, thereby allowing for a mixed display of custom nodes and built-in components.

Custom Component Node (FrameNode)

FrameNode represents the entity node of a component, with two main capabilities:

Custom Render Node (RenderNode)

The RenderNode, as a lightweight rendering node, only provides capabilities for setting rendering-related properties, custom drawing content, and node operations. It is suitable for custom scenarios that rely solely on the system's rendering and animation capabilities.

Custom Declarative Node (BuilderNode)

The BuilderNode uses a stateless UI method, the global custom builder function, which is decorated by @Builder, to generate a component tree where the nodes are built-in components. It is suitable for scenarios where a specific built-in component tree needs to be created based on the system capabilities for a mixed display with other custom nodes. Compared to built-in components, the BuilderNode offers the advantage of pre-creation and enables the control over the initiation of the creation process. Because it holds the actual node objects, the BuilderNode facilitates the synchronous reuse of nodes, and by combining with placeholder nodes, it can leverage FrameNodes and RenderNodes for display positioning.

Setting Custom Node Cross-Language Attributes

ArkUI supports creating imperative nodes using the ArkTS language on the frontend, that is, FrameNodes. It also allows for creating imperative nodes using the C language on the native side, and both types of nodes can be used together to build pages. For this scenario, ArkUI provides cross-language attribute setting for imperative nodes, meaning nodes created with ArkTS can have their attributes set on the native side, and nodes created in C can have their attributes set in ArkTS.

Dynamic Component Creation

In the ArkUI declarative development paradigm, common components need to be statically declared and built within the build method. The build logic is executed uniformly during page rendering, which cannot meet the requirements of flexible development scenarios such as on-demand generation at runtime, dynamic addition and deletion of components, pre-creation and reuse of components, and layout delivered from the server. To address this, ArkUI provides the dynamic component creation capability. Leveraging the underlying node and container capabilities such as FrameNode, BuilderNode, NodeController, and NodeContainer, components can be created, configured, laid out, bound to events, added, deleted, replaced, and partially updated in imperative mode at runtime.