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_TAB_BAR_RENDER_TAB_BAR_ITEM_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TAB_BAR_RENDER_TAB_BAR_ITEM_H
18 
19 #include "base/memory/ace_type.h"
20 #include "core/animation/animator.h"
21 #include "core/animation/keyframe_animation.h"
22 #include "core/components/box/render_box.h"
23 #include "core/components/common/layout/grid_system_manager.h"
24 #include "core/gestures/raw_recognizer.h"
25 
26 namespace OHOS::Ace {
27 
28 class RenderTabBarItem : public RenderBox {
29 DECLARE_ACE_TYPE(RenderTabBarItem, RenderBox)
30 
31 public:
32     ~RenderTabBarItem() override = default;
33     static RefPtr<RenderNode> Create();
34 
SetTouching(bool isTouching)35     void SetTouching(bool isTouching)
36     {
37         touching_ = isTouching;
38     }
39 
IsTouching()40     bool IsTouching() const
41     {
42         return touching_;
43     }
44 
SetEnableDebugBoundary(bool needEnable)45     void SetEnableDebugBoundary(bool needEnable)
46     {
47         needPaintDebugBoundary_ = needEnable;
48     }
49 
50 protected:
51     RenderTabBarItem();
52     void OnTouchTestHit(const Offset& coordinateOffset, const TouchRestrict& touchRestrict,
53         TouchTestResult& result) override;
54     void OnMouseHoverEnterTest() override;
55     void OnMouseHoverExitTest() override;
56     void PerformLayout() override;
57 
58     bool onHover_ = false;
59     double hoverOpacity_ = 0.0;
60     bool needPaintDebugBoundary_ = false;
61 
62 private:
63     void HandleTouchDown();
64     void HandleTouchUp();
65     void StartHoverAnimation(RefPtr<Animator> controller,
66         RefPtr<KeyframeAnimation<double>>& doubleAnimation);
67     void ResetController(RefPtr<Animator>& controller);
68     void CreateDoubleAnimation(RefPtr<KeyframeAnimation<double>>& doubleAnimation, double beginValue,
69         double endValue, bool hover);
70     void PlayPressAnimation(double endOpacityRatio);
71 
72     bool touching_ = false; // whether the item is in touching
73     RefPtr<RawRecognizer> touchRecognizer_;
74     RefPtr<Animator> controllerEnter_;
75     RefPtr<Animator> controllerExit_;
76     RefPtr<Animator> controllerPress_;
77     RefPtr<KeyframeAnimation<double>> doubleAnimationEnter_;
78     RefPtr<KeyframeAnimation<double>> doubleAnimationExit_;
79 };
80 
81 } // namespace OHOS::Ace
82 
83 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TAB_BAR_RENDER_TAB_BAR_ITEM_H
84