diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/modules/jsi_curves_module.cpp b/frameworks/bridge/declarative_frontend/engine/jsi/modules/jsi_curves_module.cpp index 0b7a98c28c6dea9f5a173c29268d29b45e9929f7..bfeb33f1df6244ec4942ced250a8550442ed19d6 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/modules/jsi_curves_module.cpp +++ b/frameworks/bridge/declarative_frontend/engine/jsi/modules/jsi_curves_module.cpp @@ -120,9 +120,9 @@ bool CreateStepsCurve(const shared_ptr& runtime, const shared_ptrToInt32(runtime); bool isEnd = argv[1]->ToBoolean(runtime); if (isEnd) { - curve = AceType::MakeRefPtr(stepSize, StepsCurvePosition::START); - } else { curve = AceType::MakeRefPtr(stepSize, StepsCurvePosition::END); + } else { + curve = AceType::MakeRefPtr(stepSize, StepsCurvePosition::START); } } else { stepSize = argv[0]->ToInt32(runtime); diff --git a/frameworks/bridge/declarative_frontend/engine/v8/v8_module_manager.cpp b/frameworks/bridge/declarative_frontend/engine/v8/v8_module_manager.cpp index d2b8ed774f516cfb01da40752b2f9be2f2c30bf5..82f007374f9029395f8fccde8f5c77b19289f39b 100644 --- a/frameworks/bridge/declarative_frontend/engine/v8/v8_module_manager.cpp +++ b/frameworks/bridge/declarative_frontend/engine/v8/v8_module_manager.cpp @@ -538,6 +538,49 @@ void CurvesSpring(const v8::FunctionCallbackInfo& args) ParseCurves(args, curveString); } +void CurvesSteps(const v8::FunctionCallbackInfo& args) +{ + int32_t STEPS_ARGS_NUMBER = 2; + auto argc = args.Length(); + if (argc != 1 && argc != STEPS_ARGS_NUMBER) { + LOGE("Steps curve: the number of parameters is illegal"); + return; + } + v8::Isolate* isolate = args.GetIsolate(); + v8::HandleScope handleScope(isolate); + auto context = isolate->GetCurrentContext(); + auto curveContext = v8::Object::New(isolate); + curveContext->Set(context, v8::String::NewFromUtf8(isolate, "interpolate").ToLocalChecked(), + v8::Function::New(context, CurvesInterpolate).ToLocalChecked()).ToChecked(); + RefPtr curve; + int32_t stepSize = 0; + if (argc == STEPS_ARGS_NUMBER) { + stepSize = args[0]->ToInt32(context).ToLocalChecked()->Value(); + bool isEnd = args[1]->ToBoolean(isolate)->Value(); + if (isEnd) { + curve = AceType::MakeRefPtr(stepSize, StepsCurvePosition::END); + } else { + curve = AceType::MakeRefPtr(stepSize, StepsCurvePosition::START); + } + } else { + stepSize = args[0]->ToInt32(context).ToLocalChecked()->Value(); + curve = AceType::MakeRefPtr(stepSize); + } + + auto page = static_cast*>(isolate->GetData(V8DeclarativeEngineInstance::STAGING_PAGE)); + if ((*page) == nullptr) { + LOGE("page is nullptr"); + return; + } + (*page)->AddCurve(curve->ToString(), curve); + int32_t pageId = (*page)->GetPageId(); + curveContext->Set(context, v8::String::NewFromUtf8(isolate, "__pageId").ToLocalChecked(), + v8::Int32::New(isolate, pageId)).ToChecked(); + curveContext->Set(context, v8::String::NewFromUtf8(isolate, "__curveString").ToLocalChecked(), + v8::String::NewFromUtf8(isolate, curve->ToString().c_str()).ToLocalChecked()).ToChecked(); + args.GetReturnValue().Set(curveContext); +} + void InitCurvesModule(v8::Local moduleObj, v8::Isolate* isolate) { auto context = isolate->GetCurrentContext(); @@ -546,11 +589,13 @@ void InitCurvesModule(v8::Local moduleObj, v8::Isolate* isolate) return; } moduleObj->Set(context, v8::String::NewFromUtf8(isolate, "init").ToLocalChecked(), - v8::Function::New(context, CurvesInit).ToLocalChecked()).ToChecked(); + v8::Function::New(context, CurvesInit).ToLocalChecked()).ToChecked(); moduleObj->Set(context, v8::String::NewFromUtf8(isolate, "cubicBezier").ToLocalChecked(), - v8::Function::New(context, CurvesBezier).ToLocalChecked()).ToChecked(); + v8::Function::New(context, CurvesBezier).ToLocalChecked()).ToChecked(); moduleObj->Set(context, v8::String::NewFromUtf8(isolate, "spring").ToLocalChecked(), - v8::Function::New(context, CurvesSpring).ToLocalChecked()).ToChecked(); + v8::Function::New(context, CurvesSpring).ToLocalChecked()).ToChecked(); + moduleObj->Set(context, v8::String::NewFromUtf8(isolate, "steps").ToLocalChecked(), + v8::Function::New(context, CurvesSteps).ToLocalChecked()).ToChecked(); } void InitMatrix(v8::Local moduleObj, v8::Isolate* isolate)