1 /*
2  * Copyright (c) 2022-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_SVG_PARSE_SVG_ANIMATION_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_SVG_PARSE_SVG_ANIMATION_H
18 
19 #include "base/utils/noncopyable.h"
20 #include "core/animation/svg_animate.h"
21 #include "frameworks/core/components/declaration/svg/svg_animate_declaration.h"
22 #include "frameworks/core/components_ng/svg/parse/svg_node.h"
23 
24 namespace OHOS::Ace::NG {
25 class SvgAnimation : public SvgNode, public SvgAnimate {
26     DECLARE_ACE_TYPE(SvgAnimation, SvgNode, SvgAnimate);
27 
28 public:
29     explicit SvgAnimation(SvgAnimateType svgAnimateType);
30     ~SvgAnimation() override = default;
31 
32     static RefPtr<SvgNode> Create();
33     static RefPtr<SvgNode> CreateAnimateMotion();
34     static RefPtr<SvgNode> CreateAnimateTransform();
35 
AddOnFinishCallBack(const std::function<void ()> & onFinishCallback)36     void AddOnFinishCallBack(const std::function<void()>& onFinishCallback)
37     {
38         animator_->AddStopListener(onFinishCallback);
39     }
40 
41     void SetAttr(const std::string& name, const std::string& value) override;
42     void UpdateAttr();
43 
44     template<typename T>
45     void CreatePropertyAnimation(const T& originalValue, std::function<void(T)>&& callback);
46 
47 private:
48     void OnInitStyle() override;
49 
50     static CalcMode ConvertCalcMode(const std::string& val);
51 
52     RefPtr<Animator> animator_;
53     SvgAnimateAttribute animateAttr_;
54 
55     ACE_DISALLOW_COPY_AND_MOVE(SvgAnimation);
56 };
57 } // namespace OHOS::Ace::NG
58 
59 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_SVG_PARSE_SVG_ANIMATION_H