• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <string>
22 
23 #include "base/memory/ace_type.h"
24 #include "base/memory/referenced.h"
25 #include "base/utils/macros.h"
26 #include "core/components_ng/layout/layout_wrapper.h"
27 
28 namespace OHOS::Ace {
29 
30 struct NodeInfoPU {
31     std::function<void()> appearFunc;
32     std::function<RefPtr<AceType>()> renderFunc;
33     std::function<void()> updateFunc;
34     std::function<void()> removeFunc;
35     std::function<void(const RefPtr<AceType>&)> updateNodeFunc;
36     std::function<void(const std::string&)> updateViewIdFunc;
37     std::function<void()> pageTransitionFunc;
38     std::function<void(NG::LayoutWrapper*)> measureFunc;
39     std::function<void(NG::LayoutWrapper*)> layoutFunc;
40     std::function<void(bool)> reloadFunc;
41     std::function<void(int32_t)> nodeUpdateFunc;
42 
43     bool hasMeasureOrLayout = false;
44     bool isStatic = false;
45 };
46 
47 using UpdateTask = std::tuple<int32_t, RefPtr<AceType>, RefPtr<AceType>>;
48 
49 class ACE_EXPORT ViewPartialUpdateModel {
50 public:
51     static ViewPartialUpdateModel* GetInstance();
52     virtual ~ViewPartialUpdateModel() = default;
53 
54     virtual RefPtr<AceType> CreateNode(NodeInfoPU&& info) = 0;
55     virtual bool MarkNeedUpdate(const WeakPtr<AceType>& node) = 0;
56     virtual void FlushUpdateTask(const UpdateTask& task) = 0;
57     virtual void FinishUpdate(
58         const WeakPtr<AceType>& viewNode, int32_t id, std::function<void(const UpdateTask&)>&& emplaceTaskFunc) = 0;
59 
60 private:
61     static std::unique_ptr<ViewPartialUpdateModel> instance_;
62 };
63 
64 } // namespace OHOS::Ace
65 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_BASE_VIEW_PARTIAL_UPDATE_MODEL_H
66