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