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_TAB_BAR_SIZE_ANIMATION_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TAB_BAR_TAB_BAR_SIZE_ANIMATION_H
18 
19 #include "base/memory/ace_type.h"
20 #include "core/animation/curve_animation.h"
21 #include "core/components/text/render_text.h"
22 
23 namespace OHOS::Ace {
24 
25 class TabBarSizeAnimation : public virtual AceType {
26     DECLARE_ACE_TYPE(TabBarSizeAnimation, AceType)
27 public:
28     void Initialize(const WeakPtr<PipelineContext>& context);
29     void Start(const WeakPtr<RenderNode>& tabBar, int32_t from, int32_t to);
30 
31 private:
32     struct ItemAnimationProp {
33         constexpr ItemAnimationProp() = default;
ItemAnimationPropItemAnimationProp34         constexpr ItemAnimationProp(Dimension fontSize, double opacity) : fontSize(fontSize), opacity(opacity) {}
35         constexpr ItemAnimationProp operator+(const ItemAnimationProp& prop) const
36         {
37             return { fontSize + prop.fontSize, opacity + prop.opacity };
38         }
39         constexpr ItemAnimationProp operator-(const ItemAnimationProp& prop) const
40         {
41             return { fontSize - prop.fontSize, opacity - prop.opacity };
42         }
43         constexpr ItemAnimationProp operator*(double value) const
44         {
45             return { fontSize * value, opacity * value };
46         }
47 
48         Dimension fontSize;
49         double opacity = 0;
50     };
51 
52     void ChangeItemProp(const RefPtr<RenderText>& layoutCallback, const ItemAnimationProp& animationProp);
53 
54     // animation control
55     RefPtr<Animator> controller_;
56     RefPtr<CurveAnimation<ItemAnimationProp>> onFocusTranslate_;
57     RefPtr<CurveAnimation<ItemAnimationProp>> onBlurTranslate_;
58 
59     RefPtr<RenderText> onFocusItemText_;
60     RefPtr<RenderText> onBlurItemText_;
61 
62     std::function<void()> layoutCallback_;
63 };
64 
65 } // namespace OHOS::Ace
66 
67 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TAB_BAR_TAB_BAR_SIZE_ANIMATION_H
68