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<RefPtr<AceType>()> renderFunc; 35 std::function<void()> updateFunc; 36 std::function<void()> removeFunc; 37 std::function<void(const RefPtr<AceType>&)> updateNodeFunc; 38 std::function<void(const std::string&)> updateViewIdFunc; 39 std::function<void()> pageTransitionFunc; 40 std::function<void(NG::LayoutWrapper*)> measureFunc; 41 std::function<void(NG::LayoutWrapper*)> measureSizeFunc; 42 std::function<void(NG::LayoutWrapper*)> layoutFunc; 43 std::function<void(NG::LayoutWrapper*)> placeChildrenFunc; 44 std::function<void(bool)> reloadFunc; 45 std::function<RefPtr<AceType>()> completeReloadFunc; 46 std::function<void(int32_t)> nodeUpdateFunc; 47 std::function<void(RefPtr<NG::CustomNodeBase>)> recycleCustomNodeFunc; 48 std::function<void(bool)> setActiveFunc; 49 std::function<void(const std::vector<std::string>&)> onDumpInfoFunc; 50 51 bool hasMeasureOrLayout = false; 52 bool isStatic = false; 53 bool isCustomTitle = false; 54 int32_t codeRow = -1; 55 int32_t codeCol = -1; 56 57 std::string jsViewName; 58 NG::ExtraInfo extraInfo; 59 }; 60 61 using UpdateTask = std::tuple<int32_t, RefPtr<AceType>, RefPtr<AceType>>; 62 63 class ACE_EXPORT ViewPartialUpdateModel { 64 public: 65 static ViewPartialUpdateModel* GetInstance(); 66 virtual ~ViewPartialUpdateModel() = default; 67 68 virtual RefPtr<AceType> CreateNode(NodeInfoPU&& info) = 0; 69 virtual bool MarkNeedUpdate(const WeakPtr<AceType>& node) = 0; 70 virtual void FlushUpdateTask(const UpdateTask& task) = 0; 71 virtual void FinishUpdate( 72 const WeakPtr<AceType>& viewNode, int32_t id, std::function<void(const UpdateTask&)>&& emplaceTaskFunc) = 0; 73 74 private: 75 static std::unique_ptr<ViewPartialUpdateModel> instance_; 76 static std::mutex mutex_; 77 }; 78 79 } // namespace OHOS::Ace 80 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_BASE_VIEW_PARTIAL_UPDATE_MODEL_H 81