diff --git a/frameworks/core/components_ng/syntax/node_content.h b/frameworks/core/components_ng/syntax/node_content.h index 7a6e4a5c43460af71d1f3f0563fb3b1e0419409e..83b7d54aad8aa4205f43de918c81c3567449f906 100644 --- a/frameworks/core/components_ng/syntax/node_content.h +++ b/frameworks/core/components_ng/syntax/node_content.h @@ -49,11 +49,22 @@ public: onDetachCallback_ = std::move(callback); } + void* GetUserData() const + { + return userData_; + } + + void SetUserData(void* userData) + { + userData_ = userData; + } + private: WeakPtr nodeSlot_; std::list> children_; std::function onAttachCallback_; std::function onDetachCallback_; + void* userData_ = nullptr; bool onMainTree_ = false; }; diff --git a/frameworks/core/interfaces/arkoala/arkoala_api.h b/frameworks/core/interfaces/arkoala/arkoala_api.h index 077ee987d8bfa761b8fd758078929af381a0c1f3..9e72f940a5db51b36669f3e2c6924eac8d6d0ed5 100644 --- a/frameworks/core/interfaces/arkoala/arkoala_api.h +++ b/frameworks/core/interfaces/arkoala/arkoala_api.h @@ -4005,6 +4005,7 @@ struct ArkUIFrameNodeModifier { struct ArkUINodeContentEvent { ArkUI_Int32 type; void* userData; + ArkUINodeContentHandle nodeContent; }; struct ArkUINodeContentModifier { @@ -4013,6 +4014,8 @@ struct ArkUINodeContentModifier { ArkUI_Int32 (*removeChild)(ArkUINodeContentHandle content, ArkUINodeHandle child); ArkUI_Int32 (*registerEvent)( ArkUINodeContentHandle content, void* userData, void (*receiver)(ArkUINodeContentEvent* event)); + ArkUI_Int32 (*setUserData)(ArkUINodeContentHandle content, void* userData); + void* (*getUserData)(ArkUINodeContentHandle content); }; struct ArkUIAnimation { diff --git a/frameworks/core/interfaces/native/node/node_content_modifier.cpp b/frameworks/core/interfaces/native/node/node_content_modifier.cpp index 9ea5af9fc6c81b005da234948cbe0b4ac7d41d5d..10b51bfe30a11aa3eed44a182acab89ef250541d 100644 --- a/frameworks/core/interfaces/native/node/node_content_modifier.cpp +++ b/frameworks/core/interfaces/native/node/node_content_modifier.cpp @@ -58,12 +58,12 @@ ArkUI_Int32 RegisterEvent( { CHECK_NULL_RETURN(content, ERROR_CODE_PARAM_INVALID); CHECK_NULL_RETURN(receiver, ERROR_CODE_PARAM_INVALID); - auto onAttach = [receiver, userData]() { - ArkUINodeContentEvent event { 0, userData }; + auto onAttach = [receiver, userData, content]() { + ArkUINodeContentEvent event { 0, userData, content }; receiver(&event); }; - auto onDetach = [receiver, userData]() { - ArkUINodeContentEvent event { 1, userData }; + auto onDetach = [receiver, userData, content]() { + ArkUINodeContentEvent event { 1, userData, content }; receiver(&event); }; auto* nodeContent = reinterpret_cast(content); @@ -72,12 +72,27 @@ ArkUI_Int32 RegisterEvent( return ERROR_CODE_NO_ERROR; } +ArkUI_Int32 SetUserData(ArkUINodeContentHandle content, void* userData) +{ + CHECK_NULL_RETURN(content, ERROR_CODE_PARAM_INVALID); + auto* nodeContent = reinterpret_cast(content); + nodeContent->SetUserData(userData); + return ERROR_CODE_NO_ERROR; +} + +void* GetUserData(ArkUINodeContentHandle content) +{ + CHECK_NULL_RETURN(content, nullptr); + auto* nodeContent = reinterpret_cast(content); + return nodeContent->GetUserData(); +} } // namespace namespace NodeModifier { const ArkUINodeContentModifier* GetNodeContentModifier() { - static const ArkUINodeContentModifier modifier = { AddChild, InsertChild, RemoveChild, RegisterEvent }; + static const ArkUINodeContentModifier modifier = { AddChild, InsertChild, RemoveChild, RegisterEvent, SetUserData, + GetUserData }; return &modifier; } } // namespace NodeModifier diff --git a/interfaces/native/libace.ndk.json b/interfaces/native/libace.ndk.json index f3547d0f43368148bdf4a7341e9f3ac16994f8e0..ff72b96a97329cef8eb41cbb03d3283a38d29f5b 100644 --- a/interfaces/native/libace.ndk.json +++ b/interfaces/native/libace.ndk.json @@ -663,6 +663,18 @@ "first_introduced": "12", "name": "OH_ArkUI_NodeContentEvent_GetEventType" }, + { + "first_introduced": "12", + "name": "OH_ArkUI_NodeContentEvent_GetNodeContentHandle" + }, + { + "first_introduced": "12", + "name": "OH_ArkUI_NodeContent_SetUserData" + }, + { + "first_introduced": "12", + "name": "OH_ArkUI_NodeContent_GetUserData" + }, { "first_introduced": "12", "name": "OH_ArkUI_GetNodeContentFromNapiValue" diff --git a/interfaces/native/native_node.h b/interfaces/native/native_node.h index 84333db34a2e230bf265d98a7824acf0e8838e95..88a190eaf500264bc6596dafef9c75f3ec97f8d4 100644 --- a/interfaces/native/native_node.h +++ b/interfaces/native/native_node.h @@ -6842,35 +6842,35 @@ ArkUI_NodeCustomEventType OH_ArkUI_NodeCustomEvent_GetEventType(ArkUI_NodeCustom /** * @brief Adds a component to a node content. * - * @param handle Indicates the pointer to the node content instance. + * @param content Indicates the pointer to the node content instance. * @param node Indicates the pointer to the node. * @return Returns 0 if success. * Returns 401 if a parameter exception occurs. * @since 12 */ -int32_t OH_ArkUI_NodeContent_AddNode(ArkUI_NodeContentHandle handle, ArkUI_NodeHandle node); +int32_t OH_ArkUI_NodeContent_AddNode(ArkUI_NodeContentHandle content, ArkUI_NodeHandle node); /** * @brief Adds a component to a node content. * - * @param handle Indicates the pointer to the node content instance. + * @param content Indicates the pointer to the node content instance. * @param node Indicates the pointer to the node. * @return Returns 0 if success. * Returns 401 if a parameter exception occurs. * @since 12 */ -int32_t OH_ArkUI_NodeContent_InsertNode(ArkUI_NodeContentHandle handle, ArkUI_NodeHandle node, int32_t position); +int32_t OH_ArkUI_NodeContent_InsertNode(ArkUI_NodeContentHandle content, ArkUI_NodeHandle node, int32_t position); /** * @brief Removes a component from a node content. * - * @param handle Indicates the pointer to the node content. + * @param content Indicates the pointer to the node content. * @param node Indicates the pointer to the node. * @return Returns 0 if success. * Returns 401 if a parameter exception occurs. * @since 12 */ -int32_t OH_ArkUI_NodeContent_RemoveNode(ArkUI_NodeContentHandle handle, ArkUI_NodeHandle node); +int32_t OH_ArkUI_NodeContent_RemoveNode(ArkUI_NodeContentHandle content, ArkUI_NodeHandle node); /** * @brief Defines the node content event type. @@ -6901,12 +6901,12 @@ typedef void (*ArkUI_NodeContentCallback)(ArkUI_NodeContentEvent* event); /** * @brief Register a callback for this ArkUI_NodeContentHandle instance. * - * @param handle Indicates the ArkUI_NodeContentHandle instance. + * @param content Indicates the ArkUI_NodeContentHandle instance. * @param callback Indicates the callback of ArkUI_NodeContentHandle * @return Returns the status code * @since 12 */ -int32_t OH_ArkUI_NodeContent_RegisterCallback(ArkUI_NodeContentHandle handle, ArkUI_NodeContentCallback callback); +int32_t OH_ArkUI_NodeContent_RegisterCallback(ArkUI_NodeContentHandle content, ArkUI_NodeContentCallback callback); /** * @brief Obtains the type of a node content. @@ -6917,6 +6917,36 @@ int32_t OH_ArkUI_NodeContent_RegisterCallback(ArkUI_NodeContentHandle handle, Ar */ ArkUI_NodeContentEventType OH_ArkUI_NodeContentEvent_GetEventType(ArkUI_NodeContentEvent* event); +/** + * @brief Obtains the node content object that triggers a node content event. + * + * @param event Indicates the pointer to the node content event. + * @return Returns the node content object that triggers the node content event. + * @since 12 + */ +ArkUI_NodeContentHandle OH_ArkUI_NodeContentEvent_GetNodeContentHandle(ArkUI_NodeContentEvent* event); + +/** + * @brief Saves custom data on the specified node content. + * + * @param content Indicates the node content on which the custom data will be saved. + * @param userData Indicates the custom data to be saved. + * @return Returns the error code. + * Returns {@link ARKUI_ERROR_CODE_NO_ERROR} if the operation is successful. + * Returns {@link ARKUI_ERROR_CODE_PARAM_INVALID} if a parameter error occurs. + * @since 12 + */ +int32_t OH_ArkUI_NodeContent_SetUserData(ArkUI_NodeContentHandle content, void* userData); + +/** + * @brief Obtains the custom data saved on the specified node content. + * + * @param content Indicates the target node content. + * @return Returns the custom data. + * @since 12 + */ +void* OH_ArkUI_NodeContent_GetUserData(ArkUI_NodeContentHandle content); + /** * @brief Get the size of the component layout area. * The layout area size does not include graphic variation attributes such as scaling. diff --git a/interfaces/native/node/node_model.cpp b/interfaces/native/node/node_model.cpp index 0dc63c5ee94e9304d0f95fac44d532a3c3ce6836..5f3d66d1ba1020b899672ba3fc390c1d13179b02 100644 --- a/interfaces/native/node/node_model.cpp +++ b/interfaces/native/node/node_model.cpp @@ -660,37 +660,37 @@ void* GetParseJsMedia() extern "C" { #endif -int32_t OH_ArkUI_NodeContent_AddNode(ArkUI_NodeContentHandle handle, ArkUI_NodeHandle node) +int32_t OH_ArkUI_NodeContent_AddNode(ArkUI_NodeContentHandle content, ArkUI_NodeHandle node) { auto* impl = OHOS::Ace::NodeModel::GetFullImpl(); CHECK_NULL_RETURN(impl, OHOS::Ace::ERROR_CODE_NATIVE_IMPL_LIBRARY_NOT_FOUND); return impl->getNodeModifiers()->getNodeContentModifier()->addChild( - reinterpret_cast(handle), node->uiNodeHandle); + reinterpret_cast(content), node->uiNodeHandle); } -int32_t OH_ArkUI_NodeContent_InsertNode(ArkUI_NodeContentHandle handle, ArkUI_NodeHandle node, int32_t position) +int32_t OH_ArkUI_NodeContent_InsertNode(ArkUI_NodeContentHandle content, ArkUI_NodeHandle node, int32_t position) { auto* impl = OHOS::Ace::NodeModel::GetFullImpl(); CHECK_NULL_RETURN(impl, OHOS::Ace::ERROR_CODE_NATIVE_IMPL_LIBRARY_NOT_FOUND); return impl->getNodeModifiers()->getNodeContentModifier()->insertChild( - reinterpret_cast(handle), node->uiNodeHandle, position); + reinterpret_cast(content), node->uiNodeHandle, position); } -int32_t OH_ArkUI_NodeContent_RemoveNode(ArkUI_NodeContentHandle handle, ArkUI_NodeHandle node) +int32_t OH_ArkUI_NodeContent_RemoveNode(ArkUI_NodeContentHandle content, ArkUI_NodeHandle node) { auto* impl = OHOS::Ace::NodeModel::GetFullImpl(); CHECK_NULL_RETURN(impl, OHOS::Ace::ERROR_CODE_NATIVE_IMPL_LIBRARY_NOT_FOUND); return impl->getNodeModifiers()->getNodeContentModifier()->removeChild( - reinterpret_cast(handle), node->uiNodeHandle); + reinterpret_cast(content), node->uiNodeHandle); } -int32_t OH_ArkUI_NodeContent_RegisterCallback(ArkUI_NodeContentHandle handle, ArkUI_NodeContentCallback callback) +int32_t OH_ArkUI_NodeContent_RegisterCallback(ArkUI_NodeContentHandle content, ArkUI_NodeContentCallback callback) { auto* impl = OHOS::Ace::NodeModel::GetFullImpl(); CHECK_NULL_RETURN(impl, OHOS::Ace::ERROR_CODE_NATIVE_IMPL_LIBRARY_NOT_FOUND); auto innerCallback = reinterpret_cast(callback); return impl->getNodeModifiers()->getNodeContentModifier()->registerEvent( - reinterpret_cast(handle), nullptr, innerCallback); + reinterpret_cast(content), nullptr, innerCallback); } ArkUI_NodeContentEventType OH_ArkUI_NodeContentEvent_GetEventType(ArkUI_NodeContentEvent* event) @@ -700,6 +700,29 @@ ArkUI_NodeContentEventType OH_ArkUI_NodeContentEvent_GetEventType(ArkUI_NodeCont return static_cast(innerEvent->type); } +ArkUI_NodeContentHandle OH_ArkUI_NodeContentEvent_GetNodeContentHandle(ArkUI_NodeContentEvent* event) +{ + CHECK_NULL_RETURN(event, nullptr); + auto* innerEvent = reinterpret_cast(event); + return reinterpret_cast(innerEvent->nodeContent); +} + +int32_t OH_ArkUI_NodeContent_SetUserData(ArkUI_NodeContentHandle content, void* userData) +{ + auto* impl = OHOS::Ace::NodeModel::GetFullImpl(); + CHECK_NULL_RETURN(impl, OHOS::Ace::ERROR_CODE_NATIVE_IMPL_LIBRARY_NOT_FOUND); + return impl->getNodeModifiers()->getNodeContentModifier()->setUserData( + reinterpret_cast(content), userData); +} + +void* OH_ArkUI_NodeContent_GetUserData(ArkUI_NodeContentHandle content) +{ + auto* impl = OHOS::Ace::NodeModel::GetFullImpl(); + CHECK_NULL_RETURN(impl, nullptr); + return impl->getNodeModifiers()->getNodeContentModifier()->getUserData( + reinterpret_cast(content)); +} + #ifdef __cplusplus }; #endif