• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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_RENDER_ANIMATION_UTILS_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_ANIMATION_UTILS_H
18 
19 #include "base/utils/macros.h"
20 #include "core/components/common/properties/animation_option.h"
21 #include "core/components/common/properties/color.h"
22 #include "core/pipeline/base/render_context.h"
23 #include "core/pipeline/pipeline_base.h"
24 #include "core/pipeline/pipeline_context.h"
25 
26 namespace OHOS::Rosen {
27 class RSUIContext;
28 }
29 
30 namespace OHOS::Ace {
31 
32 namespace NG {
33 class RenderContext;
34 }
35 
36 namespace {
37 
38 using PropertyCallback = std::function<void()>;
39 using FinishCallback = std::function<void()>;
40 using RepeatCallback = std::function<void()>;
41 using InteractiveAnimationCallback = std::function<void()>;
42 } // namespace
43 
44 class ACE_FORCE_EXPORT AnimationUtils {
45 public:
46     class Animation;
47 
48     class InteractiveAnimation;
49 
50     static void OpenImplicitAnimation(const AnimationOption& option, const RefPtr<Curve>& curve,
51         const std::function<void()>& finishCallback, const RefPtr<PipelineBase>& context = nullptr);
52     static bool CloseImplicitAnimation(const RefPtr<PipelineBase>& context = nullptr);
53     static bool CloseImplicitCancelAnimation(const RefPtr<PipelineBase>& context = nullptr);
54     static CancelAnimationStatus CloseImplicitCancelAnimationReturnStatus(
55         const RefPtr<PipelineBase>& context = nullptr);
56     static bool IsImplicitAnimationOpen(const RefPtr<PipelineBase>& context = nullptr);
57     static void Animate(const AnimationOption& option, const PropertyCallback& callback,
58         const FinishCallback& finishCallback = nullptr, const RepeatCallback& repeatCallback = nullptr,
59             const RefPtr<PipelineBase>& context = nullptr);
60     static void AddKeyFrame(float fraction, const RefPtr<Curve>& curve, const PropertyCallback& callback,
61         const RefPtr<PipelineBase>& context = nullptr);
62     static void AddKeyFrame(float fraction, const PropertyCallback& callback,
63         const RefPtr<PipelineBase>& context = nullptr);
64     static void AddDurationKeyFrame(int duration, const RefPtr<Curve>& curve, const PropertyCallback& callback,
65         const RefPtr<PipelineBase>& context = nullptr);
66 
67     // Similar to Animate, but reuses current options and replaces callback
68     static void AnimateWithCurrentOptions(const PropertyCallback& callback, const FinishCallback& finishCallback,
69         bool timingSensitive = true, const RefPtr<PipelineBase>& context = nullptr);
70     // Similar to Animate, but reuses current callback and replaces options
71     static void AnimateWithCurrentCallback(const AnimationOption& option, const PropertyCallback& callback,
72         const RefPtr<PipelineBase>& context = nullptr);
73 
74     static std::shared_ptr<AnimationUtils::Animation> StartAnimation(const AnimationOption& option,
75         const PropertyCallback& callback, const FinishCallback& finishCallback = nullptr,
76         const RepeatCallback& repeatCallback = nullptr, const RefPtr<PipelineBase>& context = nullptr);
77     static void StopAnimation(const std::shared_ptr<AnimationUtils::Animation>& animation);
78     static void BlendBgColorAnimation(
79         RefPtr<NG::RenderContext>& renderContext, const Color& endColor, int32_t duration, const RefPtr<Curve>& curve);
80     static void PauseAnimation(const std::shared_ptr<AnimationUtils::Animation>& animation);
81     static void ResumeAnimation(const std::shared_ptr<AnimationUtils::Animation>& animation);
82     // need to reset the attribute of arkui node after Reverse in case of attribute inconsistent
83     static void ReverseAnimation(const std::shared_ptr<AnimationUtils::Animation>& animation);
84     static void ExecuteWithoutAnimation(const PropertyCallback& callback,
85         const RefPtr<PipelineBase>& context = nullptr);
86 
87     static std::shared_ptr<AnimationUtils::InteractiveAnimation> CreateInteractiveAnimation(
88         const InteractiveAnimationCallback& addCallback, const FinishCallback& callback);
89 
90     static void UpdateInteractiveAnimation(
91         const std::shared_ptr<AnimationUtils::InteractiveAnimation>& interactiveAnimation, float progress);
92 
93     static void ContinueInteractiveAnimation(
94         const std::shared_ptr<AnimationUtils::InteractiveAnimation>& interactiveAnimation);
95 
96     static int32_t StartInteractiveAnimation(
97         const std::shared_ptr<AnimationUtils::InteractiveAnimation>& interactiveAnimation);
98 
99     static void ReverseInteractiveAnimation(
100         const std::shared_ptr<AnimationUtils::InteractiveAnimation>& interactiveAnimation);
101 
102     static void AddInteractiveAnimation(
103         const std::shared_ptr<AnimationUtils::InteractiveAnimation>& interactiveAnimation,
104         const std::function<void()>& callback);
105     static void SetNavGroupNodeTransAnimationCallback();
106     static std::shared_ptr<Rosen::RSUIContext> GetCurrentRSUIContext(RefPtr<PipelineBase> context);
107 };
108 } // namespace OHOS::Ace
109 
110 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_ANIMATION_UTILS_H
111