/* * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "frameworks/bridge/declarative_frontend/jsview/js_blank.h" #include "core/components/box/box_component.h" #include "core/components_ng/pattern/blank/blank_view.h" #include "frameworks/bridge/declarative_frontend/view_stack_processor.h" namespace OHOS::Ace::Framework { void JSBlank::Create(const JSCallbackInfo& info) { if (Container::IsCurrentUseNewPipeline()) { Dimension blankMin; NG::BlankView::Create(); if (info.Length() >= 1 && ParseJsDimensionVp(info[0], blankMin)) { NG::BlankView::SetBlankMin(blankMin.IsValid() ? blankMin : Dimension()); } return; } auto specializedBox = AceType::MakeRefPtr(); // specialized component should be firstly pushed. ViewStackProcessor::GetInstance()->ClaimElementId(specializedBox); ViewStackProcessor::GetInstance()->Push(specializedBox); // Blank fill the remain space. auto flexItem = ViewStackProcessor::GetInstance()->GetFlexItemComponent(); flexItem->SetFlexGrow(1); flexItem->SetFlexShrink(0); flexItem->SetMustStretch(true); Dimension flexBasis; if (info.Length() >= 1 && ParseJsDimensionVp(info[0], flexBasis)) { flexItem->SetFlexBasis(flexBasis.IsValid() ? flexBasis : Dimension()); } } void JSBlank::Height(const JSCallbackInfo& info) { JSViewAbstract::JsHeight(info); Dimension value; if (!ParseJsDimensionVp(info[0], value)) { return; } if (Container::IsCurrentUseNewPipeline()) { NG::BlankView::SetHeight(value); return; } auto flexItem = ViewStackProcessor::GetInstance()->GetFlexItemComponent(); if (value > flexItem->GetFlexBasis()) { flexItem->SetFlexBasis(value); } } void JSBlank::JSBind(BindingTarget globalObj) { JSClass::Declare("Blank"); MethodOptions opt = MethodOptions::NONE; JSClass::StaticMethod("create", &JSBlank::Create, opt); JSClass::StaticMethod("height", &JSBlank::Height, opt); JSClass::StaticMethod("color", &JSViewAbstract::JsBackgroundColor, opt); JSClass::StaticMethod("onAppear", &JSInteractableView::JsOnAppear); JSClass::StaticMethod("onDisAppear", &JSInteractableView::JsOnDisAppear); JSClass::StaticMethod("onTouch", &JSInteractableView::JsOnTouch); JSClass::StaticMethod("onHover", &JSInteractableView::JsOnHover); JSClass::StaticMethod("onKeyEvent", &JSInteractableView::JsOnKey); JSClass::StaticMethod("onDeleteEvent", &JSInteractableView::JsOnDelete); JSClass::StaticMethod("onClick", &JSInteractableView::JsOnClick); JSClass::StaticMethod("remoteMessage", &JSInteractableView::JsCommonRemoteMessage); JSClass::Inherit(); JSClass::Bind<>(globalObj); } } // namespace OHOS::Ace::Framework