• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "frameworks/bridge/declarative_frontend/jsview/js_lazy_grid.h"
17 
18 #include "frameworks/bridge/declarative_frontend/jsview/js_view_common_def.h"
19 #include "frameworks/core/components_ng/pattern/lazy_layout/grid_layout/lazy_grid_layout_model.h"
20 
21 namespace OHOS::Ace::Framework {
Create()22 void JSLazyVGridLayout::Create()
23 {
24     NG::LazyVGridLayoutModel::Create();
25 }
26 
JsRowsGap(const JSCallbackInfo & info)27 void JSLazyVGridLayout::JsRowsGap(const JSCallbackInfo& info)
28 {
29     if (info.Length() < 1) {
30         return;
31     }
32     CalcDimension rowGap;
33     if (!ParseLengthMetricsToDimension(info[0], rowGap) || rowGap.Value() < 0) {
34         rowGap.SetValue(0.0);
35     }
36     NG::LazyGridLayoutModel::SetRowGap(rowGap);
37 }
38 
JsColumnsGap(const JSCallbackInfo & info)39 void JSLazyVGridLayout::JsColumnsGap(const JSCallbackInfo& info)
40 {
41     if (info.Length() < 1) {
42         return;
43     }
44     CalcDimension colGap;
45     if (!ParseLengthMetricsToDimension(info[0], colGap) || colGap.Value() < 0) {
46         colGap.SetValue(0.0);
47     }
48     NG::LazyGridLayoutModel::SetColumnGap(colGap);
49 }
50 
JsColumnsTemplate(const std::string & value)51 void JSLazyVGridLayout::JsColumnsTemplate(const std::string& value)
52 {
53     NG::LazyVGridLayoutModel::SetColumnsTemplate(value);
54 }
55 
JSBind(BindingTarget globalObj)56 void JSLazyVGridLayout::JSBind(BindingTarget globalObj)
57 {
58     JSClass<JSLazyVGridLayout>::Declare("LazyVGridLayout");
59 
60     MethodOptions opt = MethodOptions::NONE;
61     JSClass<JSLazyVGridLayout>::StaticMethod("create", &JSLazyVGridLayout::Create, opt);
62     JSClass<JSLazyVGridLayout>::StaticMethod("rowsGap", &JSLazyVGridLayout::JsRowsGap, opt);
63     JSClass<JSLazyVGridLayout>::StaticMethod("columnsGap", &JSLazyVGridLayout::JsColumnsGap, opt);
64     JSClass<JSLazyVGridLayout>::StaticMethod("columnsTemplate", &JSLazyVGridLayout::JsColumnsTemplate, opt);
65 
66     JSClass<JSLazyVGridLayout>::StaticMethod("onClick", &JSInteractableView::JsOnClick);
67     JSClass<JSLazyVGridLayout>::StaticMethod("onTouch", &JSInteractableView::JsOnTouch);
68     JSClass<JSLazyVGridLayout>::StaticMethod("onHover", &JSInteractableView::JsOnHover);
69     JSClass<JSLazyVGridLayout>::StaticMethod("onKeyEvent", &JSInteractableView::JsOnKey);
70     JSClass<JSLazyVGridLayout>::StaticMethod("onDeleteEvent", &JSInteractableView::JsOnDelete);
71     JSClass<JSLazyVGridLayout>::StaticMethod("onAttach", &JSInteractableView::JsOnAttach);
72     JSClass<JSLazyVGridLayout>::StaticMethod("onAppear", &JSInteractableView::JsOnAppear);
73     JSClass<JSLazyVGridLayout>::StaticMethod("onDetach", &JSInteractableView::JsOnDetach);
74     JSClass<JSLazyVGridLayout>::StaticMethod("onDisAppear", &JSInteractableView::JsOnDisAppear);
75     JSClass<JSLazyVGridLayout>::StaticMethod("remoteMessage", &JSInteractableView::JsCommonRemoteMessage);
76 
77     JSClass<JSLazyVGridLayout>::InheritAndBind<JSContainerBase>(globalObj);
78 }
79 } // namespace OHOS::Ace::Framework
80