• 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 "base/memory/ace_type.h"
20 
21 namespace OHOS::Ace {
22 
23 using SwipeToImpl = std::function<void(const int32_t, bool)>;
24 using ShowPrevImpl = std::function<void()>;
25 using ShowNextImpl = std::function<void()>;
26 using FinishAnimationImpl = std::function<void()>;
27 
28 class SwiperController : public virtual AceType {
29     DECLARE_ACE_TYPE(SwiperController, AceType);
30 
31 public:
32     void SwipeTo(int32_t index, bool reverse = false)
33     {
34         if (swipeToImpl_) {
35             swipeToImpl_(index, reverse);
36         }
37     }
38 
SetSwipeToImpl(const SwipeToImpl & swipeToImpl)39     void SetSwipeToImpl(const SwipeToImpl& swipeToImpl)
40     {
41         swipeToImpl_ = swipeToImpl;
42     }
43 
ShowPrevious()44     void ShowPrevious()
45     {
46         if (showPrevImpl_) {
47             showPrevImpl_();
48         }
49     }
50 
SetShowPrevImpl(const ShowPrevImpl & showPrevImpl)51     void SetShowPrevImpl(const ShowPrevImpl& showPrevImpl)
52     {
53         showPrevImpl_ = showPrevImpl;
54     }
55 
ShowNext()56     void ShowNext()
57     {
58         if (showNextImpl_) {
59             showNextImpl_();
60         }
61     }
62 
SetShowNextImpl(const ShowNextImpl & showNextImpl)63     void SetShowNextImpl(const ShowNextImpl& showNextImpl)
64     {
65         showNextImpl_ = showNextImpl;
66     }
67 
FinishAnimation()68     void FinishAnimation() const
69     {
70         if (finishImpl_) {
71             finishImpl_();
72         }
73     }
74 
SetFinishImpl(const FinishAnimationImpl & finishImpl)75     void SetFinishImpl(const FinishAnimationImpl& finishImpl)
76     {
77         finishImpl_ = finishImpl;
78     }
79 
SetFinishCallback(const EventMarker & marker)80     void SetFinishCallback(const EventMarker& marker)
81     {
82         finishCallback_ = marker;
83     }
84 
GetFinishCallback()85     const EventMarker& GetFinishCallback() const
86     {
87         return finishCallback_;
88     }
89 
90 private:
91     SwipeToImpl swipeToImpl_;
92     ShowPrevImpl showPrevImpl_;
93     ShowNextImpl showNextImpl_;
94     FinishAnimationImpl finishImpl_;
95     EventMarker finishCallback_;
96 };
97 
98 } // namespace OHOS::Ace
99 
100 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SWIPER_SWIPER_CONTROLLER_H
101