!45495 修复自定义属性空指针问题

Merge pull request !45495 from 邹林肯/cp3
This commit is contained in:
openharmony_ci 2024-10-12 07:08:40 +00:00 committed by Gitee
commit 0aa05fd7d4
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 28 additions and 16 deletions

View File

@ -5805,7 +5805,6 @@ void FrameNode::ResetPredictNodes()
void FrameNode::SetJSCustomProperty(std::function<bool()> func, std::function<std::string(const std::string&)> getFunc)
{
std::lock_guard<std::mutex> lock(customPropertyMapLock_);
bool result = func();
if (IsCNode()) {
return;
@ -5832,7 +5831,6 @@ bool FrameNode::GetCapiCustomProperty(const std::string& key, std::string& value
if (!IsCNode()) {
return false;
}
std::lock_guard<std::mutex> lock(customPropertyMapLock_);
auto iter = customPropertyMap_.find(key);
if (iter != customPropertyMap_.end()) {
value = iter->second;
@ -5843,13 +5841,11 @@ bool FrameNode::GetCapiCustomProperty(const std::string& key, std::string& value
void FrameNode::AddCustomProperty(const std::string& key, const std::string& value)
{
std::lock_guard<std::mutex> lock(customPropertyMapLock_);
customPropertyMap_[key] = value;
}
void FrameNode::RemoveCustomProperty(const std::string& key)
{
std::lock_guard<std::mutex> lock(customPropertyMapLock_);
auto iter = customPropertyMap_.find(key);
if (iter != customPropertyMap_.end()) {
customPropertyMap_.erase(iter);

View File

@ -1367,7 +1367,6 @@ private:
DragPreviewOption previewOption_ { true, false, false, false, false, false, { .isShowBadge = true } };
std::unordered_map<std::string, std::string> customPropertyMap_;
std::mutex customPropertyMapLock_;
RefPtr<Recorder::ExposureProcessor> exposureProcessor_;

View File

@ -528,17 +528,24 @@ void AddCustomProperty(ArkUINodeHandle node, ArkUI_CharPtr key, ArkUI_CharPtr va
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
std::string keyStr = key;
std::string valueStr = value;
ViewAbstract::AddCustomProperty(frameNode, keyStr, valueStr);
auto pipeline = frameNode->GetContextRefPtr();
if (pipeline && !pipeline->CheckThreadSafe()) {
LOGW("AddCustomProperty doesn't run on UI thread");
return;
}
ViewAbstract::AddCustomProperty(frameNode, key, value);
}
void RemoveCustomProperty(ArkUINodeHandle node, ArkUI_CharPtr key)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
std::string keyStr = key;
ViewAbstract::RemoveCustomProperty(frameNode, keyStr);
auto pipeline = frameNode->GetContextRefPtr();
if (pipeline && !pipeline->CheckThreadSafe()) {
LOGW("RemoveCustomProperty doesn't run on UI thread");
return;
}
ViewAbstract::RemoveCustomProperty(frameNode, key);
}
namespace NodeModifier {

View File

@ -7394,21 +7394,21 @@ int32_t OH_ArkUI_NodeUtils_GetPositionWithTranslateInWindow(ArkUI_NodeHandle nod
int32_t OH_ArkUI_NodeUtils_GetPositionWithTranslateInScreen(ArkUI_NodeHandle node, ArkUI_IntOffset* translateOffset);
/**
* @brief Set the custom property of the component.
* @brief Add the custom property of the component. This interface only works on the main thread.
*
* @param node ArkUI_NodeHandle pointer.
* @param name The name of the custom property.
* @param value The value of the custom property.
* @since 14
* @param name The name of the custom property. Passing null pointers is not allowed.
* @param value The value of the custom property. Passing null pointers is not allowed.
* @since 13
*/
void OH_ArkUI_NodeUtils_AddCustomProperty(ArkUI_NodeHandle node, const char* name, const char* value);
/**
* @brief Remove the custom property of the component.
* @brief Remove the custom property of the component.
*
* @param node ArkUI_NodeHandle pointer.
* @param name The name of the custom property.
* @since 14
* @since 13
*/
void OH_ArkUI_NodeUtils_RemoveCustomProperty(ArkUI_NodeHandle node, const char* name);

View File

@ -14,8 +14,10 @@
*/
#include <cstdlib>
#include "node_model.h"
#include "base/utils/utils.h"
#include "base/error/error_code.h"
#ifdef __cplusplus
@ -165,6 +167,10 @@ void OH_ArkUI_NodeUtils_AddCustomProperty(ArkUI_NodeHandle node, const char* nam
if (node == nullptr) {
return;
}
if (name == nullptr || value == nullptr) {
LOGF("AddCustomProperty input params name or value is nullptr");
abort();
}
auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
impl->getNodeModifiers()->getFrameNodeModifier()->addCustomProperty(node->uiNodeHandle, name, value);
}
@ -174,6 +180,10 @@ void OH_ArkUI_NodeUtils_RemoveCustomProperty(ArkUI_NodeHandle node, const char*
if (node == nullptr) {
return;
}
if (name == nullptr) {
LOGF("RemoveCustomProperty input params name is nullptr");
abort();
}
auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
impl->getNodeModifiers()->getFrameNodeModifier()->removeCustomProperty(node->uiNodeHandle, name);
}