/* * Copyright (c) 2021-2023 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 "base/geometry/dimension.h" #include "core/components/common/properties/color.h" #include "core/components_ng/pattern/blank/blank_model_ng.h" #include "frameworks/bridge/declarative_frontend/jsview/models/blank_model_impl.h" #include "frameworks/bridge/declarative_frontend/view_stack_processor.h" namespace OHOS::Ace { std::unique_ptr BlankModel::instance_ = nullptr; std::mutex BlankModel::mutex_; BlankModel* BlankModel::GetInstance() { if (!instance_) { std::lock_guard lock(mutex_); if (!instance_) { #ifdef NG_BUILD instance_.reset(new NG::BlankModelNG()); #else if (Container::IsCurrentUseNewPipeline()) { instance_.reset(new NG::BlankModelNG()); } else { instance_.reset(new Framework::BlankModelImpl()); } #endif } } return instance_.get(); } } // namespace OHOS::Ace namespace OHOS::Ace::Framework { void JSBlank::Create(const JSCallbackInfo& info) { CalcDimension blankMin(0.0, DimensionUnit::VP); BlankModel::GetInstance()->Create(); if (info[0]->IsUndefined()) { BlankModel::GetInstance()->SetBlankMin(blankMin); return; } if (ParseJsDimensionVp(info[0], blankMin)) { if (blankMin.IsNegative() || blankMin.Unit() == DimensionUnit::PERCENT) { blankMin.SetValue(0.0); } BlankModel::GetInstance()->SetBlankMin(blankMin); } } void JSBlank::Height(const JSCallbackInfo& info) { JSViewAbstract::JsHeight(info); CalcDimension value; if (!ParseJsDimensionVp(info[0], value)) { return; } BlankModel::GetInstance()->SetHeight(value); } void JSBlank::Color(const JSCallbackInfo& info) { class Color value; if (!ParseJsColor(info[0], value)) { BlankModel::GetInstance()->SetColor(Color::TRANSPARENT); return; } BlankModel::GetInstance()->SetColor(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", &JSBlank::Color, opt); JSClass::StaticMethod("onAttach", &JSInteractableView::JsOnAttach); JSClass::StaticMethod("onAppear", &JSInteractableView::JsOnAppear); JSClass::StaticMethod("onDetach", &JSInteractableView::JsOnDetach); 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::InheritAndBind(globalObj); } } // namespace OHOS::Ace::Framework