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