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 16 #ifndef ARKUI_NATIVE_ANIMATE_H 17 #define ARKUI_NATIVE_ANIMATE_H 18 19 #include <cstdint> 20 21 #include "native_type.h" 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 /** 28 * @brief Defines the expected frame rate range of the animation. 29 * 30 * @since 12 31 */ 32 typedef struct { 33 /** Expected minimum frame rate. */ 34 uint32_t min; 35 /** Expected maximum frame rate. */ 36 uint32_t max; 37 /** Expected optimal frame rate. */ 38 uint32_t expected; 39 } ArkUI_ExpectedFrameRateRange; 40 41 /** 42 * @brief Defines the callback type for when the animation playback is complete. 43 * 44 * @since 12 45 */ 46 typedef struct { 47 /** Type of the <b>onFinish</b> callback. */ 48 ArkUI_FinishCallbackType type; 49 /** Callback invoked when the animation playback is complete. */ 50 void (*callback)(void* userData); 51 /** Custom type. */ 52 void* userData; 53 } ArkUI_AnimateCompleteCallback; 54 55 /** 56 * @brief Defines the animation configuration. 57 * 58 * @since 12 59 */ 60 typedef struct ArkUI_AnimateOption ArkUI_AnimateOption; 61 62 typedef struct ArkUI_Curve ArkUI_Curve; 63 typedef struct ArkUI_Curve* ArkUI_CurveHandle; 64 65 typedef struct ArkUI_KeyframeAnimateOption ArkUI_KeyframeAnimateOption; 66 typedef struct ArkUI_AnimatorOption ArkUI_AnimatorOption; 67 typedef struct ArkUI_Animator* ArkUI_AnimatorHandle; 68 69 typedef struct ArkUI_AnimatorEvent ArkUI_AnimatorEvent; 70 typedef struct ArkUI_AnimatorOnFrameEvent ArkUI_AnimatorOnFrameEvent; 71 72 73 typedef struct ArkUI_TransitionEffect ArkUI_TransitionEffect; 74 75 /** 76 * @brief Implements the native animation APIs provided by ArkUI. 77 * 78 * @version 1 79 * @since 12 80 */ 81 typedef struct { 82 /** 83 * @brief Defines an explicit animation. 84 * 85 * @note Make sure the component attributes to be set in the event closure have been set before. 86 * 87 * @param context UIContext。 88 * @param option Indicates the pointer to an animation configuration. 89 * @param update Indicates the animation closure. The system automatically inserts a transition animation 90 * for the state change caused by the closure. 91 * @param complete Indicates the callback to be invoked when the animation playback is complete. 92 * @return Returns <b>0</b> if the operation is successful; returns <b>401</b> if a parameter error occurs. 93 */ 94 int32_t (*animateTo)(ArkUI_ContextHandle context, ArkUI_AnimateOption* option, ArkUI_ContextCallback* update, 95 ArkUI_AnimateCompleteCallback* complete); 96 97 int32_t (*keyframeAnimateTo)(ArkUI_ContextHandle context, ArkUI_KeyframeAnimateOption* option); 98 ArkUI_AnimatorHandle (*createAnimator)(ArkUI_ContextHandle context, ArkUI_AnimatorOption* option); 99 void (*disposeAnimator)(ArkUI_AnimatorHandle animator); 100 } ArkUI_NativeAnimateAPI_1; 101 102 /** 103 * @brief Creates an animation configuration. 104 * 105 * @return Returns the pointer to the created animation configuration. 106 * @since 12 107 */ 108 ArkUI_AnimateOption* OH_ArkUI_AnimateOption_Create(void); 109 110 /** 111 * @brief Destroys an animation configuration. 112 * 113 * @since 12 114 */ 115 void OH_ArkUI_AnimateOption_Dispose(ArkUI_AnimateOption* option); 116 117 /** 118 * @brief Obtains the animation duration, in milliseconds. 119 * 120 * @param option Indicates the pointer to an animation configuration. 121 * @return Returns the duration. 122 * @since 12 123 */ 124 uint32_t OH_ArkUI_AnimateOption_GetDuration(ArkUI_AnimateOption* option); 125 126 /** 127 * @brief Obtains the animation playback speed. 128 * 129 * @param option Indicates the pointer to an animation configuration. 130 * @return Returns the animation playback speed. 131 * @since 12 132 */ 133 float OH_ArkUI_AnimateOption_GetTempo(ArkUI_AnimateOption* option); 134 135 /** 136 * @brief Obtains the animation curve. 137 * 138 * @param option Indicates the pointer to an animation configuration. 139 * @return Returns the animated curve. 140 * @since 12 141 */ 142 ArkUI_AnimationCurve OH_ArkUI_AnimateOption_GetCurve(ArkUI_AnimateOption* option); 143 144 /** 145 * @brief Obtains the animation delay, in milliseconds. 146 * 147 * @param option Indicates the pointer to an animation configuration. 148 * @return Returns the animation delay. 149 * @since 12 150 */ 151 int32_t OH_ArkUI_AnimateOption_GetDelay(ArkUI_AnimateOption* option); 152 153 /** 154 * @brief Obtains the number of times that an animation is played. 155 * 156 * @param option Indicates the pointer to an animation configuration. 157 * @return Returns the number of times that the animation is played. 158 * @since 12 159 */ 160 int32_t OH_ArkUI_AnimateOption_GetIterations(ArkUI_AnimateOption* option); 161 162 /** 163 * @brief Obtains the animation playback mode. 164 * 165 * @param option Indicates the pointer to an animation configuration. 166 * @return Returns the animation playback mode. 167 * @since 12 168 */ 169 ArkUI_AnimationPlayMode OH_ArkUI_AnimateOption_GetPlayMode(ArkUI_AnimateOption* option); 170 171 /** 172 * @brief Obtains the expected frame rate range of an animation. 173 * 174 * @param option Indicates the pointer to an animation configuration. 175 * @return Returns the expected frame rate range. 176 * @since 12 177 */ 178 ArkUI_ExpectedFrameRateRange* OH_ArkUI_AnimateOption_GetExpectedFrameRateRange(ArkUI_AnimateOption* option); 179 180 /** 181 * @brief Sets the animation duration. 182 * 183 * @param option Indicates the pointer to an animation configuration. 184 * @param value Indicates the duration, in milliseconds. 185 * @since 12 186 */ 187 void OH_ArkUI_AnimateOption_SetDuration(ArkUI_AnimateOption* option, int32_t value); 188 189 /** 190 * @brief Sets the animation playback speed. 191 * 192 * @param option Indicates the pointer to an animation configuration. 193 * @param value Indicates the animation playback speed. 194 * @since 12 195 */ 196 void OH_ArkUI_AnimateOption_SetTempo(ArkUI_AnimateOption* option, float value); 197 198 /** 199 * @brief Sets the animation curve. 200 * 201 * @param option Indicates the pointer to an animation configuration. 202 * @param value Indicates the animated curve. 203 * @since 12 204 */ 205 void OH_ArkUI_AnimateOption_SetCurve(ArkUI_AnimateOption* option, ArkUI_AnimationCurve value); 206 207 /** 208 * @brief Sets the animation delay. 209 * 210 * @param option Indicates the pointer to an animation configuration. 211 * @param value Indicates the animation delay. 212 * @since 12 213 */ 214 void OH_ArkUI_AnimateOption_SetDelay(ArkUI_AnimateOption* option, int32_t value); 215 216 /** 217 * @brief Sets the number of times that an animation is played. 218 * 219 * @param option Indicates the pointer to an animation configuration. 220 * @param value Indicates the number of times that the animation is played. 221 * @since 12 222 */ 223 void OH_ArkUI_AnimateOption_SetIterations(ArkUI_AnimateOption* option, int32_t value); 224 225 /** 226 * @brief Sets the animation playback mode. 227 * 228 * @param option Indicates the pointer to an animation configuration. 229 * @param value Indicates the animation playback mode. 230 * @since 12 231 */ 232 void OH_ArkUI_AnimateOption_SetPlayMode(ArkUI_AnimateOption* option, ArkUI_AnimationPlayMode value); 233 234 /** 235 * @brief Sets the expected frame rate range of an animation. 236 * 237 * @param option Indicates the pointer to an animation configuration. 238 * @param value Indicates the expected frame rate range. 239 * @since 12 240 */ 241 void OH_ArkUI_AnimateOption_SetExpectedFrameRateRange(ArkUI_AnimateOption* option, ArkUI_ExpectedFrameRateRange* value); 242 243 void OH_ArkUI_AnimateOption_SetICurve(ArkUI_AnimateOption* option, ArkUI_CurveHandle value); 244 ArkUI_CurveHandle OH_ArkUI_AnimateOption_GetICurve(ArkUI_AnimateOption* option); 245 246 ArkUI_KeyframeAnimateOption* OH_ArkUI_KeyframeAnimateOption_Create(int32_t size); 247 void OH_ArkUI_KeyframeAnimateOption_Dispose(ArkUI_KeyframeAnimateOption* option); 248 int32_t OH_ArkUI_KeyframeAnimateOption_SetDelay(ArkUI_KeyframeAnimateOption* option, int32_t value); 249 int32_t OH_ArkUI_KeyframeAnimateOption_SetIterations(ArkUI_KeyframeAnimateOption* option, int32_t value); 250 int32_t OH_ArkUI_KeyframeAnimateOption_RegisterOnFinishCallback( 251 ArkUI_KeyframeAnimateOption* option, void* userData, void (*onFinish)(void* userData)); 252 int32_t OH_ArkUI_KeyframeAnimateOption_SetDuration(ArkUI_KeyframeAnimateOption* option, int32_t value, int32_t index); 253 int32_t OH_ArkUI_KeyframeAnimateOption_SetCurve( 254 ArkUI_KeyframeAnimateOption* option, ArkUI_CurveHandle value, int32_t index); 255 int32_t OH_ArkUI_KeyframeAnimateOption_RegisterOnEventCallback( 256 ArkUI_KeyframeAnimateOption* option, void* userData, void (*event)(void* userData), int32_t index); 257 int32_t OH_ArkUI_KeyframeAnimateOption_GetDelay(ArkUI_KeyframeAnimateOption* option); 258 int32_t OH_ArkUI_KeyframeAnimateOption_GetIterations(ArkUI_KeyframeAnimateOption* option); 259 int32_t OH_ArkUI_KeyframeAnimateOption_GetDuration(ArkUI_KeyframeAnimateOption* option, int32_t index); 260 ArkUI_CurveHandle OH_ArkUI_KeyframeAnimateOption_GetCurve(ArkUI_KeyframeAnimateOption* option, int32_t index); 261 ArkUI_AnimatorOption* OH_ArkUI_AnimatorOption_Create(int32_t keyframeSize); 262 void OH_ArkUI_AnimatorOption_Dispose(ArkUI_AnimatorOption* option); 263 int32_t OH_ArkUI_AnimatorOption_SetDuration(ArkUI_AnimatorOption* option, int32_t value); 264 int32_t OH_ArkUI_AnimatorOption_SetDelay(ArkUI_AnimatorOption* option, int32_t value); 265 int32_t OH_ArkUI_AnimatorOption_SetIterations(ArkUI_AnimatorOption* option, int32_t value); 266 int32_t OH_ArkUI_AnimatorOption_SetFill(ArkUI_AnimatorOption* option, ArkUI_AnimationFillMode value); 267 int32_t OH_ArkUI_AnimatorOption_SetDirection(ArkUI_AnimatorOption* option, ArkUI_AnimationDirection value); 268 int32_t OH_ArkUI_AnimatorOption_SetCurve(ArkUI_AnimatorOption* option, ArkUI_CurveHandle value); 269 int32_t OH_ArkUI_AnimatorOption_SetBegin(ArkUI_AnimatorOption* option, float value); 270 int32_t OH_ArkUI_AnimatorOption_SetEnd(ArkUI_AnimatorOption* option, float value); 271 int32_t OH_ArkUI_AnimatorOption_SetExpectedFrameRateRange( 272 ArkUI_AnimatorOption* option, ArkUI_ExpectedFrameRateRange* value); 273 int32_t OH_ArkUI_AnimatorOption_SetKeyframe(ArkUI_AnimatorOption* option, float time, float value, int32_t index); 274 int32_t OH_ArkUI_AnimatorOption_SetKeyframeCurve(ArkUI_AnimatorOption* option, ArkUI_CurveHandle value, int32_t index); 275 int32_t OH_ArkUI_AnimatorOption_GetDuration(ArkUI_AnimatorOption* option); 276 int32_t OH_ArkUI_AnimatorOption_GetDelay(ArkUI_AnimatorOption* option); 277 int32_t OH_ArkUI_AnimatorOption_GetIterations(ArkUI_AnimatorOption* option); 278 ArkUI_AnimationFillMode OH_ArkUI_AnimatorOption_GetFill(ArkUI_AnimatorOption* option); 279 ArkUI_AnimationDirection OH_ArkUI_AnimatorOption_GetDirection(ArkUI_AnimatorOption* option); 280 ArkUI_CurveHandle OH_ArkUI_AnimatorOption_GetCurve(ArkUI_AnimatorOption* option); 281 float OH_ArkUI_AnimatorOption_GetBegin(ArkUI_AnimatorOption* option); 282 float OH_ArkUI_AnimatorOption_GetEnd(ArkUI_AnimatorOption* option); 283 ArkUI_ExpectedFrameRateRange* OH_ArkUI_AnimatorOption_GetExpectedFrameRateRange(ArkUI_AnimatorOption* option); 284 float OH_ArkUI_AnimatorOption_GetKeyframeTime(ArkUI_AnimatorOption* option, int32_t index); 285 float OH_ArkUI_AnimatorOption_GetKeyframeValue(ArkUI_AnimatorOption* option, int32_t index); 286 ArkUI_CurveHandle OH_ArkUI_AnimatorOption_GetKeyframeCurve(ArkUI_AnimatorOption* option, int32_t index); 287 void* OH_ArkUI_AnimatorEvent_GetUserData(ArkUI_AnimatorEvent* event); 288 void* OH_ArkUI_AnimatorOnFrameEvent_GetUserData(ArkUI_AnimatorOnFrameEvent* event); 289 float OH_ArkUI_AnimatorOnFrameEvent_GetValue(ArkUI_AnimatorOnFrameEvent* event); 290 int32_t OH_ArkUI_AnimatorOption_RegisterOnFrameCallback( 291 ArkUI_AnimatorOption* option, void* userData, void (*callback)(ArkUI_AnimatorOnFrameEvent* event)); 292 int32_t OH_ArkUI_AnimatorOption_RegisterOnFinishCallback( 293 ArkUI_AnimatorOption* option, void* userData, void (*callback)(ArkUI_AnimatorEvent* event)); 294 int32_t OH_ArkUI_AnimatorOption_RegisterOnCancelCallback( 295 ArkUI_AnimatorOption* option, void* userData, void (*callback)(ArkUI_AnimatorEvent* event)); 296 int32_t OH_ArkUI_AnimatorOption_RegisterOnRepeatCallback( 297 ArkUI_AnimatorOption* option, void* userData, void (*callback)(ArkUI_AnimatorEvent* event)); 298 int32_t OH_ArkUI_Animator_ResetAnimatorOption(ArkUI_AnimatorHandle animator, ArkUI_AnimatorOption* option); 299 int32_t OH_ArkUI_Animator_Play(ArkUI_AnimatorHandle animator); 300 int32_t OH_ArkUI_Animator_Finish(ArkUI_AnimatorHandle animator); 301 int32_t OH_ArkUI_Animator_Pause(ArkUI_AnimatorHandle animator); 302 int32_t OH_ArkUI_Animator_Cancel(ArkUI_AnimatorHandle animator); 303 int32_t OH_ArkUI_Animator_Reverse(ArkUI_AnimatorHandle animator); 304 ArkUI_CurveHandle OH_ArkUI_Curve_CreateCurveByType(ArkUI_AnimationCurve curve); 305 ArkUI_CurveHandle OH_ArkUI_Curve_CreateStepsCurve(int32_t count, bool end); 306 ArkUI_CurveHandle OH_ArkUI_Curve_CreateCubicBezierCurve(float x1, float y1, float x2, float y2); 307 ArkUI_CurveHandle OH_ArkUI_Curve_CreateSpringCurve(float velocity, float mass, float stiffness, float damping); 308 ArkUI_CurveHandle OH_ArkUI_Curve_CreateSpringMotion(float response, float dampingFraction, float overlapDuration); 309 ArkUI_CurveHandle OH_ArkUI_Curve_CreateResponsiveSpringMotion( 310 float response, float dampingFraction, float overlapDuration); 311 ArkUI_CurveHandle OH_ArkUI_Curve_CreateInterpolatingSpring(float velocity, float mass, float stiffness, float damping); 312 ArkUI_CurveHandle OH_ArkUI_Curve_CreateCustomCurve( 313 void* userData, float (*interpolate)(float fraction, void* userdata)); 314 void OH_ArkUI_Curve_DisposeCurve(ArkUI_CurveHandle curveHandle); 315 316 ArkUI_TransitionEffect* OH_ArkUI_CreateOpacityTransitionEffect(float opacity); 317 ArkUI_TransitionEffect* OH_ArkUI_CreateTranslationTransitionEffect(ArkUI_TranslationOptions* translate); 318 ArkUI_TransitionEffect* OH_ArkUI_CreateScaleTransitionEffect(ArkUI_ScaleOptions* scale); 319 ArkUI_TransitionEffect* OH_ArkUI_CreateRotationTransitionEffect(ArkUI_RotationOptions* rotate); 320 ArkUI_TransitionEffect* OH_ArkUI_CreateMovementTransitionEffect(ArkUI_TransitionEdge move); 321 ArkUI_TransitionEffect* OH_ArkUI_CreateAsymmetricTransitionEffect( 322 ArkUI_TransitionEffect* appear, ArkUI_TransitionEffect* disappear); 323 void OH_ArkUI_TransitionEffect_Dispose(ArkUI_TransitionEffect* effect); 324 int32_t OH_ArkUI_TransitionEffect_Combine(ArkUI_TransitionEffect* effect, ArkUI_TransitionEffect* combine); 325 int32_t OH_ArkUI_TransitionEffect_SetAnimation(ArkUI_TransitionEffect* effect, ArkUI_AnimateOption* animation); 326 #ifdef __cplusplus 327 }; 328 #endif 329 330 #endif // ARKUI_NATIVE_ANIMATE_H