diff --git a/.gitee/CODEOWNERS b/.gitee/CODEOWNERS index f102565db15ae5e24c2ca1e5e68c91e8d2beadbd..b8dbd327f88d900bdbb09a4c0611ee195a3eafd5 100644 --- a/.gitee/CODEOWNERS +++ b/.gitee/CODEOWNERS @@ -3171,6 +3171,9 @@ frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/Fra frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/RenderNode.ts @arkuiframework frameworks/core/interfaces/native/implementation/frame_node_accessor.cpp @arkuiframework frameworks/core/interfaces/native/implementation/frame_node_peer_impl.h @arkuiframework +frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/node_adapter/ @arkuiframework +frameworks/core/interfaces/native/ani/node_adapter_ani_modifier.cpp @arkuiframework +frameworks/core/interfaces/native/ani/node_adapter_ani_modifier.h @arkuiframework frameworks/core/interfaces/native/implementation/calendar_controller_accessor.cpp @arkui_image frameworks/core/interfaces/native/implementation/calendar_controller_peer.h @arkui_image diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/FrameNode.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/FrameNode.ts index 8d52e1db0d9427700e011e603827e86b349df0d0..dfdc77d80630cfe0690ab33481bd851f7638f85c 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/FrameNode.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/FrameNode.ts @@ -18,9 +18,9 @@ import { UIContextImpl } from "arkui/handwritten/UIContextImpl" import { Position, Edges, Size, LengthMetrics, SizeT } from "./Graphics" import { ArkUIGeneratedNativeModule } from "#components" import { - Finalizable, toPeerPtr, KPointer, MaterializedBase, nullptr, KSerializerBuffer, KUint8ArrayPtr, InteropNativeModule + Finalizable, toPeerPtr, KPointer, MaterializedBase, nullptr, KSerializerBuffer, KUint8ArrayPtr, pointer, NativeThunk } from "@koalaui/interop" -import { int32 } from "@koalaui/common" +import { finalizerRegister, int32 } from "@koalaui/common" import { Serializer } from "./component" import { ArkUIAniModule } from "arkui.ani" import { RenderNode, RenderNodeInternal } from "./RenderNode" @@ -105,6 +105,8 @@ import { JSBuilderNode } from "./BuilderNode" import { BusinessError } from '#external'; import { Resource } from 'global.resource'; import { ElementIdToCustomProperties } from './handwritten/CommonHandWritten' +import { ObjectLinkDecoratedVariable } from "./stateManagement/decoratorImpl/decoratorObjectLink" +import { TapGesture } from "@component_handwritten/gesture" export interface CrossLanguageOptions { attributeSetting?: boolean; @@ -164,12 +166,17 @@ export class FrameNode implements MaterializedBase { public _nodeId: number = -1; protected _commonAttribute: CommonAttribute | undefined = undefined; protected _gestureEvent: UIGestureEvent | undefined = undefined; - nodeType_?: string | undefined = undefined; + public nodeType_?: string | undefined = undefined; + private nodeAdapterRef_ ?: NodeAdapter; getType(): string { return 'CustomFrameNode'; } + setAdapterRef(adapter :NodeAdapter | undefined){ + this.nodeAdapterRef_ = adapter; + } + checkValid(node: FrameNode): boolean { return true; } @@ -1029,6 +1036,10 @@ abstract class TypedFrameNode extends FrameNode { attrCreator_: (node: FrameNode, type: ModifierType) => T type_: string = ""; + public isModifiable() : boolean { + return true; + } + constructor(uiContext: UIContext, type: string, attrCreator: (node: FrameNode, type: ModifierType) => T) { super(uiContext, type, nullptr); this.attrCreator_ = attrCreator; @@ -1814,3 +1825,202 @@ export namespace typeNode { }); } } + +class NodeAdapterThunk extends NativeThunk { + private ptr?: pointer; + + constructor(obj: pointer) { + super(obj, nullptr); + } + + clean(): void { + if (this.ptr) { + ArkUIAniModule._NodeAdapter_Dispose(this.ptr!); + } + } +} + +class NodeAdapterFinalizable extends Finalizable { + ptr: pointer + finalizer: pointer + cleaner: NativeThunk | undefined = undefined + managed: boolean + + constructor(ptr: pointer) { + super(ptr, nullptr, false); + this.init(ptr) + } + + init(ptr: pointer): void { + this.ptr = ptr + const thunk = new NodeAdapterThunk(ptr) + finalizerRegister(this, thunk) + this.cleaner = thunk + } +} + +export class NodeAdapter implements MaterializedBase { + private peer?: Finalizable | undefined = undefined; + private attachedNodeRef_?: WeakRef; + private count_: number = 0; + private nodeRefs_: Array = new Array(); + + onDisposeChild(index: number, node: FrameNode) { + + } + + onUpdateChild(index: number, node: FrameNode) { + + } + + onCreateChild(index: number): FrameNode { + return new FrameNode(undefined); + } + + constructor() { + const retval = ArkUIAniModule._NodeAdapter_Construct(this); + this.peer = new NodeAdapterFinalizable(retval); + } + getPeer(): Finalizable | undefined { + return this.peer; + } + + dispose() { + let hostNode = this.attachedNodeRef_?.deref(); + if (hostNode !== undefined) { + NodeAdapter.detachNodeAdapter(hostNode); + } + if (this.peer?.ptr) { + this.peer?.close(); + } + } + + set totalNodeCount(count: number) { + if (count < 0) { + return; + } + ArkUIAniModule._NodeAdapter_SetTotalNodeCount(this.peer!.ptr!, count); + this.count_ = count; + } + + get totalNodeCount() { + return this.count_; + } + + reloadAllItems() { + ArkUIAniModule._NodeAdapter_NotifyItemReloaded(this.peer!.ptr!); + } + reloadItem(start: number, count: number) { + if (start < 0 || count < 0) { + return; + } + ArkUIAniModule._NodeAdapter_NotifyItemChanged(this.peer!.ptr!, start, count); + } + removeItem(start: number, count: number) { + if (start < 0 || count < 0) { + return; + } + ArkUIAniModule._NodeAdapter_NotifyItemRemoved(this.peer!.ptr!, start, count); + } + insertItem(start: number, count: number) { + if (start < 0 || count < 0) { + return; + } + ArkUIAniModule._NodeAdapter_NotifyItemInserted(this.peer!.ptr!, start, count); + } + moveItem(from: number, to: number) { + if (from < 0 || to < 0) { + return; + } + ArkUIAniModule._NodeAdapter_NotifyItemMoved(this.peer!.ptr!, from, to); + } + getAllAvailableItems(): Array { + let result = new Array(); + let nodes = ArkUIAniModule._NodeAdapter_GetAllItems(this.peer!.ptr!); + if (nodes !== undefined) { + nodes.forEach((nodeId: number, index: number, arr: Array) => { + if (FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.has(nodeId)) { + let frameNode = FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.get(nodeId); + result.push(frameNode!); + } + }); + } + return result; + } + onAttachToNodePtr(nodeId: number) { + if (FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.has(nodeId)) { + let frameNode = FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.get(nodeId); + if (frameNode === undefined) { + return; + } + frameNode.setAdapterRef(this); + this.attachedNodeRef_ = new WeakRef(frameNode); + if (this.onAttachToNode !== undefined) { + this.onAttachToNode(frameNode); + } + } + } + onAttachToNode(frameNode: FrameNode): void { + + } + onDetachFromNode(): void { + + } + onDetachFromNodePtr() { + if (this === undefined) { + return; + } + if (this.onDetachFromNode !== undefined) { + this.onDetachFromNode(); + } + let attachedNode = this.attachedNodeRef_?.deref(); + if (attachedNode !== undefined) { + attachedNode.setAdapterRef(undefined); + } + this.nodeRefs_.splice(0, this.nodeRefs_.length); + } + onCreateNewNodePtr(index: number): pointer { + if (this.onCreateChild !== undefined) { + let frameNode = this.onCreateChild(index); + if (!this.nodeRefs_.find((node) => { + return node === frameNode; + })) { + this.nodeRefs_.push(frameNode); + } + if (frameNode?.peer?.ptr) { + return frameNode!.peer!.ptr!; + } + } + return nullptr; + } + + onDisposeNodePtr(index: number, nodeId: number) { + if (FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.has(nodeId)) { + let frameNode = FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.get(nodeId); + if (this.onDisposeChild !== undefined && frameNode !== undefined) { + this.onDisposeChild(index, frameNode); + let index2 = this.nodeRefs_.indexOf(frameNode); + if (index2 > -1) { + this.nodeRefs_.splice(index2, 1); + } + } + } + } + + onUpdateNodePtr(index: number, nodeId: number) { + if (FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.has(nodeId)) { + let frameNode = FrameNodeFinalizationRegisterProxy.ElementIdToOwningFrameNode_.get(nodeId); + if (this.onUpdateChild !== undefined && frameNode !== undefined) { + this.onUpdateChild(index, frameNode!); + } + } + } + + static detachNodeAdapter(node: FrameNode) { + ArkUIAniModule._NodeAdapter_DetachNodeAdapter(node.peer!.ptr!); + } + + static attachNodeAdapter(adapter: NodeAdapter, node: FrameNode) { + return ArkUIAniModule._NodeAdapter_AttachNodeAdapter(adapter.peer!.ptr!, node.peer!.ptr!); + } +} diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/arkts/ArkUIAniModule.ts b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/arkts/ArkUIAniModule.ts index b4292cf0529eb69bc35c385a61d7bf580fbc7a1f..d6f1c2001c74c08fc184a74be14b95e52bfd69d4 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/arkts/ArkUIAniModule.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/arkts/ArkUIAniModule.ts @@ -32,7 +32,7 @@ import { componentSnapshot } from "@ohos/arkui/componentSnapshot" import { DrawableDescriptor } from "@ohos.arkui.drawableDescriptor" import { uiObserver } from "@ohos/arkui/observer" import { SymbolGlyphModifier } from "../../SymbolGlyphModifier" - +import { NodeAdapter } from '../../FrameNode' export class ArkUIAniModule { static { loadLibrary('arkoala_native_ani') @@ -308,4 +308,18 @@ export class ArkUIAniModule { onThemeScopeDestroy: () => void ): void; native static _ApplyParentThemeScopeId(self: KPointer, parent: KPointer): void + + //NodeAdapter + native static _NodeAdapter_Construct( nodeAdapter : NodeAdapter): KPointer + native static _NodeAdapter_DetachNodeAdapter(ptr : KPointer) : void + native static _NodeAdapter_AttachNodeAdapter(ptr : KPointer, node: KPointer) : boolean + native static _NodeAdapter_Dispose(ptr : KPointer) : void + native static _NodeAdapter_SetTotalNodeCount(ptr : KPointer, count : number) : void + native static _NodeAdapter_NotifyItemReloaded(ptr : KPointer) : void + native static _NodeAdapter_NotifyItemChanged(ptr : KPointer, start : number, count : number) : void + native static _NodeAdapter_NotifyItemRemoved(ptr : KPointer, start : number, count : number) : void + native static _NodeAdapter_NotifyItemInserted(ptr : KPointer, start : number, count : number) : void + native static _NodeAdapter_NotifyItemMoved(ptr : KPointer, from : number, to : number) : void + native static _NodeAdapter_GetAllItems(ptr : KPointer) : Array + } diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/BUILD.gn b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/BUILD.gn index 066deee4ca8fbbca6175d19501158d222c4f8c6f..8dc909025d8613498e9c45a6e252a68ca7820879 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/BUILD.gn +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/BUILD.gn @@ -65,6 +65,7 @@ ohos_shared_library("arkoala_native_ani") { "web/web_module_methods.cpp", "xcomponent/xcomponent_module_methods.cpp", "condition_scope/condition_scope.cpp", + "node_adapter/node_adapter_module.cpp", ] external_deps = [ diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/module.cpp b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/module.cpp index e5a884682075ce5b80359c1dee0bb9198bea6f99..246e6851f7abb6808f5e83d0f382ac6365521e70 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/module.cpp +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/module.cpp @@ -44,6 +44,7 @@ #include "xcomponent/xcomponent_module_methods.h" #include "condition_scope/condition_scope.h" #include "utils/ani_trace.h" +#include "node_adapter/node_adapter_module.h" ANI_EXPORT ani_status ANI_Constructor(ani_vm* vm, uint32_t* result) { @@ -1074,6 +1075,60 @@ ANI_EXPORT ani_status ANI_Constructor(ani_vm* vm, uint32_t* result) nullptr, reinterpret_cast(OHOS::Ace::Ani::ApplyParentThemeScopeId) }, + ani_native_function { + "_NodeAdapter_Construct", + nullptr, + reinterpret_cast(OHOS::Ace::Ani::NodeAdapterConstruct) + }, + ani_native_function { + "_NodeAdapter_DetachNodeAdapter", + nullptr, + reinterpret_cast(OHOS::Ace::Ani::NodeAdapterDetachNodeAdapter) + }, + ani_native_function { + "_NodeAdapter_AttachNodeAdapter", + nullptr, + reinterpret_cast(OHOS::Ace::Ani::NodeAdapterAttachNodeAdapter) + }, + ani_native_function { + "_NodeAdapter_Dispose", + nullptr, + reinterpret_cast(OHOS::Ace::Ani::NodeAdapterDispose) + }, + ani_native_function { + "_NodeAdapter_SetTotalNodeCount", + nullptr, + reinterpret_cast(OHOS::Ace::Ani::NodeAdapterSetTotalNodeCount) + }, + ani_native_function { + "_NodeAdapter_NotifyItemReloaded", + nullptr, + reinterpret_cast(OHOS::Ace::Ani::NodeAdapterNotifyItemReloaded) + }, + ani_native_function { + "_NodeAdapter_NotifyItemChanged", + nullptr, + reinterpret_cast(OHOS::Ace::Ani::NodeAdapterNotifyItemChanged) + }, + ani_native_function { + "_NodeAdapter_NotifyItemRemoved", + nullptr, + reinterpret_cast(OHOS::Ace::Ani::NodeAdapterNotifyItemRemoved) + }, + ani_native_function { + "_NodeAdapter_NotifyItemInserted", + nullptr, + reinterpret_cast(OHOS::Ace::Ani::NodeAdapterNotifyItemInserted) + }, + ani_native_function { + "_NodeAdapter_NotifyItemMoved", + nullptr, + reinterpret_cast(OHOS::Ace::Ani::NodeAdapterNotifyItemMoved) + }, + ani_native_function { "_NodeAdapter_GetAllItems", + nullptr, + reinterpret_cast(OHOS::Ace::Ani::NodeAdapterGetAllItems) + }, }; auto bindRst = env->Class_BindNativeMethods(cls, methods.data(), methods.size()); diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/node_adapter/node_adapter_module.cpp b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/node_adapter/node_adapter_module.cpp new file mode 100644 index 0000000000000000000000000000000000000000..41627cc6e69294011a44697864925aa1bd5ff7ca --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/node_adapter/node_adapter_module.cpp @@ -0,0 +1,189 @@ +/* + * 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. + */ + +#include "node_adapter_module.h" + +#include +#include + +#include "animation/ani_global_reference.h" +#include "load.h" +#include "log/log.h" + +namespace OHOS::Ace::Ani { +ani_long NodeAdapterConstruct(ani_env* env, [[maybe_unused]] ani_object aniClass, ani_object nodeAdapter) +{ + const auto* modifier = GetNodeAniModifier(); + if (!modifier) { + return 0; + } + auto nodeAdapterRef = std::make_shared(env, nodeAdapter); + auto onAttachToNode = [env, nodeAdapterRef](ani_double nodeId) { + env->Object_CallMethodByName_Void( + reinterpret_cast(nodeAdapterRef->GetValue()), "onAttachToNodePtr", nullptr, nodeId); + }; + auto onDetachFromNode = [env, nodeAdapterRef]() { + env->Object_CallMethodByName_Void( + reinterpret_cast(nodeAdapterRef->GetValue()), "onDetachFromNodePtr", nullptr); + }; + auto onGetId = [env, nodeAdapterRef](ani_double index) -> int32_t { + ani_double nodeId = index; + ani_double id; + env->Object_CallMethodByName_Double( + reinterpret_cast(nodeAdapterRef->GetValue()), "onGetChildId", nullptr, &id, nodeId); + return static_cast(id); + }; + auto onCreateChild = [env, nodeAdapterRef](ani_double index) -> ani_long { + ani_double nodeId = index; + ani_long node; + env->Object_CallMethodByName_Long( + reinterpret_cast(nodeAdapterRef->GetValue()), "onCreateNewNodePtr", nullptr, &node, nodeId); + return node; + }; + auto onDisposeChild = [env, nodeAdapterRef](ani_double node, ani_double id) { + env->Object_CallMethodByName_Void( + reinterpret_cast(nodeAdapterRef->GetValue()), "onDisposeNodePtr", nullptr, id, node); + }; + + auto onUpdateChild = [env, nodeAdapterRef](ani_double node, ani_double id) { + env->Object_CallMethodByName_Void( + reinterpret_cast(nodeAdapterRef->GetValue()), "onUpdateNodePtr", nullptr, id, node); + }; + + NodeAdapterInfo info = { .onAttachToNode = std::move(onAttachToNode), + .onDetachFromNode = std::move(onDetachFromNode), + .onGetId = std::move(onGetId), + .onCreateChild = std::move(onCreateChild), + .onDisposeChild = std::move(onDisposeChild), + .onUpdateChild = std::move(onUpdateChild) }; + ani_long node = modifier->getNodeAdapterAniModifier()->nodeAdapterConstruct(std::move(info)); + return node; +} + +void NodeAdapterDetachNodeAdapter(ani_env* env, [[maybe_unused]] ani_object aniClass, ani_long ptr) +{ + const auto* modifier = GetNodeAniModifier(); + if (!modifier) { + return; + } + modifier->getNodeAdapterAniModifier()->nodeAdapterDetachNodeAdapter(ptr); +} + +ani_boolean NodeAdapterAttachNodeAdapter( + ani_env* env, [[maybe_unused]] ani_object aniClass, ani_long ptr, ani_long node) +{ + const auto* modifier = GetNodeAniModifier(); + if (!modifier) { + return false; + } + return modifier->getNodeAdapterAniModifier()->nodeAdapterAttachNodeAdapter(ptr, node); +} + +void NodeAdapterDispose(ani_env* env, [[maybe_unused]] ani_object aniClass, ani_long ptr) +{ + const auto* modifier = GetNodeAniModifier(); + if (!modifier) { + return; + } + modifier->getNodeAdapterAniModifier()->nodeAdapterDispose(ptr); +} + +void NodeAdapterNotifyItemReloaded(ani_env* env, [[maybe_unused]] ani_object aniClass, ani_long ptr) +{ + const auto* modifier = GetNodeAniModifier(); + if (!modifier) { + return; + } + modifier->getNodeAdapterAniModifier()->nodeAdapterNotifyItemReloaded(ptr); +} + +void NodeAdapterSetTotalNodeCount(ani_env* env, [[maybe_unused]] ani_object aniClass, ani_long ptr, ani_double count) +{ + const auto* modifier = GetNodeAniModifier(); + if (!modifier) { + return; + } + modifier->getNodeAdapterAniModifier()->nodeAdapterSetTotalNodeCount(ptr, count); +} + +void NodeAdapterNotifyItemChanged( + ani_env* env, [[maybe_unused]] ani_object aniClass, ani_long ptr, ani_double start, ani_double count) +{ + const auto* modifier = GetNodeAniModifier(); + if (!modifier) { + return; + } + + modifier->getNodeAdapterAniModifier()->nodeAdapterNotifyItemChanged(ptr, start, count); +} + +void NodeAdapterNotifyItemRemoved( + ani_env* env, [[maybe_unused]] ani_object aniClass, ani_long ptr, ani_double start, ani_double count) +{ + const auto* modifier = GetNodeAniModifier(); + if (!modifier) { + return; + } + + modifier->getNodeAdapterAniModifier()->nodeAdapterNotifyItemRemoved(ptr, start, count); +} + +void NodeAdapterNotifyItemInserted( + ani_env* env, [[maybe_unused]] ani_object aniClass, ani_long ptr, ani_double start, ani_double count) +{ + const auto* modifier = GetNodeAniModifier(); + if (!modifier) { + return; + } + + modifier->getNodeAdapterAniModifier()->nodeAdapterNotifyItemInserted(ptr, start, count); +} + +void NodeAdapterNotifyItemMoved( + ani_env* env, [[maybe_unused]] ani_object aniClass, ani_long ptr, ani_double from, ani_double to) +{ + const auto* modifier = GetNodeAniModifier(); + if (!modifier) { + return; + } + + modifier->getNodeAdapterAniModifier()->nodeAdapterNotifyItemMoved(ptr, from, to); +} + +ani_array_double NodeAdapterGetAllItems(ani_env* env, [[maybe_unused]] ani_object aniClass, ani_long ptr) +{ + const auto* modifier = GetNodeAniModifier(); + if (!modifier) { + return {}; + } + AniDoubleArray items = modifier->getNodeAdapterAniModifier()->nodeAdapterGetAllItems(ptr); + ani_array_double result; + auto size = items.size; + if (size == 0) { + delete[] items.data; + return nullptr; + } + if (env->Array_New_Double(size, &result) != ANI_OK) { + delete[] items.data; + return result; + } + if (ANI_OK != env->Array_SetRegion_Double(result, 0, size, items.data)) { + delete[] items.data; + return nullptr; + } + delete[] items.data; + return result; +} +} // namespace OHOS::Ace::Ani diff --git a/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/node_adapter/node_adapter_module.h b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/node_adapter/node_adapter_module.h new file mode 100644 index 0000000000000000000000000000000000000000..768e299df3801b3bab8b38526949054178182a16 --- /dev/null +++ b/frameworks/bridge/arkts_frontend/koala_projects/arkoala-arkts/arkui-ohos/src/ani/native/node_adapter/node_adapter_module.h @@ -0,0 +1,40 @@ +/* + * 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. + */ + +#ifndef KOALA_PROJECTS_ARKOALA_ARKTS_ARKUI_OHOS_ANI_NATIVE_NODE_ADAPTER_MODULE +#define KOALA_PROJECTS_ARKOALA_ARKTS_ARKUI_OHOS_ANI_NATIVE_NODE_ADAPTER_MODULE + +#include "ani.h" + +namespace OHOS::Ace::Ani { +ani_long NodeAdapterConstruct(ani_env* env, [[maybe_unused]] ani_object aniClass, ani_object nodeAdapter); +void NodeAdapterDetachNodeAdapter(ani_env* env, [[maybe_unused]] ani_object aniClass, ani_long ptr); +ani_boolean NodeAdapterAttachNodeAdapter( + ani_env* env, [[maybe_unused]] ani_object aniClass, ani_long ptr, ani_long node); +void NodeAdapterDispose(ani_env* env, [[maybe_unused]] ani_object aniClass, ani_long ptr); +void NodeAdapterNotifyItemReloaded(ani_env* env, [[maybe_unused]] ani_object aniClass, ani_long ptr); +void NodeAdapterSetTotalNodeCount(ani_env* env, [[maybe_unused]] ani_object aniClass, ani_long ptr, ani_double count); +void NodeAdapterNotifyItemChanged( + ani_env* env, [[maybe_unused]] ani_object aniClass, ani_long ptr, ani_double start, ani_double count); +void NodeAdapterNotifyItemRemoved( + ani_env* env, [[maybe_unused]] ani_object aniClass, ani_long ptr, ani_double start, ani_double count); +void NodeAdapterNotifyItemInserted( + ani_env* env, [[maybe_unused]] ani_object aniClass, ani_long ptr, ani_double start, ani_double count); +void NodeAdapterNotifyItemMoved( + ani_env* env, [[maybe_unused]] ani_object aniClass, ani_long ptr, ani_double from, ani_double to); +ani_array_double NodeAdapterGetAllItems(ani_env* env, [[maybe_unused]] ani_object aniClass, ani_long ptr); +} // namespace OHOS::Ace::Ani + +#endif // KOALA_PROJECTS_ARKOALA_ARKTS_ARKUI_OHOS_ANI_NATIVE_NODE_ADAPTER_MODULE diff --git a/frameworks/bridge/arkts_frontend/koala_projects/interop/src/arkts/Finalizable.ts b/frameworks/bridge/arkts_frontend/koala_projects/interop/src/arkts/Finalizable.ts index 53ef973f36e0a210d3c597c967268d3e7933e773..d767c78fd0cb944a77388b82adfadd0089e21e16 100644 --- a/frameworks/bridge/arkts_frontend/koala_projects/interop/src/arkts/Finalizable.ts +++ b/frameworks/bridge/arkts_frontend/koala_projects/interop/src/arkts/Finalizable.ts @@ -17,7 +17,7 @@ import { finalizerRegister, finalizerUnregister, Thunk } from "@koalaui/common" import { InteropNativeModule } from "./InteropNativeModule" import { pointer, nullptr } from "./InteropTypes" -class NativeThunk implements Thunk { +export class NativeThunk implements Thunk { finalizer: pointer obj: pointer name: string|undefined diff --git a/frameworks/core/interfaces/ani/ani_api.h b/frameworks/core/interfaces/ani/ani_api.h index 2ac7beef5bd008a9df4c161de6b7a14d78da3fbc..34bea4e5d50520dc80659b1b318715f477c61c97 100644 --- a/frameworks/core/interfaces/ani/ani_api.h +++ b/frameworks/core/interfaces/ani/ani_api.h @@ -84,6 +84,21 @@ typedef struct WebviewControllerInfo { std::function setWebIdFunc = nullptr; std::function setHapPathFunc = nullptr; } WebviewControllerInfo; + +typedef struct NodeAdapterInfo { + std::function onAttachToNode = nullptr; + std::function onDetachFromNode = nullptr; + std::function onGetId = nullptr; + std::function onCreateChild = nullptr; + std::function onDisposeChild = nullptr; + std::function onUpdateChild = nullptr; +} NodeAdapterInfo; + +typedef struct AniDoubleArray { + ani_double* data; + ani_size size; +} AniDoubleArray; + typedef ani_object (*ArkUIAniArithmeticAddFunction)(ani_env*, ani_object, ani_object); typedef ani_object (*ArkUIAniArithmeticMinusFunction)(ani_env*, ani_object, ani_object); typedef ani_object (*ArkUIAniArithmeticMultiplyFunction)(ani_env*, ani_object, float); @@ -615,6 +630,20 @@ struct ArkUIAniSyntaxNodeModifier { ani_long (*constructSyntaxNode)(ani_int); }; +struct ArkUIAniNodeAdapterModifier { + ani_long (*nodeAdapterConstruct)(NodeAdapterInfo&& info); + void (*nodeAdapterDetachNodeAdapter)(ani_long node); + ani_boolean (*nodeAdapterAttachNodeAdapter)(ani_long ptr, ani_long node); + void (*nodeAdapterDispose)(ani_long node); + void (*nodeAdapterNotifyItemReloaded)(ani_long node); + void (*nodeAdapterSetTotalNodeCount)(ani_long node, ani_double count); + void (*nodeAdapterNotifyItemChanged)(ani_long node, ani_double start, ani_double count); + void (*nodeAdapterNotifyItemRemoved)(ani_long node, ani_double start, ani_double count); + void (*nodeAdapterNotifyItemInserted)(ani_long node, ani_double start, ani_double count); + void (*nodeAdapterNotifyItemMoved)(ani_long node, ani_double from, ani_double to); + AniDoubleArray (*nodeAdapterGetAllItems)(ani_long node); +}; + struct ArkUIAniModifiers { ArkUI_Int32 version; const ArkUIAniImageModifier* (*getImageAniModifier)(); @@ -644,6 +673,7 @@ struct ArkUIAniModifiers { const ArkUIAniCanvasModifier* (*getCanvasAniModifier)(); const ArkUIAniTraceModifier* (*getTraceAniModifier)(); const ArkUIAniSyntaxNodeModifier* (*getSyntaxNodeAniModifier)(); + const ArkUIAniNodeAdapterModifier* (*getNodeAdapterAniModifier)(); }; __attribute__((visibility("default"))) const ArkUIAniModifiers* GetArkUIAniModifiers(void); diff --git a/frameworks/core/interfaces/native/BUILD.gn b/frameworks/core/interfaces/native/BUILD.gn index 2c27fa97b0cba656374127f0a08e0765e900d9a4..d27df6b9e603e8d798b4a4a92f629d491c78c0ac 100644 --- a/frameworks/core/interfaces/native/BUILD.gn +++ b/frameworks/core/interfaces/native/BUILD.gn @@ -156,6 +156,7 @@ template("ace_core_interfaces_native_node") { "ani/content_slot_ani_modifier.cpp", "ani/custom_node_ani_modifier.cpp", "ani/drag_ani_modifier.cpp", + "ani/node_adapter_ani_modifier.cpp", "ani/interop_ani_modifier.cpp", "ani/image_ani_modifier.cpp", "ani/image_span_ani_modifier.cpp", @@ -184,6 +185,7 @@ template("ace_core_interfaces_native_node") { "ani/custom_node_ani_modifier.cpp", "ani/node_ani_modifier.cpp", "ani/waterflow_ani_modifier.cpp", + "ani/node_adapter_ani_modifier.cpp", "ani/interop_ani_modifier.cpp", "ani/list_ani_modifier.cpp", "${ace_root}/frameworks/bridge/arkts_frontend/ani_graphics_module.cpp", diff --git a/frameworks/core/interfaces/native/ani/node_adapter_ani_modifier.cpp b/frameworks/core/interfaces/native/ani/node_adapter_ani_modifier.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ac431257cd2df6e6575deffc19e914ac4b8fdd1b --- /dev/null +++ b/frameworks/core/interfaces/native/ani/node_adapter_ani_modifier.cpp @@ -0,0 +1,180 @@ +/* + * 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. + */ + +#include "node_adapter_ani_modifier.h" + +#include + +#include "ui/base/utils/utils.h" + +#include "base/log/log.h" +#include "core/components_ng/base/frame_node.h" +#include "core/components_ng/base/ui_node.h" +#include "core/components_ng/syntax/lazy_for_each_node.h" +#include "core/interfaces/native/implementation/frame_node_peer_impl.h" +#include "core/interfaces/native/node/node_adapter_impl.h" + +namespace OHOS::Ace::NG { +namespace { +ArkUINodeHandle ConvertToNodeHandle(OHOS::Ace::RefPtr& src) +{ + CHECK_NULL_RETURN(src, nullptr); + return reinterpret_cast(AceType::RawPtr(src)); +} +} // namespace + +ani_long NodeAdapterConstruct(NodeAdapterInfo&& info) +{ + auto handle = NodeAdapter::GetNodeAdapterAPI()->create(); + if (!handle) { + return 0; + } + auto ref = AceType::MakeRefPtr(handle); + ref->IncRefCount(); + auto attachfunc = [func = std::move(info.onAttachToNode)](ArkUINodeHandle node) { + auto uiNode = reinterpret_cast(node); + CHECK_NULL_VOID(uiNode && func); + ani_double nodeId = uiNode->GetId(); + func(nodeId); + }; + ref->SetOnAttachToNodeFunc(std::move(attachfunc)); + ref->SetOnDetachFromNodeFunc(std::move(info.onDetachFromNode)); + ref->SetOnGetChildIdFunc(std::move(info.onGetId)); + auto onCreateChild = [func = std::move(info.onCreateChild)](uint32_t index) -> ArkUINodeHandle { + ani_long node = func(index); + auto frameNode = FrameNodePeer::GetFrameNodeByPeer(reinterpret_cast(node)); + return ConvertToNodeHandle(frameNode); + }; + ref->SetOnCreateNewChild(std::move(onCreateChild)); + auto onDisposeChild = [func = std::move(info.onDisposeChild)](ArkUINodeHandle node, int32_t id) { + ani_double nodeId = reinterpret_cast(node) ? reinterpret_cast(node)->GetId() : -2; + ani_double index = id; + func(nodeId, index); + }; + ref->SetOnDisposeChild(std::move(onDisposeChild)); + + auto onUpdateChild = [func = std::move(info.onUpdateChild)](ArkUINodeHandle node, int32_t id) { + ani_double nodeId = reinterpret_cast(node) ? reinterpret_cast(node)->GetId() : -2; + ani_double index = id; + func(nodeId, index); + }; + ref->SetOnUpdateChind(std::move(onUpdateChild)); + return reinterpret_cast(AceType::RawPtr(ref)); +} + +void NodeAdapterDetachNodeAdapter(ani_long ptr) +{ + auto frameNode = FrameNodePeer::GetFrameNodeByPeer(reinterpret_cast(ptr)); + CHECK_NULL_VOID(frameNode); + NodeAdapter::GetNodeAdapterAPI()->detachHostNode(ConvertToNodeHandle(frameNode)); + frameNode->MarkDirtyNode(ArkUIDirtyFlag::ARKUI_DIRTY_FLAG_MEASURE_SELF_AND_PARENT); +} + +ani_boolean NodeAdapterAttachNodeAdapter(ani_long ptr, ani_long node) +{ + auto frameNode = FrameNodePeer::GetFrameNodeByPeer(reinterpret_cast(node)); + auto adapter = reinterpret_cast(ptr); + if (!frameNode || !adapter || frameNode->GetFirstChild()) { + return false; + } + NodeAdapter::GetNodeAdapterAPI()->attachHostNode(adapter->GetHandle(), ConvertToNodeHandle(frameNode)); + return true; +} + +void NodeAdapterDispose(ani_long ptr) +{ + auto adapter = reinterpret_cast(ptr); + CHECK_NULL_VOID(ptr); + adapter->DecRefCount(); +} + +void NodeAdapterNotifyItemReloaded(ani_long ptr) +{ + auto adapter = reinterpret_cast(ptr); + CHECK_NULL_VOID(adapter); + adapter->NotifyItemReloaded(); +} + +void NodeAdapterSetTotalNodeCount(ani_long ptr, ani_double count) +{ + auto adapter = reinterpret_cast(ptr); + CHECK_NULL_VOID(adapter); + adapter->SetTotalNodeCount(count); +} + +void NodeAdapterNotifyItemChanged(ani_long ptr, ani_double start, ani_double count) +{ + auto adapter = reinterpret_cast(ptr); + CHECK_NULL_VOID(adapter); + adapter->NotifyItemChanged(start, count); +} + +void NodeAdapterNotifyItemRemoved(ani_long ptr, ani_double start, ani_double count) +{ + auto adapter = reinterpret_cast(ptr); + CHECK_NULL_VOID(adapter); + adapter->NotifyItemRemoved(start, count); +} + +void NodeAdapterNotifyItemInserted(ani_long ptr, ani_double start, ani_double count) +{ + auto adapter = reinterpret_cast(ptr); + CHECK_NULL_VOID(adapter); + adapter->NotifyItemInserted(start, count); +} + +void NodeAdapterNotifyItemMoved(ani_long ptr, ani_double start, ani_double count) +{ + auto adapter = reinterpret_cast(ptr); + CHECK_NULL_VOID(adapter); + adapter->NotifyItemMoved(start, count); +} + +AniDoubleArray NodeAdapterGetAllItems(ani_long ptr) +{ + auto adapter = reinterpret_cast(ptr); + CHECK_NULL_RETURN(adapter, {}); + auto items = adapter->GetAllItems(); + ani_double* result = new ani_double[items.size()]; + for (uint32_t i = 0; i < items.size(); i++) { + auto node = reinterpret_cast(items[i]); + if (!node) { + continue; + } + ani_double nodeId = reinterpret_cast(items[i])->GetId(); + result[i] = nodeId; + } + AniDoubleArray array = { .data = result, .size = items.size() }; + return array; +} + +const ArkUIAniNodeAdapterModifier* GetNodeAdapterAniModifier() +{ + static const ArkUIAniNodeAdapterModifier impl = { + .nodeAdapterConstruct = OHOS::Ace::NG::NodeAdapterConstruct, + .nodeAdapterDetachNodeAdapter = OHOS::Ace::NG::NodeAdapterDetachNodeAdapter, + .nodeAdapterAttachNodeAdapter = OHOS::Ace::NG::NodeAdapterAttachNodeAdapter, + .nodeAdapterDispose = OHOS::Ace::NG::NodeAdapterDispose, + .nodeAdapterNotifyItemReloaded = OHOS::Ace::NG::NodeAdapterNotifyItemReloaded, + .nodeAdapterSetTotalNodeCount = OHOS::Ace::NG::NodeAdapterSetTotalNodeCount, + .nodeAdapterNotifyItemChanged = OHOS::Ace::NG::NodeAdapterNotifyItemChanged, + .nodeAdapterNotifyItemRemoved = OHOS::Ace::NG::NodeAdapterNotifyItemRemoved, + .nodeAdapterNotifyItemInserted = OHOS::Ace::NG::NodeAdapterNotifyItemInserted, + .nodeAdapterNotifyItemMoved = OHOS::Ace::NG::NodeAdapterNotifyItemMoved, + .nodeAdapterGetAllItems = OHOS::Ace::NG::NodeAdapterGetAllItems, + }; + return &impl; +} +} // namespace OHOS::Ace::NG diff --git a/frameworks/core/interfaces/native/ani/node_adapter_ani_modifier.h b/frameworks/core/interfaces/native/ani/node_adapter_ani_modifier.h new file mode 100644 index 0000000000000000000000000000000000000000..25c71622623ce1e27fa55512953f2354a510fe54 --- /dev/null +++ b/frameworks/core/interfaces/native/ani/node_adapter_ani_modifier.h @@ -0,0 +1,36 @@ +/* + * 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. + */ + +#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_INTERFACES_NATIVE_ANI_NODE_ADAPTER_ANI_MODIFIER_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_INTERFACES_NATIVE_ANI_NODE_ADAPTER_ANI_MODIFIER_H + +#include "core/interfaces/ani/ani_api.h" + +namespace OHOS::Ace::NG { +const ArkUIAniNodeAdapterModifier* GetNodeAdapterAniModifier(); +ani_long NodeAdapterConstruct(NodeAdapterInfo&& info); +void NodeAdapterDetachNodeAdapter(ani_long ptr); +ani_boolean NodeAdapterAttachNodeAdapter(ani_long ptr, ani_long node); +void NodeAdapterDispose(ani_long ptr); +void NodeAdapterNotifyItemReloaded(ani_long ptr); +void NodeAdapterSetTotalNodeCount(ani_long ptr, ani_double count); +void NodeAdapterNotifyItemChanged(ani_long ptr, ani_double start, ani_double count); +void NodeAdapterNotifyItemRemoved(ani_long ptr, ani_double start, ani_double count); +void NodeAdapterNotifyItemInserted(ani_long ptr, ani_double start, ani_double count); +void NodeAdapterNotifyItemMoved(ani_long ptr, ani_double start, ani_double count); +AniDoubleArray NodeAdapterGetAllItems(ani_long ptr); +} // namespace OHOS::Ace::NG + +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_INTERFACES_NATIVE_ANI_NODE_ADAPTER_ANI_MODIFIER_H diff --git a/frameworks/core/interfaces/native/ani/node_ani_modifier.cpp b/frameworks/core/interfaces/native/ani/node_ani_modifier.cpp index 7758599019490145f1230a1446620061b3505ce6..6c08862fdc4e77af6e2f74a5ccafe798490bd13d 100644 --- a/frameworks/core/interfaces/native/ani/node_ani_modifier.cpp +++ b/frameworks/core/interfaces/native/ani/node_ani_modifier.cpp @@ -18,26 +18,27 @@ #include "common_ani_modifier.h" #include "component_content_ani_modifier.h" #include "component_snapshot_ani_modifier.h" +#include "condition_scope_ani_modifier.h" #include "content_slot_ani_modifier.h" -#include "image_ani_modifier.h" -#include "image_span_ani_modifier.h" -#include "search_ani_modifier.h" -#include "styled_string_ani_modifier.h" -#include "trace_ani_modifier.h" -#include "web_ani_modifier.h" #include "custom_node_ani_modifier.h" -#include "list_ani_modifier.h" -#include "waterflow_ani_modifier.h" #include "drag_ani_modifier.h" -#include "interop_ani_modifier.h" #include "drag_controller_ani_modifier.h" -#include "video_ani_modifier.h" +#include "image_ani_modifier.h" +#include "image_span_ani_modifier.h" +#include "interop_ani_modifier.h" +#include "lazy_for_each_node_ani_modifier.h" +#include "list_ani_modifier.h" +#include "node_adapter_ani_modifier.h" #include "rich_editor_ani_modifier.h" +#include "search_ani_modifier.h" #include "shape_ani_modifier.h" #include "stateMgmt_ani_modifier.h" +#include "styled_string_ani_modifier.h" +#include "trace_ani_modifier.h" +#include "video_ani_modifier.h" +#include "waterflow_ani_modifier.h" +#include "web_ani_modifier.h" #include "xcomponent_ani_modifier.h" -#include "lazy_for_each_node_ani_modifier.h" -#include "condition_scope_ani_modifier.h" #include "syntax_node_ani_modifier.h" extern "C" { @@ -72,6 +73,7 @@ const ArkUIAniModifiers* GetArkUIAniModifiers() .getCanvasAniModifier = OHOS::Ace::NG::GetCanvasAniModifier, .getTraceAniModifier = OHOS::Ace::NG::GetTraceAniModifier, .getSyntaxNodeAniModifier = OHOS::Ace::NG::GetSyntaxNodeAniModifier, + .getNodeAdapterAniModifier = OHOS::Ace::NG::GetNodeAdapterAniModifier, }; return &impl; } diff --git a/frameworks/core/interfaces/native/implementation/frame_node_accessor.cpp b/frameworks/core/interfaces/native/implementation/frame_node_accessor.cpp index 8b0c9358fe95a65142995209f1f07149c2227e53..de4e1b8db341cb8b7bf58beb0953204c6749e358 100644 --- a/frameworks/core/interfaces/native/implementation/frame_node_accessor.cpp +++ b/frameworks/core/interfaces/native/implementation/frame_node_accessor.cpp @@ -52,7 +52,8 @@ typedef enum { ARKUI_DIRTY_FLAG_MEASURE_SELF_AND_CHILD = 0b1000000000, } ArkUIDirtyFlag; } -std::map FrameNodePeer::peerMap_; +std::map> FrameNodePeer::peerMap_; + namespace OHOS::Ace::NG::GeneratedModifier { namespace { Opt_Number GetOptNumberFromDimension(const std::optional& dimension) @@ -85,12 +86,11 @@ void DestroyPeerImpl(Ark_FrameNode peer) Ark_FrameNode CtorImpl(Ark_UIContext uiContext) { - auto peer = FrameNodePeer::Create(uiContext); auto nodeId = ElementRegister::GetInstance()->MakeUniqueId(); - peer->node = NG::CustomFrameNode::GetOrCreateCustomFrameNode(nodeId); - peer->node->SetExclusiveEventForChild(true); - peer->node->SetIsArkTsFrameNode(true); - FrameNodePeer::peerMap_.emplace(nodeId, *peer); + auto node = NG::CustomFrameNode::GetOrCreateCustomFrameNode(nodeId); + node->SetExclusiveEventForChild(true); + node->SetIsArkTsFrameNode(true); + auto peer = FrameNodePeer::Create(node); return peer; } @@ -582,11 +582,9 @@ Ark_Boolean GetCrossLanguageOptionsImpl(Ark_FrameNode peer) Ark_FrameNode CreateByRawPtrImpl(void* rawPtr) { auto frameNode = reinterpret_cast(rawPtr); + frameNode->SetExclusiveEventForChild(true); + frameNode->SetIsArkTsFrameNode(true); auto peer = FrameNodePeer::Create(frameNode); - auto nodeId = frameNode->GetId(); - peer->node->SetExclusiveEventForChild(true); - peer->node->SetIsArkTsFrameNode(true); - FrameNodePeer::peerMap_.emplace(nodeId, *peer); return peer; } diff --git a/frameworks/core/interfaces/native/implementation/frame_node_peer_impl.h b/frameworks/core/interfaces/native/implementation/frame_node_peer_impl.h index 7f33e4fc2fd2bbb94b923b5e8c7ea158942baa4d..26518eb3b158af757c726318e432ee513e7b8b65 100644 --- a/frameworks/core/interfaces/native/implementation/frame_node_peer_impl.h +++ b/frameworks/core/interfaces/native/implementation/frame_node_peer_impl.h @@ -24,15 +24,14 @@ #include "core/interfaces/native/generated/interface/arkoala_api_generated.h" #include "core/interfaces/native/implementation/render_node_peer_impl.h" - struct FrameNodePeer { OHOS::Ace::RefPtr node; OHOS::Ace::WeakPtr weakNode; int32_t nodeId_ = -1; - static std::map peerMap_; + static std::map> peerMap_; - static FrameNodePeer *Create(Ark_UIContext uiContext) + static FrameNodePeer* Create(Ark_UIContext uiContext) { return new FrameNodePeer; } @@ -41,42 +40,29 @@ struct FrameNodePeer { { auto it = peerMap_.find(src->GetId()); if (it != peerMap_.end()) { - return &(it->second); + return (it->second).get(); } - auto frameNode = new FrameNodePeer; + auto frameNode = std::make_shared(); if (src->IsArkTsFrameNode()) { frameNode->node = src; } else { frameNode->weakNode = OHOS::Ace::WeakPtr(src); } - peerMap_.emplace(src->GetId(), *frameNode); - return frameNode; + peerMap_.emplace(src->GetId(), frameNode); + frameNode->nodeId_ = src->GetId(); + return frameNode.get(); } static FrameNodePeer* Create(OHOS::Ace::NG::FrameNode* src) { - auto it = peerMap_.find(src->GetId()); - if (it != peerMap_.end()) { - return &(it->second); - } - auto frameNode = new FrameNodePeer; - if (src->IsArkTsFrameNode()) { - frameNode->node = src; - } else { - frameNode->weakNode = OHOS::Ace::AceType::WeakClaim(src); - } - peerMap_.emplace(src->GetId(), *frameNode); - return frameNode; + return Create(OHOS::Ace::AceType::Claim(src)); } static void Destroy(FrameNodePeer* peer) { - auto currentNode = OHOS::Ace::AceType::DynamicCast(peer->node); - if (currentNode) { - auto nodeId = currentNode->GetId(); - peerMap_.erase(nodeId); + if (peer) { + peerMap_.erase(peer->nodeId_); } - delete peer; } static OHOS::Ace::RefPtr GetFrameNodeByPeer(FrameNodePeer* peer)