1 /*
2 * Copyright (c) 2022 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_relative_container.h"
17
18 #include "base/log/ace_trace.h"
19 #include "bridge/declarative_frontend/jsview/models/relative_container_model_impl.h"
20 #include "core/components_ng/pattern/relative_container/relative_container_model_ng.h"
21 #include "frameworks/bridge/declarative_frontend/engine/js_ref_ptr.h"
22 #include "frameworks/bridge/declarative_frontend/jsview/js_view_common_def.h"
23 #include "frameworks/bridge/declarative_frontend/view_stack_processor.h"
24
25 namespace OHOS::Ace {
26
27 std::unique_ptr<RelativeContainerModel> RelativeContainerModel::instance_ = nullptr;
28 std::mutex RelativeContainerModel::mutex_;
29
GetInstance()30 RelativeContainerModel* RelativeContainerModel::GetInstance()
31 {
32 if (!instance_) {
33 std::lock_guard<std::mutex> lock(mutex_);
34 if (!instance_) {
35 #ifdef NG_BUILD
36 instance_.reset(new NG::RelativeContainerModelNG());
37 #else
38 if (Container::IsCurrentUseNewPipeline()) {
39 instance_.reset(new NG::RelativeContainerModelNG());
40 } else {
41 instance_.reset(new Framework::RelativeContainerModelImpl());
42 }
43 #endif
44 }
45 }
46 return instance_.get();
47 }
48
49 } // namespace OHOS::Ace
50
51 namespace OHOS::Ace::Framework {
52
JSBind(BindingTarget globalObj)53 void JSRelativeContainer::JSBind(BindingTarget globalObj)
54 {
55 JSClass<JSRelativeContainer>::Declare("RelativeContainer");
56 MethodOptions opt = MethodOptions::NONE;
57 JSClass<JSRelativeContainer>::StaticMethod("create", &JSRelativeContainer::Create, opt);
58 JSClass<JSRelativeContainer>::StaticMethod("onTouch", &JSInteractableView::JsOnTouch);
59 JSClass<JSRelativeContainer>::StaticMethod("onKeyEvent", &JSInteractableView::JsOnKey);
60 JSClass<JSRelativeContainer>::StaticMethod("onDeleteEvent", &JSInteractableView::JsOnDelete);
61 JSClass<JSRelativeContainer>::StaticMethod("onClick", &JSInteractableView::JsOnClick);
62 JSClass<JSRelativeContainer>::StaticMethod("onHover", &JSInteractableView::JsOnHover);
63 JSClass<JSRelativeContainer>::StaticMethod("onAppear", &JSInteractableView::JsOnAppear);
64 JSClass<JSRelativeContainer>::StaticMethod("onDisAppear", &JSInteractableView::JsOnDisAppear);
65 JSClass<JSRelativeContainer>::StaticMethod("remoteMessage", &JSInteractableView::JsCommonRemoteMessage);
66 JSClass<JSRelativeContainer>::InheritAndBind<JSContainerBase>(globalObj);
67 }
68
Create(const JSCallbackInfo & info)69 void JSRelativeContainer::Create(const JSCallbackInfo& info)
70 {
71 RelativeContainerModel::GetInstance()->Create();
72 }
73
74 } // namespace OHOS::Ace::Framework
75