• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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_SCROLL_LAZY_COMPOSE_ADAPTER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SCROLL_LAZY_COMPOSE_ADAPTER_H
18 #include <cstdint>
19 #include <functional>
20 
21 #include "base/memory/referenced.h"
22 #include "base/utils/unique_valued_map.h"
23 
24 namespace OHOS::Ace::NG {
25 class FrameNode;
26 
27 /**
28  * @brief Adapter to access and manage lazy items in Arkoala frontend
29  *
30  */
31 class LazyComposeAdapter {
32 public:
33     using CreateItemCb = std::function<RefPtr<FrameNode>(int32_t)>;
34     using UpdateRangeCb = std::function<void(int32_t, int32_t)>;
35 
SetTotalCount(int32_t value)36     void SetTotalCount(int32_t value)
37     {
38         totalCount_ = value;
39     }
40 
GetTotalCount()41     int32_t GetTotalCount() const
42     {
43         return totalCount_;
44     }
45 
46     void SetCallbacks(CreateItemCb create, UpdateRangeCb update);
47 
48     RefPtr<FrameNode> GetOrCreateChild(uint32_t index);
49     RefPtr<FrameNode> GetChild(uint32_t index);
50 
51     uint32_t GetIndexOfChild(const RefPtr<FrameNode>& child);
52 
53     void SetActiveRange(int32_t start, int32_t end);
54 
55     void OnDataChange(int32_t changeIndex);
56 
57 private:
58     UniqueValuedMap<uint32_t, WeakPtr<FrameNode>, WeakPtr<FrameNode>::Hash> items_;
59     CreateItemCb createItem_;
60     UpdateRangeCb updateRange_;
61     int32_t totalCount_ = 0;
62 };
63 } // namespace OHOS::Ace::NG
64 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SCROLL_LAZY_COMPOSE_ADAPTER_H
65