1 /* 2 * Copyright (c) 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 #ifndef ARKUI_NATIVE_ANIMATE_IMPL_H 16 #define ARKUI_NATIVE_ANIMATE_IMPL_H 17 18 #include <cstdint> 19 #include <vector> 20 21 #include "native_animate.h" 22 #include "native_type.h" 23 24 #include "frameworks/core/interfaces/arkoala/arkoala_api.h" 25 26 #ifdef __cplusplus 27 extern "C" { 28 #endif 29 30 struct ArkUI_AnimateOption { 31 uint32_t duration; 32 float tempo; 33 ArkUI_AnimationCurve curve; 34 int32_t delay; 35 int32_t iterations; 36 ArkUI_AnimationPlayMode playMode; 37 ArkUI_ExpectedFrameRateRange* expectedFrameRateRange; 38 ArkUI_CurveHandle iCurve; 39 }; 40 41 typedef enum { 42 ARKUI_CURVE_TYPE_BASE = 0, 43 ARKUI_CURVE_TYPE_STEPS, 44 ARKUI_CURVE_TYPE_CUBIC_BEZIER, 45 ARKUI_CURVE_TYPE_SPRING, 46 ARKUI_CURVE_TYPE_SPRING_MOTION, 47 ARKUI_CURVE_TYPE_RESPONSIVE_SPRING_MOTION, 48 ARKUI_CURVE_TYPE_INTERPOLATING_SPRING, 49 ARKUI_CURVE_TYPE_CUSTOM, 50 } ArkUI_CurveType; 51 52 struct ArkUI_Curve { 53 ArkUI_CurveType type; 54 ArkUICurveHandle curve; 55 ArkUI_AnimationCurve baseCurveType; 56 }; 57 58 struct ArkUI_KeyframeState { 59 int32_t duration; 60 ArkUI_CurveHandle curve; 61 void (*event)(void* userData); 62 void* userData; 63 }; 64 65 struct ArkUI_KeyframeAnimateOption { 66 int32_t delay; 67 int32_t iterations; 68 void (*onFinish)(void* userData); 69 void* userData; 70 std::vector<ArkUI_KeyframeState> keyframes; 71 }; 72 73 struct ArkUI_Keyframe { 74 float keyTime; 75 float keyValue; 76 ArkUI_CurveHandle curve; 77 }; 78 struct ArkUI_AnimatorOption { 79 int32_t duration; 80 int32_t delay; 81 int32_t iterations; 82 ArkUI_AnimationFillMode fill; 83 ArkUI_AnimationDirection direction; 84 float begin; 85 float end; 86 ArkUI_CurveHandle easing; 87 ArkUI_ExpectedFrameRateRange* expectedFrameRateRange; 88 std::vector<ArkUI_Keyframe> keyframes; 89 void (*onFrame)(ArkUI_AnimatorOnFrameEvent* event); 90 void* frameUserData; 91 void (*onFinish)(ArkUI_AnimatorEvent* event); 92 void* finishUserData; 93 void (*onCancel)(ArkUI_AnimatorEvent* event); 94 void* cancelUserData; 95 void (*onRepeat)(ArkUI_AnimatorEvent* event); 96 void* repeatUserData; 97 }; 98 99 struct ArkUI_Animator { 100 ArkUIAnimatorHandle animator; 101 ArkUI_AnimatorOption* option; 102 ArkUIAnimatorOption* animatorOption; 103 }; 104 #ifdef __cplusplus 105 }; 106 #endif 107 108 namespace OHOS::Ace::AnimateModel { 109 110 ArkUI_CurveHandle InitCurve(ArkUI_AnimationCurve animationCurve); 111 ArkUI_CurveHandle StepsCurve(int32_t count, bool end); 112 ArkUI_CurveHandle CubicBezierCurve(float x1, float y1, float x2, float y2); 113 ArkUI_CurveHandle SpringCurve(float velocity, float mass, float stiffness, float damping); 114 ArkUI_CurveHandle SpringMotion(float response, float dampingFraction, float overlapDuration); 115 ArkUI_CurveHandle ResponsiveSpringMotion(float response, float dampingFraction, float overlapDuration); 116 ArkUI_CurveHandle InterpolatingSpring(float velocity, float mass, float stiffness, float damping); 117 ArkUI_CurveHandle CustomCurve(void* userData, float (*interpolate)(float fraction, void* userdata)); 118 void DisposeCurve(ArkUI_CurveHandle curveHandle); 119 120 int32_t AnimateTo(ArkUI_ContextHandle context, ArkUI_AnimateOption* option, ArkUI_ContextCallback* update, 121 ArkUI_AnimateCompleteCallback* complete); 122 123 int32_t KeyframeAnimateTo(ArkUI_ContextHandle context, ArkUI_KeyframeAnimateOption* option); 124 125 ArkUI_AnimatorHandle CreateAnimator(ArkUI_ContextHandle context, ArkUI_AnimatorOption* option); 126 void DisposeAnimator(ArkUI_AnimatorHandle animatorHandle); 127 128 int32_t AnimatorReset(ArkUI_AnimatorHandle animatorHandle, ArkUI_AnimatorOption* option); 129 int32_t AnimatorPlay(ArkUI_AnimatorHandle animatorHandle); 130 int32_t AnimatorFinish(ArkUI_AnimatorHandle animatorHandle); 131 int32_t AnimatorPause(ArkUI_AnimatorHandle animatorHandle); 132 int32_t AnimatorCancel(ArkUI_AnimatorHandle animatorHandle); 133 int32_t AnimatorReverse(ArkUI_AnimatorHandle animatorHandle); 134 }; // namespace OHOS::Ace::AnimateModel 135 #endif