• 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_CONTROLLER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SWIPER_SWIPER_CONTROLLER_H
18 
19 #include <functional>
20 #include <set>
21 
22 #include "base/memory/ace_type.h"
23 
24 namespace OHOS::Ace {
25 
26 using CommonFunc = std::function<void()>;
27 using SwipeToImpl = std::function<void(const int32_t, bool)>;
28 using SwipeToWithoutAnimationImpl = std::function<void(const int32_t)>;
29 using TurnPageRateFunc = std::function<void(const int32_t, float)>;
30 using PreloadItemsFunc = std::function<void(const std::set<int32_t>)>;
31 using PreloadItemsFinishFunc = std::function<void(const int32_t)>;
32 
33 class SwiperController : public virtual AceType {
34     DECLARE_ACE_TYPE(SwiperController, AceType);
35 
36 public:
37     void SwipeTo(int32_t index, bool reverse = false)
38     {
39         if (swipeToImpl_) {
40             swipeToImpl_(index, reverse);
41         }
42     }
43 
SetSwipeToImpl(const SwipeToImpl & swipeToImpl)44     void SetSwipeToImpl(const SwipeToImpl& swipeToImpl)
45     {
46         swipeToImpl_ = swipeToImpl;
47     }
48 
SwipeToWithoutAnimation(int32_t index)49     void SwipeToWithoutAnimation(int32_t index)
50     {
51         if (swipeToWithoutAnimationImpl_) {
52             swipeToWithoutAnimationImpl_(index);
53         }
54     }
55 
SetSwipeToWithoutAnimationImpl(const SwipeToWithoutAnimationImpl & swipeToWithoutAnimationImpl)56     void SetSwipeToWithoutAnimationImpl(const SwipeToWithoutAnimationImpl& swipeToWithoutAnimationImpl)
57     {
58         swipeToWithoutAnimationImpl_ = swipeToWithoutAnimationImpl;
59     }
60 
ShowPrevious()61     void ShowPrevious()
62     {
63         if (showPrevImpl_) {
64             showPrevImpl_();
65         }
66     }
67 
SetShowPrevImpl(const CommonFunc & showPrevImpl)68     void SetShowPrevImpl(const CommonFunc& showPrevImpl)
69     {
70         showPrevImpl_ = showPrevImpl;
71     }
72 
ShowNext()73     void ShowNext()
74     {
75         if (showNextImpl_) {
76             showNextImpl_();
77         }
78     }
79 
SetShowNextImpl(const CommonFunc & showNextImpl)80     void SetShowNextImpl(const CommonFunc& showNextImpl)
81     {
82         showNextImpl_ = showNextImpl;
83     }
84 
FinishAnimation()85     void FinishAnimation() const
86     {
87         if (finishImpl_) {
88             finishImpl_();
89         }
90     }
91 
SetFinishImpl(const CommonFunc & finishImpl)92     void SetFinishImpl(const CommonFunc& finishImpl)
93     {
94         finishImpl_ = finishImpl;
95     }
96 
SetFinishCallback(const CommonFunc & onFinish)97     void SetFinishCallback(const CommonFunc& onFinish)
98     {
99         finishCallback_ = onFinish;
100     }
101 
GetFinishCallback()102     const CommonFunc& GetFinishCallback() const
103     {
104         return finishCallback_;
105     }
106 
HasInitialized()107     bool HasInitialized() const
108     {
109         return showPrevImpl_ && showNextImpl_ && finishImpl_;
110     }
111 
SetTabBarFinishCallback(const CommonFunc & onTabBarFinish)112     void SetTabBarFinishCallback(const CommonFunc& onTabBarFinish)
113     {
114         tabBarFinishCallback_ = onTabBarFinish;
115     }
116 
GetTabBarFinishCallback()117     const CommonFunc& GetTabBarFinishCallback() const
118     {
119         return tabBarFinishCallback_;
120     }
121 
SetRemoveTabBarEventCallback(const CommonFunc & removeTabBarEventCallback)122     void SetRemoveTabBarEventCallback(const CommonFunc& removeTabBarEventCallback)
123     {
124         removeTabBarEventCallback_ = removeTabBarEventCallback;
125     }
126 
GetRemoveTabBarEventCallback()127     const CommonFunc& GetRemoveTabBarEventCallback() const
128     {
129         return removeTabBarEventCallback_;
130     }
131 
SetAddTabBarEventCallback(const CommonFunc & addTabBarEventCallback)132     void SetAddTabBarEventCallback(const CommonFunc& addTabBarEventCallback)
133     {
134         addTabBarEventCallback_ = addTabBarEventCallback;
135     }
136 
GetAddTabBarEventCallback()137     const CommonFunc& GetAddTabBarEventCallback() const
138     {
139         return addTabBarEventCallback_;
140     }
141 
SetRemoveSwiperEventCallback(const CommonFunc & removeSwiperEventCallback)142     void SetRemoveSwiperEventCallback(const CommonFunc& removeSwiperEventCallback)
143     {
144         removeSwiperEventCallback_ = removeSwiperEventCallback;
145     }
146 
GetRemoveSwiperEventCallback()147     const CommonFunc& GetRemoveSwiperEventCallback() const
148     {
149         return removeSwiperEventCallback_;
150     }
151 
SetAddSwiperEventCallback(const CommonFunc & addSwiperEventCallback)152     void SetAddSwiperEventCallback(const CommonFunc& addSwiperEventCallback)
153     {
154         addSwiperEventCallback_ = addSwiperEventCallback;
155     }
156 
GetAddSwiperEventCallback()157     const CommonFunc& GetAddSwiperEventCallback() const
158     {
159         return addSwiperEventCallback_;
160     }
161 
SetTurnPageRateCallback(const TurnPageRateFunc & turnPageRateCallback)162     void SetTurnPageRateCallback(const TurnPageRateFunc& turnPageRateCallback)
163     {
164         turnPageRateCallback_ = turnPageRateCallback;
165     }
166 
GetTurnPageRateCallback()167     const TurnPageRateFunc& GetTurnPageRateCallback() const
168     {
169         return turnPageRateCallback_;
170     }
171 
SetUpdateCubicCurveCallback(const CommonFunc & updateCubicCurveCallback)172     void SetUpdateCubicCurveCallback(const CommonFunc& updateCubicCurveCallback)
173     {
174         updateCubicCurveCallback_ = updateCubicCurveCallback;
175     }
176 
GetUpdateCubicCurveCallback()177     const CommonFunc& GetUpdateCubicCurveCallback() const
178     {
179         return updateCubicCurveCallback_;
180     }
181 
SetSurfaceChangeCallback(const CommonFunc & surfaceChangeCallback)182     void SetSurfaceChangeCallback(const CommonFunc& surfaceChangeCallback)
183     {
184         surfaceChangeCallback_ = surfaceChangeCallback;
185     }
186 
GetSurfaceChangeCallback()187     const CommonFunc& GetSurfaceChangeCallback() const
188     {
189         return surfaceChangeCallback_;
190     }
191 
SetPreloadFinishCallback(const PreloadItemsFinishFunc & preloadFinishCallback)192     void SetPreloadFinishCallback(const PreloadItemsFinishFunc& preloadFinishCallback)
193     {
194         preloadFinishCallback_ = preloadFinishCallback;
195     }
196 
GetPreloadFinishCallback()197     const PreloadItemsFinishFunc& GetPreloadFinishCallback() const
198     {
199         return preloadFinishCallback_;
200     }
201 
SetPreloadItemsImpl(const PreloadItemsFunc & preloadItemsImpl)202     void SetPreloadItemsImpl(const PreloadItemsFunc& preloadItemsImpl)
203     {
204         preloadItemsImpl_ = preloadItemsImpl;
205     }
206 
PreloadItems(const std::set<int32_t> & indexSet)207     void PreloadItems(const std::set<int32_t>& indexSet) const
208     {
209         if (preloadItemsImpl_) {
210             preloadItemsImpl_(indexSet);
211         }
212     }
213 
214 private:
215     SwipeToImpl swipeToImpl_;
216     SwipeToWithoutAnimationImpl swipeToWithoutAnimationImpl_;
217     CommonFunc showPrevImpl_;
218     CommonFunc showNextImpl_;
219     CommonFunc finishImpl_;
220     CommonFunc finishCallback_;
221     CommonFunc tabBarFinishCallback_;
222     CommonFunc removeTabBarEventCallback_;
223     CommonFunc addTabBarEventCallback_;
224     CommonFunc removeSwiperEventCallback_;
225     CommonFunc addSwiperEventCallback_;
226     TurnPageRateFunc turnPageRateCallback_;
227     CommonFunc updateCubicCurveCallback_;
228     CommonFunc surfaceChangeCallback_;
229     PreloadItemsFinishFunc preloadFinishCallback_;
230     PreloadItemsFunc preloadItemsImpl_;
231 };
232 
233 } // namespace OHOS::Ace
234 
235 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SWIPER_SWIPER_CONTROLLER_H
236