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_VIEW_PARTIAL_UPDATE_MODEL_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_BASE_VIEW_PARTIAL_UPDATE_MODEL_H
18 
19 #include <functional>
20 #include <memory>
21 #include <mutex>
22 #include <string>
23 
24 #include "base/memory/ace_type.h"
25 #include "base/memory/referenced.h"
26 #include "base/utils/macros.h"
27 #include "core/components_ng/layout/layout_wrapper.h"
28 #include "frameworks/core/components_ng/pattern/custom/custom_node_base.h"
29 
30 namespace OHOS::Ace {
31 
32 struct NodeInfoPU {
33     std::function<void()> appearFunc;
34     std::function<void()> didBuildFunc;
35     std::function<RefPtr<AceType>()> renderFunc;
36     std::function<void()> updateFunc;
37     std::function<void()> removeFunc;
38     std::function<void(const RefPtr<AceType>&)> updateNodeFunc;
39     std::function<void(const std::string&)> updateViewIdFunc;
40     std::function<void()> pageTransitionFunc;
41     std::function<void(NG::LayoutWrapper*)> measureFunc;
42     std::function<void(NG::LayoutWrapper*)> measureSizeFunc;
43     std::function<void(NG::LayoutWrapper*)> layoutFunc;
44     std::function<void(NG::LayoutWrapper*)> placeChildrenFunc;
45     std::function<void(bool)> reloadFunc;
46     std::function<RefPtr<AceType>()> completeReloadFunc;
47     std::function<void(int32_t)> nodeUpdateFunc;
48     std::function<bool(int32_t)> hasNodeUpdateFunc;
49     std::function<void(RefPtr<NG::CustomNodeBase>)> recycleCustomNodeFunc;
50     std::function<void(bool)> setActiveFunc;
51     std::function<void(const std::vector<std::string>&)> onDumpInfoFunc;
52     std::function<std::string()> onDumpInspectorFunc;
53     std::function<void*()> getThisFunc;
54 
55     bool hasMeasureOrLayout = false;
56     bool isStatic = false;
57     bool isCustomTitle = false;
58     int32_t codeRow = -1;
59     int32_t codeCol = -1;
60 
61     std::string jsViewName;
62     bool isV2 = false;
63     NG::ExtraInfo extraInfo;
64 };
65 
66 using UpdateTask = std::tuple<int32_t, RefPtr<AceType>, RefPtr<AceType>>;
67 
68 class ACE_FORCE_EXPORT ViewPartialUpdateModel {
69 public:
70     static ViewPartialUpdateModel* GetInstance();
71     virtual ~ViewPartialUpdateModel() = default;
72 
73     virtual RefPtr<AceType> CreateNode(NodeInfoPU&& info) = 0;
74     virtual bool MarkNeedUpdate(const WeakPtr<AceType>& node) = 0;
75     virtual void FlushUpdateTask(const UpdateTask& task) = 0;
76     virtual void FinishUpdate(
77         const WeakPtr<AceType>& viewNode, int32_t id, std::function<void(const UpdateTask&)>&& emplaceTaskFunc) = 0;
78 };
79 
80 } // namespace OHOS::Ace
81 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_BASE_VIEW_PARTIAL_UPDATE_MODEL_H
82