From 6cb184605678334f1e383b2fb39b91b996b7f64a Mon Sep 17 00:00:00 2001 From: wangtao Date: Sat, 30 Aug 2025 18:51:45 +0800 Subject: [PATCH 1/2] =?UTF-8?q?ContentSlot=E6=9B=BF=E6=8D=A2XComponent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangtao --- .../StyledStringNDK/entry/build-profile.json5 | 5 +--- .../entry/src/main/cpp/manager.cpp | 10 +++---- .../entry/src/main/cpp/manager.h | 4 +-- .../entry/src/main/cpp/napi_init.cpp | 30 +++++++------------ .../src/main/cpp/types/libentry/Index.d.ts | 3 +- .../entry/src/main/ets/pages/Index.ets | 14 ++++----- 6 files changed, 27 insertions(+), 39 deletions(-) diff --git a/ArkUIKit/StyledStringNDK/entry/build-profile.json5 b/ArkUIKit/StyledStringNDK/entry/build-profile.json5 index b449990d8e..755af24cf0 100644 --- a/ArkUIKit/StyledStringNDK/entry/build-profile.json5 +++ b/ArkUIKit/StyledStringNDK/entry/build-profile.json5 @@ -5,10 +5,7 @@ "path": "./src/main/cpp/CMakeLists.txt", "arguments": "", "cppFlags": "", - "abiFilters": [ - "arm64-v8a", - "x86_64" - ] + "abiFilters": ["arm64-v8a", "x86_64", "armeabi-v7a"] } }, "buildOptionSet": [ diff --git a/ArkUIKit/StyledStringNDK/entry/src/main/cpp/manager.cpp b/ArkUIKit/StyledStringNDK/entry/src/main/cpp/manager.cpp index b129a3fdcc..e281e0537b 100644 --- a/ArkUIKit/StyledStringNDK/entry/src/main/cpp/manager.cpp +++ b/ArkUIKit/StyledStringNDK/entry/src/main/cpp/manager.cpp @@ -13,10 +13,8 @@ * limitations under the License. */ #include "manager.h" -#include #include #include -#include #include #include @@ -30,11 +28,11 @@ NodeManager &NodeManager::GetInstance() return instance; } -void NodeManager::SetXComponent(OH_NativeXComponent *xComponent) { xComponent_ = xComponent; } +void NodeManager::SetContentHandle(ArkUI_NodeContentHandle contentHandle) { contentHandle_ = contentHandle; } void NodeManager::CreateNativeNode() { - if (!xComponent_) { + if (!contentHandle_) { return; } ArkUI_NativeNodeAPI_1 *nodeApi = reinterpret_cast( @@ -96,7 +94,7 @@ void NodeManager::CreateNativeNode() OH_ArkUI_StyledString_Destroy(styledString); // Text作为Column子组件 nodeApi->addChild(column, text); - // Column作为XComponent子组件 - OH_NativeXComponent_AttachNativeRootNode(xComponent_, column); + // Column作为ContentSlot子组件 + OH_ArkUI_NodeContent_AddNode(contentHandle_, column); } } // namespace NativeNode::Manager diff --git a/ArkUIKit/StyledStringNDK/entry/src/main/cpp/manager.h b/ArkUIKit/StyledStringNDK/entry/src/main/cpp/manager.h index 55b98a698b..40d7565e58 100644 --- a/ArkUIKit/StyledStringNDK/entry/src/main/cpp/manager.h +++ b/ArkUIKit/StyledStringNDK/entry/src/main/cpp/manager.h @@ -28,11 +28,11 @@ class NodeManager { public: ~NodeManager() = default; static NodeManager& GetInstance(); - void SetXComponent(OH_NativeXComponent* xComponent); + void SetContentHandle(ArkUI_NodeContentHandle contentHandle); void CreateNativeNode(); private: NodeManager() = default; - OH_NativeXComponent* xComponent_; + ArkUI_NodeContentHandle contentHandle_; std::unordered_map callbackMap_; }; } diff --git a/ArkUIKit/StyledStringNDK/entry/src/main/cpp/napi_init.cpp b/ArkUIKit/StyledStringNDK/entry/src/main/cpp/napi_init.cpp index 0ef82312da..8de3f3d6c4 100644 --- a/ArkUIKit/StyledStringNDK/entry/src/main/cpp/napi_init.cpp +++ b/ArkUIKit/StyledStringNDK/entry/src/main/cpp/napi_init.cpp @@ -13,27 +13,23 @@ * limitations under the License. */ #include "manager.h" +#include #include +#include #include -static OH_NativeXComponent* GetXComponent(napi_env env, napi_value exports) +static napi_value createNativeNode(napi_env env, napi_callback_info info) { - if ((env == nullptr) || (exports == nullptr)) { - return nullptr; - } - napi_value exportInstance = nullptr; - if (napi_get_named_property(env, exports, OH_NATIVE_XCOMPONENT_OBJ, &exportInstance) != napi_ok) { - return nullptr; - } - OH_NativeXComponent* xComp = nullptr; - if (napi_unwrap(env, exportInstance, reinterpret_cast(&xComp)) != napi_ok) { + size_t argc = 1; + napi_value args[1] = { nullptr }; + if (napi_get_cb_info(env, info, &argc, args, nullptr, nullptr) != napi_ok) { + OH_LOG_Print(LOG_APP, LOG_ERROR, 0xFF00, "StyledStringNDK", "CreateNativeNode napi_get_cb_info failed"); return nullptr; } - return xComp; -} - -static napi_value createNativeNode(napi_env env, napi_callback_info info) -{ + // 获取NodeContent + ArkUI_NodeContentHandle contentHandle; + OH_ArkUI_GetNodeContentFromNapiValue(env, args[0], &contentHandle); + NativeNode::Manager::NodeManager::GetInstance().SetContentHandle(contentHandle); NativeNode::Manager::NodeManager::GetInstance().CreateNativeNode(); return nullptr; } @@ -45,10 +41,6 @@ static napi_value Init(napi_env env, napi_value exports) { "createNativeNode", nullptr, createNativeNode, nullptr, nullptr, nullptr, napi_default, nullptr } }; napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); - auto xComponent = GetXComponent(env, exports); - if (xComponent) { - NativeNode::Manager::NodeManager::GetInstance().SetXComponent(xComponent); - } return exports; } EXTERN_C_END diff --git a/ArkUIKit/StyledStringNDK/entry/src/main/cpp/types/libentry/Index.d.ts b/ArkUIKit/StyledStringNDK/entry/src/main/cpp/types/libentry/Index.d.ts index c09127fac7..da6cd32915 100644 --- a/ArkUIKit/StyledStringNDK/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/ArkUIKit/StyledStringNDK/entry/src/main/cpp/types/libentry/Index.d.ts @@ -12,4 +12,5 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -export const createNativeNode: () => void; \ No newline at end of file + +export const createNativeNode: (content: object) => void; \ No newline at end of file diff --git a/ArkUIKit/StyledStringNDK/entry/src/main/ets/pages/Index.ets b/ArkUIKit/StyledStringNDK/entry/src/main/ets/pages/Index.ets index 073f244e87..4193211d18 100644 --- a/ArkUIKit/StyledStringNDK/entry/src/main/ets/pages/Index.ets +++ b/ArkUIKit/StyledStringNDK/entry/src/main/ets/pages/Index.ets @@ -13,24 +13,24 @@ * limitations under the License. */ import testNapi from 'libentry.so'; +import { NodeContent } from '@kit.ArkUI'; @Entry @Component struct Index { + private nodeContent: Content = new NodeContent(); build() { Row() { Column() { - XComponent({ - id: "xComponent", - type: XComponentType.NODE, - libraryname: "entry" - }).onAppear(()=> { - testNapi.createNativeNode() - }) + ContentSlot(this.nodeContent) } .width('100%') } .height('100%') } + + aboutToAppear(): void { + testNapi.createNativeNode(this.nodeContent); + } } -- Gitee From daf47f00cf19307e20765c25610f9455b581de77 Mon Sep 17 00:00:00 2001 From: wangtao Date: Sat, 30 Aug 2025 19:11:02 +0800 Subject: [PATCH 2/2] =?UTF-8?q?TextAreaEventNDK=20XComponent=E6=9B=BF?= =?UTF-8?q?=E6=8D=A2ContentSlot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangtao --- .../entry/build-profile.json5 | 5 +-- .../entry/src/main/cpp/manager.cpp | 6 ++-- .../entry/src/main/cpp/manager.h | 8 ++--- .../entry/src/main/cpp/napi_init.cpp | 31 +++++++------------ .../src/main/cpp/types/libentry/Index.d.ts | 3 +- .../entry/src/main/ets/pages/Index.ets | 15 ++++----- 6 files changed, 29 insertions(+), 39 deletions(-) diff --git a/ArkUIKit/TextAreaEventNDK/entry/build-profile.json5 b/ArkUIKit/TextAreaEventNDK/entry/build-profile.json5 index a20094043a..fdffbf2eda 100644 --- a/ArkUIKit/TextAreaEventNDK/entry/build-profile.json5 +++ b/ArkUIKit/TextAreaEventNDK/entry/build-profile.json5 @@ -19,10 +19,7 @@ "path": "./src/main/cpp/CMakeLists.txt", "arguments": "", "cppFlags": "", - "abiFilters": [ - "arm64-v8a", - "x86_64" - ] + "abiFilters": ["arm64-v8a", "x86_64", "armeabi-v7a"] } }, "buildOptionSet": [ diff --git a/ArkUIKit/TextAreaEventNDK/entry/src/main/cpp/manager.cpp b/ArkUIKit/TextAreaEventNDK/entry/src/main/cpp/manager.cpp index ed4971c46c..d704d77694 100644 --- a/ArkUIKit/TextAreaEventNDK/entry/src/main/cpp/manager.cpp +++ b/ArkUIKit/TextAreaEventNDK/entry/src/main/cpp/manager.cpp @@ -27,11 +27,11 @@ NodeManager &NodeManager::GetInstance() return instance; } -void NodeManager::SetXComponent(OH_NativeXComponent *xComponent) { xComponent_ = xComponent; } +void NodeManager::SetContentHandle(ArkUI_NodeContentHandle contentHandle) { contentHandle_ = contentHandle; } void NodeManager::CreateTextAreaNode() { - if (!xComponent_) { + if (!contentHandle_) { return; } ArkUI_NativeNodeAPI_1 *nodeApi = reinterpret_cast( @@ -75,7 +75,7 @@ void NodeManager::CreateTextAreaNode() nodeApi->registerNodeEvent(textArea, NODE_TEXT_AREA_ON_TEXT_SELECTION_CHANGE, id, selectionText); TextAreaNodeEventReceiver(nodeApi); nodeApi->addChild(column, textArea); - OH_NativeXComponent_AttachNativeRootNode(xComponent_, column); + OH_ArkUI_NodeContent_AddNode(contentHandle_, column); } void NodeManager::TextAreaNodeEventReceiver(ArkUI_NativeNodeAPI_1* nodeApi) diff --git a/ArkUIKit/TextAreaEventNDK/entry/src/main/cpp/manager.h b/ArkUIKit/TextAreaEventNDK/entry/src/main/cpp/manager.h index 1af1f0cb81..d6c3b8258a 100644 --- a/ArkUIKit/TextAreaEventNDK/entry/src/main/cpp/manager.h +++ b/ArkUIKit/TextAreaEventNDK/entry/src/main/cpp/manager.h @@ -29,15 +29,13 @@ class NodeManager { public: ~NodeManager() = default; static NodeManager& GetInstance(); - void SetXComponent(OH_NativeXComponent* xComponent); - void CreateNativeNode(); + void SetContentHandle(ArkUI_NodeContentHandle contentHandle); void CreateTextAreaNode(); - const EventCallback& GetCallback(int32_t id); + private: NodeManager() = default; - void AddNodeEventCallback(int32_t id, EventCallback&& callback); void TextAreaNodeEventReceiver(ArkUI_NativeNodeAPI_1* nodeApi); - OH_NativeXComponent* xComponent_; + ArkUI_NodeContentHandle contentHandle_; std::unordered_map callbackMap_; }; } diff --git a/ArkUIKit/TextAreaEventNDK/entry/src/main/cpp/napi_init.cpp b/ArkUIKit/TextAreaEventNDK/entry/src/main/cpp/napi_init.cpp index 2bbb60b807..97b997cfa5 100644 --- a/ArkUIKit/TextAreaEventNDK/entry/src/main/cpp/napi_init.cpp +++ b/ArkUIKit/TextAreaEventNDK/entry/src/main/cpp/napi_init.cpp @@ -13,27 +13,24 @@ * limitations under the License. */ #include "manager.h" +#include #include +#include #include -static OH_NativeXComponent* GetXComponent(napi_env env, napi_value exports) -{ - if ((env == nullptr) || (exports == nullptr)) { - return nullptr; - } - napi_value exportInstance = nullptr; - if (napi_get_named_property(env, exports, OH_NATIVE_XCOMPONENT_OBJ, &exportInstance) != napi_ok) { - return nullptr; - } - OH_NativeXComponent* xComp = nullptr; - if (napi_unwrap(env, exportInstance, reinterpret_cast(&xComp)) != napi_ok) { - return nullptr; - } - return xComp; -} static napi_value createNativeNode(napi_env env, napi_callback_info info) { + size_t argc = 1; + napi_value args[1] = { nullptr }; + if (napi_get_cb_info(env, info, &argc, args, nullptr, nullptr) != napi_ok) { + OH_LOG_Print(LOG_APP, LOG_ERROR, 0xFF00, "TextAreaEventNDK", "CreateNativeNode napi_get_cb_info failed"); + return nullptr; + } + // 获取NodeContent + ArkUI_NodeContentHandle contentHandle; + OH_ArkUI_GetNodeContentFromNapiValue(env, args[0], &contentHandle); + NativeNode::Manager::NodeManager::GetInstance().SetContentHandle(contentHandle); NativeNode::Manager::NodeManager::GetInstance().CreateTextAreaNode(); return nullptr; } @@ -45,10 +42,6 @@ static napi_value Init(napi_env env, napi_value exports) { "createNativeNode", nullptr, createNativeNode, nullptr, nullptr, nullptr, napi_default, nullptr } }; napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); - auto xComponent = GetXComponent(env, exports); - if (xComponent) { - NativeNode::Manager::NodeManager::GetInstance().SetXComponent(xComponent); - } return exports; } EXTERN_C_END diff --git a/ArkUIKit/TextAreaEventNDK/entry/src/main/cpp/types/libentry/Index.d.ts b/ArkUIKit/TextAreaEventNDK/entry/src/main/cpp/types/libentry/Index.d.ts index c09127fac7..da6cd32915 100644 --- a/ArkUIKit/TextAreaEventNDK/entry/src/main/cpp/types/libentry/Index.d.ts +++ b/ArkUIKit/TextAreaEventNDK/entry/src/main/cpp/types/libentry/Index.d.ts @@ -12,4 +12,5 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -export const createNativeNode: () => void; \ No newline at end of file + +export const createNativeNode: (content: object) => void; \ No newline at end of file diff --git a/ArkUIKit/TextAreaEventNDK/entry/src/main/ets/pages/Index.ets b/ArkUIKit/TextAreaEventNDK/entry/src/main/ets/pages/Index.ets index 073f244e87..9c6014f988 100644 --- a/ArkUIKit/TextAreaEventNDK/entry/src/main/ets/pages/Index.ets +++ b/ArkUIKit/TextAreaEventNDK/entry/src/main/ets/pages/Index.ets @@ -12,25 +12,26 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + import testNapi from 'libentry.so'; +import { NodeContent } from '@kit.ArkUI'; @Entry @Component struct Index { + private nodeContent: Content = new NodeContent(); build() { Row() { Column() { - XComponent({ - id: "xComponent", - type: XComponentType.NODE, - libraryname: "entry" - }).onAppear(()=> { - testNapi.createNativeNode() - }) + ContentSlot(this.nodeContent) } .width('100%') } .height('100%') } + + aboutToAppear(): void { + testNapi.createNativeNode(this.nodeContent); + } } -- Gitee