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<LayoutWrapper>& parent, bool forceMeasure, bool forceLayout) override; 39 40 RefPtr<LayoutWrapper> 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 SetCompleteReloadFunc(RenderFunction && func)59 void SetCompleteReloadFunc(RenderFunction&& func) override 60 { 61 completeReloadFunc_ = std::move(func); 62 } 63 void FlushReload(); 64 65 private: 66 std::string viewKey_; 67 RenderFunction renderFunction_; 68 RenderFunction completeReloadFunc_; 69 }; 70 } // namespace OHOS::Ace::NG 71 72 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_BASE_CUSTOM_NODE_H 73