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_LIST_LIST_ITEM_GROUP_COMPONENT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_LIST_LIST_ITEM_GROUP_COMPONENT_H
18 
19 #include "core/components/list/list_item_component.h"
20 
21 namespace OHOS::Ace {
22 
23 class ListItemGroupComponent : public ListItemComponent {
24     DECLARE_ACE_TYPE(ListItemGroupComponent, ListItemComponent);
25 
26 public:
27     explicit ListItemGroupComponent(const std::string& type);
28     ~ListItemGroupComponent() override = default;
29 
30     RefPtr<Element> CreateElement() override;
31     RefPtr<RenderNode> CreateRenderNode() override;
32 
SetOnClicked(const EventMarker & onClicked)33     void SetOnClicked(const EventMarker& onClicked)
34     {
35         onClicked_ = onClicked;
36     }
37 
GetOnClicked()38     const EventMarker& GetOnClicked() const
39     {
40         return onClicked_;
41     }
42 
SetOnCollapse(const EventMarker & onCollapse)43     void SetOnCollapse(const EventMarker& onCollapse)
44     {
45         onCollapse_ = onCollapse;
46     }
47 
GetOnCollapse()48     const EventMarker& GetOnCollapse() const
49     {
50         return onCollapse_;
51     }
52 
SetOnExpand(const EventMarker & onExpand)53     void SetOnExpand(const EventMarker& onExpand)
54     {
55         onExpand_ = onExpand;
56     }
57 
GetOnExpand()58     const EventMarker& GetOnExpand() const
59     {
60         return onExpand_;
61     }
62 
SetGroupId(const std::string & groupId)63     void SetGroupId(const std::string& groupId)
64     {
65         groupId_ = groupId;
66     }
67 
GetGroupId()68     const std::string& GetGroupId() const
69     {
70         return groupId_;
71     }
72 
GetChildren()73     const std::list<RefPtr<Component>>& GetChildren() const
74     {
75         return children_;
76     }
77 
AppendChild(const RefPtr<Component> & child)78     void AppendChild(const RefPtr<Component>& child)
79     {
80         if (child) {
81             children_.emplace_back(child);
82         }
83     }
84 
RemoveChild(const RefPtr<Component> & child)85     void RemoveChild(const RefPtr<Component>& child)
86     {
87         if (child) {
88             children_.remove(child);
89         }
90     }
91 
SetDirection(FlexDirection direction)92     void SetDirection(FlexDirection direction)
93     {
94         direction_ = direction;
95     }
96 
GetDirection()97     FlexDirection GetDirection() const
98     {
99         return direction_;
100     }
101 
SetExpand(bool expand)102     void SetExpand(bool expand)
103     {
104         expand_ = expand;
105     }
106 
GetExpand()107     bool GetExpand() const
108     {
109         return expand_;
110     }
111 
112 private:
113     EventMarker onClicked_;
114     EventMarker onCollapse_;
115     EventMarker onExpand_;
116     std::string groupId_;
117     bool expand_ = false;
118     std::list<RefPtr<Component>> children_;
119     FlexDirection direction_ = FlexDirection::COLUMN;
120 };
121 
122 } // namespace OHOS::Ace
123 
124 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_LIST_LIST_ITEM_GROUP_COMPONENT_H
125