1 /*
2  * Copyright (c) 2024 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_NG_PATTERNS_TABS_TABS_CONTROLLER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TABS_TABS_CONTROLLER_H
18 
19 #include "core/components/swiper/swiper_controller.h"
20 
21 namespace OHOS::Ace::NG {
22 
23 using StartShowTabBarFunc = std::function<void(int32_t delay)>;
24 using StopShowTabBarFunc = std::function<void()>;
25 using SetUpdateTabBarHiddenRatioFunc = std::function<void(float ratio)>;
26 using SetTabBarTranslateFunc = std::function<void(const TranslateOptions& options)>;
27 using SetTabBarOpacityFunc = std::function<void(float opacity)>;
28 
29 class TabsControllerNG : public SwiperController {
30     DECLARE_ACE_TYPE(TabsControllerNG, SwiperController);
31 
32 public:
33     TabsControllerNG() = default;
34     ~TabsControllerNG() override = default;
35 
SetStartShowTabBarImpl(const StartShowTabBarFunc & startShowTabBarImpl)36     void SetStartShowTabBarImpl(const StartShowTabBarFunc& startShowTabBarImpl)
37     {
38         startShowTabBarImpl_ = startShowTabBarImpl;
39     }
40 
41     void StartShowTabBar(int32_t delay = 0)
42     {
43         if (startShowTabBarImpl_) {
44             startShowTabBarImpl_(delay);
45         }
46     }
47 
SetStopShowTabBarImpl(const StopShowTabBarFunc & stopShowTabBarImpl)48     void SetStopShowTabBarImpl(const StopShowTabBarFunc& stopShowTabBarImpl)
49     {
50         stopShowTabBarImpl_ = stopShowTabBarImpl;
51     }
52 
StopShowTabBar()53     void StopShowTabBar()
54     {
55         if (stopShowTabBarImpl_) {
56             stopShowTabBarImpl_();
57         }
58     }
59 
SetUpdateTabBarHiddenRatioImpl(const SetUpdateTabBarHiddenRatioFunc & updateTabBarHiddenRatioImpl)60     void SetUpdateTabBarHiddenRatioImpl(const SetUpdateTabBarHiddenRatioFunc& updateTabBarHiddenRatioImpl)
61     {
62         updateTabBarHiddenRatioImpl_ = updateTabBarHiddenRatioImpl;
63     }
64 
UpdateTabBarHiddenRatio(float ratio)65     void UpdateTabBarHiddenRatio(float ratio)
66     {
67         if (updateTabBarHiddenRatioImpl_) {
68             updateTabBarHiddenRatioImpl_(ratio);
69         }
70     }
71 
SetTabBarTranslateImpl(const SetTabBarTranslateFunc & setTabBarTranslateImpl)72     void SetTabBarTranslateImpl(const SetTabBarTranslateFunc& setTabBarTranslateImpl)
73     {
74         setTabBarTranslateImpl_ = setTabBarTranslateImpl;
75     }
76 
SetTabBarTranslate(const TranslateOptions & options)77     void SetTabBarTranslate(const TranslateOptions& options)
78     {
79         if (setTabBarTranslateImpl_) {
80             setTabBarTranslateImpl_(options);
81         }
82     }
83 
SetTabBarOpacityImpl(const SetTabBarOpacityFunc & setTabBarOpacityImpl)84     void SetTabBarOpacityImpl(const SetTabBarOpacityFunc& setTabBarOpacityImpl)
85     {
86         setTabBarOpacityImpl_ = setTabBarOpacityImpl;
87     }
88 
SetTabBarOpacity(float opacity)89     void SetTabBarOpacity(float opacity)
90     {
91         if (setTabBarOpacityImpl_) {
92             setTabBarOpacityImpl_(opacity);
93         }
94     }
95 
96 private:
97     StartShowTabBarFunc startShowTabBarImpl_;
98     StopShowTabBarFunc stopShowTabBarImpl_;
99     SetUpdateTabBarHiddenRatioFunc updateTabBarHiddenRatioImpl_;
100     SetTabBarTranslateFunc setTabBarTranslateImpl_;
101     SetTabBarOpacityFunc setTabBarOpacityImpl_;
102 };
103 
104 } // namespace OHOS::ACE
105 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TABS_TABS_CONTROLLER_H