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
17#include "animate_impl.h"
18#include "node/node_model.h"
19
20#include "base/error/error_code.h"
21#include "base/utils/utils.h"
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26ArkUI_AnimateOption* OH_ArkUI_AnimateOption_Create()
27{
28    ArkUI_AnimateOption* option = new ArkUI_AnimateOption;
29    //duration default 1000
30    option->duration = 1000;
31    //tempo default 1.0
32    option->tempo = 1.0f;
33    option->curve = ArkUI_AnimationCurve::ARKUI_CURVE_EASE_IN_OUT;
34    //delay default 0
35    option->delay = 0;
36    //iterations default 1
37    option->iterations = 1;
38    option->playMode = ArkUI_AnimationPlayMode::ARKUI_ANIMATION_PLAY_MODE_NORMAL;
39    option->expectedFrameRateRange = nullptr;
40    option->iCurve = nullptr;
41    return option;
42}
43
44void OH_ArkUI_AnimateOption_Dispose(ArkUI_AnimateOption* option)
45{
46    if (option == nullptr) {
47        return;
48    }
49    if (option->expectedFrameRateRange != nullptr) {
50        delete option->expectedFrameRateRange;
51        option->expectedFrameRateRange = nullptr;
52    }
53    delete option;
54}
55
56uint32_t OH_ArkUI_AnimateOption_GetDuration(ArkUI_AnimateOption* option)
57{
58    CHECK_NULL_RETURN(option, 0);
59    return option->duration;
60}
61
62float OH_ArkUI_AnimateOption_GetTempo(ArkUI_AnimateOption* option)
63{
64    CHECK_NULL_RETURN(option, 0.0f);
65    return option->tempo;
66}
67
68ArkUI_AnimationCurve OH_ArkUI_AnimateOption_GetCurve(ArkUI_AnimateOption* option)
69{
70    CHECK_NULL_RETURN(option, static_cast<ArkUI_AnimationCurve>(-1));
71    return option->curve;
72}
73
74int32_t OH_ArkUI_AnimateOption_GetDelay(ArkUI_AnimateOption* option)
75{
76    CHECK_NULL_RETURN(option, 0);
77    return option->delay;
78}
79
80int32_t OH_ArkUI_AnimateOption_GetIterations(ArkUI_AnimateOption* option)
81{
82    CHECK_NULL_RETURN(option, 0);
83    return option->iterations;
84}
85
86ArkUI_AnimationPlayMode OH_ArkUI_AnimateOption_GetPlayMode(ArkUI_AnimateOption* option)
87{
88    CHECK_NULL_RETURN(option, static_cast<ArkUI_AnimationPlayMode>(-1));
89    return option->playMode;
90}
91
92ArkUI_ExpectedFrameRateRange* OH_ArkUI_AnimateOption_GetExpectedFrameRateRange(ArkUI_AnimateOption* option)
93{
94    CHECK_NULL_RETURN(option, nullptr);
95    return option->expectedFrameRateRange;
96}
97
98void OH_ArkUI_AnimateOption_SetDuration(ArkUI_AnimateOption* option, int32_t value)
99{
100    CHECK_NULL_VOID(option);
101    // 设置小于0的值时按0处理
102    if (value < 0) {
103        value = 0;
104    }
105    option->duration = static_cast<uint32_t>(value);
106}
107
108void OH_ArkUI_AnimateOption_SetTempo(ArkUI_AnimateOption* option, float value)
109{
110    CHECK_NULL_VOID(option);
111    // 小于0的值时按值为1处理
112    if (value < 0) {
113        value = 1;
114    }
115    option->tempo = value;
116}
117
118void OH_ArkUI_AnimateOption_SetCurve(ArkUI_AnimateOption* option, ArkUI_AnimationCurve value)
119{
120    CHECK_NULL_VOID(option);
121    if (value >= ARKUI_CURVE_LINEAR && value <= ARKUI_CURVE_FRICTION) {
122        option->curve = value;
123    }
124}
125
126void OH_ArkUI_AnimateOption_SetDelay(ArkUI_AnimateOption* option, int32_t value)
127{
128    CHECK_NULL_VOID(option);
129    option->delay = value;
130}
131
132void OH_ArkUI_AnimateOption_SetIterations(ArkUI_AnimateOption* option, int32_t value)
133{
134    CHECK_NULL_VOID(option);
135    //取值范围:[-1, +∞)
136    if (value < -1) {
137        return;
138    }
139    option->iterations = value;
140}
141
142void OH_ArkUI_AnimateOption_SetPlayMode(ArkUI_AnimateOption* option, ArkUI_AnimationPlayMode value)
143{
144    CHECK_NULL_VOID(option);
145    if (value >= ARKUI_ANIMATION_PLAY_MODE_NORMAL && value <= ARKUI_ANIMATION_PLAY_MODE_ALTERNATE_REVERSE) {
146        option->playMode = value;
147    }
148}
149
150void OH_ArkUI_AnimateOption_SetExpectedFrameRateRange(ArkUI_AnimateOption* option, ArkUI_ExpectedFrameRateRange* value)
151{
152    CHECK_NULL_VOID(option);
153    CHECK_NULL_VOID(value);
154    option->expectedFrameRateRange = new ArkUI_ExpectedFrameRateRange { value->min, value->max, value->expected };
155}
156
157void OH_ArkUI_AnimateOption_SetICurve(ArkUI_AnimateOption* option, ArkUI_CurveHandle value)
158{
159    CHECK_NULL_VOID(option);
160    CHECK_NULL_VOID(value);
161    option->iCurve = value;
162}
163
164ArkUI_CurveHandle OH_ArkUI_AnimateOption_GetICurve(ArkUI_AnimateOption* option)
165{
166    CHECK_NULL_RETURN(option, nullptr);
167    return option->iCurve;
168}
169
170ArkUI_KeyframeAnimateOption* OH_ArkUI_KeyframeAnimateOption_Create(int32_t size)
171{
172    if (size < 0) {
173        return nullptr;
174    }
175
176    ArkUI_KeyframeAnimateOption* animateOption = new ArkUI_KeyframeAnimateOption;
177    animateOption->keyframes.resize(size);
178    animateOption->delay = 0;
179    animateOption->iterations = 1;
180    animateOption->onFinish = nullptr;
181    animateOption->userData = nullptr;
182
183    for (int32_t i = 0; i < size; ++i) {
184        //duration default 1000
185        animateOption->keyframes[i].duration = 1000;
186        animateOption->keyframes[i].curve = nullptr;
187        animateOption->keyframes[i].event = nullptr;
188        animateOption->keyframes[i].userData = nullptr;
189    }
190    return animateOption;
191}
192
193void OH_ArkUI_KeyframeAnimateOption_Dispose(ArkUI_KeyframeAnimateOption* option)
194{
195    CHECK_NULL_VOID(option);
196    delete option;
197}
198
199int32_t OH_ArkUI_KeyframeAnimateOption_SetDelay(ArkUI_KeyframeAnimateOption* option, int32_t value)
200{
201    CHECK_NULL_RETURN(option, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
202    option->delay = value;
203    return OHOS::Ace::ERROR_CODE_NO_ERROR;
204}
205
206int32_t OH_ArkUI_KeyframeAnimateOption_SetIterations(ArkUI_KeyframeAnimateOption* option, int32_t value)
207{
208    CHECK_NULL_RETURN(option, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
209    //取值范围:[-1, +∞)
210    if (value < -1) {
211        return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
212    }
213    option->iterations = value;
214    return OHOS::Ace::ERROR_CODE_NO_ERROR;
215}
216
217int32_t OH_ArkUI_KeyframeAnimateOption_RegisterOnFinishCallback(
218    ArkUI_KeyframeAnimateOption* option, void* userData, void (*onFinish)(void* userData))
219{
220    CHECK_NULL_RETURN(option, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
221    option->onFinish = onFinish;
222    option->userData = userData;
223    return OHOS::Ace::ERROR_CODE_NO_ERROR;
224}
225
226int32_t OH_ArkUI_KeyframeAnimateOption_SetDuration(ArkUI_KeyframeAnimateOption* option, int32_t value, int32_t index)
227{
228    if (option == nullptr || index < 0 || index >= static_cast<int32_t>(option->keyframes.size())) {
229        return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
230    }
231    if (value < 0) {
232        value = 0;
233    }
234    option->keyframes[index].duration = value;
235    return OHOS::Ace::ERROR_CODE_NO_ERROR;
236}
237
238int32_t OH_ArkUI_KeyframeAnimateOption_SetCurve(
239    ArkUI_KeyframeAnimateOption* option, ArkUI_CurveHandle value, int32_t index)
240{
241    if (option == nullptr || index < 0 || index >= static_cast<int32_t>(option->keyframes.size())) {
242        return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
243    }
244    if (!value || !value->curve) {
245        option->keyframes[index].curve = nullptr;
246        return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
247    }
248    if (value->type == ARKUI_CURVE_TYPE_SPRING_MOTION || value->type == ARKUI_CURVE_TYPE_RESPONSIVE_SPRING_MOTION ||
249        value->type == ARKUI_CURVE_TYPE_INTERPOLATING_SPRING) {
250        return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
251    }
252    option->keyframes[index].curve = value;
253    return OHOS::Ace::ERROR_CODE_NO_ERROR;
254}
255
256int32_t OH_ArkUI_KeyframeAnimateOption_RegisterOnEventCallback(
257    ArkUI_KeyframeAnimateOption* option, void* userData, void (*event)(void* userData), int32_t index)
258{
259    if (option == nullptr || index < 0 || index >= static_cast<int32_t>(option->keyframes.size())) {
260        return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
261    }
262    option->keyframes[index].event = event;
263    option->keyframes[index].userData = userData;
264    return OHOS::Ace::ERROR_CODE_NO_ERROR;
265}
266
267int32_t OH_ArkUI_KeyframeAnimateOption_GetDelay(ArkUI_KeyframeAnimateOption* option)
268{
269    CHECK_NULL_RETURN(option, 0);
270    return option->delay;
271}
272
273int32_t OH_ArkUI_KeyframeAnimateOption_GetIterations(ArkUI_KeyframeAnimateOption* option)
274{
275    CHECK_NULL_RETURN(option, 1);
276    return option->iterations;
277}
278
279int32_t OH_ArkUI_KeyframeAnimateOption_GetDuration(ArkUI_KeyframeAnimateOption* option, int32_t index)
280{
281    if (option == nullptr || index < 0 || index >= static_cast<int32_t>(option->keyframes.size())) {
282        return 0;
283    }
284    return option->keyframes[index].duration;
285}
286
287ArkUI_CurveHandle OH_ArkUI_KeyframeAnimateOption_GetCurve(ArkUI_KeyframeAnimateOption* option, int32_t index)
288{
289    if (option == nullptr || index < 0 || index >= static_cast<int32_t>(option->keyframes.size())) {
290        return nullptr;
291    }
292    return option->keyframes[index].curve;
293}
294
295ArkUI_AnimatorOption* OH_ArkUI_AnimatorOption_Create(int32_t keyframeSize)
296{
297    if (keyframeSize < 0) {
298        return nullptr;
299    }
300
301    ArkUI_AnimatorOption* option = new ArkUI_AnimatorOption;
302    option->keyframes.resize(keyframeSize);
303    for (int32_t i = 0; i < keyframeSize; i++) {
304        option->keyframes[i].curve = nullptr;
305    }
306    option->duration = 0;
307    option->delay = 0;
308    option->iterations = 1;
309    option->fill = ARKUI_ANIMATION_FILL_MODE_FORWARDS;
310    option->direction = ARKUI_ANIMATION_DIRECTION_NORMAL;
311    option->begin = 0.0f;
312    option->end = 1.0f;
313    option->easing = nullptr;
314    option->onFrame = nullptr;
315    option->frameUserData = nullptr;
316    option->onFinish = nullptr;
317    option->finishUserData = nullptr;
318    option->onCancel = nullptr;
319    option->cancelUserData = nullptr;
320    option->onRepeat = nullptr;
321    option->repeatUserData = nullptr;
322    option->expectedFrameRateRange = nullptr;
323    return option;
324}
325
326void OH_ArkUI_AnimatorOption_Dispose(ArkUI_AnimatorOption* option)
327{
328    CHECK_NULL_VOID(option);
329    if (option->expectedFrameRateRange) {
330        delete option->expectedFrameRateRange;
331        option->expectedFrameRateRange = nullptr;
332    }
333    delete option;
334}
335
336int32_t OH_ArkUI_AnimatorOption_SetDuration(ArkUI_AnimatorOption* option, int32_t value)
337{
338    CHECK_NULL_RETURN(option, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
339    if (value < 0) {
340        return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
341    }
342    option->duration = value;
343    return OHOS::Ace::ERROR_CODE_NO_ERROR;
344}
345
346int32_t OH_ArkUI_AnimatorOption_SetDelay(ArkUI_AnimatorOption* option, int32_t value)
347{
348    CHECK_NULL_RETURN(option, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
349    option->delay = value;
350    return OHOS::Ace::ERROR_CODE_NO_ERROR;
351}
352
353int32_t OH_ArkUI_AnimatorOption_SetIterations(ArkUI_AnimatorOption* option, int32_t value)
354{
355    CHECK_NULL_RETURN(option, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
356    if (value < -1) {
357        value = 1;
358    }
359    option->iterations = value;
360    return OHOS::Ace::ERROR_CODE_NO_ERROR;
361}
362
363int32_t OH_ArkUI_AnimatorOption_SetFill(ArkUI_AnimatorOption* option, ArkUI_AnimationFillMode value)
364{
365    CHECK_NULL_RETURN(option, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
366    if (value > ARKUI_ANIMATION_FILL_MODE_BOTH || value < ARKUI_ANIMATION_FILL_MODE_NONE) {
367        return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
368    }
369    option->fill = value;
370    return OHOS::Ace::ERROR_CODE_NO_ERROR;
371}
372
373int32_t OH_ArkUI_AnimatorOption_SetDirection(ArkUI_AnimatorOption* option, ArkUI_AnimationDirection value)
374{
375    CHECK_NULL_RETURN(option, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
376    if (value > ARKUI_ANIMATION_DIRECTION_ALTERNATE_REVERSE || value < ARKUI_ANIMATION_DIRECTION_NORMAL) {
377        return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
378    }
379    option->direction = value;
380    return OHOS::Ace::ERROR_CODE_NO_ERROR;
381}
382
383int32_t OH_ArkUI_AnimatorOption_SetCurve(ArkUI_AnimatorOption* option, ArkUI_CurveHandle value)
384{
385    CHECK_NULL_RETURN(option, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
386    if (value) {
387        if (value->type == ARKUI_CURVE_TYPE_SPRING || value->type == ARKUI_CURVE_TYPE_SPRING_MOTION ||
388            value->type == ARKUI_CURVE_TYPE_RESPONSIVE_SPRING_MOTION ||
389            value->type == ARKUI_CURVE_TYPE_INTERPOLATING_SPRING || value->type == ARKUI_CURVE_TYPE_CUSTOM) {
390            option->easing = nullptr;
391            return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
392        }
393    }
394
395    option->easing = value;
396    return OHOS::Ace::ERROR_CODE_NO_ERROR;
397}
398
399int32_t OH_ArkUI_AnimatorOption_SetBegin(ArkUI_AnimatorOption* option, float value)
400{
401    CHECK_NULL_RETURN(option, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
402    if (option->keyframes.size() > 0) {
403        return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
404    }
405    option->begin = value;
406    return OHOS::Ace::ERROR_CODE_NO_ERROR;
407}
408
409int32_t OH_ArkUI_AnimatorOption_SetEnd(ArkUI_AnimatorOption* option, float value)
410{
411    CHECK_NULL_RETURN(option, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
412    if (option->keyframes.size() > 0) {
413        return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
414    }
415    option->end = value;
416    return OHOS::Ace::ERROR_CODE_NO_ERROR;
417}
418
419int32_t OH_ArkUI_AnimatorOption_SetExpectedFrameRateRange(
420    ArkUI_AnimatorOption* option, ArkUI_ExpectedFrameRateRange* value)
421{
422    CHECK_NULL_RETURN(option, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
423    CHECK_NULL_RETURN(value, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
424    option->expectedFrameRateRange = new ArkUI_ExpectedFrameRateRange { value->min, value->max, value->expected };
425    return OHOS::Ace::ERROR_CODE_NO_ERROR;
426}
427
428int32_t OH_ArkUI_AnimatorOption_SetKeyframe(ArkUI_AnimatorOption* option, float time, float value, int32_t index)
429{
430    CHECK_NULL_RETURN(option, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
431    if (time < 0 || time > 1) {
432        return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
433    }
434    if (index >= 0 && static_cast<size_t>(index) < option->keyframes.size()) {
435        option->keyframes[index].keyTime = time;
436        option->keyframes[index].keyValue = value;
437        return OHOS::Ace::ERROR_CODE_NO_ERROR;
438    }
439    return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
440}
441
442int32_t OH_ArkUI_AnimatorOption_SetKeyframeCurve(ArkUI_AnimatorOption* option, ArkUI_CurveHandle value, int32_t index)
443{
444    CHECK_NULL_RETURN(option, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
445    if (value) {
446        if (value->type == ARKUI_CURVE_TYPE_SPRING || value->type == ARKUI_CURVE_TYPE_SPRING_MOTION ||
447            value->type == ARKUI_CURVE_TYPE_RESPONSIVE_SPRING_MOTION ||
448            value->type == ARKUI_CURVE_TYPE_INTERPOLATING_SPRING || value->type == ARKUI_CURVE_TYPE_CUSTOM) {
449            option->keyframes[index].curve = nullptr;
450            return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
451        }
452    }
453
454    if (index >= 0 && static_cast<size_t>(index) < option->keyframes.size()) {
455        option->keyframes[index].curve = value;
456        return OHOS::Ace::ERROR_CODE_NO_ERROR;
457    }
458    return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
459}
460
461int32_t OH_ArkUI_AnimatorOption_GetDuration(ArkUI_AnimatorOption* option)
462{
463    if (option != nullptr) {
464        return option->duration;
465    }
466    return -1;
467}
468
469int32_t OH_ArkUI_AnimatorOption_GetDelay(ArkUI_AnimatorOption* option)
470{
471    if (option != nullptr) {
472        return option->delay;
473    }
474    return -1;
475}
476
477int32_t OH_ArkUI_AnimatorOption_GetIterations(ArkUI_AnimatorOption* option)
478{
479    if (option != nullptr) {
480        return option->iterations;
481    }
482    return -1;
483}
484
485ArkUI_AnimationFillMode OH_ArkUI_AnimatorOption_GetFill(ArkUI_AnimatorOption* option)
486{
487    if (option != nullptr) {
488        return option->fill;
489    }
490    return static_cast<ArkUI_AnimationFillMode>(-1);
491}
492
493ArkUI_AnimationDirection OH_ArkUI_AnimatorOption_GetDirection(ArkUI_AnimatorOption* option)
494{
495    if (option != nullptr) {
496        return option->direction;
497    }
498    return static_cast<ArkUI_AnimationDirection>(-1);
499}
500
501ArkUI_CurveHandle OH_ArkUI_AnimatorOption_GetCurve(ArkUI_AnimatorOption* option)
502{
503    if (option != nullptr) {
504        return option->easing;
505    }
506    return nullptr;
507}
508
509float OH_ArkUI_AnimatorOption_GetBegin(ArkUI_AnimatorOption* option)
510{
511    if (option != nullptr) {
512        return option->begin;
513    }
514    return 0.0f;
515}
516
517float OH_ArkUI_AnimatorOption_GetEnd(ArkUI_AnimatorOption* option)
518{
519    if (option != nullptr) {
520        return option->end;
521    }
522    return 1.0f;
523}
524
525ArkUI_ExpectedFrameRateRange* OH_ArkUI_AnimatorOption_GetExpectedFrameRateRange(ArkUI_AnimatorOption* option)
526{
527    if (option != nullptr) {
528        return option->expectedFrameRateRange;
529    }
530    return nullptr;
531}
532
533float OH_ArkUI_AnimatorOption_GetKeyframeTime(ArkUI_AnimatorOption* option, int32_t index)
534{
535    if (option != nullptr && index >= 0 && static_cast<size_t>(index) < option->keyframes.size()) {
536        return option->keyframes[index].keyTime;
537    }
538    return -1.0f;
539}
540
541float OH_ArkUI_AnimatorOption_GetKeyframeValue(ArkUI_AnimatorOption* option, int32_t index)
542{
543    if (option != nullptr && index >= 0 && static_cast<size_t>(index) < option->keyframes.size()) {
544        return option->keyframes[index].keyValue;
545    }
546    return -1.0f;
547}
548
549ArkUI_CurveHandle OH_ArkUI_AnimatorOption_GetKeyframeCurve(ArkUI_AnimatorOption* option, int32_t index)
550{
551    if (option != nullptr && index >= 0 && static_cast<size_t>(index) < option->keyframes.size()) {
552        return option->keyframes[index].curve;
553    }
554    return nullptr;
555}
556
557void* OH_ArkUI_AnimatorEvent_GetUserData(ArkUI_AnimatorEvent* event)
558{
559    CHECK_NULL_RETURN(event, nullptr);
560    return event->userData;
561}
562
563void* OH_ArkUI_AnimatorOnFrameEvent_GetUserData(ArkUI_AnimatorOnFrameEvent* event)
564{
565    CHECK_NULL_RETURN(event, nullptr);
566    return event->userData;
567}
568
569float OH_ArkUI_AnimatorOnFrameEvent_GetValue(ArkUI_AnimatorOnFrameEvent* event)
570{
571    CHECK_NULL_RETURN(event, 0.0f);
572    return event->progress;
573}
574
575int32_t OH_ArkUI_AnimatorOption_RegisterOnFrameCallback(
576    ArkUI_AnimatorOption* option, void* userData, void (*callback)(ArkUI_AnimatorOnFrameEvent* event))
577{
578    auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
579    if (!impl || !option || !callback) {
580        return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
581    }
582    option->onFrame = callback;
583    option->frameUserData = userData;
584    return OHOS::Ace::ERROR_CODE_NO_ERROR;
585}
586
587int32_t OH_ArkUI_AnimatorOption_RegisterOnFinishCallback(
588    ArkUI_AnimatorOption* option, void* userData, void (*callback)(ArkUI_AnimatorEvent* event))
589{
590    auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
591    if (!impl || !option || !callback) {
592        return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
593    }
594
595    option->onFinish = callback;
596    option->finishUserData = userData;
597    return OHOS::Ace::ERROR_CODE_NO_ERROR;
598}
599
600int32_t OH_ArkUI_AnimatorOption_RegisterOnCancelCallback(
601    ArkUI_AnimatorOption* option, void* userData, void (*callback)(ArkUI_AnimatorEvent* event))
602{
603    auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
604    if (!impl || !option || !callback) {
605        return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
606    }
607
608    option->onCancel = callback;
609    option->cancelUserData = userData;
610    return OHOS::Ace::ERROR_CODE_NO_ERROR;
611}
612
613int32_t OH_ArkUI_AnimatorOption_RegisterOnRepeatCallback(
614    ArkUI_AnimatorOption* option, void* userData, void (*callback)(ArkUI_AnimatorEvent* event))
615{
616    auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
617    if (!impl || !option || !callback) {
618        return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
619    }
620
621    option->onRepeat = callback;
622    option->repeatUserData = userData;
623    return OHOS::Ace::ERROR_CODE_NO_ERROR;
624}
625
626int32_t OH_ArkUI_Animator_ResetAnimatorOption(ArkUI_AnimatorHandle animator, ArkUI_AnimatorOption* option)
627{
628    return OHOS::Ace::AnimateModel::AnimatorReset(animator, option);
629}
630
631int32_t OH_ArkUI_Animator_Play(ArkUI_AnimatorHandle animator)
632{
633    return OHOS::Ace::AnimateModel::AnimatorPlay(animator);
634}
635
636int32_t OH_ArkUI_Animator_Finish(ArkUI_AnimatorHandle animator)
637{
638    return OHOS::Ace::AnimateModel::AnimatorFinish(animator);
639}
640
641int32_t OH_ArkUI_Animator_Pause(ArkUI_AnimatorHandle animator)
642{
643    return OHOS::Ace::AnimateModel::AnimatorPause(animator);
644}
645
646int32_t OH_ArkUI_Animator_Cancel(ArkUI_AnimatorHandle animator)
647{
648    return OHOS::Ace::AnimateModel::AnimatorCancel(animator);
649}
650
651int32_t OH_ArkUI_Animator_Reverse(ArkUI_AnimatorHandle animator)
652{
653    return OHOS::Ace::AnimateModel::AnimatorReverse(animator);
654}
655
656ArkUI_CurveHandle OH_ArkUI_Curve_CreateCurveByType(ArkUI_AnimationCurve curve)
657{
658    return OHOS::Ace::AnimateModel::InitCurve(curve);
659}
660
661ArkUI_CurveHandle OH_ArkUI_Curve_CreateStepsCurve(int32_t count, bool end)
662{
663    return OHOS::Ace::AnimateModel::StepsCurve(count, end);
664}
665
666ArkUI_CurveHandle OH_ArkUI_Curve_CreateCubicBezierCurve(float x1, float y1, float x2, float y2)
667{
668    return OHOS::Ace::AnimateModel::CubicBezierCurve(x1, y1, x2, y2);
669}
670
671ArkUI_CurveHandle OH_ArkUI_Curve_CreateSpringCurve(float velocity, float mass, float stiffness, float damping)
672{
673    return OHOS::Ace::AnimateModel::SpringCurve(velocity, mass, stiffness, damping);
674}
675
676ArkUI_CurveHandle OH_ArkUI_Curve_CreateSpringMotion(float response, float dampingFraction, float overlapDuration)
677{
678    return OHOS::Ace::AnimateModel::SpringMotion(response, dampingFraction, overlapDuration);
679}
680
681ArkUI_CurveHandle OH_ArkUI_Curve_CreateResponsiveSpringMotion(
682    float response, float dampingFraction, float overlapDuration)
683{
684    return OHOS::Ace::AnimateModel::ResponsiveSpringMotion(response, dampingFraction, overlapDuration);
685}
686
687ArkUI_CurveHandle OH_ArkUI_Curve_CreateInterpolatingSpring(float velocity, float mass, float stiffness, float damping)
688{
689    return OHOS::Ace::AnimateModel::InterpolatingSpring(velocity, mass, stiffness, damping);
690}
691
692ArkUI_CurveHandle OH_ArkUI_Curve_CreateCustomCurve(void* userData, float (*interpolate)(float fraction, void* userdata))
693{
694    return OHOS::Ace::AnimateModel::CustomCurve(userData, interpolate);
695}
696
697void OH_ArkUI_Curve_DisposeCurve(ArkUI_CurveHandle curveHandle)
698{
699    return OHOS::Ace::AnimateModel::DisposeCurve(curveHandle);
700}
701
702#ifdef __cplusplus
703};
704#endif