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/cj_frontend/interfaces/cj_ffi/cj_scrollbar_ffi.h"
17 
18 #include "utils.h"
19 
20 #include "base/memory/ace_type.h"
21 #include "bridge/cj_frontend/interfaces/cj_ffi/cj_scroll_ffi.h"
22 #include "core/common/container.h"
23 #include "core/components_ng/pattern/scroll_bar/scroll_bar_pattern.h"
24 #include "core/components_ng/pattern/scroll_bar/scroll_bar_model_ng.h"
25 #include "core/components_ng/pattern/scroll_bar/scroll_bar_model.h"
26 #include "cj_lambda.h"
27 
28 using namespace OHOS::Ace;
29 using namespace OHOS::FFI;
30 using namespace OHOS::Ace::Framework;
31 
32 namespace {
33 const std::vector<Axis> AXIS = { Axis::VERTICAL, Axis::HORIZONTAL };
34 const std::vector<DisplayMode> DISPLAY_MODE = { DisplayMode::OFF, DisplayMode::AUTO, DisplayMode::ON };
35 } // namespace
36 
37 extern "C" {
FfiOHOSAceFrameworkScrollBarCreate(int64_t scrollerID,int32_t direction,int32_t state)38 void FfiOHOSAceFrameworkScrollBarCreate(int64_t scrollerID, int32_t direction, int32_t state)
39 {
40     if (!Utils::CheckParamsValid(direction, AXIS.size())) {
41         LOGE("invalid value for DisplayMode");
42         return;
43     }
44     if (!Utils::CheckParamsValid(state, DISPLAY_MODE.size())) {
45         LOGE("invalid value for DisplayMode");
46         return;
47     }
48     auto scroller = FFIData::GetData<NativeNGScroller>(scrollerID);
49     if (scroller == nullptr) {
50         LOGE("invalid id to create Scroller");
51         return;
52     }
53     auto scrollBarProxy = AceType::DynamicCast<NG::ScrollBarProxy>(scroller->GetScrollBarProxy());
54 
55     bool infoflag = true;
56     bool proxyFlag = true;
57     auto proxy = ScrollBarModel::GetInstance()->GetScrollBarProxy(scrollBarProxy);
58 
59     ScrollBarModel::GetInstance()->Create(proxy, infoflag, proxyFlag, direction, state);
60 }
61 }
62