1 /*
2 * Copyright (c) 2023 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 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_path_bridge.h"
16 #include "frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h"
17
18 namespace OHOS::Ace::NG {
SetPathCommands(ArkUIRuntimeCallInfo * runtimeCallInfo)19 ArkUINativeModuleValue PathBridge::SetPathCommands(ArkUIRuntimeCallInfo* runtimeCallInfo)
20 {
21 EcmaVM* vm = runtimeCallInfo->GetVM();
22 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
23 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
24 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
25 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
26
27 if (!secondArg->IsString(vm) && !secondArg->IsObject(vm)) {
28 GetArkUINodeModifiers()->getPathModifier()->resetPathCommands(nativeNode);
29 return panda::JSValueRef::Undefined(vm);
30 }
31
32 std::string commands;
33 RefPtr<ResourceObject> resObj;
34 if (secondArg->IsString(vm)) {
35 commands = secondArg->ToString(vm)->ToString(vm);
36 } else if (secondArg->IsObject(vm)) {
37 ArkTSUtils::ParseJsStringFromResource(vm, secondArg, commands, resObj);
38 }
39 GetArkUINodeModifiers()->getPathModifier()->setPathCommands(nativeNode, commands.c_str(), AceType::RawPtr(resObj));
40 return panda::JSValueRef::Undefined(vm);
41 }
42
ResetPathCommands(ArkUIRuntimeCallInfo * runtimeCallInfo)43 ArkUINativeModuleValue PathBridge::ResetPathCommands(ArkUIRuntimeCallInfo* runtimeCallInfo)
44 {
45 EcmaVM* vm = runtimeCallInfo->GetVM();
46 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
47 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
48 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
49 GetArkUINodeModifiers()->getPathModifier()->resetPathCommands(nativeNode);
50 return panda::JSValueRef::Undefined(vm);
51 }
52 }
53