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_recycle_view.h" 17 18 #include "bridge/declarative_frontend/engine/bindings_implementation.h" 19 #include "frameworks/core/components_ng/pattern/recycle_view/recycle_view_model.h" 20 #include "frameworks/core/components_ng/pattern/recycle_view/recycle_view_model_ng.h" 21 22 namespace OHOS::Ace { 23 std::unique_ptr<RecycleViewModel> RecycleViewModel::instance_ = nullptr; 24 std::mutex RecycleViewModel::mutex_; 25 GetInstance()26RecycleViewModel* RecycleViewModel::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::RecycleViewModelNG()); 33 #else 34 if (Container::IsCurrentUseNewPipeline()) { 35 instance_.reset(new NG::RecycleViewModelNG()); 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 { Create(const JSCallbackInfo & info)47void JSRecycleView::Create(const JSCallbackInfo& info) 48 { 49 if (Container::IsCurrentUseNewPipeline()) { 50 RecycleViewModel::GetInstance()->Create(); 51 } 52 return; 53 } 54 Pop(const JSCallbackInfo & info)55void JSRecycleView::Pop(const JSCallbackInfo& info) 56 { 57 return; 58 } 59 JSBind(BindingTarget globalObj)60void JSRecycleView::JSBind(BindingTarget globalObj) 61 { 62 MethodOptions opt = MethodOptions::NONE; 63 JSClass<JSRecycleView>::Declare("__Recycle__"); 64 JSClass<JSRecycleView>::StaticMethod("create", &JSRecycleView::Create, opt); 65 JSClass<JSRecycleView>::StaticMethod("pop", &JSRecycleView::Pop, opt); 66 67 JSClass<JSRecycleView>::InheritAndBind<JSContainerBase>(globalObj); 68 } 69 } // namespace OHOS::Ace::Framework 70