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_PROPERTIES_ANIMATABLE_PATH_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_PROPERTIES_ANIMATABLE_PATH_H
18 
19 #include "core/animation/animator.h"
20 #include "core/animation/curve_animation.h"
21 #include "core/components/common/properties/animation_option.h"
22 
23 namespace OHOS::Ace {
24 
25 using RenderNodeAnimationCallback = std::function<void()>;
26 
27 class ACE_EXPORT AnimatablePath final {
28 public:
29     AnimatablePath() = default;
30     explicit AnimatablePath(std::string path, const AnimationOption& option = AnimationOption())
31         : path_(path), animationOption_(option) {}
32     ~AnimatablePath() = default;
33 
SetContextAndCallback(const WeakPtr<PipelineBase> & context,const RenderNodeAnimationCallback & callback)34     void SetContextAndCallback(const WeakPtr<PipelineBase>& context, const RenderNodeAnimationCallback& callback)
35     {
36         context_ = context;
37         animationCallback_ = callback;
38     }
39 
GetValue()40     std::string GetValue() const
41     {
42         return path_;
43     }
44 
SetValue(std::string path)45     void SetValue(std::string path)
46     {
47         path_ = path;
48     }
49 
GetAnimationOption()50     const AnimationOption& GetAnimationOption() const
51     {
52         return animationOption_;
53     }
54 
SetAnimationOption(const AnimationOption & option)55     void SetAnimationOption(const AnimationOption& option)
56     {
57         animationOption_ = option;
58     }
59 
60     AnimatablePath& operator=(const AnimatablePath& newPath);
61 private:
62     void AnimateTo(std::string endValue);
63     void ResetController();
64     void OnAnimationCallback(double value);
65     std::string FormatPathString(const std::string& path);
66 
67     bool isFirstAssign_ = true;
68     std::string path_;
69     std::string pathFrom_;
70     std::string pathTo_;
71     AnimationOption animationOption_;
72     RefPtr<Animator> animationController_;
73     WeakPtr<PipelineBase> context_;
74     RenderNodeAnimationCallback animationCallback_ = nullptr;
75 };
76 
77 } // namespace OHOS::Ace
78 
79 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_PROPERTIES_ANIMATABLE_PATH_H