diff --git a/ArkUIKit/StyledStringNDK/entry/build-profile.json5 b/ArkUIKit/StyledStringNDK/entry/build-profile.json5 index b449990d8ee1f256ca37150e7d07c33945c40842..755af24cf0ff279e87eddde320e6dd5d31fba6cc 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 b129a3fdcc39d2f3f06772de059a1d7d7a45d934..e281e0537b4a68b48b5820f242b35ea450db2c4f 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 55b98a698bbe197db182c77b76f89e18e188ef28..40d7565e58b7363d5d78d39301b6e699bb56f5e6 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 0ef82312dac42685be4726c2b45e6abcd9f3ef84..8de3f3d6c4047f660641e603fe3dc3375cb99f61 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 c09127fac743a5190aedf27d6e07056b20076bbd..da6cd329155de245079074d62cd65bdb08919a65 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 073f244e87c658da43efdecb3f509569af441c95..4193211d18d31821f4c1a9a5e62a1faa0d462258 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); + } } diff --git a/ArkUIKit/TextAreaEventNDK/entry/build-profile.json5 b/ArkUIKit/TextAreaEventNDK/entry/build-profile.json5 index a20094043a5b912b06e6fca193486f1fbaf0aafb..fdffbf2eda0e6e3025bbc4c46af7eaa304df3b57 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 ed4971c46c8ab976365aad20f1d5f0403754003c..d704d77694e92bcc8274d209af18cecf6ebb7b77 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 1af1f0cb81456b4e0695b8e36cade55eba1c4963..d6c3b8258a83ecd21b4897aa17b77b3eaf327024 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 2bbb60b807299294a563c4fb81af59bd9ac6aec4..97b997cfa57bb0cf6e26af4b064c4a2da7bee34c 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 c09127fac743a5190aedf27d6e07056b20076bbd..da6cd329155de245079074d62cd65bdb08919a65 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 073f244e87c658da43efdecb3f509569af441c95..9c6014f988ee166eb8b3bf64d20564e5622d3714 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); + } }