• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_SYNTAX_REPEAT_NODE_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_SYNTAX_REPEAT_NODE_H
18 
19 #include <cstdint>
20 #include <list>
21 #include <string>
22 #include <type_traits>
23 
24 #include "base/utils/macros.h"
25 #include "core/components_ng/base/ui_node.h"
26 #include "core/components_ng/syntax/for_each_base_node.h"
27 #include "core/components_v2/inspector/inspector_constants.h"
28 
29 namespace OHOS::Ace::NG {
30 
31 class ACE_EXPORT RepeatNode : public ForEachBaseNode {
32     DECLARE_ACE_TYPE(RepeatNode, ForEachBaseNode);
33 
34 public:
35     static RefPtr<RepeatNode> GetOrCreateRepeatNode(int32_t nodeId);
36 
RepeatNode(int32_t nodeId)37     explicit RepeatNode(int32_t nodeId) : ForEachBaseNode(V2::JS_REPEAT_ETS_TAG, nodeId) {}
38 
39     ~RepeatNode() override = default;
40 
IsAtomicNode()41     bool IsAtomicNode() const override
42     {
43         return false;
44     }
45 
46     void CreateTempItems();
47 
48     // RepeatNode only
49     void FinishRepeatRender(std::list<int32_t>& removedElmtId);
50 
51     void FlushUpdateAndMarkDirty() override;
52 
53     // RepeatNode only
54     void MoveChild(uint32_t fromIndex);
55 
GetTempIds()56     const std::list<std::string>& GetTempIds() const
57     {
58         return tempIds_;
59     }
60 
SetIds(std::list<std::string> && ids)61     void SetIds(std::list<std::string>&& ids)
62     {
63         ids_ = std::move(ids);
64     }
65 
66     void AfterAddChild();
67     void SetOnMove(std::function<void(int32_t, int32_t)>&& onMove);
68     void SetItemDragHandler(std::function<void(int32_t)>&& onLongPress, std::function<void(int32_t)>&& onDragStart,
69         std::function<void(int32_t, int32_t)>&& onMoveThrough, std::function<void(int32_t)>&& onDrop);
70 
71     void MoveData(int32_t from, int32_t to) override;
72     RefPtr<FrameNode> GetFrameNode(int32_t index) override;
73     void InitDragManager(const RefPtr<UINode>& childNode);
74     void InitAllChildrenDragManager(bool init);
75 
76 private:
77     std::list<std::string> ids_;
78     int32_t from_ = -1;
79     int32_t to_ = -1;
80 
81     // temp items use to compare each update.
82     std::list<std::string> tempIds_;
83     std::list<RefPtr<UINode>> tempChildren_;
84 
85     // RepeatNode only
86     std::vector<RefPtr<UINode>> tempChildrenOfRepeat_;
87 
88     ACE_DISALLOW_COPY_AND_MOVE(RepeatNode);
89 };
90 
91 } // namespace OHOS::Ace::NG
92 
93 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_SYNTAX_REPEAT_NODE_H
94