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 "bridge/declarative_frontend/jsview/window_scene/js_screen.h"
17 
18 #include "core/components_ng/pattern/window_scene/screen/screen_model.h"
19 
20 namespace OHOS::Ace::Framework {
JSBind(BindingTarget globalObj)21 void JSScreen::JSBind(BindingTarget globalObj)
22 {
23     JSClass<JSScreen>::Declare("Screen");
24     JSClass<JSScreen>::StaticMethod("create", &JSScreen::Create, MethodOptions::NONE);
25 
26     JSClass<JSScreen>::Inherit<JSInteractableView>();
27     JSClass<JSScreen>::InheritAndBind<JSViewAbstract>(globalObj);
28 }
29 
Create(const JSCallbackInfo & info)30 void JSScreen::Create(const JSCallbackInfo& info)
31 {
32     if (!Container::IsCurrentUseNewPipeline()) {
33         return;
34     }
35 
36     if (info.Length() != 1) {
37         return;
38     }
39 
40     if (!info[0]->IsNumber()) {
41         return;
42     }
43 
44     auto screenId = static_cast<uint64_t>(info[0]->ToNumber<double>());
45     NG::ScreenModel::Create(screenId);
46 }
47 } // namespace OHOS::Ace::Framework
48