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