• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
30     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
31 
32     bool selected = false;
33     if (secondArg->IsBoolean()) {
34         selected = secondArg->ToBoolean(vm)->Value();
35     }
36     GetArkUINodeModifiers()->getListItemModifier()->setListItemSelected(nativeNode, selected);
37 
38     return panda::JSValueRef::Undefined(vm);
39 }
40 
ResetListItemSelected(ArkUIRuntimeCallInfo * runtimeCallInfo)41 ArkUINativeModuleValue ListItemBridge::ResetListItemSelected(ArkUIRuntimeCallInfo* runtimeCallInfo)
42 {
43     EcmaVM* vm = runtimeCallInfo->GetVM();
44     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
45     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
46     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
47     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
48     GetArkUINodeModifiers()->getListItemModifier()->resetListItemSelected(nativeNode);
49     return panda::JSValueRef::Undefined(vm);
50 }
51 
SetSelectable(ArkUIRuntimeCallInfo * runtimeCallInfo)52 ArkUINativeModuleValue ListItemBridge::SetSelectable(ArkUIRuntimeCallInfo* runtimeCallInfo)
53 {
54     EcmaVM* vm = runtimeCallInfo->GetVM();
55     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
56     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
57     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
58     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
59     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
60     if (!secondArg->IsUndefined() && secondArg->IsBoolean()) {
61         bool selectable = secondArg->ToBoolean(vm)->Value();
62         GetArkUINodeModifiers()->getListItemModifier()->setSelectable(nativeNode, selectable);
63     }
64 
65     return panda::JSValueRef::Undefined(vm);
66 }
67 
ResetSelectable(ArkUIRuntimeCallInfo * runtimeCallInfo)68 ArkUINativeModuleValue ListItemBridge::ResetSelectable(ArkUIRuntimeCallInfo* runtimeCallInfo)
69 {
70     EcmaVM* vm = runtimeCallInfo->GetVM();
71     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
72     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
73     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
74     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
75     GetArkUINodeModifiers()->getListItemModifier()->resetSelectable(nativeNode);
76     return panda::JSValueRef::Undefined(vm);
77 }
78 
SetSwipeAction(ArkUIRuntimeCallInfo * runtimeCallInfo)79 ArkUINativeModuleValue ListItemBridge::SetSwipeAction(ArkUIRuntimeCallInfo* runtimeCallInfo)
80 {
81     EcmaVM* vm = runtimeCallInfo->GetVM();
82     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
83     Framework::JsiCallbackInfo info = Framework::JsiCallbackInfo(runtimeCallInfo);
84     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
85     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
86     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
87     auto frameNode = reinterpret_cast<FrameNode*>(nativeNode);
88     CHECK_NULL_RETURN(frameNode, panda::NativePointerRef::New(vm, nullptr));
89     // 2: argument count.
90     if (info.Length() != 2 || !(info[1]->IsObject())) {
91         GetArkUINodeModifiers()->getListItemModifier()->resetListItemSwipeAction(nativeNode);
92         return panda::JSValueRef::Undefined(vm);
93     }
94     JSListItem::ParseSwiperAction(Framework::JSRef<Framework::JSObject>::Cast(info[1]),
95         info.GetExecutionContext(), frameNode);
96 
97     return panda::JSValueRef::Undefined(vm);
98 }
99 
ResetSwipeAction(ArkUIRuntimeCallInfo * runtimeCallInfo)100 ArkUINativeModuleValue ListItemBridge::ResetSwipeAction(ArkUIRuntimeCallInfo* runtimeCallInfo)
101 {
102     EcmaVM* vm = runtimeCallInfo->GetVM();
103     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
104     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
105     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
106     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
107     GetArkUINodeModifiers()->getListItemModifier()->resetListItemSwipeAction(nativeNode);
108     return panda::JSValueRef::Undefined(vm);
109 }
110 } // namespace OHOS::Ace::NG