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_TRANSFORM_CLICK_SPRING_EFFECT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TRANSFORM_CLICK_SPRING_EFFECT_H
18 
19 #include <functional>
20 
21 #include "base/memory/ace_type.h"
22 #include "core/animation/animator.h"
23 #include "core/animation/spring_motion.h"
24 #include "core/event/touch_event.h"
25 #include "core/pipeline/base/render_node.h"
26 #include "core/pipeline/pipeline_context.h"
27 
28 namespace OHOS::Ace {
29 
30 enum class ClickSpringEffectType {
31     NONE,
32     SMALL,
33     MEDIUM,
34     LARGE
35 };
36 
37 class ClickSpringEffect : public AceType {
38     DECLARE_ACE_TYPE(ClickSpringEffect, AceType)
39 
40 public:
41     explicit ClickSpringEffect(const WeakPtr<PipelineContext>& context);
42     virtual ~ClickSpringEffect() = default;
43 
44     void ShowAnimation(TouchType touchType, ClickSpringEffectType type);
45 
46     void MarkRender();
47 
SetRenderNode(const WeakPtr<RenderNode> & renderNode)48     void SetRenderNode(const WeakPtr<RenderNode>& renderNode)
49     {
50         renderNode_ = renderNode;
51     }
52 
GetScale()53     double GetScale() const
54     {
55         return scale_;
56     }
57 
SetScale(double scale)58     void SetScale(double scale)
59     {
60         scale_ = scale;
61     }
62 
SetController(const RefPtr<Animator> & controller)63     void SetController(const RefPtr<Animator>& controller)
64     {
65         controller_ = controller;
66     }
67 
68 private:
69     void FinishPreviousAnimation();
70 
71     double scale_ { 1.0 };
72     RefPtr<Animator> controller_ = nullptr;
73     WeakPtr<RenderNode> renderNode_ = nullptr;
74 };
75 
76 } // namespace OHOS::Ace
77 
78 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TRANSFORM_CLICK_SPRING_EFFECT_H
79