1 /* 2 * Copyright (c) 2024 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 ACE_ENGINE_CJ_LAZYFOREACH_H 17 #define ACE_ENGINE_CJ_LAZYFOREACH_H 18 19 #include <string> 20 21 #include "base/memory/referenced.h" 22 #include "base/utils/macros.h" 23 #include "bridge/cj_frontend/cppview/lazy_foreach_func.h" 24 #include "bridge/cj_frontend/cppview/native_view.h" 25 #include "bridge/cj_frontend/interfaces/cj_ffi/cj_native_view_ffi.h" 26 #include "core/components_ng/base/view_stack_processor.h" 27 #include "core/components_ng/syntax/lazy_for_each_model.h" 28 #include "core/components_ng/syntax/lazy_for_each_builder.h" 29 30 namespace OHOS { 31 namespace Ace { 32 namespace Framework { 33 34 class ACE_EXPORT CJLazyForEachBuilder : public NG::LazyForEachBuilder, public LazyForEachActuator { DECLARE_ACE_TYPE(CJLazyForEachBuilder,NG::LazyForEachBuilder,LazyForEachActuator)35 DECLARE_ACE_TYPE(CJLazyForEachBuilder, NG::LazyForEachBuilder, LazyForEachActuator) 36 public: 37 explicit CJLazyForEachBuilder(sptr<LazyForEachFuncs>&& cjBuilder) : cjBuilder_(cjBuilder) {} OnGetTotalCount()38 int32_t OnGetTotalCount() override 39 { 40 return cjBuilder_->GetTotalCount(); 41 } 42 void OnExpandChildrenOnInitialInNG() override; 43 std::pair<std::string, RefPtr<NG::UINode>> OnGetChildByIndex( 44 int32_t index, std::unordered_map<std::string, std::pair<int32_t, RefPtr<NG::UINode>>>& cachedItems) override; 45 std::pair<std::string, RefPtr<NG::UINode>> OnGetChildByIndexNew(int32_t index, 46 std::map<int32_t, NG::LazyForEachChild>& cachedItems, 47 std::unordered_map<std::string, NG::LazyForEachCacheChild>& expiringItems) override; 48 void ReleaseChildGroupById(const std::string& id) override; 49 void RegisterDataChangeListener(const RefPtr<V2::DataChangeListener>& listener) override; 50 void UnregisterDataChangeListener(V2::DataChangeListener* listener) override; DeleteExpiringItemImmediately()51 bool DeleteExpiringItemImmediately() override 52 { 53 return false; 54 } 55 void NotifyDataChanged(size_t index, const RefPtr<NG::UINode>& lazyForEachNode, bool isRebuild = true) override {}; NotifyDataDeleted(const RefPtr<NG::UINode> & lazyForEachNode,size_t index,bool removeIds)56 void NotifyDataDeleted(const RefPtr<NG::UINode>& lazyForEachNode, size_t index, bool removeIds) override {}; NotifyDataAdded(size_t index)57 void NotifyDataAdded(size_t index) override {}; KeepRemovedItemInCache(NG::LazyForEachChild node,std::unordered_map<std::string,NG::LazyForEachCacheChild> & cachedItems)58 void KeepRemovedItemInCache(NG::LazyForEachChild node, 59 std::unordered_map<std::string, NG::LazyForEachCacheChild>& cachedItems) override {} 60 61 private: 62 sptr<LazyForEachFuncs> cjBuilder_; 63 wptr<CJDataChangeListener> weakListenerManager_; 64 }; 65 66 } // namespace Framework 67 } // namespace Ace 68 } // namespace OHOS 69 70 #endif // ACE_ENGINE_CJ_LAZYFOREACH_H 71