# FrameNode
**FrameNode** represents an entity node in the component tree. It can be used by a [NodeController](./js-apis-arkui-nodeController.md#nodecontroller) to mount a [BuilderNode](./js-apis-arkui-builderNode.md#buildernode) (that holds the FrameNode) to a [NodeContainer](arkui-ts/ts-basic-components-nodecontainer.md#nodecontainer) or mount a [RenderNode](./js-apis-arkui-renderNode.md#rendernode) to another FrameNode.
> **NOTE**
>
> The initial APIs of this module are supported since API version 11. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> **FrameNode** is not available in DevEco Studio Previewer.
>
> FrameNodes cannot be dragged.
## Modules to Import
```ts
import { FrameNode, LayoutConstraint, typeNode, NodeAdapter } from "@kit.ArkUI";
```
## FrameNode
### constructor
constructor(uiContext: UIContext)
Constructor used to create a FrameNode.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Parameters**
| Name | Type | Mandatory | Description |
| --------- | ----------------------------------------- | ---- | ---------------------------------- |
| uiContext | [UIContext](./js-apis-arkui-UIContext.md) | Yes | UI context required for creating a node. |
### getRenderNode
getRenderNode(): RenderNode | null
Obtains the RenderNode instance held in this FrameNode.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Return value**
| Type | Description |
| -------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
| [RenderNode](./js-apis-arkui-renderNode.md#rendernode) \| null | **RenderNode** instance. If the current FrameNode does not hold any RenderNode, **null** is returned. If the current FrameNode is a node created by a declarative component, **null** is returned. |
**Example**
```ts
import { NodeController, FrameNode } from '@kit.ArkUI';
class MyNodeController extends NodeController {
private rootNode: FrameNode | null = null;
makeNode(uiContext: UIContext): FrameNode | null {
this.rootNode = new FrameNode(uiContext);
const renderNode = this.rootNode.getRenderNode();
if (renderNode !== null) {
renderNode.size = { width: 100, height: 100 };
renderNode.backgroundColor = 0XFFFF0000;
}
return this.rootNode;
}
}
@Entry
@Component
struct Index {
private myNodeController: MyNodeController = new MyNodeController();
build() {
Row() {
NodeContainer(this.myNodeController)
}
}
}
```
### isModifiable12+
isModifiable(): boolean
Checks whether this FrameNode is modifiable.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Return value**
| Type | Description |
| ------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| boolean | Whether the current FrameNode is modifiable. When **false** is returned, the FrameNode does not support the **appendChild**, **insertChildAfter**, **removeChild**, and **clearChildren** operations. |
**Example**
See [Example of Node Operations](#example-of-node-operations).
### appendChild12+
appendChild(node: FrameNode): void
Appends a child node to this FrameNode. If this FrameNode is not modifiable, an exception is thrown.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ----------------------- | ---- | --------------------- |
| node | [FrameNode](#framenode) | Yes | Child node to append. **NOTE** The child node cannot be one created declaratively, which is not modifiable. Only declarative nodes obtained from a BuilderNode can be used as child nodes. If the child node does not meet the specifications, an exception is thrown. The FrameNode cannot have a parent node. Otherwise, an exception is thrown.|
**Error codes**
| ID | Error Message |
| -------- | -------------------------------- |
| 100021 | The FrameNode is not modifiable. |
**Example**
See [Example of Node Operations](#example-of-node-operations).
### insertChildAfter12+
insertChildAfter(child: FrameNode, sibling: FrameNode | null): void
Inserts a child node after the specified child node of this FrameNode. If this FrameNode is not modifiable, an exception is thrown.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ----------------------------------------- | ---- | ---------------------------------------------------------------------------- |
| child | [FrameNode](#framenode) | Yes | Child node to add. **NOTE** The child node cannot be a declarative node, that is, a FrameNode that cannot be modified. Only declarative nodes obtained from a BuilderNode can be used as child nodes. If the child node does not meet the specifications, an exception is thrown. The child node cannot have a parent node. Otherwise, an exception is thrown. |
| sibling | [FrameNode](#framenode) \| null | Yes | Node after which the new child node will be inserted. If this parameter is left empty, the new node is inserted before the first subnode. |
**Error codes**
| ID | Error Message |
| -------- | -------------------------------- |
| 100021 | The FrameNode is not modifiable. |
**Example**
See [Example of Node Operations](#example-of-node-operations).
### removeChild12+
removeChild(node: FrameNode): void
Deletes the specified child node from this FrameNode. If this FrameNode is not modifiable, an exception is thrown.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ----------------------- | ---- | ------------------ |
| node | [FrameNode](#framenode) | Yes | Child node to delete. |
**Error codes**
| ID | Error Message |
| -------- | -------------------------------- |
| 100021 | The FrameNode is not modifiable. |
**Example**
See [Example of Node Operations](#example-of-node-operations).
### clearChildren12+
clearChildren(): void
Clears all child nodes of this FrameNode. If this FrameNode is not modifiable, an exception is thrown.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Error codes**
| ID | Error Message |
| -------- | -------------------------------- |
| 100021 | The FrameNode is not modifiable. |
**Example**
See [Example of Node Operations](#example-of-node-operations).
### getChild12+
getChild(index: number): FrameNode | null
Obtains the child node in the specified position of this RenderNode.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | -------------------------- |
| index | number | Yes | Index of the child node to obtain. |
**Return value**
| Type | Description |
| ------------------------------- | ------------------------------------------------------------- |
| [FrameNode](#framenode) \| null | Child node obtained. If the FrameNode does not contain the specified child node, null is returned. |
**Example**
See [Example of Node Operations](#example-of-node-operations).
### getFirstChild12+
getFirstChild(): FrameNode | null
Obtains the first child node of this FrameNode.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Return value**
| Type | Description |
| ------------------------------- | --------------------------------------------------------- |
| [FrameNode](#framenode) \| null | First child node. If the FrameNode does not contain any child node, null is returned. |
**Example**
See [Example of Node Operations](#example-of-node-operations).
### getNextSibling12+
getNextSibling(): FrameNode | null
Obtains the next sibling node of this FrameNode.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Return value**
| Type | Description |
| ------------------------------- | ------------------------------------------------------------------------------------ |
| [FrameNode](#framenode) \| null | Next sibling node of the current FrameNode. If the FrameNode does not have the next sibling node, null is returned. |
**Example**
See [Example of Node Operations](#example-of-node-operations).
### getPreviousSibling12+
getPreviousSibling(): FrameNode | null
Obtains the previous sibling node of this FrameNode.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Return value**
| Type | Description |
| -------------------------------- | ------------------------------------------------------------------------------------ |
| [FrameNode](#framenode) \| null | Previous sibling node of the current FrameNode. If the FrameNode does not have the previous sibling node, null is returned. |
**Example**
See [Example of Node Operations](#example-of-node-operations).
### getParent12+
getParent(): FrameNode | null;
Obtains the parent node of this FrameNode.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Return value**
| Type | Description |
| -------------------------------- | -------------------------------------------------------------------- |
| [FrameNode](#framenode) \| null | Parent node of the current FrameNode. If the FrameNode does not contain a parent node, null is returned. |
**Example**
See [Example of Node Operations](#example-of-node-operations).
### getChildrenCount12+
getChildrenCount(): number;
Obtains the number of child nodes of this FrameNode.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Return value**
| Type | Description |
| -------- | ------------------------------- |
| number | Number of child nodes of the current FrameNode. |
**Example**
See [Example of Node Operations](#example-of-node-operations).
### getPositionToWindow12+
getPositionToWindow(): Position
Obtains the position offset of this FrameNode relative to the window.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Return value**
| Type | Description |
| -------- | ------------------------------- |
| [Position](./js-apis-arkui-graphics.md#position) | Position offset of the node relative to the window. |
**Example**
See [Example of Node Operations](#example-of-node-operations).
### getPositionToParent12+
getPositionToParent(): Position
Obtains the position offset of this FrameNode relative to the parent component.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Return value**
| Type | Description |
| -------------------------------------------------------------- | --------------------------------------------------------------------- |
| [Position](./js-apis-arkui-graphics.md#position) | Position offset of the node relative to the parent component. |
**Example**
See [Example of Node Operations](#example-of-node-operations).
### getPositionToScreen12+
getPositionToScreen(): Position
Obtains the position offset of this FrameNode relative to the screen.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Return value**
| Type | Description |
| -------- | ------------------------------- |
| [Position](./js-apis-arkui-graphics.md#position) | Position offset of the node relative to the screen. |
**Example**
See [Example of Node Operations](#example-of-node-operations).
### getPositionToParentWithTransform12+
getPositionToParentWithTransform(): Position
Obtains the position offset of this FrameNode relative to the parent component, taking into account drawing attributes such as **transform** and **translate**. The coordinates returned are the coordinates of the upper left corner during layout after transformation.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Return value**
| Type | Description |
| -------------------------------------------------------------- | --------------------------------------------------------------------- |
| [Position](./js-apis-arkui-graphics.md#position) | Position offset of the node relative to the parent component. If other drawing attributes (such as **transform** and **translate**) are set, the return value may slightly deviate due to the precision of floating point numbers. |
**Example**
See [Example of Node Operations](#example-of-node-operations).
### getPositionToWindowWithTransform12+
getPositionToWindowWithTransform(): Position
Obtains the position offset of this FrameNode relative to the window, taking into account drawing attributes such as **transform** and **translate**. The coordinates returned are the coordinates of the upper left corner during layout after transformation.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Return value**
| Type | Description |
| -------------------------------------------------------------- | --------------------------------------------------------------------- |
| [Position](./js-apis-arkui-graphics.md#position) | Position offset of the node relative to the window. If other drawing attributes (such as **transform** and **translate**) are set, the return value may slightly deviate due to the precision of floating point numbers. |
**Example**
See [Example of Node Operations](#example-of-node-operations).
### getPositionToScreenWithTransform12+
getPositionToScreenWithTransform(): Position
Obtains the position offset of this FrameNode relative to the screen, taking into account drawing attributes such as **transform** and **translate**. The coordinates returned are the coordinates of the upper left corner during layout after transformation.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Return value**
| Type | Description |
| -------------------------------------------------------------- | --------------------------------------------------------------------- |
| [Position](./js-apis-arkui-graphics.md#position) | Position offset of the node relative to the screen. If other drawing attributes (such as **transform** and **translate**) are set, the return value may slightly deviate due to the precision of floating point numbers. |
**Example**
See [Example of Node Operations](#example-of-node-operations).
### getMeasuredSize12+
getMeasuredSize(): Size
Obtains the measured size of this FrameNode.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Return value**
| Type | Description |
| -------------------------------------------------------------- | --------------------------------------------------------------------- |
| [Size](./js-apis-arkui-graphics.md#size) | Measured size of the node. |
**Example**
See [Example of Node Operations](#example-of-node-operations).
### getLayoutPosition12+
getLayoutPosition(): Position
Obtains the position offset of this FrameNode relative to the parent component after layout. The offset is the result of the parent component's layout on this node; therefore, the **offset** attribute that takes effect after layout and the **position** attribute that does not participate in layout do not affect this offset value.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Return value**
| Type | Description |
| -------------------------------------------------------------- | --------------------------------------------------------------------- |
| [Position](./js-apis-arkui-graphics.md#position) | Position offset relative to the parent component after layout. |
**Example**
See [Example of Node Operations](#example-of-node-operations).
### getUserConfigBorderWidth12+
getUserConfigBorderWidth(): Edges\
Obtains the border width set by the user.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Return value**
| Type | Description |
| -------------------------------------------------------------- | --------------------------------------------------------------------- |
| [Edges](./js-apis-arkui-graphics.md#edgest12)\<[LengthMetrics](./js-apis-arkui-graphics.md#lengthmetrics12)\> | Border width set by the user. |
**Example**
See [Example of Node Operations](#example-of-node-operations).
### getUserConfigPadding12+
getUserConfigPadding(): Edges\
Obtains the padding set by the user.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Return value**
| Type | Description |
| -------------------------------------------------------------- | --------------------------------------------------------------------- |
| [Edges](./js-apis-arkui-graphics.md#edgest12)\<[LengthMetrics](./js-apis-arkui-graphics.md#lengthmetrics12)\> | Padding set by the user. |
**Example**
See [Example of Node Operations](#example-of-node-operations).
### getUserConfigMargin12+
getUserConfigMargin(): Edges\
Obtains the margin set by the user.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Return value**
| Type | Description |
| -------------------------------------------------------------- | --------------------------------------------------------------------- |
| [Edges](./js-apis-arkui-graphics.md#edgest12)\<[LengthMetrics](./js-apis-arkui-graphics.md#lengthmetrics12)\> | Margin set by the user. |
**Example**
See [Example of Node Operations](#example-of-node-operations).
### getUserConfigSize12+
getUserConfigSize(): SizeT\
Obtains the width and height set by the user.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Return value**
| Type | Description |
| ------------------------------------------------------------ | ---------------- |
| [SizeT](./js-apis-arkui-graphics.md#sizett12)\<[LengthMetrics](./js-apis-arkui-graphics.md#lengthmetrics12)\> | Width and height set by the user. |
**Example**
See [Example of Node Operations](#example-of-node-operations).
### getId12+
getId(): string
Obtains the node ID set by the user (the [ID](./arkui-ts/ts-universal-attributes-component-id.md) set in the universal attributes).
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Return value**
| Type | Description |
| -------------------------------------------------------------- | --------------------------------------------------------------------- |
| string | Node ID set by the user (the [ID](./arkui-ts/ts-universal-attributes-component-id.md) set in the universal attributes). |
**Example**
See [Example of Node Operations](#example-of-node-operations).
### getUniqueId12+
getUniqueId(): number
Obtains the system-assigned unique ID of the node.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Return value**
| Type | Description |
| -------------------------------------------------------------- | --------------------------------------------------------------------- |
| number | System-assigned unique ID of the node. |
**Example**
See [Example of Node Operations](#example-of-node-operations).
### getNodeType12+
getNodeType(): string
Obtains the type of the node. Built-in component types are named after the components themselves, for example, the type of a **Button** component is Button. For custom components, if they have rendering content, their type is __Common__.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Return value**
| Type | Description |
| -------------------------------------------------------------- | --------------------------------------------------------------------- |
| string | Type of the node. |
**Example**
See [Example of Node Operations](#example-of-node-operations).
### getOpacity12+
getOpacity(): number
Obtains the opacity of the node. The minimum value is 0, and the maximum value is 1.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Return value**
| Type | Description |
| -------------------------------------------------------------- | --------------------------------------------------------------------- |
| number | Opacity of the node. |
**Example**
See [Example of Node Operations](#example-of-node-operations).
### isVisible12+
isVisible(): boolean
Obtains whether the node is visible.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Return value**
| Type | Description |
| -------------------------------------------------------------- | --------------------------------------------------------------------- |
| boolean | Whether the node is visible. |
**Example**
See [Example of Node Operations](#example-of-node-operations).
### isClipToFrame12+
isClipToFrame(): boolean
Obtains whether the node is clipped to the component area.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Return value**
| Type | Description |
| -------------------------------------------------------------- | --------------------------------------------------------------------- |
| boolean | Whether the node is clipped to the component area. |
**Example**
See [Example of Node Operations](#example-of-node-operations).
### isAttached12+
isAttached(): boolean
Obtains whether the node is mounted to the main node tree.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Return value**
| Type | Description |
| -------------------------------------------------------------- | --------------------------------------------------------------------- |
| boolean | Whether the node is mounted to the main node tree. |
**Example**
See [Example of Node Operations](#example-of-node-operations).
### getInspectorInfo12+
getInspectorInfo(): Object
Obtains the structure information of the node, which is consistent with what is found in DevEco Studio's built-in ArkUI Inspector tool.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Return value**
| Type | Description |
| -------------------------------------------------------------- | --------------------------------------------------------------------- |
| Object | Structure information of the node. |
**Example**
See [Example of Node Operations](#example-of-node-operations).
### getCustomProperty12+
getCustomProperty(name: string): Object | undefined
Obtains the component's custom property by its name.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ---------------------------------------------------- | ---- | ------------------------------------------------------------ |
| name | string | Yes | Name of the custom property. |
**Return value**
| Type | Description |
| -------------------------------------------------------------- | --------------------------------------------------------------------- |
| Object \| undefined | Value of the custom property. |
**Example**
See [Example of Node Operations](#example-of-node-operations).
### dispose12+
dispose(): void
Disposes of this FrameNode.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Example**
```ts
import { NodeController, FrameNode, BuilderNode } from '@kit.ArkUI';
@Component
struct TestComponent {
build() {
Column() {
Text('This is a BuilderNode.')
.fontSize(16)
.fontWeight(FontWeight.Bold)
}
.width('100%')
.backgroundColor(Color.Gray)
}
aboutToAppear() {
console.error('aboutToAppear');
}
aboutToDisappear() {
console.error('aboutToDisappear');
}
}
@Builder
function buildComponent() {
TestComponent()
}
class MyNodeController extends NodeController {
private rootNode: FrameNode | null = null;
private builderNode: BuilderNode<[]> | null = null;
makeNode(uiContext: UIContext): FrameNode | null {
this.rootNode = new FrameNode(uiContext);
this.builderNode = new BuilderNode(uiContext, { selfIdealSize: { width: 200, height: 100 } });
this.builderNode.build(new WrappedBuilder(buildComponent));
const rootRenderNode = this.rootNode.getRenderNode();
if (rootRenderNode !== null) {
rootRenderNode.size = { width: 200, height: 200 };
rootRenderNode.backgroundColor = 0xff00ff00;
rootRenderNode.appendChild(this.builderNode!.getFrameNode()!.getRenderNode());
}
return this.rootNode;
}
disposeFrameNode() {
if (this.rootNode !== null && this.builderNode !== null) {
this.rootNode.removeChild(this.builderNode.getFrameNode());
this.builderNode.dispose();
this.rootNode.dispose();
}
}
removeBuilderNode() {
const rootRenderNode = this.rootNode!.getRenderNode();
if (rootRenderNode !== null && this.builderNode !== null && this.builderNode.getFrameNode() !== null) {
rootRenderNode.removeChild(this.builderNode!.getFrameNode()!.getRenderNode());
}
}
}
@Entry
@Component
struct Index {
private myNodeController: MyNodeController = new MyNodeController();
build() {
Column({ space: 4 }) {
NodeContainer(this.myNodeController)
Button('FrameNode dispose')
.onClick(() => {
this.myNodeController.disposeFrameNode();
})
.width('100%')
}
}
}
```
### commonAttribute12+
get commonAttribute(): CommonAttribute
Obtains the **CommonAttribute** object held in this FrameNode for setting common attributes.
Note that only the attributes of a custom node can be modified.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Return value**
| Type | Description |
| -------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
| CommonAttribute | **CommonAttribute** object held in the current FrameNode for setting common attributes.|
> **NOTE**
>
> The visual representation of the FrameNode is similar to that of a [Stack](./arkui-ts/ts-container-stack.md) container that is aligned to the top start edge.
>
> For details about the supported attributes, see [CommonModifier](./arkui-ts/ts-universal-attributes-attribute-modifier.md#custom-modifier).
**Example**
See [Basic Event Example](#basic-event-example).
### commonEvent12+
get commonEvent(): UICommonEvent
Obtains the **UICommonEvent** object held in this FrameNode to set basic events. The set basic events will compete with declaratively defined events for event handling without overriding them. If two event callbacks are set at the same time, the callback for the declaratively defined event is prioritized.
In scenarios involving **LazyForEach**, where nodes may be destroyed and reconstructed, you need to reset or re-attach event listeners to the newly created nodes to ensure they respond to events correctly.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Return value**
| Type | Description |
| -------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
| [UICommonEvent](./arkui-ts/ts-uicommonevent.md#common-event-callback) | **UICommonEvent** object, which is used to set basic events. |
**Example**
See [Basic Event Example](#basic-event-example) and [Example of Using Basic Events in the LazyForEach Scenario](#example-of-using-basic-events-in-the-lazyforeach-scenario).
### onDraw12+
onDraw?(context: DrawContext): void
Called when this FrameNode performs content rendering.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ------------------------------------------------------ | ---- | ---------------- |
| context | [DrawContext](./js-apis-arkui-graphics.md#drawcontext) | Yes | Graphics drawing context. The self-drawing area cannot exceed the component's own size. |
**Example**
See [Example of Customizing a Node](#example-of-customizing-a-node).
### onMeasure12+
onMeasure(constraint: LayoutConstraint): void
Called when this FrameNode needs to determine its size. This API provides custom measurement and overrides the default measurement method.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ------------------------------------------------------ | ---- | ---------------- |
| constraint | [LayoutConstraint](#layoutconstraint12) | Yes | Layout constraints used by the component for measurement. |
**Example**
See [Example of Customizing a Node](#example-of-customizing-a-node).
### LayoutConstraint12+
Describes the layout constraints of the component.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
| Name | Type | Mandatory | Description |
| -------------- | ------ | ----- | ------------------------------------------ |
| maxSize | [Size](./js-apis-arkui-graphics.md#size) | Yes | Maximum size. |
| minSize | [Size](./js-apis-arkui-graphics.md#size) | Yes | Minimum size. |
| percentReference | [Size](./js-apis-arkui-graphics.md#size) | Yes | Size reference for calculating the percentage of a child node.
### onLayout12+
onLayout(position: Position): void
Called when this FrameNode needs to determine its layout. This API provides custom layout and overrides the default layout method. It can be used to specify how the FrameNode and its child nodes are positioned and sized within the layout.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ------------------------------------------------------ | ---- | ---------------- |
| position | [Position](./js-apis-arkui-graphics.md#position) | Yes | Position information used in layout. |
**Example**
See [Example of Customizing a Node](#example-of-customizing-a-node).
### setMeasuredSize12+
setMeasuredSize(size: Size): void
Sets the measured size of this FrameNode. The default unit is PX. If the configured width and height are negative numbers, the value is automatically set to 0.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ------------------------------------------------------ | ---- | ---------------- |
| size | [Size](./js-apis-arkui-graphics.md#size) | Yes | Measured size of the FrameNode. |
**Example**
See [Example of Customizing a Node](#example-of-customizing-a-node).
### setLayoutPosition12+
setLayoutPosition(position: Position): void
Sets the position of this FrameNode after layout. The default unit is PX.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ------------------------------------------------------ | ---- | ---------------- |
| position | [Position](./js-apis-arkui-graphics.md#position) | Yes | Position of the FrameNode after layout. |
**Example**
See [Example of Customizing a Node](#example-of-customizing-a-node).
### measure12+
measure(constraint: LayoutConstraint): void
Measures this FrameNode and calculates its size based on the layout constraints of the parent container. If the measurement method is overridden, the overridden method is called. It is recommended that this API be called in [onMeasure](#onmeasure12).
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ------------------------------------------------------ | ---- | ---------------- |
| constraint | [LayoutConstraint](#layoutconstraint12) | Yes | Parent container layout constraints used for measurement. |
**Example**
See [Example of Customizing a Node](#example-of-customizing-a-node).
### layout12+
layout(position: Position): void
Lays out this FrameNode, specifying the layout positions for the FrameNode and its child nodes. If the layout method is overridden, the overridden method is called. It is recommended that this API be called in [onLayout](#onlayout12).
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ------------------------------------------------------ | ---- | ---------------- |
| position | [Position](./js-apis-arkui-graphics.md#position) | Yes | Position information used in layout. |
**Example**
See [Example of Customizing a Node](#example-of-customizing-a-node).
### setNeedsLayout12+
setNeedsLayout(): void
Marks this FrameNode as needing layout, so that it will be relaid out in the next frame.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Example**
See [Example of Customizing a Node](#example-of-customizing-a-node).
### invalidate12+
invalidate(): void
Invalidates this FrameNode to trigger a re-rendering of the self-drawing content.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
### addComponentContent12+
addComponentContent\(content: ComponentContent\): void
Adds component content.
**Atomic service API**: This API can be used in atomic services since API version 12.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ------------------------------------------------------ | ---- | ---------------- |
| content | [ComponentContent](./js-apis-arkui-ComponentContent.md#componentcontent)\ | Yes | Component content to display on the FrameNode. |
```ts
import { NodeController, FrameNode, ComponentContent, typeNode } from '@kit.ArkUI';
@Builder
function buildText() {
Column() {
Text('hello')
.width(50)
.height(50)
.backgroundColor(Color.Yellow)
}
}
class MyNodeController extends NodeController {
makeNode(uiContext: UIContext): FrameNode | null {
let node = new FrameNode(uiContext)
node.commonAttribute.width(300).height(300).backgroundColor(Color.Red)
let col = typeNode.createNode(uiContext, "Column")
col.initialize({ space: 10 })
node.appendChild(col)
let row4 = typeNode.createNode(uiContext, "Row")
row4.attribute.width(200)
.height(200)
.borderWidth(1)
.borderColor(Color.Black)
.backgroundColor(Color.Green)
let component = new ComponentContent