1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_BASE_CUSTOM_NODE_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_BASE_CUSTOM_NODE_H 18 19 #include <functional> 20 #include <string> 21 22 #include "base/utils/macros.h" 23 #include "core/components_ng/base/frame_node.h" 24 #include "core/components_ng/pattern/custom/custom_node_base.h" 25 #include "core/components_ng/pattern/custom/custom_node_pattern.h" 26 27 namespace OHOS::Ace::NG { 28 // CustomNode is the frame node of @Component struct. 29 class ACE_EXPORT CustomNode : public UINode, public CustomNodeBase { 30 DECLARE_ACE_TYPE(CustomNode, UINode, CustomNodeBase); 31 32 public: 33 static RefPtr<CustomNode> CreateCustomNode(int32_t nodeId, const std::string& viewKey); 34 35 CustomNode(int32_t nodeId, const std::string& viewKey); 36 ~CustomNode() override = default; 37 38 void AdjustLayoutWrapperTree(const RefPtr<LayoutWrapperNode>& parent, bool forceMeasure, bool forceLayout) override; 39 40 RefPtr<LayoutWrapperNode> CreateLayoutWrapper(bool forceMeasure = false, bool forceLayout = false) override; 41 IsAtomicNode()42 bool IsAtomicNode() const override 43 { 44 return true; 45 } 46 SetRenderFunction(const RenderFunction & renderFunction)47 void SetRenderFunction(const RenderFunction& renderFunction) override 48 { 49 renderFunction_ = renderFunction; 50 } 51 52 void Build() override; 53 FrameCount()54 int32_t FrameCount() const override 55 { 56 return 1; 57 } 58 59 void Render(); 60 SetCompleteReloadFunc(RenderFunction && func)61 void SetCompleteReloadFunc(RenderFunction&& func) override 62 { 63 completeReloadFunc_ = std::move(func); 64 } 65 void FlushReload(); 66 ToJsonValue(std::unique_ptr<JsonValue> & json)67 void ToJsonValue(std::unique_ptr<JsonValue>& json) const override 68 { 69 json->Put("viewKey", viewKey_.c_str()); 70 } 71 FromJson(const std::unique_ptr<JsonValue> & json)72 void FromJson(const std::unique_ptr<JsonValue>& json) override {} 73 GetCustomTag()74 std::string GetCustomTag() override 75 { 76 return jsViewName_; 77 } 78 79 void MarkNeedSyncRenderTree(bool needRebuild = false) override; 80 RefPtr<UINode> GetFrameChildByIndex(uint32_t index, bool needBuild) override; 81 void SetJSViewActive(bool active) override; 82 83 private: 84 std::string viewKey_; 85 RenderFunction renderFunction_; 86 RenderFunction completeReloadFunc_; 87 bool needMarkParent_ = true; 88 }; 89 } // namespace OHOS::Ace::NG 90 91 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_BASE_CUSTOM_NODE_H 92