!43692 customProperty 能力增强

Merge pull request !43692 from 王丽莉/master0422
This commit is contained in:
openharmony_ci 2024-09-21 12:42:17 +00:00 committed by Gitee
commit 9d725688a6
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
19 changed files with 424 additions and 41 deletions

View File

@ -4439,10 +4439,13 @@ class ArkComponent implements CommonMethod<CommonAttribute> {
}
customProperty(key: string, value: object): this {
const property = new ArkCustomProperty();
property.key = key;
property.value = value;
modifierWithKey(this._modifiersWithKeys, CustomPropertyModifier.identity, CustomPropertyModifier, property);
let returnBool = getUINativeModule().frameNode.setCustomPropertyModiferByKey(this.nativePtr, key, value);
if (!returnBool) {
const property = new ArkCustomProperty();
property.key = key;
property.value = value;
modifierWithKey(this._modifiersWithKeys, CustomPropertyModifier.identity, CustomPropertyModifier, property);
}
return this;
}
@ -4871,6 +4874,18 @@ function __getCustomProperty__(nodeId: number, key: string): Object | undefined
return undefined;
}
function __getCustomPropertyString__(nodeId: number, key: string): string | undefined {
if (__elementIdToCustomProperties__.has(nodeId)) {
const customProperties = __elementIdToCustomProperties__.get(nodeId);
if (customProperties) {
return JSON.stringify(customProperties.get(key));
}
}
return undefined;
}
function __setCustomProperty__(nodeId: number, key: string, value: Object): boolean {
if (value !== undefined) {
__setValidCustomProperty__(nodeId, key, value);

View File

@ -470,7 +470,15 @@ class FrameNode {
}
getCustomProperty(key: string): Object | undefined {
return key === undefined ? undefined : __getCustomProperty__(this._nodeId, key);
if (key === undefined) {
return undefined;
}
let value = __getCustomProperty__(this._nodeId, key);
if (value === undefined) {
const valueStr = getUINativeModule().frameNode.getCustomPropertyCapiByKey(this.getNodePtr(), key);
value = valueStr === undefined ? undefined : valueStr;
}
return value;
}
setMeasuredSize(size: Size): void {

View File

@ -254,3 +254,4 @@ declare class NativeUtils {
}
declare function __getCustomProperty__(nodeId: number, key: string): Object | undefined;
declare function __getCustomPropertyString__(nodeId: number, key: string): string | undefined;

View File

@ -4221,10 +4221,13 @@ class ArkComponent {
return this;
}
customProperty(key, value) {
const property = new ArkCustomProperty();
property.key = key;
property.value = value;
modifierWithKey(this._modifiersWithKeys, CustomPropertyModifier.identity, CustomPropertyModifier, property);
let returnBool = getUINativeModule().frameNode.setCustomPropertyModiferByKey(this.nativePtr, key, value);
if (!returnBool) {
const property = new ArkCustomProperty();
property.key = key;
property.value = value;
modifierWithKey(this._modifiersWithKeys, CustomPropertyModifier.identity, CustomPropertyModifier, property);
}
return this;
}
systemBarEffect() {
@ -4835,6 +4838,18 @@ function __getCustomProperty__(nodeId, key) {
return undefined;
}
function __getCustomPropertyString__(nodeId, key) {
if (__elementIdToCustomProperties__.has(nodeId)) {
const customProperties = __elementIdToCustomProperties__.get(nodeId);
if (customProperties) {
return JSON.stringify(customProperties.get(key));
}
}
return undefined;
}
function __setCustomProperty__(nodeId, key, value) {
if (value !== undefined) {
__setValidCustomProperty__(nodeId, key, value);

View File

@ -1127,7 +1127,15 @@ class FrameNode {
return inspectorInfo;
}
getCustomProperty(key) {
return key === undefined ? undefined : __getCustomProperty__(this._nodeId, key);
if (key === undefined) {
return undefined;
}
let value = __getCustomProperty__(this._nodeId, key);
if (value === undefined) {
const valueStr = getUINativeModule().frameNode.getCustomPropertyCapiByKey(this.getNodePtr(), key);
value = valueStr === undefined ? undefined : valueStr;
}
return value;
}
setMeasuredSize(size) {
getUINativeModule().frameNode.setMeasuredSize(this.getNodePtr(), Math.max(size.width, 0), Math.max(size.height, 0));

View File

@ -3764,6 +3764,10 @@ void ArkUINativeModule::RegisterFrameNodeAttributes(Local<panda::ObjectRef> obje
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), FrameNodeBridge::RemoveFrameNodeFromNodeContent));
frameNode->Set(vm, panda::StringRef::NewFromUtf8(vm, "getFirstUINode"),
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), FrameNodeBridge::GetFirstUINode));
frameNode->Set(vm, panda::StringRef::NewFromUtf8(vm, "getCustomPropertyCapiByKey"),
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), FrameNodeBridge::GetCustomPropertyCapiByKey));
frameNode->Set(vm, panda::StringRef::NewFromUtf8(vm, "setCustomPropertyModiferByKey"),
panda::FunctionRef::New(const_cast<panda::EcmaVM*>(vm), FrameNodeBridge::SetCustomPropertyModiferByKey));
object->Set(vm, panda::StringRef::NewFromUtf8(vm, "frameNode"), frameNode);
}

View File

@ -1284,6 +1284,121 @@ ArkUINativeModuleValue FrameNodeBridge::GetInspectorInfo(ArkUIRuntimeCallInfo* r
auto inspectorInfo = GetArkUINodeModifiers()->getFrameNodeModifier()->getInspectorInfo(nativeNode);
return panda::StringRef::NewFromUtf8(vm, inspectorInfo);
}
ArkUINativeModuleValue FrameNodeBridge::GetCustomPropertyCapiByKey(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
auto defaultReturnValue = panda::JSValueRef::Undefined(vm);
CHECK_NULL_RETURN(vm, defaultReturnValue);
Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
CHECK_NULL_RETURN(!firstArg.IsNull(), defaultReturnValue);
auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
CHECK_NULL_RETURN(!secondArg.IsNull(), defaultReturnValue);
if (!secondArg->IsString(vm)) {
return defaultReturnValue;
}
auto key = secondArg->ToString(vm)->ToString(vm);
auto valueInfo =
GetArkUINodeModifiers()->getFrameNodeModifier()->getCustomPropertyCapiByKey(nativeNode, key.c_str());
CHECK_NULL_RETURN(valueInfo, defaultReturnValue);
return panda::StringRef::NewFromUtf8(vm, valueInfo);
}
std::function<std::string(const std::string&)> ParseGetFunc(ArkUIRuntimeCallInfo* runtimeCallInfo, int32_t nodeId)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
return [vm, nodeId](const std::string& key) -> std::string {
std::string resultString = std::string();
CHECK_NULL_RETURN(vm, resultString);
panda::LocalScope scope(vm);
auto global = JSNApi::GetGlobalObject(vm);
auto getCustomProperty = global->Get(vm, panda::StringRef::NewFromUtf8(vm, "__getCustomPropertyString__"));
if (getCustomProperty->IsUndefined() || !getCustomProperty->IsFunction(vm)) {
return resultString;
}
auto obj = getCustomProperty->ToObject(vm);
panda::Local<panda::FunctionRef> func = obj;
panda::Local<panda::JSValueRef> params2[2] = { panda::NumberRef::New(vm, nodeId), // 2 number of parameters
panda::StringRef::NewFromUtf8(vm, key.c_str()) };
auto function = panda::CopyableGlobal(vm, func);
auto callValue = function->Call(vm, function.ToLocal(), params2, 2);
if (callValue.IsNull() || callValue->IsUndefined() || !callValue->IsString(vm)) {
return resultString;
}
auto value = callValue->ToString(vm)->ToString(vm);
return value.c_str();
};
}
std::function<bool()> ParseFunc(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
Local<JSValueRef> keyArg = runtimeCallInfo->GetCallArgRef(1); // 1 key
Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(2); // 2 value
auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
auto frameNode = reinterpret_cast<FrameNode*>(nativeNode);
auto nodeId = frameNode->GetId();
panda::Local<panda::JSValueRef> params3[3] = { panda::NumberRef::New(vm, nodeId), keyArg, // 3 number of parameters
valueArg };
return [vm, frameNode, params3]() -> bool {
CHECK_NULL_RETURN(vm, false);
panda::LocalScope scope(vm);
auto global = JSNApi::GetGlobalObject(vm);
auto setCustomProperty = global->Get(vm, panda::StringRef::NewFromUtf8(vm, "__setCustomProperty__"));
if (setCustomProperty->IsUndefined() || !setCustomProperty->IsFunction(vm)) {
return false;
}
auto obj = setCustomProperty->ToObject(vm);
panda::Local<panda::FunctionRef> func = obj;
auto nodeId = frameNode->GetId();
auto function = panda::CopyableGlobal(vm, func);
auto customPropertyExisted = function->Call(vm, function.ToLocal(), params3, 3)->ToBoolean(vm)->Value();
if (customPropertyExisted) {
frameNode->SetRemoveCustomProperties([vm, nodeId]() -> void {
CHECK_NULL_VOID(vm);
panda::LocalScope scope(vm);
auto global = JSNApi::GetGlobalObject(vm);
auto removeCustomProperty =
global->Get(vm, panda::StringRef::NewFromUtf8(vm, "__removeCustomProperties__"));
if (removeCustomProperty->IsUndefined() || !removeCustomProperty->IsFunction(vm)) {
return;
}
auto obj = removeCustomProperty->ToObject(vm);
panda::Local<panda::FunctionRef> func = obj;
panda::Local<panda::JSValueRef> params[1] = { panda::NumberRef::New(vm, nodeId) };
auto function = panda::CopyableGlobal(vm, func);
function->Call(vm, function.ToLocal(), params, 1);
});
}
return true;
};
}
ArkUINativeModuleValue FrameNodeBridge::SetCustomPropertyModiferByKey(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
CHECK_NULL_RETURN(vm, panda::BooleanRef::New(vm, false));
if (!AceApplicationInfo::GetInstance().GreatOrEqualTargetAPIVersion(PlatformVersion::VERSION_FOURTEEN)) {
return panda::BooleanRef::New(vm, false);
}
auto defaultReturnValue = panda::BooleanRef::New(vm, true);
Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
Local<JSValueRef> keyArg = runtimeCallInfo->GetCallArgRef(1); // 1 key
auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
auto frameNode = reinterpret_cast<FrameNode*>(nativeNode);
CHECK_NULL_RETURN(frameNode, defaultReturnValue);
if (keyArg->IsUndefined() || keyArg->IsNull() || !keyArg->IsString(vm)) {
return defaultReturnValue;
}
auto nodeId = frameNode->GetId();
std::function<bool()> funcCallback = ParseFunc(runtimeCallInfo);
std::function<std::string(const std::string&)> getFuncCallback = ParseGetFunc(runtimeCallInfo, nodeId);
GetArkUINodeModifiers()->getFrameNodeModifier()->setCustomPropertyModiferByKey(
nativeNode, reinterpret_cast<void*>(&funcCallback), reinterpret_cast<void*>(&getFuncCallback));
return defaultReturnValue;
}
ArkUINativeModuleValue FrameNodeBridge::SetMeasuredSize(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();

View File

@ -75,6 +75,8 @@ public:
static ArkUINativeModuleValue IsClipToFrame(ArkUIRuntimeCallInfo* runtimeCallInfo);
static ArkUINativeModuleValue IsAttached(ArkUIRuntimeCallInfo* runtimeCallInfo);
static ArkUINativeModuleValue GetInspectorInfo(ArkUIRuntimeCallInfo* runtimeCallInfo);
static ArkUINativeModuleValue GetCustomPropertyCapiByKey(ArkUIRuntimeCallInfo* runtimeCallInfo);
static ArkUINativeModuleValue SetCustomPropertyModiferByKey(ArkUIRuntimeCallInfo* runtimeCallInfo);
static ArkUINativeModuleValue SetMeasuredSize(ArkUIRuntimeCallInfo* runtimeCallInfo);
static ArkUINativeModuleValue SetLayoutPosition(ArkUIRuntimeCallInfo* runtimeCallInfo);
static Local<JSValueRef> GetObjectValueByKey(EcmaVM* vm, Local<JSValueRef> object, const char* key);

View File

@ -10530,45 +10530,84 @@ std::function<void(NG::DrawingContext& context)> JSViewAbstract::GetDrawCallback
return drawCallback;
}
std::function<std::string(const std::string&)> ParseJsGetFunc(const JSCallbackInfo& info, int32_t nodeId)
{
auto* vm = info.GetVm();
return [vm, nodeId](const std::string& key) -> std::string {
std::string resultString = std::string();
CHECK_NULL_RETURN(vm, resultString);
panda::LocalScope scope(vm);
auto global = JSNApi::GetGlobalObject(vm);
auto getCustomProperty = global->Get(vm, panda::StringRef::NewFromUtf8(vm, "__getCustomPropertyString__"));
if (getCustomProperty->IsUndefined() || !getCustomProperty->IsFunction(vm)) {
return resultString;
}
auto obj = getCustomProperty->ToObject(vm);
panda::Local<panda::FunctionRef> func = obj;
panda::Local<panda::JSValueRef> params2[2] = { panda::NumberRef::New(vm, nodeId),
panda::StringRef::NewFromUtf8(vm, key.c_str()) };
auto function = panda::CopyableGlobal(vm, func);
auto callValue = function->Call(vm, function.ToLocal(), params2, 2);
if (callValue.IsNull() || callValue->IsUndefined() || !callValue->IsString(vm)) {
return resultString;
}
auto value = callValue->ToString(vm)->ToString(vm);
return value.c_str();
};
}
std::function<bool()> ParseJsFunc(const JSCallbackInfo& info, int32_t nodeId)
{
auto* vm = info.GetVm();
panda::Local<panda::JSValueRef> params3[3] = { panda::NumberRef::New(vm, nodeId), info[0]->GetLocalHandle(),
info[1]->GetLocalHandle() };
return [vm, params3]() -> bool {
CHECK_NULL_RETURN(vm, false);
panda::LocalScope scope(vm);
auto global = JSNApi::GetGlobalObject(vm);
auto setCustomProperty = global->Get(vm, panda::StringRef::NewFromUtf8(vm, "__setCustomProperty__"));
if (setCustomProperty->IsUndefined() || !setCustomProperty->IsFunction(vm)) {
return false;
}
auto obj = setCustomProperty->ToObject(vm);
panda::Local<panda::FunctionRef> func = obj;
auto frameNode = static_cast<NG::FrameNode*>(ViewAbstractModel::GetInstance()->GetFrameNode());
auto nodeId = frameNode->GetId();
auto function = panda::CopyableGlobal(vm, func);
auto customPropertyExisted = function->Call(vm, function.ToLocal(), params3, 3)->ToBoolean(vm)->Value();
if (customPropertyExisted) {
frameNode->SetRemoveCustomProperties([vm, nodeId]() -> void {
CHECK_NULL_VOID(vm);
panda::LocalScope scope(vm);
auto global = JSNApi::GetGlobalObject(vm);
auto removeCustomProperty =
global->Get(vm, panda::StringRef::NewFromUtf8(vm, "__removeCustomProperties__"));
if (removeCustomProperty->IsUndefined() || !removeCustomProperty->IsFunction(vm)) {
return;
}
auto obj = removeCustomProperty->ToObject(vm);
panda::Local<panda::FunctionRef> func = obj;
panda::Local<panda::JSValueRef> params[1] = { panda::NumberRef::New(vm, nodeId) };
auto function = panda::CopyableGlobal(vm, func);
function->Call(vm, function.ToLocal(), params, 1);
});
}
return true;
};
}
void JSViewAbstract::JsCustomProperty(const JSCallbackInfo& info)
{
if (info[0]->GetLocalHandle()->IsUndefined()) {
return;
}
auto* vm = info.GetVm();
CHECK_NULL_VOID(vm);
auto global = JSNApi::GetGlobalObject(vm);
auto setCustomProperty = global->Get(vm, panda::StringRef::NewFromUtf8(vm, "__setCustomProperty__"));
if (setCustomProperty->IsUndefined() || !setCustomProperty->IsFunction(vm)) {
return;
}
auto obj = setCustomProperty->ToObject(vm);
panda::Local<panda::FunctionRef> func = obj;
auto thisObj = info.This()->GetLocalHandle();
auto frameNode = static_cast<NG::FrameNode*>(ViewAbstractModel::GetInstance()->GetFrameNode());
auto nodeId = frameNode->GetId();
panda::Local<panda::JSValueRef> params[3] = { panda::NumberRef::New(vm, nodeId), info[0]->GetLocalHandle(),
info[1]->GetLocalHandle()
};
auto customPropertyExisted = func->Call(vm, thisObj, params, 3)->ToBoolean(vm)->Value();
if (customPropertyExisted) {
frameNode->SetRemoveCustomProperties([vm, thisObj, nodeId]()->void {
CHECK_NULL_VOID(vm);
panda::LocalScope scope(vm);
auto global = JSNApi::GetGlobalObject(vm);
auto removeCustomProperty = global->Get(vm,
panda::StringRef::NewFromUtf8(vm, "__removeCustomProperties__"));
if (removeCustomProperty->IsUndefined() || !removeCustomProperty->IsFunction(vm)) {
return;
}
auto obj = removeCustomProperty->ToObject(vm);
panda::Local<panda::FunctionRef> func = obj;
panda::Local<panda::JSValueRef> params[1] = { panda::NumberRef::New(vm, nodeId) };
func->Call(vm, thisObj, params, 1);
});
}
auto getFunc = ParseJsGetFunc(info, nodeId);
auto func = ParseJsFunc(info, nodeId);
frameNode->SetJSCustomProperty(func, getFunc);
}
void JSViewAbstract::JsGestureModifier(const JSCallbackInfo& info)

View File

@ -74,6 +74,7 @@ constexpr uint8_t APP_RENDER_GROUP_MARKED_MASK = 1 << 7;
constexpr float HIGHT_RATIO_LIMIT = 0.8;
// Min area for OPINC
constexpr int32_t MIN_OPINC_AREA = 10000;
constexpr char UPDATE_FLAG_KEY[] = "updateFlag";
} // namespace
namespace OHOS::Ace::NG {
@ -5729,4 +5730,55 @@ void FrameNode::ResetPredictNodes()
}
}
}
void FrameNode::SetJSCustomProperty(std::function<bool()> func, std::function<std::string(const std::string&)> getFunc)
{
std::lock_guard<std::mutex> lock(mutex_);
bool result = func();
if (isCNode_) {
return;
}
if (result) {
customPropertyMap_[UPDATE_FLAG_KEY] = true;
}
if (!getCustomProperty_) {
getCustomProperty_ = getFunc;
}
}
std::string FrameNode::GetJSCustomProperty(const std::string& key)
{
if (getCustomProperty_) {
return getCustomProperty_(key);
}
return nullptr;
}
std::string FrameNode::GetCapiCustomProperty(const std::string& key)
{
if (!isCNode_) {
return std::string();
}
std::lock_guard<std::mutex> lock(mutex_);
auto iter = customPropertyMap_.find(key);
if (iter != customPropertyMap_.end()) {
return customPropertyMap_[key];
}
return std::string();
}
void FrameNode::AddCustomProperty(const std::string& key, const std::string& value)
{
std::lock_guard<std::mutex> lock(mutex_);
customPropertyMap_[key] = value;
}
void FrameNode::RemoveCustomProperty(const std::string& key)
{
std::lock_guard<std::mutex> lock(mutex_);
auto iter = customPropertyMap_.find(key);
if (iter != customPropertyMap_.end()) {
customPropertyMap_.erase(iter);
}
}
} // namespace OHOS::Ace::NG

View File

@ -1089,6 +1089,18 @@ public:
void OnForegroundColorUpdate(const Color& value);
void SetJSCustomProperty(std::function<bool()> func, std::function<std::string(const std::string&)> getFunc);
std::string GetJSCustomProperty(const std::string& key);
std::string GetCapiCustomProperty(const std::string& key);
void AddCustomProperty(const std::string& key, const std::string& value);
void RemoveCustomProperty(const std::string& key);
void setIsCNode(bool createByCapi)
{
isCNode_ = createByCapi;
}
protected:
void DumpInfo() override;
std::unordered_map<std::string, std::function<void()>> destroyCallbacksMap_;
@ -1257,6 +1269,7 @@ private:
std::set<std::string> allowDrop_;
const static std::set<std::string> layoutTags_;
std::function<void()> removeCustomProperties_;
std::function<std::string(const std::string& key)> getCustomProperty_;
std::optional<RectF> viewPort_;
NG::DragDropInfo dragPreviewInfo_;
@ -1326,12 +1339,17 @@ private:
bool isUseTransitionAnimator_ = false;
bool isCNode_ = false;
RefPtr<FrameNode> overlayNode_;
std::unordered_map<std::string, int32_t> sceneRateMap_;
DragPreviewOption previewOption_ { true, false, false, false, false, false, { .isShowBadge = true } };
std::unordered_map<std::string, std::string> customPropertyMap_;
std::mutex mutex_;
RefPtr<Recorder::ExposureProcessor> exposureProcessor_;
std::pair<uint64_t, OffsetF> cachedGlobalOffset_ = { 0, OffsetF() };

View File

@ -4984,4 +4984,17 @@ void ViewAbstract::SetSystemFontChangeEvent(FrameNode* frameNode, std::function<
CHECK_NULL_VOID(frameNode);
frameNode->SetNDKFontUpdateCallback(std::move(onFontChange));
}
void ViewAbstract::AddCustomProperty(FrameNode* frameNode, const std::string& key, const std::string& value)
{
CHECK_NULL_VOID(frameNode);
frameNode->AddCustomProperty(key, value);
}
void ViewAbstract::RemoveCustomProperty(FrameNode* frameNode, const std::string& key)
{
CHECK_NULL_VOID(frameNode);
frameNode->RemoveCustomProperty(key);
}
} // namespace OHOS::Ace::NG

View File

@ -762,6 +762,8 @@ public:
static void SetPositionLocalizedEdges(bool needLocalized);
static void SetLocalizedMarkAnchor(bool needLocalized);
static void SetOffsetLocalizedEdges(bool needLocalized);
static void AddCustomProperty(FrameNode* frameNode, const std::string& key, const std::string& value);
static void RemoveCustomProperty(FrameNode* frameNode, const std::string& key);
private:
static void AddDragFrameNodeToManager();

View File

@ -4749,6 +4749,10 @@ struct ArkUIFrameNodeModifier {
void (*resetSystemColorModeChangeEvent)(ArkUINodeHandle node);
ArkUI_Int32 (*setSystemFontStyleChangeEvent)(ArkUINodeHandle node, void* userData, void* onFontStyleChange);
void (*resetSystemFontStyleChangeEvent)(ArkUINodeHandle node);
ArkUI_CharPtr (*getCustomPropertyCapiByKey)(ArkUINodeHandle node, ArkUI_CharPtr key);
void (*setCustomPropertyModiferByKey)(ArkUINodeHandle node, void* callback, void* getCallback);
void (*addCustomProperty)(ArkUINodeHandle node, ArkUI_CharPtr key, ArkUI_CharPtr value);
void (*removeCustomProperty)(ArkUINodeHandle node, ArkUI_CharPtr key);
};
struct ArkUINodeContentEvent {

View File

@ -492,6 +492,45 @@ void ResetSystemFontStyleChangeEvent(ArkUINodeHandle node)
ViewAbstract::SetSystemFontChangeEvent(frameNode, nullptr);
}
ArkUI_CharPtr getCustomPropertyCapiByKey(ArkUINodeHandle node, ArkUI_CharPtr key)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_RETURN(frameNode, nullptr);
static std::string capiCustomProperty;
capiCustomProperty = frameNode->GetCapiCustomProperty(key);
if (capiCustomProperty.empty()) {
return nullptr;
}
return capiCustomProperty.c_str();
}
void SetCustomPropertyModiferByKey(ArkUINodeHandle node, void* callback, void* getCallback)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
std::function<bool()>* func = reinterpret_cast<std::function<bool()>*>(callback);
std::function<std::string(const std::string&)>* getFunc =
reinterpret_cast<std::function<std::string(const std::string&)>*>(getCallback);
frameNode->SetJSCustomProperty(*func, *getFunc);
}
void AddCustomProperty(ArkUINodeHandle node, ArkUI_CharPtr key, ArkUI_CharPtr value)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
std::string keyStr = key;
std::string valueStr = value;
ViewAbstract::AddCustomProperty(frameNode, keyStr, valueStr);
}
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);
}
namespace NodeModifier {
const ArkUIFrameNodeModifier* GetFrameNodeModifier()
{
@ -503,7 +542,8 @@ const ArkUIFrameNodeModifier* GetFrameNodeModifier()
GetInspectorId, GetNodeType, IsVisible, IsAttached, GetInspectorInfo, GetFrameNodeById, GetFrameNodeByUniqueId,
GetFrameNodeByKey, GetAttachedFrameNodeById, PropertyUpdate, GetLast, GetFirstUINode, GetLayoutSize,
GetLayoutPositionWithoutMargin, SetSystemColorModeChangeEvent, ResetSystemColorModeChangeEvent,
SetSystemFontStyleChangeEvent, ResetSystemFontStyleChangeEvent };
SetSystemFontStyleChangeEvent, ResetSystemFontStyleChangeEvent, getCustomPropertyCapiByKey,
SetCustomPropertyModiferByKey, AddCustomProperty, RemoveCustomProperty };
return &modifier;
}

View File

@ -200,6 +200,8 @@ ArkUINodeHandle CreateNode(ArkUINodeType type, int peerId, ArkUI_Int32 flags)
if (flags == ARKUI_NODE_FLAG_C) {
ContainerScope Scope(Container::CurrentIdSafelyWithCheck());
node = reinterpret_cast<ArkUINodeHandle>(ViewModel::CreateNode(type, peerId));
auto* frameNode = reinterpret_cast<FrameNode*>(node);
frameNode->setIsCNode(true);
} else {
node = reinterpret_cast<ArkUINodeHandle>(ViewModel::CreateNode(type, peerId));
}

View File

@ -1419,6 +1419,14 @@
"first_introduced": "12",
"name": "OH_ArkUI_NodeUtils_GetPositionWithTranslateInScreen"
},
{
"first_introduced": "14",
"name": "OH_ArkUI_NodeUtils_AddCustomProperty"
},
{
"first_introduced": "14",
"name": "OH_ArkUI_NodeUtils_RemoveCustomProperty"
},
{
"first_introduced": "12",
"name": "OH_ArkUI_ListChildrenMainSizeOption_Create"

View File

@ -7382,6 +7382,25 @@ 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.
*
* @param node ArkUI_NodeHandle pointer.
* @param name The name of the custom property.
* @param value The value of the custom property.
* @since 14
*/
void OH_ArkUI_NodeUtils_AddCustomProperty(ArkUI_NodeHandle node, const char* name, const char* value);
/**
* @brief Remove the custom property of the component.
*
* @param node ArkUI_NodeHandle pointer.
* @param name The name of the custom property.
* @since 14
*/
void OH_ArkUI_NodeUtils_RemoveCustomProperty(ArkUI_NodeHandle node, const char* name);
/**
* @brief The event called when the sliding operation offset changes.
*

View File

@ -160,6 +160,24 @@ float OH_ArkUI_SystemFontStyleEvent_GetFontWeightScale(const ArkUI_SystemFontSty
return event->fontWeight;
}
void OH_ArkUI_NodeUtils_AddCustomProperty(ArkUI_NodeHandle node, const char* name, const char* value)
{
if (node == nullptr) {
return;
}
auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
impl->getNodeModifiers()->getFrameNodeModifier()->addCustomProperty(node->uiNodeHandle, name, value);
}
void OH_ArkUI_NodeUtils_RemoveCustomProperty(ArkUI_NodeHandle node, const char* name)
{
if (node == nullptr) {
return;
}
auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
impl->getNodeModifiers()->getFrameNodeModifier()->removeCustomProperty(node->uiNodeHandle, name);
}
#ifdef __cplusplus
};
#endif