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_list_item_bridge.h"
16
17 #include "core/interfaces/native/node/api.h"
18
19 namespace OHOS::Ace::NG {
20 constexpr int32_t NUM_0 = 0;
21 constexpr int32_t NUM_1 = 1;
22
SetListItemSelected(ArkUIRuntimeCallInfo * runtimeCallInfo)23 ArkUINativeModuleValue ListItemBridge::SetListItemSelected(ArkUIRuntimeCallInfo* runtimeCallInfo)
24 {
25 EcmaVM* vm = runtimeCallInfo->GetVM();
26 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
27 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
28 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
29 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
30
31 bool selected = false;
32 if (secondArg->IsBoolean()) {
33 selected = secondArg->ToBoolean(vm)->Value();
34 }
35 GetArkUIInternalNodeAPI()->GetListItemModifier().SetListItemSelected(nativeNode, selected);
36
37 return panda::JSValueRef::Undefined(vm);
38 }
39
ResetListItemSelected(ArkUIRuntimeCallInfo * runtimeCallInfo)40 ArkUINativeModuleValue ListItemBridge::ResetListItemSelected(ArkUIRuntimeCallInfo* runtimeCallInfo)
41 {
42 EcmaVM* vm = runtimeCallInfo->GetVM();
43 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
44 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
45 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
46 GetArkUIInternalNodeAPI()->GetListItemModifier().ResetListItemSelected(nativeNode);
47 return panda::JSValueRef::Undefined(vm);
48 }
49
SetSelectable(ArkUIRuntimeCallInfo * runtimeCallInfo)50 ArkUINativeModuleValue ListItemBridge::SetSelectable(ArkUIRuntimeCallInfo* runtimeCallInfo)
51 {
52 EcmaVM* vm = runtimeCallInfo->GetVM();
53 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
54 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
55 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
56 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
57 if (!secondArg->IsUndefined() && secondArg->IsBoolean()) {
58 bool selectable = secondArg->ToBoolean(vm)->Value();
59 GetArkUIInternalNodeAPI()->GetListItemModifier().SetSelectable(nativeNode, selectable);
60 }
61
62 return panda::JSValueRef::Undefined(vm);
63 }
64
ResetSelectable(ArkUIRuntimeCallInfo * runtimeCallInfo)65 ArkUINativeModuleValue ListItemBridge::ResetSelectable(ArkUIRuntimeCallInfo* runtimeCallInfo)
66 {
67 EcmaVM* vm = runtimeCallInfo->GetVM();
68 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
69 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
70 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
71 GetArkUIInternalNodeAPI()->GetListItemModifier().ResetSelectable(nativeNode);
72 return panda::JSValueRef::Undefined(vm);
73 }
74
75 } // namespace OHOS::Ace::NG