/* * 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_divider.h" #include "bridge/declarative_frontend/jsview/models/divider_model_impl.h" #include "core/components/divider/divider_theme.h" #include "core/components_ng/pattern/divider/divider_model_ng.h" namespace OHOS::Ace { std::unique_ptr DividerModel::instance_ = nullptr; DividerModel* DividerModel::GetInstance() { if (!instance_) { #ifdef NG_BUILD instance_.reset(new NG::DividerModelNG()); #else if (Container::IsCurrentUseNewPipeline()) { instance_.reset(new NG::DividerModelNG()); } else { instance_.reset(new Framework::DividerModelImpl()); } #endif } return instance_.get(); } } // namespace OHOS::Ace namespace OHOS::Ace::Framework { void JSDivider::Create() { DividerModel::GetInstance()->Create(); } void JSDivider::SetVertical(bool isVertical) { DividerModel::GetInstance()->Vertical(isVertical); } void JSDivider::SetLineCap(int lineCap) { auto lineCapStyle = LineCap::BUTT; if (static_cast(LineCap::SQUARE) == lineCap) { lineCapStyle = LineCap::SQUARE; } else if (static_cast(LineCap::ROUND) == lineCap) { lineCapStyle = LineCap::ROUND; } else { // default linecap of divider lineCapStyle = LineCap::BUTT; } DividerModel::GetInstance()->LineCap(lineCapStyle); } void JSDivider::SetDividerColor(const JSCallbackInfo& info) { if (info.Length() < 1) { LOGE("The argv is wrong, it is supposed to have at least 1 argument"); return; } Color dividerColor; if (!ParseJsColor(info[0], dividerColor)) { auto theme = GetTheme(); if (theme) { dividerColor = theme->GetColor(); } DividerModel::GetInstance()->DividerColor(dividerColor); return; } DividerModel::GetInstance()->DividerColor(dividerColor); } void JSDivider::SetStrokeWidth(const JSCallbackInfo& info) { if (info.Length() < 1) { LOGE("The arg is wrong, it is supposed to have at least 1 argument"); return; } Dimension strokeWidth; if (!ParseJsDimensionVp(info[0], strokeWidth)) { return; } DividerModel::GetInstance()->StrokeWidth(strokeWidth); } void JSDivider::JSBind(BindingTarget globalObj) { JSClass::Declare("Divider"); MethodOptions opt = MethodOptions::NONE; JSClass::StaticMethod("create", &JSDivider::Create, opt); JSClass::StaticMethod("color", &JSDivider::SetDividerColor, opt); JSClass::StaticMethod("vertical", &JSDivider::SetVertical, opt); JSClass::StaticMethod("strokeWidth", &JSDivider::SetStrokeWidth, opt); JSClass::StaticMethod("lineCap", &JSDivider::SetLineCap, 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