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<RefPtr<AceType>()> completeReloadFunc; 42 std::function<void(int32_t)> nodeUpdateFunc; 43 44 bool hasMeasureOrLayout = false; 45 bool isStatic = false; 46 }; 47 48 using UpdateTask = std::tuple<int32_t, RefPtr<AceType>, RefPtr<AceType>>; 49 50 class ACE_EXPORT ViewPartialUpdateModel { 51 public: 52 static ViewPartialUpdateModel* GetInstance(); 53 virtual ~ViewPartialUpdateModel() = default; 54 55 virtual RefPtr<AceType> CreateNode(NodeInfoPU&& info) = 0; 56 virtual bool MarkNeedUpdate(const WeakPtr<AceType>& node) = 0; 57 virtual void FlushUpdateTask(const UpdateTask& task) = 0; 58 virtual void FinishUpdate( 59 const WeakPtr<AceType>& viewNode, int32_t id, std::function<void(const UpdateTask&)>&& emplaceTaskFunc) = 0; 60 61 private: 62 static std::unique_ptr<ViewPartialUpdateModel> instance_; 63 }; 64 65 } // namespace OHOS::Ace 66 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_BASE_VIEW_PARTIAL_UPDATE_MODEL_H 67