• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
GetInstance()25 RecycleViewModel* RecycleViewModel::GetInstance()
26 {
27     if (!instance_) {
28 #ifdef NG_BUILD
29         instance_.reset(new NG::RecycleViewModelNG());
30 #else
31         if (Container::IsCurrentUseNewPipeline()) {
32             instance_.reset(new NG::RecycleViewModelNG());
33         } else {
34             instance_.reset(nullptr);
35         }
36 #endif
37     }
38     return instance_.get();
39 }
40 } // namespace OHOS::Ace
41 
42 namespace OHOS::Ace::Framework {
Create(const JSCallbackInfo & info)43 void JSRecycleView::Create(const JSCallbackInfo& info)
44 {
45     if (Container::IsCurrentUseNewPipeline()) {
46         RecycleViewModel::GetInstance()->Create();
47     }
48 }
49 
JSBind(BindingTarget globalObj)50 void JSRecycleView::JSBind(BindingTarget globalObj)
51 {
52     MethodOptions opt = MethodOptions::NONE;
53     JSClass<JSRecycleView>::Declare("__Recycle__");
54     JSClass<JSRecycleView>::StaticMethod("create", &JSRecycleView::Create, opt);
55 
56     JSClass<JSRecycleView>::InheritAndBind<JSViewAbstract>(globalObj);
57 }
58 } // namespace OHOS::Ace::Framework
59