• 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/engine/functions/js_swiper_function.h"
17 
18 
19 namespace OHOS::Ace::Framework {
Execute(int32_t index,int32_t targetIndex,const AnimationCallbackInfo & animationCallbackInfo)20 void JsSwiperFunction::Execute(int32_t index, int32_t targetIndex, const AnimationCallbackInfo& animationCallbackInfo)
21 {
22     JSRef<JSObject> obj = JSRef<JSObject>::New();
23     float currentOffset = animationCallbackInfo.currentOffset.value_or(0.0f);
24     float targetOffset = animationCallbackInfo.targetOffset.value_or(0.0f);
25     float velocity = animationCallbackInfo.velocity.value_or(0.0f);
26 
27     obj->SetProperty<float>("currentOffset", currentOffset);
28     obj->SetProperty<float>("targetOffset", targetOffset);
29     obj->SetProperty<float>("velocity", velocity);
30 
31     int32_t paramCount = 3;
32     JSRef<JSVal> params[paramCount];
33     params[0] = JSRef<JSVal>::Make(ToJSValue(index));
34     params[1] = JSRef<JSVal>::Make(ToJSValue(targetIndex));
35     params[2] = obj;
36     JsFunction::ExecuteJS(paramCount, params);
37 }
38 
Execute(int32_t index,const AnimationCallbackInfo & animationCallbackInfo)39 void JsSwiperFunction::Execute(int32_t index, const AnimationCallbackInfo& animationCallbackInfo)
40 {
41     JSRef<JSObject> obj = JSRef<JSObject>::New();
42     float currentOffset = animationCallbackInfo.currentOffset.value_or(0.0f);
43     float targetOffset = animationCallbackInfo.targetOffset.value_or(0.0f);
44     float velocity = animationCallbackInfo.velocity.value_or(0.0f);
45 
46     obj->SetProperty<float>("currentOffset", currentOffset);
47     obj->SetProperty<float>("targetOffset", targetOffset);
48     obj->SetProperty<float>("velocity", velocity);
49 
50     int32_t paramCount = 2;
51     JSRef<JSVal> params[paramCount];
52     params[0] = JSRef<JSVal>::Make(ToJSValue(index));
53     params[1] = obj;
54     JsFunction::ExecuteJS(paramCount, params);
55 }
56 } // namespace OHOS::Ace::Framework
57