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 "core/components_ng/pattern/relative_container/relative_container_view.h"
20 #include "frameworks/bridge/declarative_frontend/engine/js_ref_ptr.h"
21 #include "frameworks/bridge/declarative_frontend/jsview/js_view_common_def.h"
22 #include "frameworks/bridge/declarative_frontend/view_stack_processor.h"
23 #include "frameworks/core/components/relative_container/relative_container_component.h"
24
25 namespace OHOS::Ace::Framework {
26
JSBind(BindingTarget globalObj)27 void JSRelativeContainer::JSBind(BindingTarget globalObj)
28 {
29 JSClass<JSRelativeContainer>::Declare("RelativeContainer");
30 MethodOptions opt = MethodOptions::NONE;
31 JSClass<JSRelativeContainer>::StaticMethod("create", &JSRelativeContainer::Create, opt);
32 JSClass<JSRelativeContainer>::StaticMethod("onTouch", &JSInteractableView::JsOnTouch);
33 JSClass<JSRelativeContainer>::StaticMethod("onKeyEvent", &JSInteractableView::JsOnKey);
34 JSClass<JSRelativeContainer>::StaticMethod("onDeleteEvent", &JSInteractableView::JsOnDelete);
35 JSClass<JSRelativeContainer>::StaticMethod("onClick", &JSInteractableView::JsOnClick);
36 JSClass<JSRelativeContainer>::StaticMethod("onHover", &JSInteractableView::JsOnHover);
37 JSClass<JSRelativeContainer>::StaticMethod("onAppear", &JSInteractableView::JsOnAppear);
38 JSClass<JSRelativeContainer>::StaticMethod("onDisAppear", &JSInteractableView::JsOnDisAppear);
39 JSClass<JSRelativeContainer>::StaticMethod("remoteMessage", &JSInteractableView::JsCommonRemoteMessage);
40 JSClass<JSRelativeContainer>::Inherit<JSContainerBase>();
41 JSClass<JSRelativeContainer>::Inherit<JSViewAbstract>();
42 JSClass<JSRelativeContainer>::Bind<>(globalObj);
43 }
44
Create(const JSCallbackInfo & info)45 void JSRelativeContainer::Create(const JSCallbackInfo& info)
46 {
47 if (Container::IsCurrentUseNewPipeline()) {
48 NG::RelativeContainerView::Create();
49 return;
50 }
51
52 std::list<RefPtr<Component>> children;
53 RefPtr<OHOS::Ace::RelativeContainerComponent> component = AceType::MakeRefPtr<RelativeContainerComponent>(children);
54 ViewStackProcessor::GetInstance()->Push(component);
55 JSInteractableView::SetFocusNode(true);
56 }
57
58 } // namespace OHOS::Ace::Framework
59