diff --git a/frameworks/bridge/declarative_frontend/ark_component/src/ArkXComponent.ts b/frameworks/bridge/declarative_frontend/ark_component/src/ArkXComponent.ts index 78186569e879a6f6b5e9f832d80b45fad9bf934c..d9093cf66b12755ae1f0f60a01421febb53b441f 100644 --- a/frameworks/bridge/declarative_frontend/ark_component/src/ArkXComponent.ts +++ b/frameworks/bridge/declarative_frontend/ark_component/src/ArkXComponent.ts @@ -61,14 +61,6 @@ class ArkXComponentComponent extends ArkComponent implements XComponentAttribute outlineWidth(value: Dimension | EdgeOutlineWidths): this { throw new Error('Method not implemented.'); } - width(value: Length): this { - modifierWithKey(this._modifiersWithKeys, XComponentWidthModifier.identity, XComponentWidthModifier, value); - return this; - } - height(value: Length): this { - modifierWithKey(this._modifiersWithKeys, XComponentHeightModifier.identity, XComponentHeightModifier, value); - return this; - } expandSafeArea(types?: SafeAreaType[], edges?: SafeAreaEdge[]): this { throw new Error('Method not implemented.'); } @@ -539,42 +531,6 @@ class XComponentInitializeModifier extends ModifierWithKey { } } -class XComponentWidthModifier extends ModifierWithKey { - constructor(value: Length) { - super(value); - } - static identity: Symbol = Symbol('xComponentWidth'); - applyPeer(node: KNode, reset: boolean): void { - if (reset) { - getUINativeModule().xComponent.resetWidth(node); - } else { - getUINativeModule().xComponent.setWidth(node, this.value); - } - } - - checkObjectDiff(): boolean { - return !isBaseOrResourceEqual(this.stageValue, this.value); - } -} - -class XComponentHeightModifier extends ModifierWithKey { - constructor(value: Length) { - super(value); - } - static identity: Symbol = Symbol('xComponentHeight'); - applyPeer(node: KNode, reset: boolean): void { - if (reset) { - getUINativeModule().xComponent.resetHeight(node); - } else { - getUINativeModule().xComponent.setHeight(node, this.value); - } - } - - checkObjectDiff(): boolean { - return !isBaseOrResourceEqual(this.stageValue, this.value); - } -} - class XComponentOpacityModifier extends ModifierWithKey { constructor(value: number | Resource) { super(value); diff --git a/frameworks/bridge/declarative_frontend/engine/arkComponent.js b/frameworks/bridge/declarative_frontend/engine/arkComponent.js index e256cb3dd06d9a6281aee497a545820e27984c96..0778cfe931a78c7952b49aa965605b575fa50ee6 100644 --- a/frameworks/bridge/declarative_frontend/engine/arkComponent.js +++ b/frameworks/bridge/declarative_frontend/engine/arkComponent.js @@ -24220,14 +24220,6 @@ class ArkXComponentComponent extends ArkComponent { outlineWidth(value) { throw new Error('Method not implemented.'); } - width(value) { - modifierWithKey(this._modifiersWithKeys, XComponentWidthModifier.identity, XComponentWidthModifier, value); - return this; - } - height(value) { - modifierWithKey(this._modifiersWithKeys, XComponentHeightModifier.identity, XComponentHeightModifier, value); - return this; - } expandSafeArea(types, edges) { throw new Error('Method not implemented.'); } @@ -24710,40 +24702,6 @@ class XComponentOpacityModifier extends ModifierWithKey { } } XComponentOpacityModifier.identity = Symbol('xComponentOpacity'); -class XComponentWidthModifier extends ModifierWithKey { - constructor(value) { - super(value); - } - applyPeer(node, reset) { - if (reset) { - getUINativeModule().xComponent.resetWidth(node); - } - else { - getUINativeModule().xComponent.setWidth(node, this.value); - } - } - checkObjectDiff() { - return !isBaseOrResourceEqual(this.stageValue, this.value); - } -} -XComponentWidthModifier.identity = Symbol('xComponentWidth'); -class XComponentHeightModifier extends ModifierWithKey { - constructor(value) { - super(value); - } - applyPeer(node, reset) { - if (reset) { - getUINativeModule().xComponent.resetHeight(node); - } - else { - getUINativeModule().xComponent.setHeight(node, this.value); - } - } - checkObjectDiff() { - return !isBaseOrResourceEqual(this.stageValue, this.value); - } -} -XComponentHeightModifier.identity = Symbol('xComponentHeight'); class XComponentBackgroundColorModifier extends ModifierWithKey { constructor(value) { super(value); diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/jsi_declarative_engine.cpp b/frameworks/bridge/declarative_frontend/engine/jsi/jsi_declarative_engine.cpp index ce6e389cbf56e7965765ada1fc3b3467d9e61e81..b24d337e06b99e25a165a2e8b2bcfdbf6fb6a046 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/jsi_declarative_engine.cpp +++ b/frameworks/bridge/declarative_frontend/engine/jsi/jsi_declarative_engine.cpp @@ -2146,21 +2146,11 @@ void JsiDeclarativeEngine::FireExternalEvent( CHECK_EQUAL_VOID(xcPattern->GetLibraryName().has_value(), false); std::weak_ptr weakNativeXComponent; RefPtr nativeXComponentImpl = nullptr; - std::tie(nativeXComponentImpl, weakNativeXComponent) = xcPattern->GetNativeXComponent(); auto nativeXComponent = weakNativeXComponent.lock(); CHECK_NULL_VOID(nativeXComponent); CHECK_NULL_VOID(nativeXComponentImpl); - auto type = xcPattern->GetType(); - if (type == XComponentType::SURFACE || type == XComponentType::TEXTURE) { - void* nativeWindow = nullptr; - nativeWindow = xcPattern->GetNativeWindow(); - if (!nativeWindow) { - return; - } - nativeXComponentImpl->SetSurface(nativeWindow); - } nativeXComponentImpl->SetXComponentId(componentId); #ifdef XCOMPONENT_SUPPORTED xcPattern->SetExpectedRateRangeInit(); @@ -2193,6 +2183,7 @@ void JsiDeclarativeEngine::FireExternalEvent( OHOS::Ace::Framework::XComponentClient::GetInstance().AddJsValToJsValMap(componentId, obj); napi_close_handle_scope(reinterpret_cast(nativeEngine_), handleScope); + auto type = xcPattern->GetType(); if (type == XComponentType::SURFACE || type == XComponentType::TEXTURE) { auto task = [weak = WeakClaim(this), weakPattern = AceType::WeakClaim(AceType::RawPtr(xcPattern))]() { auto pattern = weakPattern.Upgrade(); diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_api_impl_bridge.cpp b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_api_impl_bridge.cpp index 2978e8fb6c67e557d84e2fe543d604023c7fa890..b0f2f70354d0e9e0c757ed096b4df64840c90d3c 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_api_impl_bridge.cpp +++ b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_api_impl_bridge.cpp @@ -869,18 +869,6 @@ ArkUINativeModuleValue ArkUINativeModule::GetArkUINativeModule(ArkUIRuntimeCallI panda::FunctionRef::New(const_cast(vm), CommonBridge::SetOnDetach)); common->Set(vm, panda::StringRef::NewFromUtf8(vm, "resetOnDetach"), panda::FunctionRef::New(const_cast(vm), CommonBridge::ResetOnDetach)); - common->Set(vm, panda::StringRef::NewFromUtf8(vm, "setOnLoad"), - panda::FunctionRef::New(const_cast(vm), CommonBridge::SetOnLoad)); - common->Set(vm, panda::StringRef::NewFromUtf8(vm, "resetOnLoad"), - panda::FunctionRef::New(const_cast(vm), CommonBridge::ResetOnLoad)); - common->Set(vm, panda::StringRef::NewFromUtf8(vm, "setOnDestroy"), - panda::FunctionRef::New(const_cast(vm), CommonBridge::SetOnDestroy)); - common->Set(vm, panda::StringRef::NewFromUtf8(vm, "resetOnDestroy"), - panda::FunctionRef::New(const_cast(vm), CommonBridge::ResetOnDestroy)); - common->Set(vm, panda::StringRef::NewFromUtf8(vm, "setEnableAnalyzer"), - panda::FunctionRef::New(const_cast(vm), CommonBridge::SetEnableAnalyzer)); - common->Set(vm, panda::StringRef::NewFromUtf8(vm, "resetEnableAnalyzer"), - panda::FunctionRef::New(const_cast(vm), CommonBridge::ResetEnableAnalyzer)); common->Set(vm, panda::StringRef::NewFromUtf8(vm, "setOnKeyEvent"), panda::FunctionRef::New(const_cast(vm), CommonBridge::SetOnKeyEvent)); common->Set(vm, panda::StringRef::NewFromUtf8(vm, "resetOnKeyEvent"), @@ -5008,14 +4996,6 @@ void ArkUINativeModule::RegisterXComponentAttributes(Local obj panda::FunctionRef::New(const_cast(vm), XComponentBridge::SetXComponentInitialize)); xComponent->Set(vm, panda::StringRef::NewFromUtf8(vm, "resetXComponentInitialize"), panda::FunctionRef::New(const_cast(vm), XComponentBridge::ResetXComponentInitialize)); - xComponent->Set(vm, panda::StringRef::NewFromUtf8(vm, "setWidth"), - panda::FunctionRef::New(const_cast(vm), XComponentBridge::SetWidth)); - xComponent->Set(vm, panda::StringRef::NewFromUtf8(vm, "resetWidth"), - panda::FunctionRef::New(const_cast(vm), XComponentBridge::ResetWidth)); - xComponent->Set(vm, panda::StringRef::NewFromUtf8(vm, "setHeight"), - panda::FunctionRef::New(const_cast(vm), XComponentBridge::SetHeight)); - xComponent->Set(vm, panda::StringRef::NewFromUtf8(vm, "resetHeight"), - panda::FunctionRef::New(const_cast(vm), XComponentBridge::ResetHeight)); xComponent->Set(vm, panda::StringRef::NewFromUtf8(vm, "setBackgroundColor"), panda::FunctionRef::New(const_cast(vm), XComponentBridge::SetBackgroundColor)); xComponent->Set(vm, panda::StringRef::NewFromUtf8(vm, "resetBackgroundColor"), diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.cpp b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.cpp index 56938603dc745ddd589e1b468addb006c269b523..83e418c55be9d68d901999ddce0c9c1931f28bcb 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.cpp +++ b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.cpp @@ -6482,102 +6482,6 @@ ArkUINativeModuleValue CommonBridge::ResetOnDetach(ArkUIRuntimeCallInfo* runtime return panda::JSValueRef::Undefined(vm); } -ArkUINativeModuleValue CommonBridge::SetOnLoad(ArkUIRuntimeCallInfo* runtimeCallInfo) -{ - EcmaVM* vm = runtimeCallInfo->GetVM(); - CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm)); - auto* frameNode = GetFrameNode(runtimeCallInfo); - CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm)); - Local secondeArg = runtimeCallInfo->GetCallArgRef(1); - CHECK_NULL_RETURN(secondeArg->IsFunction(vm), panda::JSValueRef::Undefined(vm)); - auto obj = secondeArg->ToObject(vm); - auto containerId = Container::CurrentId(); - panda::Local func = obj; - auto onLoad = [vm, func = panda::CopyableGlobal(vm, func), node = AceType::WeakClaim(frameNode), - containerId](const std::string& xcomponentId) { - panda::LocalScope pandaScope(vm); - panda::TryCatch trycatch(vm); - ContainerScope scope(containerId); - PipelineContext::SetCallBackNode(node); - const char* keys[] = { "load" }; - Local values[] = { panda::StringRef::NewFromUtf8(vm, xcomponentId.c_str()) }; - auto obj = panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keys), keys, values); - panda::Local params[1] = { obj }; - func->Call(vm, func.ToLocal(), params, 1); - }; - NG::ViewAbstract::SetOnLoad(frameNode, std::move(onLoad)); - return panda::JSValueRef::Undefined(vm); -} - -ArkUINativeModuleValue CommonBridge::ResetOnLoad(ArkUIRuntimeCallInfo* runtimeCallInfo) -{ - EcmaVM* vm = runtimeCallInfo->GetVM(); - CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm)); - auto* frameNode = GetFrameNode(runtimeCallInfo); - CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm)); - ViewAbstract::DisableOnLoad(frameNode); - return panda::JSValueRef::Undefined(vm); -} - -ArkUINativeModuleValue CommonBridge::SetOnDestroy(ArkUIRuntimeCallInfo* runtimeCallInfo) -{ - EcmaVM* vm = runtimeCallInfo->GetVM(); - CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm)); - auto* frameNode = GetFrameNode(runtimeCallInfo); - CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm)); - Local secondeArg = runtimeCallInfo->GetCallArgRef(1); - CHECK_NULL_RETURN(secondeArg->IsFunction(vm), panda::JSValueRef::Undefined(vm)); - auto obj = secondeArg->ToObject(vm); - auto containerId = Container::CurrentId(); - panda::Local func = obj; - auto onDestroy = [vm, func = panda::CopyableGlobal(vm, func), node = AceType::WeakClaim(frameNode), - containerId]() { - panda::LocalScope pandaScope(vm); - panda::TryCatch trycatch(vm); - ContainerScope scope(containerId); - PipelineContext::SetCallBackNode(node); - func->Call(vm, func.ToLocal(), nullptr, 0); - }; - NG::ViewAbstract::SetOnDestroy(frameNode, std::move(onDestroy)); - return panda::JSValueRef::Undefined(vm); -} - -ArkUINativeModuleValue CommonBridge::ResetOnDestroy(ArkUIRuntimeCallInfo* runtimeCallInfo) -{ - EcmaVM* vm = runtimeCallInfo->GetVM(); - CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm)); - auto* frameNode = GetFrameNode(runtimeCallInfo); - CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm)); - ViewAbstract::DisableOnDestroy(frameNode); - return panda::JSValueRef::Undefined(vm); -} - -ArkUINativeModuleValue CommonBridge::SetEnableAnalyzer(ArkUIRuntimeCallInfo* runtimeCallInfo) -{ - EcmaVM* vm = runtimeCallInfo->GetVM(); - CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm)); - Local firstArg = runtimeCallInfo->GetCallArgRef(NUM_0); - Local secondArg = runtimeCallInfo->GetCallArgRef(NUM_1); - auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value()); - if (secondArg->IsBoolean()) { - bool boolValue = secondArg->ToBoolean(vm)->Value(); - GetArkUINodeModifiers()->getCommonModifier()->setEnableAnalyzer(nativeNode, boolValue); - } else { - GetArkUINodeModifiers()->getCommonModifier()->resetEnableAnalyzer(nativeNode); - } - return panda::JSValueRef::Undefined(vm); -} - -ArkUINativeModuleValue CommonBridge::ResetEnableAnalyzer(ArkUIRuntimeCallInfo* runtimeCallInfo) -{ - EcmaVM* vm = runtimeCallInfo->GetVM(); - CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm)); - Local firstArg = runtimeCallInfo->GetCallArgRef(NUM_0); - auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value()); - GetArkUINodeModifiers()->getCommonModifier()->resetEnableAnalyzer(nativeNode); - return panda::JSValueRef::Undefined(vm); -} - ArkUINativeModuleValue CommonBridge::SetOnKeyEvent(ArkUIRuntimeCallInfo* runtimeCallInfo) { EcmaVM* vm = runtimeCallInfo->GetVM(); diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.h b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.h index 6fa8a17ca6231fa1e5239ae4a6ee65d16fb4515f..080912f44c5115da94b902989cae79050084134b 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.h +++ b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.h @@ -295,12 +295,6 @@ public: static ArkUINativeModuleValue ResetOnAttach(ArkUIRuntimeCallInfo* runtimeCallInfo); static ArkUINativeModuleValue SetOnDetach(ArkUIRuntimeCallInfo* runtimeCallInfo); static ArkUINativeModuleValue ResetOnDetach(ArkUIRuntimeCallInfo* runtimeCallInfo); - static ArkUINativeModuleValue SetOnLoad(ArkUIRuntimeCallInfo* runtimeCallInfo); - static ArkUINativeModuleValue ResetOnLoad(ArkUIRuntimeCallInfo* runtimeCallInfo); - static ArkUINativeModuleValue SetOnDestroy(ArkUIRuntimeCallInfo* runtimeCallInfo); - static ArkUINativeModuleValue ResetOnDestroy(ArkUIRuntimeCallInfo* runtimeCallInfo); - static ArkUINativeModuleValue SetEnableAnalyzer(ArkUIRuntimeCallInfo* runtimeCallInfo); - static ArkUINativeModuleValue ResetEnableAnalyzer(ArkUIRuntimeCallInfo* runtimeCallInfo); static ArkUINativeModuleValue SetOnKeyEvent(ArkUIRuntimeCallInfo* runtimeCallInfo); static ArkUINativeModuleValue ResetOnKeyEvent(ArkUIRuntimeCallInfo* runtimeCallInfo); static ArkUINativeModuleValue SetOnKeyPreIme(ArkUIRuntimeCallInfo* runtimeCallInfo); diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_frame_node_bridge.cpp b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_frame_node_bridge.cpp index eb3ea4dae1a34d90c3b7fb862d8977f9fa20be11..9c4044191c6dbb27e4529256973b466930ad3d09 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_frame_node_bridge.cpp +++ b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_frame_node_bridge.cpp @@ -27,6 +27,7 @@ #include "core/components_ng/base/view_abstract.h" #include "core/components_ng/pattern/custom_frame_node/custom_frame_node.h" #include "core/components_ng/pattern/custom_frame_node/custom_frame_node_pattern.h" +#include "core/components_ng/pattern/xcomponent/xcomponent_model_ng.h" #include "core/components_ng/syntax/node_content.h" #include "core/interfaces/arkoala/arkoala_api.h" #include "core/interfaces/native/node/extension_custom_node.h" @@ -179,7 +180,7 @@ ArkUINativeModuleValue FrameNodeBridge::CreateTypedFrameNode(ArkUIRuntimeCallInf if (nodeType != ARKUI_CUSTOM) { if (nodeType == ARKUI_XCOMPONENT) { #ifdef XCOMPONENT_SUPPORTED - ArkUI_Params params; + ArkUI_XComponent_Params params; XComponentBridge::ParseParams(runtimeCallInfo, params); params.nodeType = ARKUI_XCOMPONENT; nodePtr = GetArkUIFullNodeAPI()->getBasicAPI()->createNodeWithParams(nodeType, nodeId, 0, params); diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_xcomponent_bridge.cpp b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_xcomponent_bridge.cpp index 8157f9555b3948d9d3e2a9e0f6981a72b220b2e5..c0a55e599ca7a5a58c9949becdebd597e978bbf8 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_xcomponent_bridge.cpp +++ b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_xcomponent_bridge.cpp @@ -74,7 +74,9 @@ void XComponentBridge::ParseParams(ArkUIRuntimeCallInfo* runtimeCallInfo, ArkUI_ auto imageAIOptionsArg = obj->Get(vm, imageAIOptionsStr); xcParams->id = idArg->IsString(vm) ? idArg->ToString(vm)->ToString(vm) : ""; - xcParams->libraryName = libraryNameArg->IsString(vm) ? libraryNameArg->ToString(vm)->ToString(vm) : ""; + if (libraryNameArg->IsString(vm)) { + xcParams->libraryName = libraryNameArg->ToString(vm)->ToString(vm); + } if (typeArg->IsString(vm)) { xcParams->type = ConvertToXComponentType(typeArg->ToString(vm)->ToString(vm)); } else if (typeArg->IsNumber()) { @@ -277,22 +279,25 @@ ArkUINativeModuleValue XComponentBridge::SetXComponentInitialize(ArkUIRuntimeCal } else if (typeArg->IsNumber()) { xcomponentType = static_cast(typeArg->Int32Value(vm)); } - std::string libraryName = librarynameArg->IsString(vm) ? librarynameArg->ToString(vm)->ToString(vm) : ""; GetArkUINodeModifiers()->getXComponentModifier()->setXComponentId( nativeNode, idArg->ToString(vm)->ToString(vm).c_str()); GetArkUINodeModifiers()->getXComponentModifier()->setXComponentType( nativeNode, static_cast(xcomponentType)); - GetArkUINodeModifiers()->getXComponentModifier()->setXComponentLibraryname(nativeNode, libraryName.c_str()); + if (librarynameArg->IsString(vm)) { + auto libraryName = librarynameArg->ToString(vm)->ToString(vm); + GetArkUINodeModifiers()->getXComponentModifier()->setXComponentLibraryname(nativeNode, libraryName.c_str()); + } if ((librarynameArg->IsNull() || librarynameArg->IsUndefined()) && xcomponentController && !controllerObj->IsUndefined()) { SetControllerCallback(runtimeCallInfo); } - HandlerDetachCallback(runtimeCallInfo); - HandlerImageAIOptions(runtimeCallInfo); + HandleDetachCallback(runtimeCallInfo); + HandleImageAIOptions(runtimeCallInfo); + GetArkUINodeModifiers()->getXComponentModifier()->initXComponent(nativeNode); return panda::JSValueRef::Undefined(vm); } -void XComponentBridge::HandlerDetachCallback(ArkUIRuntimeCallInfo *runtimeCallInfo) +void XComponentBridge::HandleDetachCallback(ArkUIRuntimeCallInfo *runtimeCallInfo) { EcmaVM* vm = runtimeCallInfo->GetVM(); Local firstArg = runtimeCallInfo->GetCallArgRef(ARG_FIRST); @@ -304,7 +309,7 @@ void XComponentBridge::HandlerDetachCallback(ArkUIRuntimeCallInfo *runtimeCallIn XComponentModelNG::SetDetachCallback(frameNode, std::move(detachCallback)); } -void XComponentBridge::HandlerImageAIOptions(ArkUIRuntimeCallInfo *runtimeCallInfo) +void XComponentBridge::HandleImageAIOptions(ArkUIRuntimeCallInfo *runtimeCallInfo) { EcmaVM* vm = runtimeCallInfo->GetVM(); Local firstArg = runtimeCallInfo->GetCallArgRef(ARG_FIRST); @@ -329,68 +334,6 @@ ArkUINativeModuleValue XComponentBridge::ResetXComponentInitialize(ArkUIRuntimeC return panda::JSValueRef::Undefined(vm); } -ArkUINativeModuleValue XComponentBridge::SetWidth(ArkUIRuntimeCallInfo *runtimeCallInfo) -{ - EcmaVM *vm = runtimeCallInfo->GetVM(); - CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr)); - Local firstArg = runtimeCallInfo->GetCallArgRef(ARG_FIRST); - Local secondArg = runtimeCallInfo->GetCallArgRef(ARG_ID); - auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value()); - CalcDimension width; - if (!ArkTSUtils::ParseJsDimensionVpNG(vm, secondArg, width)) { - GetArkUINodeModifiers()->getXComponentModifier()->resetXComponentWidth(nativeNode); - return panda::JSValueRef::Undefined(vm); - } - if (LessNotEqual(width.Value(), 0.0)) { - width.SetValue(0.0); - } - std::string widthCalc = width.CalcValue(); - GetArkUINodeModifiers()->getXComponentModifier()->setXComponentWidth( - nativeNode, width.Value(), static_cast(width.Unit()), widthCalc.c_str()); - return panda::JSValueRef::Undefined(vm); -} - -ArkUINativeModuleValue XComponentBridge::ResetWidth(ArkUIRuntimeCallInfo *runtimeCallInfo) -{ - EcmaVM *vm = runtimeCallInfo->GetVM(); - CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr)); - Local firstArg = runtimeCallInfo->GetCallArgRef(ARG_FIRST); - auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value()); - GetArkUINodeModifiers()->getXComponentModifier()->resetXComponentWidth(nativeNode); - return panda::JSValueRef::Undefined(vm); -} - -ArkUINativeModuleValue XComponentBridge::SetHeight(ArkUIRuntimeCallInfo *runtimeCallInfo) -{ - EcmaVM *vm = runtimeCallInfo->GetVM(); - CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr)); - Local firstArg = runtimeCallInfo->GetCallArgRef(ARG_FIRST); - Local secondArg = runtimeCallInfo->GetCallArgRef(ARG_ID); - auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value()); - CalcDimension height; - if (!ArkTSUtils::ParseJsDimensionVpNG(vm, secondArg, height)) { - GetArkUINodeModifiers()->getXComponentModifier()->resetXComponentHeight(nativeNode); - return panda::JSValueRef::Undefined(vm); - } - if (LessNotEqual(height.Value(), 0.0)) { - height.SetValue(0.0); - } - std::string heightCalc = height.CalcValue(); - GetArkUINodeModifiers()->getXComponentModifier()->setXComponentHeight( - nativeNode, height.Value(), static_cast(height.Unit()), heightCalc.c_str()); - return panda::JSValueRef::Undefined(vm); -} - -ArkUINativeModuleValue XComponentBridge::ResetHeight(ArkUIRuntimeCallInfo *runtimeCallInfo) -{ - EcmaVM *vm = runtimeCallInfo->GetVM(); - CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr)); - Local firstArg = runtimeCallInfo->GetCallArgRef(ARG_FIRST); - auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value()); - GetArkUINodeModifiers()->getXComponentModifier()->resetXComponentHeight(nativeNode); - return panda::JSValueRef::Undefined(vm); -} - ArkUINativeModuleValue XComponentBridge::SetBackgroundColor(ArkUIRuntimeCallInfo *runtimeCallInfo) { EcmaVM *vm = runtimeCallInfo->GetVM(); diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_xcomponent_bridge.h b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_xcomponent_bridge.h index 4387ad4e4da58538e31f7e9fa8229c5badb47a72..b95c927d65ce40636774356ab41e3d3dd83d1f49 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_xcomponent_bridge.h +++ b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_xcomponent_bridge.h @@ -30,10 +30,6 @@ public: static void SetControllerOnDestroyed(ArkUIRuntimeCallInfo* runtimeCallInfo, FrameNode* frameNode); static ArkUINativeModuleValue SetXComponentInitialize(ArkUIRuntimeCallInfo* runtimeCallInfo); static ArkUINativeModuleValue ResetXComponentInitialize(ArkUIRuntimeCallInfo* runtimeCallInfo); - static ArkUINativeModuleValue SetWidth(ArkUIRuntimeCallInfo* runtimeCallInfo); - static ArkUINativeModuleValue ResetWidth(ArkUIRuntimeCallInfo* runtimeCallInfo); - static ArkUINativeModuleValue SetHeight(ArkUIRuntimeCallInfo* runtimeCallInfo); - static ArkUINativeModuleValue ResetHeight(ArkUIRuntimeCallInfo* runtimeCallInfo); static ArkUINativeModuleValue SetBackgroundColor(ArkUIRuntimeCallInfo* runtimeCallInfo); static ArkUINativeModuleValue ResetBackgroundColor(ArkUIRuntimeCallInfo* runtimeCallInfo); static ArkUINativeModuleValue SetOpacity(ArkUIRuntimeCallInfo* runtimeCallInfo); @@ -82,8 +78,8 @@ public: private: static XComponentType ConvertToXComponentType(const std::string& type); static void SetControllerCallback(ArkUIRuntimeCallInfo *runtimeCallInfo); - static void HandlerImageAIOptions(ArkUIRuntimeCallInfo *runtimeCallInfo); - static void HandlerDetachCallback(ArkUIRuntimeCallInfo *runtimeCallInfo); + static void HandleImageAIOptions(ArkUIRuntimeCallInfo *runtimeCallInfo); + static void HandleDetachCallback(ArkUIRuntimeCallInfo *runtimeCallInfo); }; } diff --git a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_ext_surface_callback_client.cpp b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_ext_surface_callback_client.cpp index 82f2877ef75dfaac9ee5d841a3dd90c58cd05521..d77f03d0001d4aba980c9e6572625a840e85a0ad 100644 --- a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_ext_surface_callback_client.cpp +++ b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_ext_surface_callback_client.cpp @@ -36,7 +36,7 @@ void XComponentExtSurfaceCallbackClient::ProcessSurfaceDestroy() { auto xcPattern = weakXComponentPattern_.Upgrade(); if (xcPattern) { - xcPattern->NativeXComponentDestroy(); + xcPattern->OnSurfaceDestroyed(); } } } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_model_ng.cpp b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_model_ng.cpp index 5c80e73775c3ca7bad20fb57c94cfee630c1d4ad..0fb6fc9cb90d61bdfdf9a4f8eff3377440350038 100644 --- a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_model_ng.cpp +++ b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_model_ng.cpp @@ -61,6 +61,19 @@ RefPtr XComponentModelNG::Create(int32_t nodeId, float width, float hei return frameNode; } +void XComponentModelNG::InitXComponent(FrameNode* frameNode) +{ + CHECK_NULL_VOID(frameNode); + auto node = AceType::Claim(frameNode); + auto type = GetTypeImpl(node); + if (type == XComponentType::COMPONENT || type == XComponentType::NODE) { + return; + } + auto xcPattern = AceType::DynamicCast(frameNode->GetPattern()); + CHECK_NULL_VOID(xcPattern); + xcPattern->InitXComponent(); +} + std::optional XComponentModelNG::GetLibraryName() { auto frameNode = AceType::Claim(ViewStackProcessor::GetInstance()->GetMainFrameNode()); @@ -122,6 +135,14 @@ void XComponentModelNG::SetOnLoad(FrameNode* frameNode, LoadEvent&& onLoad) if (type == XComponentType::COMPONENT || type == XComponentType::NODE) { return; } + auto xcPattern = AceType::DynamicCast(frameNode->GetPattern()); + CHECK_NULL_VOID(xcPattern); + if (xcPattern->NeedTriggerLoadEventImmediately()) { + if (onLoad) { + onLoad(xcPattern->GetId()); + } + return; + } auto eventHub = frameNode->GetEventHub(); CHECK_NULL_VOID(eventHub); eventHub->SetOnLoad(std::move(onLoad)); @@ -271,15 +292,15 @@ RefPtr XComponentModelNG::CreateTypeNode(int32_t nodeId, ArkUI_XCompo auto type = params->type; auto libraryName = params->libraryName; auto controller = params->controller; - auto frameNode = FrameNode::CreateFrameNode( - V2::XCOMPONENT_ETS_TAG, nodeId, AceType::MakeRefPtr(id, type, libraryName, controller)); + + auto frameNode = FrameNode::CreateFrameNode(V2::XCOMPONENT_ETS_TAG, nodeId, + AceType::MakeRefPtr(id, type, libraryName, controller, 0.0, 0.0, true)); auto layoutProperty = frameNode->GetLayoutProperty(); if (layoutProperty) { layoutProperty->UpdateXComponentType(type); } auto xcPattern = AceType::DynamicCast(frameNode->GetPattern()); CHECK_NULL_RETURN(xcPattern, nullptr); - xcPattern->SetIsTypeNode(true); xcPattern->SetImageAIOptions(params->aiOptions); return frameNode; } diff --git a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_model_ng.h b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_model_ng.h index 8d3930ded24c8ff65e45b1b3f821c7931c0e06be..34876eacc5b679965c1ae7a011095b93aa8bf1c5 100644 --- a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_model_ng.h +++ b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_model_ng.h @@ -28,10 +28,10 @@ class FrameNode; class ArkUI_XComponent_Params final : public ArkUI_Params { public: std::string id; - XComponentType type; - std::string libraryName; - std::shared_ptr controller; - void* aiOptions; + XComponentType type = XComponentType::SURFACE; + std::optional libraryName = std::nullopt; + std::shared_ptr controller = nullptr; + void* aiOptions = nullptr; }; class ACE_EXPORT XComponentModelNG : public OHOS::Ace::XComponentModel { @@ -62,6 +62,7 @@ public: static RefPtr CreateFrameNode( int32_t nodeId, const std::string& id, XComponentType type, const std::string& libraryname); static RefPtr CreateTypeNode(int32_t nodeId, ArkUI_XComponent_Params* params); + static void InitXComponent(FrameNode* frameNode); static void SetXComponentId(FrameNode* frameNode, const std::string& id); static void SetXComponentType(FrameNode* frameNode, XComponentType type); static void SetXComponentSurfaceSize(FrameNode* frameNode, uint32_t width, uint32_t height); diff --git a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern.cpp b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern.cpp index a96adb4323954a33b678cd9588244668a38ba766..c64d63e0784772a2414588f2f18cc567f196b644 100644 --- a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern.cpp +++ b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern.cpp @@ -160,55 +160,94 @@ OH_NativeXComponent_KeyEvent ConvertNativeXComponentKeyEvent(const KeyEvent& eve XComponentPattern::XComponentPattern(const std::optional& id, XComponentType type, const std::optional& libraryname, - const std::shared_ptr& xcomponentController, float initWidth, float initHeight) - : id_(id), type_(type), xcomponentController_(xcomponentController), initSize_(initWidth, initHeight) + const std::shared_ptr& xcomponentController, float initWidth, float initHeight, + bool isTypedNode) + : id_(id), type_(type), xcomponentController_(xcomponentController), initSize_(initWidth, initHeight), + isTypedNode_(isTypedNode) { SetLibraryName(libraryname); + if (!isTypedNode_) { + InitNativeXComponent(); + } } -void XComponentPattern::Initialize() +void XComponentPattern::InitNativeXComponent() +{ + if ((type_ == XComponentType::SURFACE || type_ == XComponentType::TEXTURE) && libraryname_.has_value()) { + isNativeXComponent_ = true; + nativeXComponentImpl_ = AceType::MakeRefPtr(); + nativeXComponent_ = std::make_shared(AceType::RawPtr(nativeXComponentImpl_)); + } +} + +void XComponentPattern::InitXComponent() +{ + // used for TypedNode, not for declareative + if (isTypedNode_) { + InitNativeXComponent(); + if (isNativeXComponent_) { + LoadNative(); + } + } +} + +void XComponentPattern::InitSurface() { auto host = GetHost(); CHECK_NULL_VOID(host); auto renderContext = host->GetRenderContext(); - if (type_ == XComponentType::SURFACE || type_ == XComponentType::TEXTURE) { - renderContext->SetClipToFrame(true); - renderContext->SetClipToBounds(true); -#ifdef RENDER_EXTRACT_SUPPORTED - renderSurface_ = RenderSurface::Create(CovertToRenderSurfaceType(type_)); -#else - renderSurface_ = RenderSurface::Create(); -#endif - renderSurface_->SetInstanceId(GetHostInstanceId()); - if (type_ == XComponentType::SURFACE) { - InitializeRenderContext(); - if (!SystemProperties::GetExtSurfaceEnabled()) { - renderSurface_->SetRenderContext(renderContextForSurface_); - } else { - auto pipelineContext = host->GetContextRefPtr(); - CHECK_NULL_VOID(pipelineContext); - pipelineContext->AddOnAreaChangeNode(host->GetId()); - extSurfaceClient_ = MakeRefPtr(WeakClaim(this)); - renderSurface_->SetExtSurfaceCallback(extSurfaceClient_); -#ifdef RENDER_EXTRACT_SUPPORTED - RegisterRenderContextCallBack(); -#endif - } - handlingSurfaceRenderContext_ = renderContextForSurface_; - } else if (type_ == XComponentType::TEXTURE) { - renderSurface_->SetRenderContext(renderContext); - renderSurface_->SetIsTexture(true); - } - auto* controllerNG = static_cast(xcomponentController_.get()); - if (controllerNG) { - controllerNG->SetPattern(AceType::Claim(this)); + CHECK_NULL_VOID(renderContext); + + renderContext->SetClipToFrame(true); + renderContext->SetClipToBounds(true); + renderSurface_ = RenderSurface::Create(); + renderSurface_->SetInstanceId(GetHostInstanceId()); + if (type_ == XComponentType::SURFACE) { + renderContextForSurface_ = RenderContext::Create(); + RenderContext::ContextParam param = { RenderContext::ContextType::HARDWARE_SURFACE, GetId() + "Surface" }; + renderContextForSurface_->InitContext(false, param); + renderContextForSurface_->UpdateBackgroundColor(Color::BLACK); + if (!SystemProperties::GetExtSurfaceEnabled()) { + renderSurface_->SetRenderContext(renderContextForSurface_); + } else { + auto pipelineContext = host->GetContextRefPtr(); + CHECK_NULL_VOID(pipelineContext); + pipelineContext->AddOnAreaChangeNode(host->GetId()); + extSurfaceClient_ = MakeRefPtr(WeakClaim(this)); + renderSurface_->SetExtSurfaceCallback(extSurfaceClient_); } - renderSurface_->InitSurface(); - renderSurface_->UpdateSurfaceConfig(); - surfaceId_ = renderSurface_->GetUniqueId(); + handlingSurfaceRenderContext_ = renderContextForSurface_; + } else if (type_ == XComponentType::TEXTURE) { + renderSurface_->SetRenderContext(renderContext); + renderSurface_->SetIsTexture(true); + } + renderSurface_->InitSurface(); + renderSurface_->UpdateSurfaceConfig(); + surfaceId_ = renderSurface_->GetUniqueId(); + + auto pipelineContext = host->GetContextRefPtr(); + CHECK_NULL_VOID(pipelineContext); + pipelineContext->AddWindowStateChangedCallback(host->GetId()); + SetRotation(pipelineContext->GetTransformHint()); + auto callbackId = + pipelineContext->RegisterTransformHintChangeCallback([weak = WeakClaim(this)](uint32_t transform) { + auto pattern = weak.Upgrade(); + if (pattern) { + pattern->SetRotation(transform); + } + }); + UpdateTransformHintChangedCallbackId(callbackId); +} + +void XComponentPattern::Initialize() +{ + if (type_ == XComponentType::SURFACE || type_ == XComponentType::TEXTURE) { + InitSurface(); InitEvent(); - SetMethodCall(); + InitController(); } else if (type_ == XComponentType::NODE && id_.has_value()) { + auto host = GetHost(); + CHECK_NULL_VOID(host); auto context = host->GetContextRefPtr(); if (context) { FireExternalEvent(context, id_.value(), host->GetId(), false); @@ -217,6 +256,32 @@ void XComponentPattern::Initialize() } } +void XComponentPattern::OnAttachToMainTree() +{ + if (isTypedNode_) { + CHECK_NULL_VOID(renderSurface_); + renderSurface_->RegisterSurface(); + renderSurface_->Connect(); + surfaceId_ = renderSurface_->GetUniqueId(); + CHECK_NULL_VOID(xcomponentController_); + xcomponentController_->SetSurfaceId(surfaceId_); + OnSurfaceCreated(); + } +} + +void XComponentPattern::OnDetachFromMainTree() +{ + if (isTypedNode_) { + CHECK_NULL_VOID(renderSurface_); + renderSurface_->ReleaseSurfaceBuffers(); + renderSurface_->Disconnect(); + renderSurface_->UnregisterSurface(); + CHECK_NULL_VOID(xcomponentController_); + OnSurfaceDestroyed(); + xcomponentController_->SetSurfaceId(""); + } +} + void XComponentPattern::InitializeRenderContext() { renderContextForSurface_ = RenderContext::Create(); @@ -354,19 +419,6 @@ void XComponentPattern::PrepareSurface() void XComponentPattern::OnAttachToFrameNode() { Initialize(); - auto host = GetHost(); - CHECK_NULL_VOID(host); - auto pipeline = host->GetContextRefPtr(); - CHECK_NULL_VOID(pipeline); - pipeline->AddWindowStateChangedCallback(host->GetId()); - SetRotation(pipeline->GetTransformHint()); - auto callbackId = pipeline->RegisterTransformHintChangeCallback([weak = WeakClaim(this)](uint32_t transform) { - auto pattern = weak.Upgrade(); - if (pattern) { - pattern->SetRotation(transform); - } - }); - UpdateTransformHintChangedCallbackId(callbackId); if (FrameReport::GetInstance().GetEnable()) { FrameReport::GetInstance().EnableSelfRender(); } @@ -527,31 +579,36 @@ void XComponentPattern::OnRebuildFrame() void XComponentPattern::OnDetachFromFrameNode(FrameNode* frameNode) { CHECK_NULL_VOID(frameNode); - if (!isTypeNode_ && !hasXComponentInit_) { - return; - } - if (type_ == XComponentType::SURFACE || type_ == XComponentType::TEXTURE) { - NativeXComponentDestroy(); - auto eventHub = frameNode->GetEventHub(); - CHECK_NULL_VOID(eventHub); - { - ACE_LAYOUT_SCOPED_TRACE("XComponent[%s] FireDestroyEvent", GetId().c_str()); - eventHub->FireDestroyEvent(); + if (isTypedNode_) { + if (isNativeXComponent_) { + OnNativeUnload(frameNode); } - if (id_.has_value()) { - eventHub->FireDetachEvent(id_.value()); + } else { + if (!hasXComponentInit_) { + return; } - { - ACE_LAYOUT_SCOPED_TRACE("XComponent[%s] FireControllerDestroyedEvent", GetId().c_str()); - eventHub->FireControllerDestroyedEvent(surfaceId_); + if (type_ == XComponentType::SURFACE || type_ == XComponentType::TEXTURE) { + OnSurfaceDestroyed(); + auto eventHub = frameNode->GetEventHub(); + CHECK_NULL_VOID(eventHub); + { + ACE_LAYOUT_SCOPED_TRACE("XComponent[%s] FireDestroyEvent", GetId().c_str()); + eventHub->FireDestroyEvent(); + } + if (id_.has_value()) { + eventHub->FireDetachEvent(id_.value()); + } + { + ACE_LAYOUT_SCOPED_TRACE("XComponent[%s] FireControllerDestroyedEvent", GetId().c_str()); + eventHub->FireControllerDestroyedEvent(surfaceId_); + } } + } #ifdef RENDER_EXTRACT_SUPPORTED - if (renderContextForSurface_) { - renderContextForSurface_->RemoveSurfaceChangedCallBack(); - } -#endif + if (renderContextForSurface_) { + renderContextForSurface_->RemoveSurfaceChangedCallBack(); } - +#endif auto id = frameNode->GetId(); auto pipeline = frameNode->GetContextRefPtr(); CHECK_NULL_VOID(pipeline); @@ -564,7 +621,7 @@ void XComponentPattern::OnDetachFromFrameNode(FrameNode* frameNode) } } -void XComponentPattern::SetMethodCall() +void XComponentPattern::InitController() { CHECK_NULL_VOID(xcomponentController_); auto host = GetHost(); @@ -572,16 +629,23 @@ void XComponentPattern::SetMethodCall() auto pipelineContext = host->GetContextRefPtr(); CHECK_NULL_VOID(pipelineContext); auto uiTaskExecutor = SingleTaskExecutor::Make(pipelineContext->GetTaskExecutor(), TaskExecutor::TaskType::UI); + auto* controllerNG = static_cast(xcomponentController_.get()); + if (controllerNG) { + controllerNG->SetPattern(AceType::Claim(this)); + } xcomponentController_->SetConfigSurfaceImpl( [weak = WeakClaim(this), uiTaskExecutor](uint32_t surfaceWidth, uint32_t surfaceHeight) { - uiTaskExecutor.PostSyncTask([weak, surfaceWidth, surfaceHeight]() { - auto pattern = weak.Upgrade(); - CHECK_NULL_VOID(pattern); - pattern->ConfigSurface(surfaceWidth, surfaceHeight); - }, "ArkUIXComponentSurfaceConfigChange"); + uiTaskExecutor.PostSyncTask( + [weak, surfaceWidth, surfaceHeight]() { + auto pattern = weak.Upgrade(); + CHECK_NULL_VOID(pattern); + pattern->ConfigSurface(surfaceWidth, surfaceHeight); + }, + "ArkUIXComponentSurfaceConfigChange"); }); - - xcomponentController_->SetSurfaceId(surfaceId_); + if (!isTypedNode_) { + xcomponentController_->SetSurfaceId(surfaceId_); + } } void XComponentPattern::ConfigSurface(uint32_t surfaceWidth, uint32_t surfaceHeight) @@ -641,7 +705,7 @@ void XComponentPattern::BeforeSyncGeometryProperties(const DirtySwapConfig& conf const auto& [offsetChanged, sizeChanged, needFireNativeEvent] = UpdateSurfaceRect(); if (!hasXComponentInit_) { initSize_ = drawSize_; - if (!SystemProperties::GetExtSurfaceEnabled()) { + if (!SystemProperties::GetExtSurfaceEnabled() && !isTypedNode_) { XComponentSizeInit(); } auto offset = globalPosition_ + localPosition_; @@ -709,38 +773,6 @@ void XComponentPattern::DumpAdvanceInfo() } } -void XComponentPattern::NativeXComponentChange(float width, float height) -{ - CHECK_RUN_ON(UI); - CHECK_NULL_VOID(nativeXComponent_); - CHECK_NULL_VOID(nativeXComponentImpl_); - nativeXComponentImpl_->SetXComponentWidth(static_cast(width)); - nativeXComponentImpl_->SetXComponentHeight(static_cast(height)); - auto* surface = const_cast(nativeXComponentImpl_->GetSurface()); - const auto* callback = nativeXComponentImpl_->GetCallback(); - CHECK_NULL_VOID(callback); - CHECK_NULL_VOID(callback->OnSurfaceChanged); - callback->OnSurfaceChanged(nativeXComponent_.get(), surface); -#ifdef RENDER_EXTRACT_SUPPORTED - auto host = GetHost(); - CHECK_NULL_VOID(host); - host->MarkDirtyNode(PROPERTY_UPDATE_MEASURE); -#endif -} - -void XComponentPattern::NativeXComponentDestroy() -{ - ACE_LAYOUT_SCOPED_TRACE("XComponent[%s] NativeXComponentDestroy", GetId().c_str()); - CHECK_RUN_ON(UI); - CHECK_NULL_VOID(nativeXComponent_); - CHECK_NULL_VOID(nativeXComponentImpl_); - auto* surface = const_cast(nativeXComponentImpl_->GetSurface()); - const auto* callback = nativeXComponentImpl_->GetCallback(); - CHECK_NULL_VOID(callback); - CHECK_NULL_VOID(callback->OnSurfaceDestroyed); - callback->OnSurfaceDestroyed(nativeXComponent_.get(), surface); -} - void XComponentPattern::NativeXComponentOffset(double x, double y) { CHECK_RUN_ON(UI); @@ -781,6 +813,7 @@ void XComponentPattern::InitNativeWindow(float textureWidth, float textureHeight renderSurface_->CreateNativeWindow(); renderSurface_->AdjustNativeWindowSize( static_cast(textureWidth * viewScale), static_cast(textureHeight * viewScale)); + nativeWindow_ = renderSurface_->GetNativeWindow(); } } @@ -789,8 +822,6 @@ void XComponentPattern::XComponentSizeInit() CHECK_RUN_ON(UI); auto host = GetHost(); CHECK_NULL_VOID(host); - auto context = host->GetContextRefPtr(); - CHECK_NULL_VOID(context); InitNativeWindow(initSize_.Width(), initSize_.Height()); #ifdef RENDER_EXTRACT_SUPPORTED if (xcomponentController_ && renderSurface_) { @@ -818,20 +849,15 @@ void XComponentPattern::XComponentSizeChange(const RectF& surfaceRect, bool need { auto host = GetHost(); CHECK_NULL_VOID(host); - // do not trigger when the size is first initialized - if (needFireNativeEvent) { - auto context = host->GetContextRefPtr(); - CHECK_NULL_VOID(context); - auto viewScale = context->GetViewScale(); - renderSurface_->AdjustNativeWindowSize(static_cast(surfaceRect.Width() * viewScale), - static_cast(surfaceRect.Height() * viewScale)); - NativeXComponentChange(surfaceRect.Width(), surfaceRect.Height()); - } renderSurface_->UpdateSurfaceSizeInUserData( static_cast(surfaceRect.Width()), static_cast(surfaceRect.Height())); - auto eventHub = host->GetEventHub(); - CHECK_NULL_VOID(eventHub); - eventHub->FireControllerChangedEvent(surfaceId_, surfaceRect); + + // In declarative mode: Native onSurfaceCreated callback is triggred + // when the component finish it's first layout, so do not trigger the native onSurfaceChanged callback + if (!isTypedNode_ && isNativeXComponent_ && !needFireNativeEvent) { + return; + } + OnSurfaceChanged(surfaceRect); } void XComponentPattern::InitNativeNodeCallbacks() @@ -1569,17 +1595,129 @@ std::tuple XComponentPattern::UpdateSurfaceRect() return { preLocalPosition != localPosition_, preSurfaceSize != surfaceSize_, preSurfaceSize.IsPositive() }; } -void XComponentPattern::NativeSurfaceHide() +void XComponentPattern::LoadNative() +{ + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto eventHub = host->GetEventHub(); + CHECK_NULL_VOID(eventHub); + eventHub->FireSurfaceInitEvent(id_.value_or(""), host->GetId()); + OnNativeLoad(reinterpret_cast(AceType::RawPtr(host))); +} + +void XComponentPattern::OnNativeLoad(FrameNode* frameNode) +{ + hasLoadNativeDone_ = true; + CHECK_NULL_VOID(frameNode); + auto eventHub = frameNode->GetEventHub(); + CHECK_NULL_VOID(eventHub); + { + ACE_LAYOUT_SCOPED_TRACE("XComponent[%s] FireLoadEvent", GetId().c_str()); + eventHub->FireLoadEvent(GetId()); + } +} + +void XComponentPattern::OnNativeUnload(FrameNode* frameNode) +{ + hasLoadNativeDone_ = false; + CHECK_NULL_VOID(frameNode); + auto eventHub = frameNode->GetEventHub(); + CHECK_NULL_VOID(eventHub); + { + ACE_LAYOUT_SCOPED_TRACE("XComponent[%s] FireDestroyEvent", GetId().c_str()); + eventHub->FireDestroyEvent(); + } +} + +void XComponentPattern::OnSurfaceCreated() { CHECK_RUN_ON(UI); - CHECK_NULL_VOID(nativeXComponent_); - CHECK_NULL_VOID(nativeXComponentImpl_); - auto* surface = const_cast(nativeXComponentImpl_->GetSurface()); - const auto surfaceHideCallback = nativeXComponentImpl_->GetSurfaceHideCallback(); - CHECK_NULL_VOID(surfaceHideCallback); - surfaceHideCallback(nativeXComponent_.get(), surface); - CHECK_NULL_VOID(renderSurface_); - renderSurface_->ReleaseSurfaceBuffers(); + auto width = initSize_.Width(); + auto height = initSize_.Height(); + if (isNativeXComponent_) { + CHECK_NULL_VOID(nativeXComponentImpl_); + CHECK_NULL_VOID(nativeXComponent_); + TAG_LOGI(AceLogTag::ACE_XCOMPONENT, "XComponent[%{public}s] native OnSurfaceCreated", GetId().c_str()); + ACE_LAYOUT_SCOPED_TRACE("XComponent[%s] NativeSurfaceCreated", GetId().c_str()); + InitNativeWindow(width, height); + nativeXComponentImpl_->SetXComponentWidth(static_cast(width)); + nativeXComponentImpl_->SetXComponentHeight(static_cast(height)); + nativeXComponentImpl_->SetSurface(nativeWindow_); + const auto* callback = nativeXComponentImpl_->GetCallback(); + CHECK_NULL_VOID(callback); + CHECK_NULL_VOID(callback->OnSurfaceCreated); + callback->OnSurfaceCreated(nativeXComponent_.get(), nativeWindow_); + } else { + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto eventHub = host->GetEventHub(); + CHECK_NULL_VOID(eventHub); + { + ACE_LAYOUT_SCOPED_TRACE("XComponent[%s] FireControllerCreatedEvent", GetId().c_str()); + eventHub->FireControllerCreatedEvent(surfaceId_); + } + } +} + +void XComponentPattern::OnSurfaceChanged(const RectF& surfaceRect) +{ + CHECK_RUN_ON(UI); + auto host = GetHost(); + CHECK_NULL_VOID(host); + if (isNativeXComponent_) { + CHECK_NULL_VOID(nativeXComponent_); + CHECK_NULL_VOID(nativeXComponentImpl_); + CHECK_NULL_VOID(renderSurface_); + auto context = host->GetContextRefPtr(); + CHECK_NULL_VOID(context); + auto viewScale = context->GetViewScale(); + auto width = surfaceRect.Width(); + auto height = surfaceRect.Height(); + renderSurface_->AdjustNativeWindowSize(static_cast(width * viewScale), + static_cast(height * viewScale)); + nativeXComponentImpl_->SetXComponentWidth(static_cast(width)); + nativeXComponentImpl_->SetXComponentHeight(static_cast(height)); + auto* surface = const_cast(nativeXComponentImpl_->GetSurface()); + const auto* callback = nativeXComponentImpl_->GetCallback(); + CHECK_NULL_VOID(callback); + CHECK_NULL_VOID(callback->OnSurfaceChanged); + { + ACE_LAYOUT_SCOPED_TRACE("XComponent[%s] native OnSurfaceChanged", GetId().c_str()); + callback->OnSurfaceChanged(nativeXComponent_.get(), surface); + } + } else { + auto eventHub = host->GetEventHub(); + CHECK_NULL_VOID(eventHub); + { + ACE_LAYOUT_SCOPED_TRACE("XComponent[%s] FireControllerChangedEvent", GetId().c_str()); + eventHub->FireControllerChangedEvent(surfaceId_, surfaceRect); + } + } +} + +void XComponentPattern::OnSurfaceDestroyed() +{ + if (isNativeXComponent_) { + ACE_LAYOUT_SCOPED_TRACE("XComponent[%s] native OnSurfaceDestroyed", GetId().c_str()); + CHECK_RUN_ON(UI); + CHECK_NULL_VOID(nativeXComponent_); + CHECK_NULL_VOID(nativeXComponentImpl_); + auto* surface = const_cast(nativeXComponentImpl_->GetSurface()); + const auto* callback = nativeXComponentImpl_->GetCallback(); + CHECK_NULL_VOID(callback); + CHECK_NULL_VOID(callback->OnSurfaceDestroyed); + callback->OnSurfaceDestroyed(nativeXComponent_.get(), surface); + nativeXComponentImpl_->SetSurface(nullptr); + } else { + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto eventHub = host->GetEventHub(); + CHECK_NULL_VOID(eventHub); + { + ACE_LAYOUT_SCOPED_TRACE("XComponent[%s] FireControllerDestroyedEvent", GetId().c_str()); + eventHub->FireControllerDestroyedEvent(surfaceId_); + } + } } void XComponentPattern::NativeSurfaceShow() @@ -1593,6 +1731,19 @@ void XComponentPattern::NativeSurfaceShow() surfaceShowCallback(nativeXComponent_.get(), surface); } +void XComponentPattern::NativeSurfaceHide() +{ + CHECK_RUN_ON(UI); + CHECK_NULL_VOID(nativeXComponent_); + CHECK_NULL_VOID(nativeXComponentImpl_); + auto* surface = const_cast(nativeXComponentImpl_->GetSurface()); + const auto surfaceHideCallback = nativeXComponentImpl_->GetSurfaceHideCallback(); + CHECK_NULL_VOID(surfaceHideCallback); + surfaceHideCallback(nativeXComponent_.get(), surface); + CHECK_NULL_VOID(renderSurface_); + renderSurface_->ReleaseSurfaceBuffers(); +} + void XComponentPattern::OnWindowHide() { if (!hasXComponentInit_ || hasReleasedSurface_ diff --git a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern.h b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern.h index 9ccf2cbc681e5974c6157f0d52a5c62de8b8fd99..009a3c7c85c79788a3f6c61d9519dc07bde3f28f 100644 --- a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern.h +++ b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern.h @@ -61,9 +61,12 @@ public: XComponentPattern(const std::optional& id, XComponentType type, const std::optional& libraryname, const std::shared_ptr& xcomponentController, float initWidth = 0.0f, - float initHeight = 0.0f); + float initHeight = 0.0f, bool isTypedNode = false); ~XComponentPattern() override = default; + void OnAttachToMainTree() override; + void OnDetachFromMainTree() override; + bool IsAtomicNode() const override { #ifdef PLATFORM_VIEW_SUPPORTED @@ -116,46 +119,28 @@ public: std::pair, std::weak_ptr> GetNativeXComponent() { if (!nativeXComponent_ || !nativeXComponentImpl_) { + // for XComponentType::NODE nativeXComponentImpl_ = AceType::MakeRefPtr(); nativeXComponent_ = std::make_shared(AceType::RawPtr(nativeXComponentImpl_)); } return std::make_pair(nativeXComponentImpl_, nativeXComponent_); } - void NativeXComponentInit() - { - ACE_LAYOUT_SCOPED_TRACE("XComponent[%s] NativeXComponentInit", GetId().c_str()); - CHECK_RUN_ON(UI); - CHECK_NULL_VOID(nativeXComponentImpl_); - CHECK_NULL_VOID(nativeXComponent_); - auto host = GetHost(); - CHECK_NULL_VOID(host); - auto width = initSize_.Width(); - auto height = initSize_.Height(); - nativeXComponentImpl_->SetXComponentWidth(static_cast(width)); - nativeXComponentImpl_->SetXComponentHeight(static_cast(height)); - auto* surface = const_cast(nativeXComponentImpl_->GetSurface()); - const auto* callback = nativeXComponentImpl_->GetCallback(); - if (callback && callback->OnSurfaceCreated != nullptr) { - callback->OnSurfaceCreated(nativeXComponent_.get(), surface); - } - } - - void NativeXComponentOffset(double x, double y); - void NativeXComponentChange(float width, float height); - void NativeXComponentDestroy(); void NativeXComponentDispatchTouchEvent(const OH_NativeXComponent_TouchEvent& touchEvent, const std::vector& xComponentTouchPoints); void NativeXComponentDispatchMouseEvent(const OH_NativeXComponent_MouseEvent& mouseEvent); void NativeXComponentDispatchAxisEvent(AxisEvent* axisEvent); + void InitXComponent(); + void InitNativeXComponent(); void InitNativeWindow(float textureWidth, float textureHeight); void XComponentSizeInit(); void XComponentSizeChange(const RectF& surfaceRect, bool needFireNativeEvent); - - void* GetNativeWindow() + void NativeXComponentInit() { - return renderSurface_->GetNativeWindow(); + if (!isTypedNode_) { + OnSurfaceCreated(); + } } std::string GetId() const @@ -233,7 +218,7 @@ public: void SetIsTypeNode(bool isTypeNode) { - isTypeNode_ = isTypeNode; + isTypedNode_ = isTypeNode; } std::shared_ptr GetXComponentController() @@ -283,8 +268,6 @@ public: hasXComponentInit_ = isInit; } - void Initialize(); - bool ChangeRenderType(NodeRenderType renderType); void SetRenderType(NodeRenderType renderType) @@ -302,6 +285,11 @@ public: return transformHintChangedCallbackId_.has_value(); } + bool NeedTriggerLoadEventImmediately() const + { + return isTypedNode_ && isNativeXComponent_ && hasLoadNativeDone_; + } + void SetExportTextureSurfaceId(const std::string& surfaceId); void FireExternalEvent(RefPtr context, const std::string& componentId, const uint32_t nodeId, const bool isDestroy); @@ -321,6 +309,7 @@ public: void StopImageAnalyzer(); RectF AdjustPaintRect(float positionX, float positionY, float width, float height, bool isRound); float RoundValueToPixelGrid(float value, bool isRound, bool forceCeil, bool forceFloor); + void OnSurfaceDestroyed(); private: void OnAttachToFrameNode() override; @@ -330,14 +319,27 @@ private: void OnAreaChangedInner() override; void OnWindowHide() override; void OnWindowShow() override; - void NativeSurfaceHide(); - void NativeSurfaceShow(); void OnModifyDone() override; void DumpInfo() override; void DumpAdvanceInfo() override; void OnAttachContext(PipelineContext *context) override; void OnDetachContext(PipelineContext *context) override; + void NativeXComponentOffset(double x, double y); + + void LoadNative(); + void OnNativeLoad(FrameNode* frameNode); + void OnNativeUnload(FrameNode* frameNode); + + void OnSurfaceCreated(); + void OnSurfaceChanged(const RectF& surfaceRect); + + void NativeSurfaceShow(); + void NativeSurfaceHide(); + + void Initialize(); + void InitController(); + void InitSurface(); void InitNativeNodeCallbacks(); void InitEvent(); void InitTouchEvent(const RefPtr& gestureHub); @@ -354,8 +356,7 @@ private: bool HandleKeyEvent(const KeyEvent& event); void HandleBlurEvent(); ExternalEvent CreateExternalEvent(); - void CreateSurface(); - void SetMethodCall(); + void SetTouchPoint( const std::list& touchInfoList, int64_t timeStamp, const TouchType& touchType); void HandleSetExpectedRateRangeEvent(); @@ -434,6 +435,7 @@ private: std::optional selfIdealSurfaceOffsetX_; std::optional selfIdealSurfaceOffsetY_; std::string surfaceId_; + void* nativeWindow_ = nullptr; bool isSurfaceLock_ = false; @@ -445,7 +447,9 @@ private: bool isEnableAnalyzer_ = false; std::optional transformHintChangedCallbackId_; uint32_t rotation_ = 0; - bool isTypeNode_ = false; + bool isTypedNode_ = false; + bool isNativeXComponent_ = false; + bool hasLoadNativeDone_ = false; }; } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/render/adapter/rosen_render_surface.cpp b/frameworks/core/components_ng/render/adapter/rosen_render_surface.cpp index 37ca8b61421c83a3f18e340f048dc31268defe39..262a6447216d389717aaceeccc21aac2c1aa65b0 100644 --- a/frameworks/core/components_ng/render/adapter/rosen_render_surface.cpp +++ b/frameworks/core/components_ng/render/adapter/rosen_render_surface.cpp @@ -80,13 +80,7 @@ RosenRenderSurface::~RosenRenderSurface() DestoryNativeWindow(nativeWindow_); nativeWindow_ = nullptr; } - CHECK_NULL_VOID(producerSurface_); - auto* surfaceUtils = SurfaceUtils::GetInstance(); - CHECK_NULL_VOID(surfaceUtils); - auto ret = surfaceUtils->Remove(producerSurface_->GetUniqueId()); - if (ret != SurfaceError::SURFACE_ERROR_OK) { - LOGE("remove surface error: %{public}d", ret); - } + UnregisterSurface(); while (!availableBuffers_.empty()) { auto surfaceNode = availableBuffers_.front(); availableBuffers_.pop(); @@ -143,6 +137,18 @@ void RosenRenderSurface::InitSurface() RegisterSurface(); } +void RosenRenderSurface::Connect() const +{ + CHECK_NULL_VOID(producerSurface_); + producerSurface_->Connect(); +} + +void RosenRenderSurface::Disconnect() const +{ + CHECK_NULL_VOID(producerSurface_); + producerSurface_->Disconnect(); +} + void RosenRenderSurface::RegisterSurface() const { CHECK_NULL_VOID(producerSurface_); @@ -150,7 +156,18 @@ void RosenRenderSurface::RegisterSurface() const CHECK_NULL_VOID(surfaceUtils); auto ret = surfaceUtils->Add(producerSurface_->GetUniqueId(), producerSurface_); if (ret != SurfaceError::SURFACE_ERROR_OK) { - LOGW("add surface error: %{public}d", ret); + LOGE("add surface error: %{public}d", ret); + } +} + +void RosenRenderSurface::UnregisterSurface() const +{ + CHECK_NULL_VOID(producerSurface_); + auto* surfaceUtils = SurfaceUtils::GetInstance(); + CHECK_NULL_VOID(surfaceUtils); + auto ret = surfaceUtils->Remove(producerSurface_->GetUniqueId()); + if (ret != SurfaceError::SURFACE_ERROR_OK) { + LOGE("remove surface error: %{public}d", ret); } } diff --git a/frameworks/core/components_ng/render/adapter/rosen_render_surface.h b/frameworks/core/components_ng/render/adapter/rosen_render_surface.h index 97308b50cb0104314f9897f4ff057e6f3fdb6671..6ca2592a31864aeb872e616e9efe1faf5163e014 100644 --- a/frameworks/core/components_ng/render/adapter/rosen_render_surface.h +++ b/frameworks/core/components_ng/render/adapter/rosen_render_surface.h @@ -129,11 +129,18 @@ public: void SetTransformHint(uint32_t rotation) override; + void RegisterSurface() const override; + + void UnregisterSurface() const override; + + void Connect() const override; + + void Disconnect() const override; + void DumpInfo() override; private: void PostRenderOnlyTaskToUI(); - void RegisterSurface() const; std::mutex surfaceNodeMutex_; OffsetF orgin_ { 0, 0 }; diff --git a/frameworks/core/components_ng/render/adapter/rosen_render_surface_mingw.cpp b/frameworks/core/components_ng/render/adapter/rosen_render_surface_mingw.cpp index c9dc1cc2312220dc35fbb95365d3d2c08129f074..2eba1163958321595a4e676c3b3f28372308e28f 100644 --- a/frameworks/core/components_ng/render/adapter/rosen_render_surface_mingw.cpp +++ b/frameworks/core/components_ng/render/adapter/rosen_render_surface_mingw.cpp @@ -95,4 +95,12 @@ void RosenRenderSurface::UpdateSurfaceSizeInUserData(uint32_t width, uint32_t he void RosenRenderSurface::DumpInfo() {} +void RosenRenderSurface::RegisterSurface() const {} + +void RosenRenderSurface::UnregisterSurface() const {} + +void RosenRenderSurface::Connect() const {} + +void RosenRenderSurface::Disconnect() const {} + } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/render/render_surface.h b/frameworks/core/components_ng/render/render_surface.h index 83f8996d746fbf2206301821b30088b1c734c122..edac9c054bf19ca5362c835a7bc592978cb68f69 100644 --- a/frameworks/core/components_ng/render/render_surface.h +++ b/frameworks/core/components_ng/render/render_surface.h @@ -122,6 +122,14 @@ public: virtual void ReleaseSurfaceBuffers() {} + virtual void RegisterSurface() const {}; + + virtual void UnregisterSurface() const {}; + + virtual void Connect() const {}; + + virtual void Disconnect() const {}; + protected: ACE_DISALLOW_COPY_AND_MOVE(RenderSurface); }; diff --git a/frameworks/core/interfaces/arkoala/arkoala_api.h b/frameworks/core/interfaces/arkoala/arkoala_api.h index c22ed50c8050e94f429ee3f12734075876f4f0dd..c5c4d83b3dde1cbce779257d020e4104f3868e7c 100644 --- a/frameworks/core/interfaces/arkoala/arkoala_api.h +++ b/frameworks/core/interfaces/arkoala/arkoala_api.h @@ -4489,11 +4489,6 @@ struct ArkUIXComponentModifier { void (*setXComponentOptions)(ArkUINodeHandle node, ArkUI_CharPtr id, ArkUI_CharPtr type, ArkUI_CharPtr libraryName); ArkUI_CharPtr (*getXComponentSurfaceId)(ArkUIXComponentControllerHandle controller); ArkUIXComponentControllerHandle (*getXComponentController)(ArkUINodeHandle node); - - void (*setXComponentWidth)(ArkUINodeHandle node, ArkUI_Float32 value, ArkUI_Int32 unit, ArkUI_CharPtr calcValue); - void (*resetXComponentWidth)(ArkUINodeHandle node); - void (*setXComponentHeight)(ArkUINodeHandle node, ArkUI_Float32 value, ArkUI_Int32 unit, ArkUI_CharPtr calcValue); - void (*resetXComponentHeight)(ArkUINodeHandle node); void (*setXComponentEnableAnalyzer)(ArkUINodeHandle node, ArkUI_Bool enable); void (*resetXComponentEnableAnalyzer)(ArkUINodeHandle node); void (*setXComponentBackgroundColor)(ArkUINodeHandle node, ArkUI_Uint32 color); @@ -4510,6 +4505,7 @@ struct ArkUIXComponentModifier { void* (*getNativeXComponent)(ArkUINodeHandle node); void (*setXComponentLibraryname)(ArkUINodeHandle node, ArkUI_CharPtr libraryname); void (*setImageAIOptions)(ArkUINodeHandle node, void* options); + void (*initXComponent)(ArkUINodeHandle node); }; struct ArkUIStateModifier { diff --git a/frameworks/core/interfaces/native/node/node_api.cpp b/frameworks/core/interfaces/native/node/node_api.cpp index e9e5423ded25a867906e0c64a19df96249c8b4d6..99905ff33fbbf41f75105542823a200085834509 100644 --- a/frameworks/core/interfaces/native/node/node_api.cpp +++ b/frameworks/core/interfaces/native/node/node_api.cpp @@ -208,19 +208,18 @@ void SetCustomCallback(ArkUIVMContext context, ArkUINodeHandle node, ArkUI_Int32 ArkUINodeHandle CreateNode(ArkUINodeType type, int peerId, ArkUI_Int32 flags) { ArkUINodeHandle node = nullptr; - ArkUI_Params params = { .nodeType = type }; if (flags == ARKUI_NODE_FLAG_C) { ContainerScope Scope(Container::CurrentIdSafelyWithCheck()); - node = reinterpret_cast(ViewModel::CreateNode(type, peerId, params)); + node = reinterpret_cast(ViewModel::CreateNode(type, peerId)); } else { - node = reinterpret_cast(ViewModel::CreateNode(type, peerId, params)); + node = reinterpret_cast(ViewModel::CreateNode(type, peerId)); } return node; } ArkUINodeHandle CreateNodeWithParams(ArkUINodeType type, int peerId, ArkUI_Int32 flags, const ArkUI_Params& params) { - auto* node = reinterpret_cast(ViewModel::CreateNode(type, peerId, params)); + auto* node = reinterpret_cast(ViewModel::CreateNodeWithParams(type, peerId, params)); return node; } diff --git a/frameworks/core/interfaces/native/node/node_xcomponent_modifier.cpp b/frameworks/core/interfaces/native/node/node_xcomponent_modifier.cpp index 5704c7561d229b219d771a411f068b67a6eea12b..d06359e85910c74d690eded4754ea46b66da948c 100644 --- a/frameworks/core/interfaces/native/node/node_xcomponent_modifier.cpp +++ b/frameworks/core/interfaces/native/node/node_xcomponent_modifier.cpp @@ -27,44 +27,6 @@ namespace { const uint32_t ERROR_UINT_CODE = -1; std::string g_strValue; -void SetXComponentWidth(ArkUINodeHandle node, ArkUI_Float32 value, ArkUI_Int32 unit, ArkUI_CharPtr calcValue) -{ - auto* frameNode = reinterpret_cast(node); - CHECK_NULL_VOID(frameNode); - auto unitEnum = static_cast(unit); - if (unitEnum == DimensionUnit::CALC) { - ViewAbstract::SetWidth(frameNode, CalcLength(CalcLength(std::string(calcValue)))); - } else { - ViewAbstract::SetWidth(frameNode, CalcLength(value, unitEnum)); - } -} - -void ResetXComponentWidth(ArkUINodeHandle node) -{ - auto* frameNode = reinterpret_cast(node); - CHECK_NULL_VOID(frameNode); - ViewAbstract::ClearWidthOrHeight(frameNode, true); -} - -void SetXComponentHeight(ArkUINodeHandle node, ArkUI_Float32 value, ArkUI_Int32 unit, ArkUI_CharPtr calcValue) -{ - auto* frameNode = reinterpret_cast(node); - CHECK_NULL_VOID(frameNode); - auto unitEnum = static_cast(unit); - if (unitEnum == DimensionUnit::CALC) { - ViewAbstract::SetHeight(frameNode, CalcLength(CalcLength(std::string(calcValue)))); - } else { - ViewAbstract::SetHeight(frameNode, CalcLength(value, unitEnum)); - } -} - -void ResetXComponentHeight(ArkUINodeHandle node) -{ - auto* frameNode = reinterpret_cast(node); - CHECK_NULL_VOID(frameNode); - ViewAbstract::ClearWidthOrHeight(frameNode, false); -} - void SetXComponentEnableAnalyzer(ArkUINodeHandle node, ArkUI_Bool enable) { auto* frameNode = reinterpret_cast(node); @@ -197,6 +159,13 @@ void SetImageAIOptions(ArkUINodeHandle node, void* options) CHECK_NULL_VOID(frameNode); XComponentModelNG::SetImageAIOptions(frameNode, options); } + +void InitXComponent(ArkUINodeHandle node) +{ + auto* frameNode = reinterpret_cast(node); + CHECK_NULL_VOID(frameNode); + XComponentModelNG::InitXComponent(frameNode); +} } // namespace namespace NodeModifier { @@ -207,10 +176,6 @@ const ArkUIXComponentModifier* GetXComponentModifier() nullptr, // setXComponentOptions nullptr, // getXComponentSurfaceId nullptr, // getXComponentController - SetXComponentWidth, - ResetXComponentWidth, - SetXComponentHeight, - ResetXComponentHeight, SetXComponentEnableAnalyzer, ResetXComponentEnableAnalyzer, SetXComponentBackgroundColor, @@ -227,6 +192,7 @@ const ArkUIXComponentModifier* GetXComponentModifier() GetNativeXComponent, SetXComponentLibraryname, SetImageAIOptions, + InitXComponent, }; return &modifier; diff --git a/frameworks/core/interfaces/native/node/view_model.cpp b/frameworks/core/interfaces/native/node/view_model.cpp index 1fc0dca38d4039895bcbf6a802a44cf6ba1c2ff7..5d171cd827bf1473d024ced6a6c59860ed9f4b50 100644 --- a/frameworks/core/interfaces/native/node/view_model.cpp +++ b/frameworks/core/interfaces/native/node/view_model.cpp @@ -589,7 +589,20 @@ static createArkUIFrameNode* createArkUIFrameNodes[] = { createBadgeNode, }; -void* CreateNode(ArkUINodeType tag, ArkUI_Int32 nodeId, const ArkUI_Params& params) +void* CreateNode(ArkUINodeType tag, ArkUI_Int32 nodeId) +{ + if (tag >= sizeof(createArkUIFrameNodes) / sizeof(createArkUIFrameNode*)) { + TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "fail to create %{public}d type of node", tag); + return nullptr; + } + CHECK_NULL_RETURN(createArkUIFrameNodes[tag], nullptr); + if (nodeId == ARKUI_AUTO_GENERATE_NODE_ID) { + nodeId = ElementRegister::GetInstance()->MakeUniqueId(); + } + return createArkUIFrameNodes[tag](nodeId); +} + +void* CreateNodeWithParams(ArkUINodeType tag, ArkUI_Int32 nodeId, const ArkUI_Params& params) { if (tag >= sizeof(createArkUIFrameNodes) / sizeof(createArkUIFrameNode*)) { TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "fail to create %{public}d type of node", tag); diff --git a/frameworks/core/interfaces/native/node/view_model.h b/frameworks/core/interfaces/native/node/view_model.h index 571af55da04faf4238f3482f1172b054efd693a9..38950c2e304daa792d0833b59d45a3e9066b0bf9 100644 --- a/frameworks/core/interfaces/native/node/view_model.h +++ b/frameworks/core/interfaces/native/node/view_model.h @@ -22,7 +22,9 @@ namespace OHOS::Ace::NG::ViewModel { -void* CreateNode(ArkUINodeType tag, ArkUI_Int32 nodeId, const ArkUI_Params& params); +void* CreateNode(ArkUINodeType tag, ArkUI_Int32 nodeId); + +void* CreateNodeWithParams(ArkUINodeType tag, ArkUI_Int32 nodeId, const ArkUI_Params& params); ArkUI_CharPtr GetName(void* nativePtr); diff --git a/test/unittest/core/pattern/web/mock_rosen_render_surface.cpp b/test/unittest/core/pattern/web/mock_rosen_render_surface.cpp index 7e423dabc66b08c2f7b2b7064eeed90b149ab35e..43c8a8d6f64e6f749ce91d93d21a3363205c741d 100644 --- a/test/unittest/core/pattern/web/mock_rosen_render_surface.cpp +++ b/test/unittest/core/pattern/web/mock_rosen_render_surface.cpp @@ -38,4 +38,8 @@ namespace OHOS::Ace::NG { void RosenRenderSurface::SetSurfaceDefaultSize(int, int) {} void RosenRenderSurface::DrawBufferForXComponent(OHOS::Ace::Testing::TestingCanvas&, float, float, float, float) {} void RosenRenderSurface::ReleaseSurfaceBuffers() {} -} \ No newline at end of file + void RosenRenderSurface::RegisterSurface() const {} + void RosenRenderSurface::UnregisterSurface() const {} + void RosenRenderSurface::Connect() const {} + void RosenRenderSurface::Disconnect() const {} +}