1 /* 2 * Copyright (c) 2021 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_V2_FOREACH_LAZY_FOREACH_COMPONENT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_FOREACH_LAZY_FOREACH_COMPONENT_H 18 19 #include "base/memory/ace_type.h" 20 #include "base/utils/macros.h" 21 #include "core/components/foreach/for_each_component.h" 22 #include "core/components_v2/common/common_def.h" 23 24 namespace OHOS::Ace::V2 { 25 26 typedef struct Operation { 27 std::string type; 28 int32_t count; 29 int32_t index; 30 std::pair<int32_t, int32_t> coupleIndex; 31 std::string key; 32 std::pair<std::string, std::string> coupleKey; 33 std::list<std::string> keyList; 34 } Operation; 35 36 class DataChangeListener : virtual public AceType { 37 DECLARE_ACE_TYPE(DataChangeListener, AceType) 38 public: 39 virtual void OnDataReloaded() = 0; 40 virtual void OnDataAdded(size_t index) = 0; 41 virtual void OnDataBulkAdded(size_t index, size_t count) = 0; 42 virtual void OnDataDeleted(size_t index) = 0; 43 virtual void OnDataBulkDeleted(size_t index, size_t count) = 0; 44 virtual void OnDataChanged(size_t index) = 0; 45 // this is exchange impl. 46 virtual void OnDataMoved(size_t from, size_t to) = 0; 47 virtual void OnDatasetChange(const std::list<Operation>& DataOperations) = 0; OnDataBulkChanged(size_t index,size_t count)48 virtual void OnDataBulkChanged(size_t index, size_t count) {} OnDataMoveToNewPlace(size_t from,size_t to)49 virtual void OnDataMoveToNewPlace(size_t from, size_t to) {} 50 }; 51 52 class ACE_EXPORT LazyForEachComponent : public V1::ForEachComponent { 53 DECLARE_ACE_TYPE(V2::LazyForEachComponent, V1::ForEachComponent); 54 55 public: LazyForEachComponent(const std::string & id)56 explicit LazyForEachComponent(const std::string& id) : V1::ForEachComponent(id, "LazyForEach") {} 57 ~LazyForEachComponent() override = default; 58 59 RefPtr<Element> CreateElement() override; 60 Count()61 size_t Count() override 62 { 63 return TotalCount(); 64 } 65 66 size_t TotalCount(); 67 RefPtr<Component> GetChildByIndex(size_t index); 68 ReleaseChildGroupByComposedId(const std::string & composedId)69 virtual void ReleaseChildGroupByComposedId(const std::string& composedId) {} 70 virtual void RegisterDataChangeListener(const RefPtr<DataChangeListener>& listener) = 0; 71 virtual void UnregisterDataChangeListener(DataChangeListener* listener) = 0; 72 73 protected: 74 virtual size_t OnGetTotalCount() = 0; 75 virtual RefPtr<Component> OnGetChildByIndex(size_t index) = 0; 76 77 std::list<RefPtr<Component>>& ExpandChildren() override; 78 Expanded()79 bool Expanded() const 80 { 81 return expanded_; 82 } 83 84 private: 85 bool expanded_ = false; 86 87 ACE_DISALLOW_COPY_AND_MOVE(LazyForEachComponent); 88 }; 89 90 } // namespace OHOS::Ace::V2 91 92 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_FOREACH_LAZY_FOREACH_COMPONENT_H 93