From a3d66eb7af863d75ec688bfe0da4989d8084a3ee Mon Sep 17 00:00:00 2001 From: wujinhui Date: Sat, 29 Mar 2025 09:24:43 +0800 Subject: [PATCH] init builderNode Signed-off-by: wujinhui --- .../arkui/src/handwritten/BuilderNdoe.ts | 80 +++++++++++++++++++ arkoala-arkts/arkui/src/handwritten/index.ts | 1 + arkoala-arkts/arkui/types/index-full.d.ts | 24 ++++++ arkoala/arkui-types/index-full.d.ts | 24 ++++++ arkoala/arkui/src/handwritten/BuilderNdoe.ts | 80 +++++++++++++++++++ arkoala/arkui/src/handwritten/index.ts | 1 + 6 files changed, 210 insertions(+) create mode 100644 arkoala-arkts/arkui/src/handwritten/BuilderNdoe.ts create mode 100644 arkoala/arkui/src/handwritten/BuilderNdoe.ts diff --git a/arkoala-arkts/arkui/src/handwritten/BuilderNdoe.ts b/arkoala-arkts/arkui/src/handwritten/BuilderNdoe.ts new file mode 100644 index 000000000..88a43e000 --- /dev/null +++ b/arkoala-arkts/arkui/src/handwritten/BuilderNdoe.ts @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { PeerNode } from "../PeerNode"; +import { ArkComponentRootPeer, ArkRootPeer } from "../generated/peers/ArkStaticComponentsPeer"; +import { FrameNode, FrameNodeInternal, Size } from "../generated"; +import { createUiDetachedRoot, destroyUiDetachedRoot } from "../Application"; +import { KPointer } from "@koalaui/interop"; +export enum NodeRenderType { + RENDER_TYPE_DISPLAY = 0, + RENDER_TYPE_TEXTURE = 1, +} +export interface RenderOptions { + selfIdealSize?: Size; + type?: NodeRenderType; + surfaceId?: string; +} +export class WrappedBuilder { + constructor( + /** @memo */ + builder: (args: Args) => void + ) { + this.builder = builder; + } + /** @memo */ + builder?: (args: Args) => void; +} +export class BuilderNode { + private __options?: RenderOptions; + private __builder?: WrappedBuilder; + private __root?: PeerNode; + + constructor(options?: RenderOptions) { + this.__options = options; + } + build(builder: WrappedBuilder, arg?: Args): void { + this.__builder = builder; + createUiDetachedRoot(() => { + if (this.__root == null) { + let root = ArkComponentRootPeer.create(); + this.__root = root; + } else { + this.__root?.firstChild?.dispose(); + } + return this.__root!; + }, () => { + if (arg) { + this.__builder?.builder?.(arg); + } + }) + } + update(arg: Args): void { + if (this.__builder) { + this.build(this.__builder!, arg); + } + } + getFrameNode(): FrameNode | null { + if (!this.__root){ + return null; + }else { + let ptr:KPointer=this.__root!.peer.ptr; + let node = FrameNodeInternal.fromPtr(ptr); + return node; + } + } + dispose(): void { + if (this.__root) destroyUiDetachedRoot(this.__root!) + } +} \ No newline at end of file diff --git a/arkoala-arkts/arkui/src/handwritten/index.ts b/arkoala-arkts/arkui/src/handwritten/index.ts index d2bde379d..336cccb22 100644 --- a/arkoala-arkts/arkui/src/handwritten/index.ts +++ b/arkoala-arkts/arkui/src/handwritten/index.ts @@ -4,6 +4,7 @@ export * from "./ArkPageTransitionData" export * from "./Router" export * from "./ForeignFunctions" export * from "./resources" +export * from "./BuilderNdoe" // TODO: implement this diff --git a/arkoala-arkts/arkui/types/index-full.d.ts b/arkoala-arkts/arkui/types/index-full.d.ts index 4de299b58..c81307c8c 100644 --- a/arkoala-arkts/arkui/types/index-full.d.ts +++ b/arkoala-arkts/arkui/types/index-full.d.ts @@ -9009,6 +9009,30 @@ declare interface RawFileDescriptor { offset: number; length: number; } +declare enum NodeRenderType { + RENDER_TYPE_DISPLAY = 0, + RENDER_TYPE_TEXTURE = 1, +} +declare class RenderOptions { + selfIdealSize?: Size; + type?: NodeRenderType; + surfaceId?: string; +} +declare class WrappedBuilder { + constructor( + /** @memo */ + builder: (args: Args) => void + ); + /** @memo */ + builder: (args: Args) => void; +} +declare class BuilderNode { + constructor(options?: RenderOptions); + build(builder: WrappedBuilder, arg?: Args): void; + getFrameNode(): FrameNode | null; + update(arg: Args): void; + dispose(): void; +} declare const AbilityComponent: AbilityComponentInterface declare const AbilityComponentInstance: AbilityComponentAttribute declare const AlphabetIndexer: AlphabetIndexerInterface diff --git a/arkoala/arkui-types/index-full.d.ts b/arkoala/arkui-types/index-full.d.ts index 31f758598..3bff503fa 100644 --- a/arkoala/arkui-types/index-full.d.ts +++ b/arkoala/arkui-types/index-full.d.ts @@ -9087,6 +9087,30 @@ declare interface RawFileDescriptor { offset: number; length: number; } +declare enum NodeRenderType { + RENDER_TYPE_DISPLAY = 0, + RENDER_TYPE_TEXTURE = 1, +} +declare class RenderOptions { + selfIdealSize?: Size; + type?: NodeRenderType; + surfaceId?: string; +} +declare class WrappedBuilder { + constructor( + /** @memo */ + builder: (args: Args) => void + ); + /** @memo */ + builder: (args: Args) => void; +} +declare class BuilderNode { + constructor(options?: RenderOptions); + build(builder: WrappedBuilder, arg?: Args): void; + getFrameNode(): FrameNode | null; + update(arg: Args): void; + dispose(): void; +} declare const AbilityComponent: AbilityComponentInterface declare const AbilityComponentInstance: AbilityComponentAttribute declare const AlphabetIndexer: AlphabetIndexerInterface diff --git a/arkoala/arkui/src/handwritten/BuilderNdoe.ts b/arkoala/arkui/src/handwritten/BuilderNdoe.ts new file mode 100644 index 000000000..88a43e000 --- /dev/null +++ b/arkoala/arkui/src/handwritten/BuilderNdoe.ts @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { PeerNode } from "../PeerNode"; +import { ArkComponentRootPeer, ArkRootPeer } from "../generated/peers/ArkStaticComponentsPeer"; +import { FrameNode, FrameNodeInternal, Size } from "../generated"; +import { createUiDetachedRoot, destroyUiDetachedRoot } from "../Application"; +import { KPointer } from "@koalaui/interop"; +export enum NodeRenderType { + RENDER_TYPE_DISPLAY = 0, + RENDER_TYPE_TEXTURE = 1, +} +export interface RenderOptions { + selfIdealSize?: Size; + type?: NodeRenderType; + surfaceId?: string; +} +export class WrappedBuilder { + constructor( + /** @memo */ + builder: (args: Args) => void + ) { + this.builder = builder; + } + /** @memo */ + builder?: (args: Args) => void; +} +export class BuilderNode { + private __options?: RenderOptions; + private __builder?: WrappedBuilder; + private __root?: PeerNode; + + constructor(options?: RenderOptions) { + this.__options = options; + } + build(builder: WrappedBuilder, arg?: Args): void { + this.__builder = builder; + createUiDetachedRoot(() => { + if (this.__root == null) { + let root = ArkComponentRootPeer.create(); + this.__root = root; + } else { + this.__root?.firstChild?.dispose(); + } + return this.__root!; + }, () => { + if (arg) { + this.__builder?.builder?.(arg); + } + }) + } + update(arg: Args): void { + if (this.__builder) { + this.build(this.__builder!, arg); + } + } + getFrameNode(): FrameNode | null { + if (!this.__root){ + return null; + }else { + let ptr:KPointer=this.__root!.peer.ptr; + let node = FrameNodeInternal.fromPtr(ptr); + return node; + } + } + dispose(): void { + if (this.__root) destroyUiDetachedRoot(this.__root!) + } +} \ No newline at end of file diff --git a/arkoala/arkui/src/handwritten/index.ts b/arkoala/arkui/src/handwritten/index.ts index af522bc05..a3f301a01 100644 --- a/arkoala/arkui/src/handwritten/index.ts +++ b/arkoala/arkui/src/handwritten/index.ts @@ -15,5 +15,6 @@ export * from "./ArkNavPathStack" export * from "./ArkPageTransition" +export * from "./BuilderNdoe" export interface AttributeModifier {} export interface NavigationAttribute {} \ No newline at end of file -- Gitee