• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_SWIPER_SWIPER_COMPONENT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SWIPER_SWIPER_COMPONENT_H
18 
19 #include "core/components/common/layout/constants.h"
20 #include "base/utils/macros.h"
21 #include "core/components/common/properties/swiper_indicator.h"
22 #include "core/components/declaration/swiper/swiper_declaration.h"
23 #include "core/components/swiper/swiper_controller.h"
24 #include "core/components_v2/foreach/lazy_foreach_component.h"
25 #include "core/pipeline/base/component_group.h"
26 
27 namespace OHOS::Ace {
28 
29 using SwiperChangeEndListener = std::function<void(int32_t)>;
30 using MoveCallback = std::function<void(int32_t)>;
31 
32 class ACE_EXPORT SwiperChangeEvent : public BaseEventInfo, public EventToJSONStringAdapter {
33     DECLARE_RELATIONSHIP_OF_CLASSES(SwiperChangeEvent, BaseEventInfo, EventToJSONStringAdapter);
34 
35 public:
SwiperChangeEvent(int32_t index)36     SwiperChangeEvent(int32_t index) : BaseEventInfo("SwiperChangeEvent"), index_(index) {}
37     ~SwiperChangeEvent() = default;
38 
GetIndex()39     int32_t GetIndex() const
40     {
41         return index_;
42     }
43 
ToJSONString()44     std::string ToJSONString() const override
45     {
46         return std::string(R"("change",{"index":)").append(std::to_string(index_).append("},null"));
47     }
48 
49 private:
50     int32_t index_ = 0;
51 };
52 
53 class ACE_EXPORT SwiperComponent : public ComponentGroup {
54     DECLARE_ACE_TYPE(SwiperComponent, ComponentGroup);
55 
56 public:
57     explicit SwiperComponent(const std::list<RefPtr<Component>>& children);
58     SwiperComponent(const std::list<RefPtr<Component>>& children, bool showIndicator);
59     ~SwiperComponent() override = default;
60 
61     RefPtr<RenderNode> CreateRenderNode() override;
62     RefPtr<Element> CreateElement() override;
63     void AppendChild(const RefPtr<Component>& child) override;
64 
65     uint32_t GetIndex() const;
66     void SetIndex(uint32_t index);
67     void SetDuration(double duration);
68     double GetDuration() const;
69     Axis GetAxis() const;
70     void SetAxis(Axis axis);
71     bool IsLoop() const;
72     void SetLoop(bool loop);
73     bool IsAutoPlay() const;
74     void SetAutoPlay(bool autoPlay);
75     bool IsShow() const;
76     void SetShow(bool show);
77     bool IsAnimationOpacity() const;
78     void SetAnimationOpacity(bool animationOpacity);
79     const Dimension& GetItemSpace() const;
80     void SetItemSpace(const Dimension& space);
81     int32_t GetDisplayCount() const;
82     void SetDisplayCount(int32_t displayCount);
83     void SetDigitalIndicator(bool digitalIndicator);
84     bool GetDigitalIndicator() const;
85     Color GetFadeColor() const;
86     void SetFadeColor(const Color& fadeColor);
87     int32_t GetCachedSize() const;
88     void SetCachedSize(int32_t cachedSize);
89     const Dimension& GetPreviousMargin() const;
90     void SetPreviousMargin(const Dimension& margin);
91     const Dimension& GetNextMargin() const;
92     void SetNextMargin(const Dimension& margin);
93     EdgeEffect GetEdgeEffect() const;
94     void SetEdgeEffect(const EdgeEffect edgeEffect);
95     void SetAnimationFinishEventId(const EventMarker& animationFinishEventId);
96     const EventMarker& GetAnimationFinishEventId() const;
97     double GetAutoPlayInterval() const;
98     void SetAutoPlayInterval(double autoPlayInterval);
99     SwiperDisplayMode GetDisplayMode() const;
100     void SetDisplayMode(SwiperDisplayMode displayMode);
101 
102     AnimationCurve GetAnimationCurve() const;
103     void SetAnimationCurve(AnimationCurve animationCurve);
104 
105     const EventMarker& GetChangeEventId() const;
106     void SetChangeEventId(const EventMarker& changeEventId);
107     const EventMarker& GetRotationEventId() const;
108     void SetRotationEventId(const EventMarker& rotationEventId);
109     const EventMarker& GetClickEventId() const;
110     void SetClickEventId(const EventMarker& clickEventId);
111     const EventMarker& GetRemoteMessageEventId() const;
112     void SetRemoteMessageEventId(const EventMarker& eventId);
113 
114     RefPtr<SwiperController> GetSwiperController() const;
115     const RefPtr<RotationController>& GetRotationController() const;
116 
117     void SetShowIndicator(bool showIndicator);
118     bool IsShowIndicator() const;
119     RefPtr<SwiperIndicator> GetIndicator() const;
120     void SetIndicator(const RefPtr<SwiperIndicator>& indicator);
121 
GetChangeEndListener()122     const SwiperChangeEndListener& GetChangeEndListener() const
123     {
124         return changeEndListener_;
125     }
126 
SetChangeEndListener(const SwiperChangeEndListener & changeEndListener)127     void SetChangeEndListener(const SwiperChangeEndListener& changeEndListener)
128     {
129         changeEndListener_ = changeEndListener;
130     }
131 
SetMoveCallback(const MoveCallback & moveCallback)132     void SetMoveCallback(const MoveCallback& moveCallback)
133     {
134         moveCallback_ = moveCallback;
135     }
136 
GetMoveCallback()137     const MoveCallback& GetMoveCallback() const
138     {
139         return moveCallback_;
140     }
141 
SetSlideContinue(bool slideContinued)142     void SetSlideContinue(bool slideContinued)
143     {
144         slideContinued_ = slideContinued;
145     }
146 
GetSlideContinue()147     bool GetSlideContinue() const
148     {
149         return slideContinued_;
150     }
151 
DisableSwipe(bool disableSwipe)152     void DisableSwipe(bool disableSwipe)
153     {
154         disableSwipe_ = disableSwipe;
155     }
156 
GetDisableSwipe()157     bool GetDisableSwipe() const
158     {
159         return disableSwipe_;
160     }
161 
SetDeclaration(const RefPtr<SwiperDeclaration> & declaration)162     void SetDeclaration(const RefPtr<SwiperDeclaration>& declaration)
163     {
164         if (declaration) {
165             declaration_ = declaration;
166         }
167     }
168 
GetDisableRotation()169     bool GetDisableRotation() const
170     {
171         return disableRation_;
172     }
173 
SetDisableRotation(bool disableRation)174     void SetDisableRotation(bool disableRation)
175     {
176         disableRation_ = disableRation;
177     }
178 
SetMainSwiperSize(MainSwiperSize mainSwiperSize)179     void SetMainSwiperSize(MainSwiperSize mainSwiperSize)
180     {
181         mainSwiperSize_ = mainSwiperSize;
182     }
183 
GetMainSwiperSize()184     MainSwiperSize GetMainSwiperSize() const
185     {
186         return mainSwiperSize_;
187     }
188 
GetLazyForEachComponent()189     RefPtr<V2::LazyForEachComponent> GetLazyForEachComponent() const
190     {
191         return lazyForEachComponent_.Upgrade();
192     }
193 
SetCurve(const RefPtr<Curve> & curve)194     void SetCurve(const RefPtr<Curve>& curve)
195     {
196         curve_ = curve;
197     }
198 
GetCurve()199     const RefPtr<Curve>& GetCurve() const
200     {
201         return curve_;
202     }
203 
204 private:
205     RefPtr<SwiperDeclaration> declaration_;
206     bool show_ { true };
207     bool slideContinued_ { false };
208     bool disableRation_ { false };
209     bool disableSwipe_ { false };
210     SwiperChangeEndListener changeEndListener_;
211     MoveCallback moveCallback_;
212     MainSwiperSize mainSwiperSize_ = MainSwiperSize::AUTO;
213     WeakPtr<V2::LazyForEachComponent> lazyForEachComponent_;
214     RefPtr<Curve> curve_;
215 };
216 
217 } // namespace OHOS::Ace
218 
219 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SWIPER_SWIPER_COMPONENT_H
220