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 #include "core/components_ng/pattern/custom/custom_node.h"
17
18 #include "base/log/dump_log.h"
19 #include "core/components_ng/base/frame_node.h"
20 #include "core/components_ng/base/view_stack_processor.h"
21 #include "core/components_ng/pattern/custom/custom_node_pattern.h"
22 #include "core/components_v2/inspector/inspector_constants.h"
23 #include "core/pipeline/base/element_register.h"
24 #include "core/pipeline_ng/pipeline_context.h"
25 #include "core/pipeline_ng/ui_task_scheduler.h"
26
27 namespace OHOS::Ace::NG {
CreateCustomNode(int32_t nodeId,const std::string & viewKey)28 RefPtr<CustomNode> CustomNode::CreateCustomNode(int32_t nodeId, const std::string& viewKey)
29 {
30 auto node = MakeRefPtr<CustomNode>(nodeId, viewKey);
31 ElementRegister::GetInstance()->AddUINode(node);
32 return node;
33 }
34
CustomNode(int32_t nodeId,const std::string & viewKey)35 CustomNode::CustomNode(int32_t nodeId, const std::string& viewKey)
36 : UINode(V2::JS_VIEW_ETS_TAG, nodeId, MakeRefPtr<CustomNodePattern>()), viewKey_(viewKey)
37 {}
38
Build()39 void CustomNode::Build()
40 {
41 if (renderFunction_) {
42 {
43 ACE_SCOPED_TRACE("CustomNode:OnAppear");
44 FireOnAppear();
45 }
46 {
47 ACE_SCOPED_TRACE("CustomNode:BuildItem");
48 // first create child node and wrapper.
49 ScopedViewStackProcessor scopedViewStackProcessor;
50 auto child = renderFunction_();
51 if (child) {
52 child->MountToParent(Claim(this));
53 }
54 }
55 renderFunction_ = nullptr;
56 }
57 UINode::Build();
58 }
59
60 // used in HotReload to update root view @Component
FlushReload()61 void CustomNode::FlushReload()
62 {
63 CHECK_NULL_VOID(completeReloadFunc_);
64 Clean();
65 renderFunction_ = completeReloadFunc_;
66 Build();
67 }
68
AdjustLayoutWrapperTree(const RefPtr<LayoutWrapper> & parent,bool forceMeasure,bool forceLayout)69 void CustomNode::AdjustLayoutWrapperTree(const RefPtr<LayoutWrapper>& parent, bool forceMeasure, bool forceLayout)
70 {
71 Build();
72 UINode::AdjustLayoutWrapperTree(parent, forceMeasure, forceLayout);
73 }
74
CreateLayoutWrapper(bool forceMeasure,bool forceLayout)75 RefPtr<LayoutWrapper> CustomNode::CreateLayoutWrapper(bool forceMeasure, bool forceLayout)
76 {
77 Build();
78 return UINode::CreateLayoutWrapper(forceMeasure, forceLayout);
79 }
80
81 } // namespace OHOS::Ace::NG
82