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_window_scene.h"
17
18 #include "core/components_ng/pattern/window_scene/scene/window_scene_model.h"
19
20 namespace OHOS::Ace::Framework {
JSBind(BindingTarget globalObj)21 void JSWindowScene::JSBind(BindingTarget globalObj)
22 {
23 JSClass<JSWindowScene>::Declare("WindowScene");
24 JSClass<JSWindowScene>::StaticMethod("create", &JSWindowScene::Create, MethodOptions::NONE);
25 JSClass<JSWindowScene>::StaticMethod("attractionEffect", &JSWindowScene::JsAttractionEffect);
26
27 JSClass<JSWindowScene>::Inherit<JSInteractableView>();
28 JSClass<JSWindowScene>::InheritAndBind<JSViewAbstract>(globalObj);
29 }
30
Create(const JSCallbackInfo & info)31 void JSWindowScene::Create(const JSCallbackInfo& info)
32 {
33 if (!Container::IsCurrentUseNewPipeline()) {
34 return;
35 }
36
37 if (info.Length() != 1) {
38 return;
39 }
40
41 if (!info[0]->IsNumber()) {
42 return;
43 }
44
45 auto persistentId = static_cast<int32_t>(info[0]->ToNumber<double>());
46 NG::WindowSceneModel::Create(persistentId);
47 }
48
JsAttractionEffect(const JSCallbackInfo & info)49 void JSWindowScene::JsAttractionEffect(const JSCallbackInfo& info)
50 {
51 if (info.Length() < 2) {
52 return;
53 }
54 NG::AttractionEffect property;
55 if (info[0]->IsObject()) {
56 auto point = JSRef<JSObject>::Cast(info[0]);
57 if (!JSViewAbstract::ParseJsDimensionVpNG(point->GetProperty("x"), property.destinationX, false)) {
58 property.destinationX.Reset();
59 }
60 if (!JSViewAbstract::ParseJsDimensionVpNG(point->GetProperty("y"), property.destinationY, false)) {
61 property.destinationY.Reset();
62 }
63 }
64 if (info[1]->IsNumber()) {
65 auto fraction = info[1]->ToNumber<float>();
66 property.fraction = std::clamp(fraction, 0.0f, 1.0f);
67 }
68 NG::WindowSceneModel::SetAttractionEffect(property);
69 }
70 } // namespace OHOS::Ace::Framework
71