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 class DataChangeListener : virtual public Referenced { 27 public: 28 virtual void OnDataReloaded() = 0; 29 virtual void OnDataAdded(size_t index) = 0; 30 virtual void OnDataDeleted(size_t index) = 0; 31 virtual void OnDataChanged(size_t index) = 0; 32 virtual void OnDataMoved(size_t from, size_t to) = 0; 33 }; 34 35 class ACE_EXPORT LazyForEachComponent : public V1::ForEachComponent { 36 DECLARE_ACE_TYPE(V2::LazyForEachComponent, V1::ForEachComponent); 37 38 public: LazyForEachComponent(const std::string & id)39 explicit LazyForEachComponent(const std::string& id) : V1::ForEachComponent(id, "LazyForEach") {} 40 ~LazyForEachComponent() override = default; 41 42 RefPtr<Element> CreateElement() override; 43 Count()44 size_t Count() override 45 { 46 return TotalCount(); 47 } 48 49 size_t TotalCount(); 50 RefPtr<Component> GetChildByIndex(size_t index); 51 ReleaseChildGroupByComposedId(const std::string & composedId)52 virtual void ReleaseChildGroupByComposedId(const std::string& composedId) {} 53 virtual void RegisterDataChangeListener(const RefPtr<DataChangeListener>& listener) = 0; 54 virtual void UnregisterDataChangeListener(const RefPtr<DataChangeListener>& listener) = 0; 55 56 protected: 57 virtual size_t OnGetTotalCount() = 0; 58 virtual RefPtr<Component> OnGetChildByIndex(size_t index) = 0; 59 60 std::list<RefPtr<Component>>& ExpandChildren() override; 61 Expanded()62 bool Expanded() const 63 { 64 return expanded_; 65 } 66 67 private: 68 bool expanded_ = false; 69 70 ACE_DISALLOW_COPY_AND_MOVE(LazyForEachComponent); 71 }; 72 73 } // namespace OHOS::Ace::V2 74 75 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_FOREACH_LAZY_FOREACH_COMPONENT_H 76