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 int32_t OH_ArkUI_KeyframeAnimateOption_SetDuration(ArkUI_KeyframeAnimateOption* option, int32_t value, int32_t index);
257 int32_t OH_ArkUI_KeyframeAnimateOption_SetCurve(
258     ArkUI_KeyframeAnimateOption* option, ArkUI_CurveHandle value, int32_t index);
259 int32_t OH_ArkUI_KeyframeAnimateOption_RegisterOnEventCallback(
260     ArkUI_KeyframeAnimateOption* option, void* userData, void (*event)(void* userData), int32_t index);
261 int32_t OH_ArkUI_KeyframeAnimateOption_GetDelay(ArkUI_KeyframeAnimateOption* option);
262 int32_t OH_ArkUI_KeyframeAnimateOption_GetIterations(ArkUI_KeyframeAnimateOption* option);
263 int32_t OH_ArkUI_KeyframeAnimateOption_GetDuration(ArkUI_KeyframeAnimateOption* option, int32_t index);
264 ArkUI_CurveHandle OH_ArkUI_KeyframeAnimateOption_GetCurve(ArkUI_KeyframeAnimateOption* option, int32_t index);
265 ArkUI_AnimatorOption* OH_ArkUI_AnimatorOption_Create(int32_t keyframeSize);
266 void OH_ArkUI_AnimatorOption_Dispose(ArkUI_AnimatorOption* option);
267 int32_t OH_ArkUI_AnimatorOption_SetDuration(ArkUI_AnimatorOption* option, int32_t value);
268 int32_t OH_ArkUI_AnimatorOption_SetDelay(ArkUI_AnimatorOption* option, int32_t value);
269 int32_t OH_ArkUI_AnimatorOption_SetIterations(ArkUI_AnimatorOption* option, int32_t value);
270 int32_t OH_ArkUI_AnimatorOption_SetFill(ArkUI_AnimatorOption* option, ArkUI_AnimationFillMode value);
271 int32_t OH_ArkUI_AnimatorOption_SetDirection(ArkUI_AnimatorOption* option, ArkUI_AnimationDirection value);
272 int32_t OH_ArkUI_AnimatorOption_SetCurve(ArkUI_AnimatorOption* option, ArkUI_CurveHandle value);
273 int32_t OH_ArkUI_AnimatorOption_SetBegin(ArkUI_AnimatorOption* option, float value);
274 int32_t OH_ArkUI_AnimatorOption_SetEnd(ArkUI_AnimatorOption* option, float value);
275 int32_t OH_ArkUI_AnimatorOption_SetExpectedFrameRateRange(
276     ArkUI_AnimatorOption* option, ArkUI_ExpectedFrameRateRange* value);
277 int32_t OH_ArkUI_AnimatorOption_SetKeyframe(ArkUI_AnimatorOption* option, float time, float value, int32_t index);
278 int32_t OH_ArkUI_AnimatorOption_SetKeyframeCurve(ArkUI_AnimatorOption* option, ArkUI_CurveHandle value, int32_t index);
279 int32_t OH_ArkUI_AnimatorOption_GetDuration(ArkUI_AnimatorOption* option);
280 int32_t OH_ArkUI_AnimatorOption_GetDelay(ArkUI_AnimatorOption* option);
281 int32_t OH_ArkUI_AnimatorOption_GetIterations(ArkUI_AnimatorOption* option);
282 ArkUI_AnimationFillMode OH_ArkUI_AnimatorOption_GetFill(ArkUI_AnimatorOption* option);
283 ArkUI_AnimationDirection OH_ArkUI_AnimatorOption_GetDirection(ArkUI_AnimatorOption* option);
284 ArkUI_CurveHandle OH_ArkUI_AnimatorOption_GetCurve(ArkUI_AnimatorOption* option);
285 float OH_ArkUI_AnimatorOption_GetBegin(ArkUI_AnimatorOption* option);
286 float OH_ArkUI_AnimatorOption_GetEnd(ArkUI_AnimatorOption* option);
287 ArkUI_ExpectedFrameRateRange* OH_ArkUI_AnimatorOption_GetExpectedFrameRateRange(ArkUI_AnimatorOption* option);
288 float OH_ArkUI_AnimatorOption_GetKeyframeTime(ArkUI_AnimatorOption* option, int32_t index);
289 float OH_ArkUI_AnimatorOption_GetKeyframeValue(ArkUI_AnimatorOption* option, int32_t index);
290 ArkUI_CurveHandle OH_ArkUI_AnimatorOption_GetKeyframeCurve(ArkUI_AnimatorOption* option, int32_t index);
291 void* OH_ArkUI_AnimatorEvent_GetUserData(ArkUI_AnimatorEvent* event);
292 void* OH_ArkUI_AnimatorOnFrameEvent_GetUserData(ArkUI_AnimatorOnFrameEvent* event);
293 float OH_ArkUI_AnimatorOnFrameEvent_GetValue(ArkUI_AnimatorOnFrameEvent* event);
294 int32_t OH_ArkUI_AnimatorOption_RegisterOnFrameCallback(
295     ArkUI_AnimatorOption* option, void* userData, void (*callback)(ArkUI_AnimatorOnFrameEvent* event));
296 int32_t OH_ArkUI_AnimatorOption_RegisterOnFinishCallback(
297     ArkUI_AnimatorOption* option, void* userData, void (*callback)(ArkUI_AnimatorEvent* event));
298 int32_t OH_ArkUI_AnimatorOption_RegisterOnCancelCallback(
299     ArkUI_AnimatorOption* option, void* userData, void (*callback)(ArkUI_AnimatorEvent* event));
300 int32_t OH_ArkUI_AnimatorOption_RegisterOnRepeatCallback(
301     ArkUI_AnimatorOption* option, void* userData, void (*callback)(ArkUI_AnimatorEvent* event));
302 int32_t OH_ArkUI_Animator_ResetAnimatorOption(ArkUI_AnimatorHandle animator, ArkUI_AnimatorOption* option);
303 int32_t OH_ArkUI_Animator_Play(ArkUI_AnimatorHandle animator);
304 int32_t OH_ArkUI_Animator_Finish(ArkUI_AnimatorHandle animator);
305 int32_t OH_ArkUI_Animator_Pause(ArkUI_AnimatorHandle animator);
306 int32_t OH_ArkUI_Animator_Cancel(ArkUI_AnimatorHandle animator);
307 int32_t OH_ArkUI_Animator_Reverse(ArkUI_AnimatorHandle animator);
308 ArkUI_CurveHandle OH_ArkUI_Curve_CreateCurveByType(ArkUI_AnimationCurve curve);
309 ArkUI_CurveHandle OH_ArkUI_Curve_CreateStepsCurve(int32_t count, bool end);
310 ArkUI_CurveHandle OH_ArkUI_Curve_CreateCubicBezierCurve(float x1, float y1, float x2, float y2);
311 ArkUI_CurveHandle OH_ArkUI_Curve_CreateSpringCurve(float velocity, float mass, float stiffness, float damping);
312 ArkUI_CurveHandle OH_ArkUI_Curve_CreateSpringMotion(float response, float dampingFraction, float overlapDuration);
313 ArkUI_CurveHandle OH_ArkUI_Curve_CreateResponsiveSpringMotion(
314     float response, float dampingFraction, float overlapDuration);
315 ArkUI_CurveHandle OH_ArkUI_Curve_CreateInterpolatingSpring(float velocity, float mass, float stiffness, float damping);
316 ArkUI_CurveHandle OH_ArkUI_Curve_CreateCustomCurve(
317     void* userData, float (*interpolate)(float fraction, void* userdata));
318 void OH_ArkUI_Curve_DisposeCurve(ArkUI_CurveHandle curveHandle);
319 
320 ArkUI_TransitionEffect* OH_ArkUI_CreateOpacityTransitionEffect(float opacity);
321 ArkUI_TransitionEffect* OH_ArkUI_CreateTranslationTransitionEffect(ArkUI_TranslationOptions* translate);
322 ArkUI_TransitionEffect* OH_ArkUI_CreateScaleTransitionEffect(ArkUI_ScaleOptions* scale);
323 ArkUI_TransitionEffect* OH_ArkUI_CreateRotationTransitionEffect(ArkUI_RotationOptions* rotate);
324 ArkUI_TransitionEffect* OH_ArkUI_CreateMovementTransitionEffect(ArkUI_TransitionEdge move);
325 ArkUI_TransitionEffect* OH_ArkUI_CreateAsymmetricTransitionEffect(
326     ArkUI_TransitionEffect* appear, ArkUI_TransitionEffect* disappear);
327 void OH_ArkUI_TransitionEffect_Dispose(ArkUI_TransitionEffect* effect);
328 int32_t OH_ArkUI_TransitionEffect_Combine(ArkUI_TransitionEffect* effect, ArkUI_TransitionEffect* combine);
329 int32_t OH_ArkUI_TransitionEffect_SetAnimation(ArkUI_TransitionEffect* effect, ArkUI_AnimateOption* animation);
330 #ifdef __cplusplus
331 };
332 #endif
333 
334 #endif // ARKUI_NATIVE_ANIMATE_H