1 /*
2 * Copyright (c) 2024 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
16 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_scrollbar_bridge.h"
17
18 #include "base/log/log.h"
19 #include "base/utils/string_utils.h"
20 #include "base/utils/utils.h"
21 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_scrollbar_bridge.h"
22 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h"
23 #include "bridge/declarative_frontend/jsview/scroll_bar/js_scroll_bar.h"
24 #include "core/components_ng/pattern/scroll_bar/scroll_bar_model_ng.h"
25
26 namespace OHOS::Ace::NG {
SetScrollBarEnableNestedScroll(ArkUIRuntimeCallInfo * runtimeCallInfo)27 ArkUINativeModuleValue ScrollBarBridge::SetScrollBarEnableNestedScroll(ArkUIRuntimeCallInfo* runtimeCallInfo)
28 {
29 EcmaVM* vm = runtimeCallInfo->GetVM();
30 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
31 Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(0);
32 Local<JSValueRef> enablePagingArg = runtimeCallInfo->GetCallArgRef(1);
33 CHECK_NULL_RETURN(nativeNodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
34 auto nativeNode = nodePtr(nativeNodeArg->ToNativePointer(vm)->Value());
35 if (enablePagingArg->IsBoolean()) {
36 bool enablePaging = enablePagingArg->ToBoolean(vm)->Value();
37 GetArkUINodeModifiers()->getScrollBarModifier()->setScrollBarEnableNestedScroll(nativeNode, enablePaging);
38 }
39 return panda::JSValueRef::Undefined(vm);
40 }
41
ResetScrollBarEnableNestedScroll(ArkUIRuntimeCallInfo * runtimeCallInfo)42 ArkUINativeModuleValue ScrollBarBridge::ResetScrollBarEnableNestedScroll(ArkUIRuntimeCallInfo* runtimeCallInfo)
43 {
44 EcmaVM* vm = runtimeCallInfo->GetVM();
45 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
46 Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(0);
47 CHECK_NULL_RETURN(nativeNodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
48 auto nativeNode = nodePtr(nativeNodeArg->ToNativePointer(vm)->Value());
49 GetArkUINodeModifiers()->getScrollBarModifier()->resetScrollBarEnableNestedScroll(nativeNode);
50 return panda::JSValueRef::Undefined(vm);
51 }
52 } // namespace OHOS::Ace::NG