1 /* 2 * Copyright (c) 2023 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_form_link.h" 17 18 #include "core/components_ng/base/view_abstract.h" 19 #include "core/components_ng/pattern/form_link/form_link_model_ng.h" 20 21 namespace OHOS::Ace { 22 23 std::unique_ptr<FormLinkModel> FormLinkModel::instance_ = nullptr; 24 std::mutex FormLinkModel::mutex_; 25 GetInstance()26FormLinkModel* FormLinkModel::GetInstance() 27 { 28 if (!instance_) { 29 std::lock_guard<std::mutex> lock(mutex_); 30 if (!instance_) { 31 #ifdef NG_BUILD 32 instance_.reset(new NG::FormLinkModelNG()); 33 #else 34 if (Container::IsCurrentUseNewPipeline()) { 35 instance_.reset(new NG::FormLinkModelNG()); 36 } else { 37 instance_.reset(nullptr); 38 } 39 #endif 40 } 41 } 42 return instance_.get(); 43 } 44 } // namespace OHOS::Ace 45 46 namespace OHOS::Ace::Framework { 47 Create(const JSCallbackInfo & info)48void JSFormLink::Create(const JSCallbackInfo& info) 49 { 50 if (!Container::IsInFormContainer()) { 51 APP_LOGW("[Engine Log] FormLink only support in form widget."); 52 } 53 if (info.Length() == 0 || !info[0]->IsObject()) { 54 return; 55 } 56 auto action = info[0]->ToString(); 57 FormLinkModel::GetInstance()->Create(action); 58 } 59 JSBind(BindingTarget globalObj)60void JSFormLink::JSBind(BindingTarget globalObj) 61 { 62 JSClass<JSFormLink>::Declare("FormLink"); 63 MethodOptions opt = MethodOptions::NONE; 64 JSClass<JSFormLink>::StaticMethod("create", &JSFormLink::Create, opt); 65 66 JSClass<JSFormLink>::InheritAndBind<JSViewAbstract>(globalObj); 67 } 68 69 } // namespace OHOS::Ace::Framework 70