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_toolbaritem.h" 17 18 #include "core/components_ng/pattern/toolbaritem/toolbaritem_model.h" 19 #include "core/components_ng/pattern/toolbaritem/toolbaritem_model_ng.h" 20 21 namespace OHOS::Ace { 22 GetInstance()23ToolBarItemModel* ToolBarItemModel::GetInstance() 24 { 25 #ifdef NG_BUILD 26 static NG::ToolBarItemModelNG instance; 27 return &instance; 28 #else 29 if (Container::IsCurrentUseNewPipeline()) { 30 static NG::ToolBarItemModelNG instance; 31 return &instance; 32 } else { 33 static NG::ToolBarItemModelNG instance; 34 return &instance; 35 } 36 #endif 37 } 38 } // namespace OHOS::Ace 39 40 namespace OHOS::Ace::Framework { 41 42 namespace {} // namespace 43 Create(const JSCallbackInfo & info)44void JSToolBarItem::Create(const JSCallbackInfo& info) 45 { 46 ToolBarItemPlacement value = ToolBarItemPlacement::TOP_BAR_LEADING; 47 if (info.Length() == 1 && info[0]->IsObject()) { 48 JSRef<JSObject> toolbaritemObj = JSRef<JSObject>::Cast(info[0]); 49 if (toolbaritemObj->GetProperty(JSToolBarItem::PLACEMENT)->IsNumber()) { 50 value = static_cast<ToolBarItemPlacement>( 51 toolbaritemObj->GetProperty(JSToolBarItem::PLACEMENT)->ToNumber<int32_t>()); 52 } 53 if (value != ToolBarItemPlacement::TOP_BAR_LEADING && value != ToolBarItemPlacement::TOP_BAR_TRAILING) { 54 value = ToolBarItemPlacement::TOP_BAR_LEADING; 55 } 56 } 57 ToolBarItemModel::GetInstance()->Create(static_cast<int32_t>(value)); 58 } 59 JSBind(BindingTarget globalObj)60void JSToolBarItem::JSBind(BindingTarget globalObj) 61 { 62 JSClass<JSToolBarItem>::Declare("ToolBarItem"); 63 JSClass<JSToolBarItem>::StaticMethod("create", &JSToolBarItem::Create); 64 JSClass<JSToolBarItem>::InheritAndBind<JSContainerBase>(globalObj); 65 } 66 } // namespace OHOS::Ace::Framework