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 #include "frameworks/bridge/declarative_frontend/jsview/js_list_item.h"
17 using namespace OHOS::Ace::Framework;
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 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
30
31 bool selected = false;
32 if (secondArg->IsBoolean()) {
33 selected = secondArg->ToBoolean(vm)->Value();
34 }
35 GetArkUINodeModifiers()->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 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
46 GetArkUINodeModifiers()->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 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
57 if (!secondArg->IsUndefined() && secondArg->IsBoolean()) {
58 bool selectable = secondArg->ToBoolean(vm)->Value();
59 GetArkUINodeModifiers()->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 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
71 GetArkUINodeModifiers()->getListItemModifier()->resetSelectable(nativeNode);
72 return panda::JSValueRef::Undefined(vm);
73 }
74
SetSwipeAction(ArkUIRuntimeCallInfo * runtimeCallInfo)75 ArkUINativeModuleValue ListItemBridge::SetSwipeAction(ArkUIRuntimeCallInfo* runtimeCallInfo)
76 {
77 EcmaVM* vm = runtimeCallInfo->GetVM();
78 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
79 Framework::JsiCallbackInfo info = Framework::JsiCallbackInfo(runtimeCallInfo);
80 // 2: argument count.
81 if (info.Length() != 2 || !(info[1]->IsObject())) {
82 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
83 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
84 GetArkUINodeModifiers()->getListItemModifier()->resetListItemSwipeAction(nativeNode);
85 return panda::JSValueRef::Undefined(vm);
86 }
87 JSListItem::ParseSwiperAction(Framework::JSRef<Framework::JSObject>::Cast(info[1]), info.GetExecutionContext());
88
89 return panda::JSValueRef::Undefined(vm);
90 }
91
ResetSwipeAction(ArkUIRuntimeCallInfo * runtimeCallInfo)92 ArkUINativeModuleValue ListItemBridge::ResetSwipeAction(ArkUIRuntimeCallInfo* runtimeCallInfo)
93 {
94 EcmaVM* vm = runtimeCallInfo->GetVM();
95 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
96 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
97 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
98 GetArkUINodeModifiers()->getListItemModifier()->resetListItemSwipeAction(nativeNode);
99 return panda::JSValueRef::Undefined(vm);
100 }
101 } // namespace OHOS::Ace::NG