123b3eb3cSopenharmony_ci/*
223b3eb3cSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
323b3eb3cSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
423b3eb3cSopenharmony_ci * you may not use this file except in compliance with the License.
523b3eb3cSopenharmony_ci * You may obtain a copy of the License at
623b3eb3cSopenharmony_ci *
723b3eb3cSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
823b3eb3cSopenharmony_ci *
923b3eb3cSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1023b3eb3cSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1123b3eb3cSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1223b3eb3cSopenharmony_ci * See the License for the specific language governing permissions and
1323b3eb3cSopenharmony_ci * limitations under the License.
1423b3eb3cSopenharmony_ci */
1523b3eb3cSopenharmony_ci
1623b3eb3cSopenharmony_ci#include "node/animate_impl.h"
1723b3eb3cSopenharmony_ci
1823b3eb3cSopenharmony_ci#include "node/node_model.h"
1923b3eb3cSopenharmony_ci
2023b3eb3cSopenharmony_ci#include "base/error/error_code.h"
2123b3eb3cSopenharmony_ci
2223b3eb3cSopenharmony_cinamespace OHOS::Ace::AnimateModel {
2323b3eb3cSopenharmony_ci
2423b3eb3cSopenharmony_ciint32_t AnimateTo(ArkUI_ContextHandle context, ArkUI_AnimateOption* option, ArkUI_ContextCallback* update,
2523b3eb3cSopenharmony_ci    ArkUI_AnimateCompleteCallback* complete)
2623b3eb3cSopenharmony_ci{
2723b3eb3cSopenharmony_ci    auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
2823b3eb3cSopenharmony_ci    if (!impl || !context || !option || !update || !update->callback) {
2923b3eb3cSopenharmony_ci        return ERROR_CODE_PARAM_INVALID;
3023b3eb3cSopenharmony_ci    }
3123b3eb3cSopenharmony_ci
3223b3eb3cSopenharmony_ci    ArkUIAnimateOption animateOption {};
3323b3eb3cSopenharmony_ci    animateOption.duration = option->duration;
3423b3eb3cSopenharmony_ci    animateOption.tempo = option->tempo;
3523b3eb3cSopenharmony_ci    animateOption.curve = static_cast<ArkUI_Int32>(option->curve);
3623b3eb3cSopenharmony_ci    animateOption.delay = option->delay;
3723b3eb3cSopenharmony_ci    animateOption.iterations = option->iterations;
3823b3eb3cSopenharmony_ci    if (option->iCurve) {
3923b3eb3cSopenharmony_ci        animateOption.iCurve = option->iCurve->curve;
4023b3eb3cSopenharmony_ci        animateOption.curveType = option->iCurve->baseCurveType;
4123b3eb3cSopenharmony_ci    }
4223b3eb3cSopenharmony_ci    animateOption.playMode = static_cast<ArkUI_Int32>(option->playMode);
4323b3eb3cSopenharmony_ci    if (option->expectedFrameRateRange) {
4423b3eb3cSopenharmony_ci        animateOption.expectedFrameRateRange =
4523b3eb3cSopenharmony_ci            reinterpret_cast<ArkUIExpectedFrameRateRange*>(option->expectedFrameRateRange);
4623b3eb3cSopenharmony_ci    }
4723b3eb3cSopenharmony_ci
4823b3eb3cSopenharmony_ci    if (complete && complete->callback) {
4923b3eb3cSopenharmony_ci        animateOption.onFinishCallback = reinterpret_cast<void*>(complete->callback);
5023b3eb3cSopenharmony_ci    }
5123b3eb3cSopenharmony_ci
5223b3eb3cSopenharmony_ci    if (complete && complete->userData) {
5323b3eb3cSopenharmony_ci        animateOption.user = complete->userData;
5423b3eb3cSopenharmony_ci    }
5523b3eb3cSopenharmony_ci    auto finishCallbackType = static_cast<ArkUI_Int32>(ARKUI_FINISH_CALLBACK_REMOVED);
5623b3eb3cSopenharmony_ci    if (complete && complete->type == ARKUI_FINISH_CALLBACK_LOGICALLY) {
5723b3eb3cSopenharmony_ci        finishCallbackType = static_cast<ArkUI_Int32>(ARKUI_FINISH_CALLBACK_LOGICALLY);
5823b3eb3cSopenharmony_ci    }
5923b3eb3cSopenharmony_ci    animateOption.finishCallbackType = finishCallbackType;
6023b3eb3cSopenharmony_ci
6123b3eb3cSopenharmony_ci    impl->getAnimation()->animateTo(reinterpret_cast<ArkUIContext*>(context), animateOption,
6223b3eb3cSopenharmony_ci        reinterpret_cast<void*>(update->callback), update->userData);
6323b3eb3cSopenharmony_ci    return ERROR_CODE_NO_ERROR;
6423b3eb3cSopenharmony_ci}
6523b3eb3cSopenharmony_ci
6623b3eb3cSopenharmony_ciint32_t KeyframeAnimateTo(ArkUI_ContextHandle context, ArkUI_KeyframeAnimateOption* option)
6723b3eb3cSopenharmony_ci{
6823b3eb3cSopenharmony_ci    auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
6923b3eb3cSopenharmony_ci    if (!impl || !context || !option || option->keyframes.size() == 0) {
7023b3eb3cSopenharmony_ci        return ERROR_CODE_PARAM_INVALID;
7123b3eb3cSopenharmony_ci    }
7223b3eb3cSopenharmony_ci
7323b3eb3cSopenharmony_ci    ArkUIKeyframeAnimateOption animateOption {};
7423b3eb3cSopenharmony_ci    animateOption.delay = option->delay;
7523b3eb3cSopenharmony_ci    animateOption.iterations = option->iterations;
7623b3eb3cSopenharmony_ci    animateOption.onFinish = option->onFinish;
7723b3eb3cSopenharmony_ci    animateOption.userData = option->userData;
7823b3eb3cSopenharmony_ci    ArkUIKeyframeState keyframes[option->keyframes.size()];
7923b3eb3cSopenharmony_ci    for (size_t i = 0; i < option->keyframes.size(); i++) {
8023b3eb3cSopenharmony_ci        keyframes[i].duration = option->keyframes[i].duration;
8123b3eb3cSopenharmony_ci        keyframes[i].event = option->keyframes[i].event;
8223b3eb3cSopenharmony_ci        keyframes[i].userData = option->keyframes[i].userData;
8323b3eb3cSopenharmony_ci
8423b3eb3cSopenharmony_ci        auto curve = option->keyframes[i].curve;
8523b3eb3cSopenharmony_ci        if (!curve) {
8623b3eb3cSopenharmony_ci            continue;
8723b3eb3cSopenharmony_ci        }
8823b3eb3cSopenharmony_ci        //不支持当前curve
8923b3eb3cSopenharmony_ci        if (curve->type == ARKUI_CURVE_TYPE_SPRING_MOTION || curve->type == ARKUI_CURVE_TYPE_RESPONSIVE_SPRING_MOTION ||
9023b3eb3cSopenharmony_ci            curve->type == ARKUI_CURVE_TYPE_INTERPOLATING_SPRING) {
9123b3eb3cSopenharmony_ci            continue;
9223b3eb3cSopenharmony_ci        }
9323b3eb3cSopenharmony_ci        keyframes[i].curve = curve->curve;
9423b3eb3cSopenharmony_ci        keyframes[i].curveType = curve->type;
9523b3eb3cSopenharmony_ci    }
9623b3eb3cSopenharmony_ci    animateOption.keyframes = keyframes;
9723b3eb3cSopenharmony_ci    animateOption.keyframeSize = static_cast<int32_t>(option->keyframes.size());
9823b3eb3cSopenharmony_ci
9923b3eb3cSopenharmony_ci    impl->getAnimation()->keyframeAnimateTo(reinterpret_cast<ArkUIContext*>(context), &animateOption);
10023b3eb3cSopenharmony_ci    return ERROR_CODE_NO_ERROR;
10123b3eb3cSopenharmony_ci}
10223b3eb3cSopenharmony_ci
10323b3eb3cSopenharmony_ciArkUIAnimatorOption* ConvertAnimatorOption(ArkUI_AnimatorOption* option)
10423b3eb3cSopenharmony_ci{
10523b3eb3cSopenharmony_ci    ArkUIAnimatorOption* animatorOption = new ArkUIAnimatorOption;
10623b3eb3cSopenharmony_ci    animatorOption->duration = option->duration;
10723b3eb3cSopenharmony_ci    animatorOption->delay = option->delay;
10823b3eb3cSopenharmony_ci    animatorOption->iterations = option->iterations;
10923b3eb3cSopenharmony_ci    animatorOption->begin = option->begin;
11023b3eb3cSopenharmony_ci    animatorOption->end = option->end;
11123b3eb3cSopenharmony_ci    animatorOption->fill = option->fill;
11223b3eb3cSopenharmony_ci    animatorOption->direction = option->direction;
11323b3eb3cSopenharmony_ci    if (option->easing) {
11423b3eb3cSopenharmony_ci        animatorOption->easing = option->easing->curve;
11523b3eb3cSopenharmony_ci        animatorOption->curveType = option->easing->type;
11623b3eb3cSopenharmony_ci    } else {
11723b3eb3cSopenharmony_ci        animatorOption->easing = nullptr;
11823b3eb3cSopenharmony_ci    }
11923b3eb3cSopenharmony_ci
12023b3eb3cSopenharmony_ci    if (option->expectedFrameRateRange) {
12123b3eb3cSopenharmony_ci        animatorOption->isHasExpectedFrameRateRange = 1;
12223b3eb3cSopenharmony_ci        animatorOption->expectedFrameRateRange = { option->expectedFrameRateRange->min,
12323b3eb3cSopenharmony_ci            option->expectedFrameRateRange->max, option->expectedFrameRateRange->expected };
12423b3eb3cSopenharmony_ci    } else {
12523b3eb3cSopenharmony_ci        animatorOption->isHasExpectedFrameRateRange = 0;
12623b3eb3cSopenharmony_ci    }
12723b3eb3cSopenharmony_ci
12823b3eb3cSopenharmony_ci    int32_t keyframeSize = static_cast<int32_t>(option->keyframes.size());
12923b3eb3cSopenharmony_ci    if (keyframeSize > 0) {
13023b3eb3cSopenharmony_ci        animatorOption->keyframes = new ArkUIKeyframe[keyframeSize];
13123b3eb3cSopenharmony_ci        for (int32_t i = 0; i < keyframeSize; ++i) {
13223b3eb3cSopenharmony_ci            animatorOption->keyframes[i].keyTime = option->keyframes[i].keyTime;
13323b3eb3cSopenharmony_ci            animatorOption->keyframes[i].keyValue = option->keyframes[i].keyValue;
13423b3eb3cSopenharmony_ci            if (option->keyframes[i].curve) {
13523b3eb3cSopenharmony_ci                animatorOption->keyframes[i].curve = option->keyframes[i].curve->curve;
13623b3eb3cSopenharmony_ci                animatorOption->keyframes[i].curveType = option->keyframes[i].curve->type;
13723b3eb3cSopenharmony_ci            } else {
13823b3eb3cSopenharmony_ci                animatorOption->keyframes[i].curve = nullptr;
13923b3eb3cSopenharmony_ci                animatorOption->keyframes[i].curveType = 0; // 默认或无效的曲线类型
14023b3eb3cSopenharmony_ci            }
14123b3eb3cSopenharmony_ci        }
14223b3eb3cSopenharmony_ci    } else {
14323b3eb3cSopenharmony_ci        animatorOption->keyframes = nullptr;
14423b3eb3cSopenharmony_ci    }
14523b3eb3cSopenharmony_ci    animatorOption->keyframeSize = keyframeSize;
14623b3eb3cSopenharmony_ci
14723b3eb3cSopenharmony_ci    animatorOption->onFrame = option->onFrame;
14823b3eb3cSopenharmony_ci    animatorOption->onFinish = option->onFinish;
14923b3eb3cSopenharmony_ci    animatorOption->onCancel = option->onCancel;
15023b3eb3cSopenharmony_ci    animatorOption->onRepeat = option->onRepeat;
15123b3eb3cSopenharmony_ci
15223b3eb3cSopenharmony_ci    animatorOption->frameUserData = option->frameUserData;
15323b3eb3cSopenharmony_ci    animatorOption->finishUserData = option->finishUserData;
15423b3eb3cSopenharmony_ci    animatorOption->cancelUserData = option->cancelUserData;
15523b3eb3cSopenharmony_ci    animatorOption->repeatUserData = option->repeatUserData;
15623b3eb3cSopenharmony_ci    return animatorOption;
15723b3eb3cSopenharmony_ci}
15823b3eb3cSopenharmony_ci
15923b3eb3cSopenharmony_ciArkUI_AnimatorHandle CreateAnimator(ArkUI_ContextHandle context, ArkUI_AnimatorOption* option)
16023b3eb3cSopenharmony_ci{
16123b3eb3cSopenharmony_ci    auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
16223b3eb3cSopenharmony_ci    if (!impl || !context || !option) {
16323b3eb3cSopenharmony_ci        return nullptr;
16423b3eb3cSopenharmony_ci    }
16523b3eb3cSopenharmony_ci
16623b3eb3cSopenharmony_ci    auto animatorOption = ConvertAnimatorOption(option);
16723b3eb3cSopenharmony_ci    auto animator = impl->getAnimation()->createAnimator(reinterpret_cast<ArkUIContext*>(context), animatorOption);
16823b3eb3cSopenharmony_ci    ArkUI_Animator* animatorHandle = new ArkUI_Animator { animator, option, animatorOption };
16923b3eb3cSopenharmony_ci    return animatorHandle;
17023b3eb3cSopenharmony_ci}
17123b3eb3cSopenharmony_ci
17223b3eb3cSopenharmony_civoid DisposeAnimator(ArkUI_AnimatorHandle animatorHandle)
17323b3eb3cSopenharmony_ci{
17423b3eb3cSopenharmony_ci    auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
17523b3eb3cSopenharmony_ci    if (!animatorHandle || !animatorHandle->animator) {
17623b3eb3cSopenharmony_ci        return;
17723b3eb3cSopenharmony_ci    }
17823b3eb3cSopenharmony_ci    impl->getAnimation()->disposeAnimator(animatorHandle->animator);
17923b3eb3cSopenharmony_ci    if (animatorHandle->animatorOption) {
18023b3eb3cSopenharmony_ci        auto* animatorOption = reinterpret_cast<ArkUIAnimatorOption*>(animatorHandle->animatorOption);
18123b3eb3cSopenharmony_ci        if (animatorOption->keyframes) {
18223b3eb3cSopenharmony_ci            delete[] animatorOption->keyframes;
18323b3eb3cSopenharmony_ci            animatorOption->keyframes = nullptr;
18423b3eb3cSopenharmony_ci        }
18523b3eb3cSopenharmony_ci        delete animatorOption;
18623b3eb3cSopenharmony_ci        animatorHandle->animatorOption = nullptr;
18723b3eb3cSopenharmony_ci    }
18823b3eb3cSopenharmony_ci    delete animatorHandle;
18923b3eb3cSopenharmony_ci}
19023b3eb3cSopenharmony_ci
19123b3eb3cSopenharmony_ciint32_t AnimatorReset(ArkUI_AnimatorHandle animatorHandle, ArkUI_AnimatorOption* option)
19223b3eb3cSopenharmony_ci{
19323b3eb3cSopenharmony_ci    auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
19423b3eb3cSopenharmony_ci    if (!impl || !animatorHandle || !animatorHandle->animator || !option) {
19523b3eb3cSopenharmony_ci        return ERROR_CODE_PARAM_INVALID;
19623b3eb3cSopenharmony_ci    }
19723b3eb3cSopenharmony_ci
19823b3eb3cSopenharmony_ci    auto animatorOption = ConvertAnimatorOption(option);
19923b3eb3cSopenharmony_ci    impl->getAnimation()->animatorReset(animatorHandle->animator, animatorOption);
20023b3eb3cSopenharmony_ci    if (animatorHandle->animatorOption) {
20123b3eb3cSopenharmony_ci        auto* animatorOption = reinterpret_cast<ArkUIAnimatorOption*>(animatorHandle->animatorOption);
20223b3eb3cSopenharmony_ci        if (animatorOption->keyframes) {
20323b3eb3cSopenharmony_ci            delete[] animatorOption->keyframes;
20423b3eb3cSopenharmony_ci            animatorOption->keyframes = nullptr;
20523b3eb3cSopenharmony_ci        }
20623b3eb3cSopenharmony_ci        delete animatorOption;
20723b3eb3cSopenharmony_ci        animatorHandle->animatorOption = nullptr;
20823b3eb3cSopenharmony_ci    }
20923b3eb3cSopenharmony_ci    animatorHandle->animatorOption = animatorOption;
21023b3eb3cSopenharmony_ci    return ERROR_CODE_NO_ERROR;
21123b3eb3cSopenharmony_ci}
21223b3eb3cSopenharmony_ci
21323b3eb3cSopenharmony_ciint32_t AnimatorPlay(ArkUI_AnimatorHandle animatorHandle)
21423b3eb3cSopenharmony_ci{
21523b3eb3cSopenharmony_ci    auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
21623b3eb3cSopenharmony_ci    if (!impl || !animatorHandle || !animatorHandle->animator) {
21723b3eb3cSopenharmony_ci        return ERROR_CODE_PARAM_INVALID;
21823b3eb3cSopenharmony_ci    }
21923b3eb3cSopenharmony_ci    impl->getAnimation()->animatorPlay(animatorHandle->animator);
22023b3eb3cSopenharmony_ci    return ERROR_CODE_NO_ERROR;
22123b3eb3cSopenharmony_ci}
22223b3eb3cSopenharmony_ci
22323b3eb3cSopenharmony_ciint32_t AnimatorFinish(ArkUI_AnimatorHandle animatorHandle)
22423b3eb3cSopenharmony_ci{
22523b3eb3cSopenharmony_ci    auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
22623b3eb3cSopenharmony_ci    if (!impl || !animatorHandle || !animatorHandle->animator) {
22723b3eb3cSopenharmony_ci        return ERROR_CODE_PARAM_INVALID;
22823b3eb3cSopenharmony_ci    }
22923b3eb3cSopenharmony_ci    impl->getAnimation()->animatorFinish(animatorHandle->animator);
23023b3eb3cSopenharmony_ci    return ERROR_CODE_NO_ERROR;
23123b3eb3cSopenharmony_ci}
23223b3eb3cSopenharmony_ci
23323b3eb3cSopenharmony_ciint32_t AnimatorPause(ArkUI_AnimatorHandle animatorHandle)
23423b3eb3cSopenharmony_ci{
23523b3eb3cSopenharmony_ci    auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
23623b3eb3cSopenharmony_ci    if (!impl || !animatorHandle || !animatorHandle->animator) {
23723b3eb3cSopenharmony_ci        return ERROR_CODE_PARAM_INVALID;
23823b3eb3cSopenharmony_ci    }
23923b3eb3cSopenharmony_ci    impl->getAnimation()->animatorPause(animatorHandle->animator);
24023b3eb3cSopenharmony_ci    return ERROR_CODE_NO_ERROR;
24123b3eb3cSopenharmony_ci}
24223b3eb3cSopenharmony_ci
24323b3eb3cSopenharmony_ciint32_t AnimatorCancel(ArkUI_AnimatorHandle animatorHandle)
24423b3eb3cSopenharmony_ci{
24523b3eb3cSopenharmony_ci    auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
24623b3eb3cSopenharmony_ci    if (!impl || !animatorHandle || !animatorHandle->animator) {
24723b3eb3cSopenharmony_ci        return ERROR_CODE_PARAM_INVALID;
24823b3eb3cSopenharmony_ci    }
24923b3eb3cSopenharmony_ci    impl->getAnimation()->animatorCancel(animatorHandle->animator);
25023b3eb3cSopenharmony_ci    return ERROR_CODE_NO_ERROR;
25123b3eb3cSopenharmony_ci}
25223b3eb3cSopenharmony_ci
25323b3eb3cSopenharmony_ciint32_t AnimatorReverse(ArkUI_AnimatorHandle animatorHandle)
25423b3eb3cSopenharmony_ci{
25523b3eb3cSopenharmony_ci    auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
25623b3eb3cSopenharmony_ci    if (!impl || !animatorHandle || !animatorHandle->animator) {
25723b3eb3cSopenharmony_ci        return ERROR_CODE_PARAM_INVALID;
25823b3eb3cSopenharmony_ci    }
25923b3eb3cSopenharmony_ci    impl->getAnimation()->animatorReverse(animatorHandle->animator);
26023b3eb3cSopenharmony_ci    return ERROR_CODE_NO_ERROR;
26123b3eb3cSopenharmony_ci}
26223b3eb3cSopenharmony_ci
26323b3eb3cSopenharmony_ciArkUI_CurveHandle InitCurve(ArkUI_AnimationCurve animationCurve)
26423b3eb3cSopenharmony_ci{
26523b3eb3cSopenharmony_ci    auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
26623b3eb3cSopenharmony_ci    if (!impl) {
26723b3eb3cSopenharmony_ci        return nullptr;
26823b3eb3cSopenharmony_ci    }
26923b3eb3cSopenharmony_ci    auto curve = impl->getAnimation()->initCurve(animationCurve);
27023b3eb3cSopenharmony_ci    ArkUI_Curve* iCurve = new ArkUI_Curve({ ARKUI_CURVE_TYPE_BASE, curve, animationCurve });
27123b3eb3cSopenharmony_ci    return iCurve;
27223b3eb3cSopenharmony_ci}
27323b3eb3cSopenharmony_ci
27423b3eb3cSopenharmony_ciArkUI_CurveHandle StepsCurve(int32_t count, bool end)
27523b3eb3cSopenharmony_ci{
27623b3eb3cSopenharmony_ci    auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
27723b3eb3cSopenharmony_ci    if (!impl || count < 1) {
27823b3eb3cSopenharmony_ci        return nullptr;
27923b3eb3cSopenharmony_ci    }
28023b3eb3cSopenharmony_ci    auto curve = impl->getAnimation()->stepsCurve(count, end);
28123b3eb3cSopenharmony_ci    ArkUI_Curve* iCurve = new ArkUI_Curve({ ARKUI_CURVE_TYPE_STEPS, curve });
28223b3eb3cSopenharmony_ci    return iCurve;
28323b3eb3cSopenharmony_ci}
28423b3eb3cSopenharmony_ci
28523b3eb3cSopenharmony_ciArkUI_CurveHandle CubicBezierCurve(float x1, float y1, float x2, float y2)
28623b3eb3cSopenharmony_ci{
28723b3eb3cSopenharmony_ci    auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
28823b3eb3cSopenharmony_ci    if (!impl) {
28923b3eb3cSopenharmony_ci        return nullptr;
29023b3eb3cSopenharmony_ci    }
29123b3eb3cSopenharmony_ci    x1 = std::clamp(x1, 0.0f, 1.0f);
29223b3eb3cSopenharmony_ci    x2 = std::clamp(x2, 0.0f, 1.0f);
29323b3eb3cSopenharmony_ci    auto curve = impl->getAnimation()->cubicBezierCurve(x1, y1, x2, y2);
29423b3eb3cSopenharmony_ci    ArkUI_Curve* iCurve = new ArkUI_Curve({ ARKUI_CURVE_TYPE_CUBIC_BEZIER, curve });
29523b3eb3cSopenharmony_ci    return iCurve;
29623b3eb3cSopenharmony_ci}
29723b3eb3cSopenharmony_ci
29823b3eb3cSopenharmony_ciArkUI_CurveHandle SpringCurve(float velocity, float mass, float stiffness, float damping)
29923b3eb3cSopenharmony_ci{
30023b3eb3cSopenharmony_ci    auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
30123b3eb3cSopenharmony_ci    if (!impl) {
30223b3eb3cSopenharmony_ci        return nullptr;
30323b3eb3cSopenharmony_ci    }
30423b3eb3cSopenharmony_ci    if (mass <= 0) {
30523b3eb3cSopenharmony_ci        mass = 1;
30623b3eb3cSopenharmony_ci    }
30723b3eb3cSopenharmony_ci    if (stiffness <= 0) {
30823b3eb3cSopenharmony_ci        stiffness = 1;
30923b3eb3cSopenharmony_ci    }
31023b3eb3cSopenharmony_ci    if (damping <= 0) {
31123b3eb3cSopenharmony_ci        damping = 1;
31223b3eb3cSopenharmony_ci    }
31323b3eb3cSopenharmony_ci    auto curve = impl->getAnimation()->springCurve(velocity, mass, stiffness, damping);
31423b3eb3cSopenharmony_ci    ArkUI_Curve* iCurve = new ArkUI_Curve({ ARKUI_CURVE_TYPE_SPRING, curve });
31523b3eb3cSopenharmony_ci    return iCurve;
31623b3eb3cSopenharmony_ci}
31723b3eb3cSopenharmony_ci
31823b3eb3cSopenharmony_ciArkUI_CurveHandle SpringMotion(float response, float dampingFraction, float overlapDuration)
31923b3eb3cSopenharmony_ci{
32023b3eb3cSopenharmony_ci    auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
32123b3eb3cSopenharmony_ci    if (!impl) {
32223b3eb3cSopenharmony_ci        return nullptr;
32323b3eb3cSopenharmony_ci    }
32423b3eb3cSopenharmony_ci    //default
32523b3eb3cSopenharmony_ci    if (response <= 0) {
32623b3eb3cSopenharmony_ci        response = 0.55f;
32723b3eb3cSopenharmony_ci    }
32823b3eb3cSopenharmony_ci    //default
32923b3eb3cSopenharmony_ci    if (dampingFraction <= 0) {
33023b3eb3cSopenharmony_ci        dampingFraction = 0.825f;
33123b3eb3cSopenharmony_ci    }
33223b3eb3cSopenharmony_ci    //default
33323b3eb3cSopenharmony_ci    if (overlapDuration < 0) {
33423b3eb3cSopenharmony_ci        overlapDuration = 0;
33523b3eb3cSopenharmony_ci    }
33623b3eb3cSopenharmony_ci    auto curve = impl->getAnimation()->springMotion(response, dampingFraction, overlapDuration);
33723b3eb3cSopenharmony_ci    ArkUI_Curve* iCurve = new ArkUI_Curve({ ARKUI_CURVE_TYPE_SPRING_MOTION, curve });
33823b3eb3cSopenharmony_ci    return iCurve;
33923b3eb3cSopenharmony_ci}
34023b3eb3cSopenharmony_ci
34123b3eb3cSopenharmony_ciArkUI_CurveHandle ResponsiveSpringMotion(float response, float dampingFraction, float overlapDuration)
34223b3eb3cSopenharmony_ci{
34323b3eb3cSopenharmony_ci    auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
34423b3eb3cSopenharmony_ci    if (!impl) {
34523b3eb3cSopenharmony_ci        return nullptr;
34623b3eb3cSopenharmony_ci    }
34723b3eb3cSopenharmony_ci    //default
34823b3eb3cSopenharmony_ci    if (response <= 0) {
34923b3eb3cSopenharmony_ci        response = 0.15f;
35023b3eb3cSopenharmony_ci    }
35123b3eb3cSopenharmony_ci    //default
35223b3eb3cSopenharmony_ci    if (dampingFraction < 0) {
35323b3eb3cSopenharmony_ci        dampingFraction = 0.86f;
35423b3eb3cSopenharmony_ci    }
35523b3eb3cSopenharmony_ci    //default
35623b3eb3cSopenharmony_ci    if (overlapDuration < 0) {
35723b3eb3cSopenharmony_ci        overlapDuration = 0.25f;
35823b3eb3cSopenharmony_ci    }
35923b3eb3cSopenharmony_ci    auto curve = impl->getAnimation()->responsiveSpringMotion(response, dampingFraction, overlapDuration);
36023b3eb3cSopenharmony_ci    ArkUI_Curve* iCurve = new ArkUI_Curve({ ARKUI_CURVE_TYPE_RESPONSIVE_SPRING_MOTION, curve });
36123b3eb3cSopenharmony_ci    return iCurve;
36223b3eb3cSopenharmony_ci}
36323b3eb3cSopenharmony_ci
36423b3eb3cSopenharmony_ciArkUI_CurveHandle InterpolatingSpring(float velocity, float mass, float stiffness, float damping)
36523b3eb3cSopenharmony_ci{
36623b3eb3cSopenharmony_ci    auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
36723b3eb3cSopenharmony_ci    if (!impl) {
36823b3eb3cSopenharmony_ci        return nullptr;
36923b3eb3cSopenharmony_ci    }
37023b3eb3cSopenharmony_ci    if (mass <= 0) {
37123b3eb3cSopenharmony_ci        mass = 1;
37223b3eb3cSopenharmony_ci    }
37323b3eb3cSopenharmony_ci    if (stiffness <= 0) {
37423b3eb3cSopenharmony_ci        stiffness = 1;
37523b3eb3cSopenharmony_ci    }
37623b3eb3cSopenharmony_ci    if (damping <= 0) {
37723b3eb3cSopenharmony_ci        damping = 1;
37823b3eb3cSopenharmony_ci    }
37923b3eb3cSopenharmony_ci    auto curve = impl->getAnimation()->interpolatingSpring(velocity, mass, stiffness, damping);
38023b3eb3cSopenharmony_ci    ArkUI_Curve* iCurve = new ArkUI_Curve({ ARKUI_CURVE_TYPE_INTERPOLATING_SPRING, curve });
38123b3eb3cSopenharmony_ci    return iCurve;
38223b3eb3cSopenharmony_ci}
38323b3eb3cSopenharmony_ci
38423b3eb3cSopenharmony_ciArkUI_CurveHandle CustomCurve(void* userData, float (*interpolate)(float fraction, void* userdata))
38523b3eb3cSopenharmony_ci{
38623b3eb3cSopenharmony_ci    auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
38723b3eb3cSopenharmony_ci    if (!impl) {
38823b3eb3cSopenharmony_ci        return nullptr;
38923b3eb3cSopenharmony_ci    }
39023b3eb3cSopenharmony_ci    auto curve = impl->getAnimation()->customCurve(interpolate, userData);
39123b3eb3cSopenharmony_ci    ArkUI_Curve* iCurve = new ArkUI_Curve({ ARKUI_CURVE_TYPE_CUSTOM, curve });
39223b3eb3cSopenharmony_ci    return iCurve;
39323b3eb3cSopenharmony_ci}
39423b3eb3cSopenharmony_ci
39523b3eb3cSopenharmony_civoid DisposeCurve(ArkUI_CurveHandle curveHandle)
39623b3eb3cSopenharmony_ci{
39723b3eb3cSopenharmony_ci    auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
39823b3eb3cSopenharmony_ci    if (!impl || !curveHandle) {
39923b3eb3cSopenharmony_ci        return;
40023b3eb3cSopenharmony_ci    }
40123b3eb3cSopenharmony_ci    impl->getAnimation()->disposeCurve(curveHandle->curve);
40223b3eb3cSopenharmony_ci    delete curveHandle;
40323b3eb3cSopenharmony_ci}
40423b3eb3cSopenharmony_ci} // namespace OHOS::Ace::AnimateModel