1 /*
2 * Copyright (c) 2021-2022 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_blank.h"
17
18 #include "core/components/box/box_component.h"
19 #include "core/components_ng/pattern/blank/blank_view.h"
20 #include "frameworks/bridge/declarative_frontend/view_stack_processor.h"
21 namespace OHOS::Ace::Framework {
Create(const JSCallbackInfo & info)22 void JSBlank::Create(const JSCallbackInfo& info)
23 {
24 if (Container::IsCurrentUseNewPipeline()) {
25 Dimension blankMin;
26 NG::BlankView::Create();
27 if (info.Length() >= 1 && ParseJsDimensionVp(info[0], blankMin)) {
28 NG::BlankView::SetBlankMin(blankMin.IsValid() ? blankMin : Dimension());
29 }
30 return;
31 }
32 auto specializedBox = AceType::MakeRefPtr<OHOS::Ace::BoxComponent>();
33 // specialized component should be firstly pushed.
34 ViewStackProcessor::GetInstance()->ClaimElementId(specializedBox);
35 ViewStackProcessor::GetInstance()->Push(specializedBox);
36 // Blank fill the remain space.
37 auto flexItem = ViewStackProcessor::GetInstance()->GetFlexItemComponent();
38 flexItem->SetFlexGrow(1);
39 flexItem->SetFlexShrink(0);
40 flexItem->SetMustStretch(true);
41
42 Dimension flexBasis;
43 if (info.Length() >= 1 && ParseJsDimensionVp(info[0], flexBasis)) {
44 flexItem->SetFlexBasis(flexBasis.IsValid() ? flexBasis : Dimension());
45 }
46 }
47
Height(const JSCallbackInfo & info)48 void JSBlank::Height(const JSCallbackInfo& info)
49 {
50 JSViewAbstract::JsHeight(info);
51 Dimension value;
52 if (!ParseJsDimensionVp(info[0], value)) {
53 return;
54 }
55 if (Container::IsCurrentUseNewPipeline()) {
56 NG::BlankView::SetHeight(value);
57 return;
58 }
59 auto flexItem = ViewStackProcessor::GetInstance()->GetFlexItemComponent();
60 if (value > flexItem->GetFlexBasis()) {
61 flexItem->SetFlexBasis(value);
62 }
63 }
64
JSBind(BindingTarget globalObj)65 void JSBlank::JSBind(BindingTarget globalObj)
66 {
67 JSClass<JSBlank>::Declare("Blank");
68 MethodOptions opt = MethodOptions::NONE;
69 JSClass<JSBlank>::StaticMethod("create", &JSBlank::Create, opt);
70 JSClass<JSBlank>::StaticMethod("height", &JSBlank::Height, opt);
71 JSClass<JSBlank>::StaticMethod("color", &JSViewAbstract::JsBackgroundColor, opt);
72 JSClass<JSBlank>::StaticMethod("onAppear", &JSInteractableView::JsOnAppear);
73 JSClass<JSBlank>::StaticMethod("onDisAppear", &JSInteractableView::JsOnDisAppear);
74 JSClass<JSBlank>::StaticMethod("onTouch", &JSInteractableView::JsOnTouch);
75 JSClass<JSBlank>::StaticMethod("onHover", &JSInteractableView::JsOnHover);
76 JSClass<JSBlank>::StaticMethod("onKeyEvent", &JSInteractableView::JsOnKey);
77 JSClass<JSBlank>::StaticMethod("onDeleteEvent", &JSInteractableView::JsOnDelete);
78 JSClass<JSBlank>::StaticMethod("onClick", &JSInteractableView::JsOnClick);
79 JSClass<JSBlank>::StaticMethod("remoteMessage", &JSInteractableView::JsCommonRemoteMessage);
80
81 JSClass<JSBlank>::Inherit<JSViewAbstract>();
82 JSClass<JSBlank>::Bind<>(globalObj);
83 }
84 } // namespace OHOS::Ace::Framework
85