• 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 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_swiper_bridge.h"
16 
17 #include <string>
18 
19 #include "base/geometry/calc_dimension.h"
20 #include "base/geometry/dimension.h"
21 #include "base/log/log_wrapper.h"
22 #include "base/utils/utils.h"
23 #include "base/log/ace_scoring_log.h"
24 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h"
25 #include "bridge/declarative_frontend/engine/functions/js_swiper_function.h"
26 #include "bridge/declarative_frontend/jsview/js_indicator.h"
27 #include "bridge/declarative_frontend/jsview/js_swiper.h"
28 #include "core/components_ng/pattern/swiper/swiper_model_ng.h"
29 
30 namespace OHOS::Ace::NG {
31 namespace {
32 constexpr int32_t CALL_ARG_NODE_INDEX = 0;
33 constexpr int32_t CALL_ARG_VALUE_INDEX = 1;
34 constexpr int32_t CALL_ARG_TYPE_INDEX = 2;
35 constexpr int32_t DISPLAY_ARROW_VALUE = 1;
36 constexpr int32_t ARROW_IS_SHOW_BACKGROUND = 2;
37 constexpr int32_t ARROW_IS_SIDE_BAR_MIDDLE = 3;
38 constexpr int32_t ARROW_BACKGROUND_SIZE = 4;
39 constexpr int32_t ARROW_BACKGROUND_COLOR = 5;
40 constexpr int32_t ARROW_SIZE = 6;
41 constexpr int32_t ARROW_COLOR = 7;
42 constexpr int32_t DISPLAY_ARROW_IS_HOVER_SHOW_INDEX = 8;
43 constexpr int32_t INDICATOR_VALUE_INDEX = 2;
44 constexpr int32_t DIGIT_INDICATOR_FONT_COLOR = 2;
45 constexpr int32_t DIGIT_INDICATOR_SELECTED_FONT_COLOR = 3;
46 constexpr int32_t DIGIT_INDICATOR_DIGIT_FONT_SIZE = 4;
47 constexpr int32_t DIGIT_INDICATOR_DIGIT_FONT_WEIGHT = 5;
48 constexpr int32_t DIGIT_INDICATOR_SELECTED_DIGIT_FONT_SIZE = 6;
49 constexpr int32_t DIGIT_INDICATOR_SELECTED_DIGIT_FONT_WEIGHT = 7;
50 constexpr int32_t DIGIT_INDICATOR_LEFT = 8;
51 constexpr int32_t DIGIT_INDICATOR_TOP = 9;
52 constexpr int32_t DIGIT_INDICATOR_RIGHT = 10;
53 constexpr int32_t DIGIT_INDICATOR_BOTTOM = 11;
54 constexpr int32_t DIGIT_INDICATOR_IGNORE_SIZE = 12;
55 constexpr int32_t DIGIT_INDICATOR_SET_IGNORE_SIZE = 13;
56 constexpr int32_t DOT_INDICATOR_ITEM_WIDTH = 2;
57 constexpr int32_t DOT_INDICATOR_ITEM_HEIGHT = 3;
58 constexpr int32_t DOT_INDICATOR_SELECTED_ITEM_WIDTH = 4;
59 constexpr int32_t DOT_INDICATOR_SELECTED_ITEM_HEIGHT = 5;
60 constexpr int32_t DOT_INDICATOR_MASK = 6;
61 constexpr int32_t DOT_INDICATOR_COLOR = 7;
62 constexpr int32_t DOT_INDICATOR_SELECTED_COLOR = 8;
63 constexpr int32_t DOT_INDICATOR_LEFT = 9;
64 constexpr int32_t DOT_INDICATOR_TOP = 10;
65 constexpr int32_t DOT_INDICATOR_RIGHT = 11;
66 constexpr int32_t DOT_INDICATOR_BOTTOM = 12;
67 constexpr int32_t DOT_INDICATOR_MAX_DISPLAY_COUNT = 13;
68 constexpr int32_t DOT_INDICATOR_SPACE = 14;
69 constexpr int32_t DOT_INDICATOR_IGNORE_SIZE = 15;
70 constexpr int32_t DOT_INDICATOR_SET_IGNORE_SIZE = 16;
71 constexpr double DEFAULT_PERCENT_VALUE = 100.0;
72 constexpr int32_t DEFAULT_ANIMATION_MODE = 0;
73 constexpr int32_t STOP_WHEN_TOUCHED = 2;
74 constexpr int32_t INDICATOR_RESOURCE_LEFT = 0;
75 constexpr int32_t INDICATOR_RESOURCE_TOP = 1;
76 constexpr int32_t INDICATOR_RESOURCE_RIGHT = 2;
77 constexpr int32_t INDICATOR_RESOURCE_BOTTOM = 3;
78 constexpr int32_t DOT_INDICATOR_RESOURCE_ITEM_WIDTH = 4;
79 constexpr int32_t DOT_INDICATOR_RESOURCE_ITEM_HEIGHT = 5;
80 constexpr int32_t DOT_INDICATOR_RESOURCE_SELECTED_ITEM_WIDTH = 6;
81 constexpr int32_t DOT_INDICATOR_RESOURCE_SELECTED_ITEM_HEIGHT = 7;
82 constexpr int32_t DOT_INDICATOR_RESOURCE_COLOR = 8;
83 constexpr int32_t DOT_INDICATOR_RESOURCE_SELECTED_COLOR = 9;
84 constexpr int32_t INDICATOR_RESOURCE_VECTOR_LENGTH = 10;
85 constexpr int32_t DIGIT_INDICATOR_RESOURCE_FONT_COLOR = 4;
86 constexpr int32_t DIGIT_INDICATOR_RESOURCE_FONT_SELECTED_COLOR = 5;
87 constexpr int32_t DIGIT_INDICATOR_RESOURCE_FONT_SIZE = 6;
88 constexpr int32_t DIGIT_INDICATOR_RESOURCE_SELECTED_FONT_SIZE = 7;
89 constexpr int32_t ARROW_RESOURCE_BACKGROUND_SIZE = 0;
90 constexpr int32_t ARROW_RESOURCE_BACKGROUND_COLOR = 1;
91 constexpr int32_t ARROW_RESOURCE_SIZE = 2;
92 constexpr int32_t ARROW_RESOURCE_COLOR = 3;
93 constexpr int32_t ARROW_RESOURCE_VECTOR_LENGTH = 4;
94 } // namespace
95 
SetSwiperInitialize(ArkUIRuntimeCallInfo * runtimeCallInfo)96 ArkUINativeModuleValue SwiperBridge::SetSwiperInitialize(ArkUIRuntimeCallInfo* runtimeCallInfo)
97 {
98     EcmaVM* vm = runtimeCallInfo->GetVM();
99     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
100     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
101     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
102     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
103 
104     auto nodePtr = GetArkUINodeModifiers()->getSwiperModifier()->getSwiperController(nativeNode);
105     auto node = AceType::Claim(reinterpret_cast<OHOS::Ace::SwiperController*>(nodePtr));
106 
107     Framework::JsiCallbackInfo info = Framework::JsiCallbackInfo(runtimeCallInfo);
108     Framework::JSSwiperController* jsController =
109         Framework::JSRef<Framework::JSObject>::Cast(info[1])->Unwrap<Framework::JSSwiperController>();
110     if (jsController) {
111         jsController->SetInstanceId(Container::CurrentId());
112         jsController->SetController(node);
113     }
114     return panda::JSValueRef::Undefined(vm);
115 }
ResetSwiperInitialize(ArkUIRuntimeCallInfo * runtimeCallInfo)116 ArkUINativeModuleValue SwiperBridge::ResetSwiperInitialize(ArkUIRuntimeCallInfo* runtimeCallInfo)
117 {
118     EcmaVM* vm = runtimeCallInfo->GetVM();
119     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
120     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
121     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
122     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
123     GetArkUINodeModifiers()->getSwiperModifier()->getSwiperController(nativeNode);
124     return panda::JSValueRef::Undefined(vm);
125 }
SetSwiperNextMargin(ArkUIRuntimeCallInfo * runtimeCallInfo)126 ArkUINativeModuleValue SwiperBridge::SetSwiperNextMargin(ArkUIRuntimeCallInfo* runtimeCallInfo)
127 {
128     EcmaVM* vm = runtimeCallInfo->GetVM();
129     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
130     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
131     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
132     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
133     Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
134     Ace::CalcDimension nextMargin;
135     RefPtr<ResourceObject> nextMarginResObj;
136     if (valueArg->IsUndefined() || valueArg->IsNull() ||
137         !ArkTSUtils::ParseJsDimension(vm, valueArg, nextMargin, DimensionUnit::VP, nextMarginResObj) ||
138         LessNotEqual(nextMargin.Value(), 0.0)) {
139         nextMargin.SetValue(0.0);
140     }
141     int32_t nextMarginUnit = static_cast<int32_t>(nextMargin.Unit());
142     if (SystemProperties::ConfigChangePerform()) {
143         auto nextMarginRawPtr = AceType::RawPtr(nextMarginResObj);
144         GetArkUINodeModifiers()->getSwiperModifier()->setSwiperNextMarginRaw(
145             nativeNode, nextMargin.Value(), nextMarginUnit, 0, nextMarginRawPtr);
146     } else {
147         GetArkUINodeModifiers()->getSwiperModifier()->setSwiperNextMargin(
148             nativeNode, nextMargin.Value(), nextMarginUnit, 0);
149     }
150     return panda::JSValueRef::Undefined(vm);
151 }
ResetSwiperNextMargin(ArkUIRuntimeCallInfo * runtimeCallInfo)152 ArkUINativeModuleValue SwiperBridge::ResetSwiperNextMargin(ArkUIRuntimeCallInfo* runtimeCallInfo)
153 {
154     EcmaVM* vm = runtimeCallInfo->GetVM();
155     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
156     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
157     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
158     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
159     GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperNextMargin(nativeNode);
160     return panda::JSValueRef::Undefined(vm);
161 }
SetSwiperPrevMargin(ArkUIRuntimeCallInfo * runtimeCallInfo)162 ArkUINativeModuleValue SwiperBridge::SetSwiperPrevMargin(ArkUIRuntimeCallInfo* runtimeCallInfo)
163 {
164     EcmaVM* vm = runtimeCallInfo->GetVM();
165     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
166     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
167     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
168     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
169     Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
170     Ace::CalcDimension prevMargin;
171     RefPtr<ResourceObject> preMarginResObj;
172     if (valueArg->IsUndefined() || valueArg->IsNull() ||
173         !ArkTSUtils::ParseJsDimension(vm, valueArg, prevMargin, DimensionUnit::VP, preMarginResObj) ||
174         LessNotEqual(prevMargin.Value(), 0.0)) {
175         prevMargin.SetValue(0.0);
176     }
177     int32_t prevMarginUnit = static_cast<int32_t>(prevMargin.Unit());
178     if (SystemProperties::ConfigChangePerform()) {
179         auto preMarginRawPtr = AceType::RawPtr(preMarginResObj);
180         GetArkUINodeModifiers()->getSwiperModifier()->setSwiperPrevMarginRaw(
181             nativeNode, prevMargin.Value(), prevMarginUnit, 0, preMarginRawPtr);
182     } else {
183         GetArkUINodeModifiers()->getSwiperModifier()->setSwiperPrevMargin(
184             nativeNode, prevMargin.Value(), prevMarginUnit, 0);
185     }
186     return panda::JSValueRef::Undefined(vm);
187 }
ResetSwiperPrevMargin(ArkUIRuntimeCallInfo * runtimeCallInfo)188 ArkUINativeModuleValue SwiperBridge::ResetSwiperPrevMargin(ArkUIRuntimeCallInfo* runtimeCallInfo)
189 {
190     EcmaVM* vm = runtimeCallInfo->GetVM();
191     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
192     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
193     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
194     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
195     GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperPrevMargin(nativeNode);
196     return panda::JSValueRef::Undefined(vm);
197 }
198 
SetNestedScroll(ArkUIRuntimeCallInfo * runtimeCallInfo)199 ArkUINativeModuleValue SwiperBridge::SetNestedScroll(ArkUIRuntimeCallInfo* runtimeCallInfo)
200 {
201     EcmaVM* vm = runtimeCallInfo->GetVM();
202     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
203     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
204     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
205     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
206     Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
207     if (valueArg->IsNumber()) {
208         int32_t index = valueArg->Int32Value(vm);
209         int32_t values[1] = { 0 };
210         values[0] = index;
211         GetArkUINodeModifiers()->getSwiperModifier()->setSwiperNestedScroll(nativeNode, &values);
212     } else {
213         GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperNestedScroll(nativeNode);
214     }
215     return panda::JSValueRef::Undefined(vm);
216 }
217 
ResetNestedScroll(ArkUIRuntimeCallInfo * runtimeCallInfo)218 ArkUINativeModuleValue SwiperBridge::ResetNestedScroll(ArkUIRuntimeCallInfo* runtimeCallInfo)
219 {
220     EcmaVM* vm = runtimeCallInfo->GetVM();
221     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
222     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
223     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
224     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
225     GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperNestedScroll(nativeNode);
226     return panda::JSValueRef::Undefined(vm);
227 }
228 
SetIndicatorInteractive(ArkUIRuntimeCallInfo * runtimeCallInfo)229 ArkUINativeModuleValue SwiperBridge::SetIndicatorInteractive(ArkUIRuntimeCallInfo* runtimeCallInfo)
230 {
231     EcmaVM* vm = runtimeCallInfo->GetVM();
232     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
233     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
234     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
235     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
236     Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
237     bool interactive = valueArg->ToBoolean(vm)->Value();
238     GetArkUINodeModifiers()->getSwiperModifier()->setIndicatorInteractive(nativeNode, interactive);
239     return panda::JSValueRef::Undefined(vm);
240 }
241 
ResetIndicatorInteractive(ArkUIRuntimeCallInfo * runtimeCallInfo)242 ArkUINativeModuleValue SwiperBridge::ResetIndicatorInteractive(ArkUIRuntimeCallInfo* runtimeCallInfo)
243 {
244     EcmaVM* vm = runtimeCallInfo->GetVM();
245     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
246     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
247     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
248     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
249     GetArkUINodeModifiers()->getSwiperModifier()->resetIndicatorInteractive(nativeNode);
250     return panda::JSValueRef::Undefined(vm);
251 }
252 
SetSwiperDisplayCount(ArkUIRuntimeCallInfo * runtimeCallInfo)253 ArkUINativeModuleValue SwiperBridge::SetSwiperDisplayCount(ArkUIRuntimeCallInfo* runtimeCallInfo)
254 {
255     EcmaVM* vm = runtimeCallInfo->GetVM();
256     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
257     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
258     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
259     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
260     Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
261     if (valueArg->IsNumber() || valueArg->IsString(vm)) {
262         Local<JSValueRef> typeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_TYPE_INDEX);
263         std::string displayCountValue;
264         std::string type = typeArg->ToString(vm)->ToString(vm);
265         if (type == "number") {
266             displayCountValue = std::to_string(valueArg->Int32Value(vm));
267         } else {
268             displayCountValue = valueArg->ToString(vm)->ToString(vm);
269         }
270         GetArkUINodeModifiers()->getSwiperModifier()->setSwiperDisplayCount(
271             nativeNode, displayCountValue.c_str(), type.c_str());
272     } else {
273         GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperDisplayCount(nativeNode);
274     }
275     return panda::JSValueRef::Undefined(vm);
276 }
ResetSwiperDisplayCount(ArkUIRuntimeCallInfo * runtimeCallInfo)277 ArkUINativeModuleValue SwiperBridge::ResetSwiperDisplayCount(ArkUIRuntimeCallInfo* runtimeCallInfo)
278 {
279     EcmaVM* vm = runtimeCallInfo->GetVM();
280     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
281     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
282     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
283     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
284     GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperDisplayCount(nativeNode);
285     return panda::JSValueRef::Undefined(vm);
286 }
287 
SetSwiperSwipeByGroup(ArkUIRuntimeCallInfo * runtimeCallInfo)288 ArkUINativeModuleValue SwiperBridge::SetSwiperSwipeByGroup(ArkUIRuntimeCallInfo* runtimeCallInfo)
289 {
290     EcmaVM* vm = runtimeCallInfo->GetVM();
291     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
292     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
293     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
294     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
295     Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
296     bool swipeByGroup = valueArg->ToBoolean(vm)->Value();
297     GetArkUINodeModifiers()->getSwiperModifier()->setSwiperSwipeByGroup(nativeNode, swipeByGroup);
298     return panda::JSValueRef::Undefined(vm);
299 }
300 
ResetSwiperSwipeByGroup(ArkUIRuntimeCallInfo * runtimeCallInfo)301 ArkUINativeModuleValue SwiperBridge::ResetSwiperSwipeByGroup(ArkUIRuntimeCallInfo* runtimeCallInfo)
302 {
303     EcmaVM* vm = runtimeCallInfo->GetVM();
304     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
305     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
306     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
307     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
308     GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperSwipeByGroup(nativeNode);
309     return panda::JSValueRef::Undefined(vm);
310 }
GetDimensionUnitString(DimensionUnit unit)311 std::string GetDimensionUnitString(DimensionUnit unit)
312 {
313     switch (unit) {
314         case DimensionUnit::VP:
315             return "vp";
316         case DimensionUnit::PX:
317             return "px";
318         case DimensionUnit::FP:
319             return "fp";
320         case DimensionUnit::CALC:
321             return "calc";
322         default:
323             return "px";
324     }
325 }
SetSwiperDisplayArrow(ArkUIRuntimeCallInfo * runtimeCallInfo)326 ArkUINativeModuleValue SwiperBridge::SetSwiperDisplayArrow(ArkUIRuntimeCallInfo* runtimeCallInfo)
327 {
328     EcmaVM* vm = runtimeCallInfo->GetVM();
329     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
330     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
331     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
332     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
333     Local<JSValueRef> displayArrowValue = runtimeCallInfo->GetCallArgRef(DISPLAY_ARROW_VALUE);
334     Local<JSValueRef> showBackground = runtimeCallInfo->GetCallArgRef(ARROW_IS_SHOW_BACKGROUND);
335     Local<JSValueRef> isSidebarMiddle = runtimeCallInfo->GetCallArgRef(ARROW_IS_SIDE_BAR_MIDDLE);
336     Local<JSValueRef> backgroundSize = runtimeCallInfo->GetCallArgRef(ARROW_BACKGROUND_SIZE);
337     Local<JSValueRef> backgroundColor = runtimeCallInfo->GetCallArgRef(ARROW_BACKGROUND_COLOR);
338     Local<JSValueRef> arrowSize = runtimeCallInfo->GetCallArgRef(ARROW_SIZE);
339     Local<JSValueRef> arrowColor = runtimeCallInfo->GetCallArgRef(ARROW_COLOR);
340     Local<JSValueRef> isHoverShow = runtimeCallInfo->GetCallArgRef(DISPLAY_ARROW_IS_HOVER_SHOW_INDEX);
341     std::string displayArrowValueStr = std::to_string(displayArrowValue->Int32Value(vm));
342     std::string showBackgroundStr = "2";
343     if (!showBackground->IsUndefined()) {
344         showBackgroundStr = showBackground->ToBoolean(vm)->Value() ? "1" : "0";
345     }
346     std::string isSidebarMiddleStr = "2";
347     if (!isSidebarMiddle->IsUndefined()) {
348         isSidebarMiddleStr = isSidebarMiddle->ToBoolean(vm)->Value() ? "1" : "0";
349     }
350     CalcDimension lengthValue;
351     Color color;
352     std::vector<RefPtr<ResourceObject>> resObjs;
353     auto nodeInfo = ArkTSUtils::MakeNativeNodeInfo(nativeNode);
354     resObjs.resize(ARROW_RESOURCE_VECTOR_LENGTH);
355     std::string backgroundSizeStr = ArkTSUtils::ParseJsDimension(vm, backgroundSize, lengthValue, DimensionUnit::VP,
356         resObjs.at(ARROW_RESOURCE_BACKGROUND_SIZE), false)
357         ? std::to_string(lengthValue.Value()) + GetDimensionUnitString(lengthValue.Unit()) : "-";
358     std::string backgroundColorStr = ArkTSUtils::ParseJsColorAlpha(vm, backgroundColor, color,
359         resObjs.at(ARROW_RESOURCE_BACKGROUND_COLOR), nodeInfo) ? std::to_string(color.GetValue()) : "-";
360     std::string arrowSizeStr = ArkTSUtils::ParseJsDimensionNG(vm, arrowSize, lengthValue, DimensionUnit::VP,
361         resObjs.at(ARROW_RESOURCE_SIZE), false)
362         ? std::to_string(lengthValue.Value()) + GetDimensionUnitString(lengthValue.Unit()) : "-";
363     std::string arrowColorStr = ArkTSUtils::ParseJsColorAlpha(vm, arrowColor, color,
364         resObjs.at(ARROW_RESOURCE_COLOR), nodeInfo) ? std::to_string(color.GetValue()) : "-";
365     std::string isHoverShowStr = "2";
366     if (!isHoverShow->IsUndefined()) {
367         isHoverShowStr = isHoverShow->ToBoolean(vm)->Value() ? "1" : "0";
368     }
369     std::string displayArrowStr = displayArrowValueStr + "|" + showBackgroundStr + "|" + isSidebarMiddleStr + "|" +
370                                   backgroundSizeStr + "|" + backgroundColorStr + "|" + arrowSizeStr + "|" +
371                                   arrowColorStr + "|" + isHoverShowStr + "|";
372     if (SystemProperties::ConfigChangePerform()) {
373         GetArkUINodeModifiers()->getSwiperModifier()->setSwiperDisplayArrowRaw(nativeNode, displayArrowStr.c_str(),
374             static_cast<void*>(&resObjs));
375     } else {
376         GetArkUINodeModifiers()->getSwiperModifier()->setSwiperDisplayArrow(nativeNode, displayArrowStr.c_str());
377     }
378     return panda::JSValueRef::Undefined(vm);
379 }
ResetSwiperDisplayArrow(ArkUIRuntimeCallInfo * runtimeCallInfo)380 ArkUINativeModuleValue SwiperBridge::ResetSwiperDisplayArrow(ArkUIRuntimeCallInfo* runtimeCallInfo)
381 {
382     EcmaVM* vm = runtimeCallInfo->GetVM();
383     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
384     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
385     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
386     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
387     GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperDisplayArrow(nativeNode);
388     return panda::JSValueRef::Undefined(vm);
389 }
SetSwiperCurve(ArkUIRuntimeCallInfo * runtimeCallInfo)390 ArkUINativeModuleValue SwiperBridge::SetSwiperCurve(ArkUIRuntimeCallInfo* runtimeCallInfo)
391 {
392     EcmaVM* vm = runtimeCallInfo->GetVM();
393     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
394     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
395     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
396     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
397     Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
398     if (valueArg->IsString(vm)) {
399         std::string curve = valueArg->ToString(vm)->ToString(vm);
400         GetArkUINodeModifiers()->getSwiperModifier()->setSwiperCurve(nativeNode, curve.c_str());
401     } else {
402         GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperCurve(nativeNode);
403     }
404     return panda::JSValueRef::Undefined(vm);
405 }
ResetSwiperCurve(ArkUIRuntimeCallInfo * runtimeCallInfo)406 ArkUINativeModuleValue SwiperBridge::ResetSwiperCurve(ArkUIRuntimeCallInfo* runtimeCallInfo)
407 {
408     EcmaVM* vm = runtimeCallInfo->GetVM();
409     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
410     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
411     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
412     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
413     GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperCurve(nativeNode);
414     return panda::JSValueRef::Undefined(vm);
415 }
SetSwiperDisableSwipe(ArkUIRuntimeCallInfo * runtimeCallInfo)416 ArkUINativeModuleValue SwiperBridge::SetSwiperDisableSwipe(ArkUIRuntimeCallInfo* runtimeCallInfo)
417 {
418     EcmaVM* vm = runtimeCallInfo->GetVM();
419     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
420     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
421     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
422     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
423     Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
424     if (valueArg->IsBoolean()) {
425         bool disableswipe = valueArg->ToBoolean(vm)->Value();
426         GetArkUINodeModifiers()->getSwiperModifier()->setSwiperDisableSwipe(nativeNode, disableswipe);
427     } else {
428         GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperDisableSwipe(nativeNode);
429     }
430     return panda::JSValueRef::Undefined(vm);
431 }
ResetSwiperDisableSwipe(ArkUIRuntimeCallInfo * runtimeCallInfo)432 ArkUINativeModuleValue SwiperBridge::ResetSwiperDisableSwipe(ArkUIRuntimeCallInfo* runtimeCallInfo)
433 {
434     EcmaVM* vm = runtimeCallInfo->GetVM();
435     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
436     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
437     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
438     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
439     GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperDisableSwipe(nativeNode);
440     return panda::JSValueRef::Undefined(vm);
441 }
SetSwiperEffectMode(ArkUIRuntimeCallInfo * runtimeCallInfo)442 ArkUINativeModuleValue SwiperBridge::SetSwiperEffectMode(ArkUIRuntimeCallInfo* runtimeCallInfo)
443 {
444     EcmaVM* vm = runtimeCallInfo->GetVM();
445     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
446     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
447     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
448     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
449     Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
450     if (valueArg->IsNumber()) {
451         auto edgeEffect = valueArg->Int32Value(vm);
452         GetArkUINodeModifiers()->getSwiperModifier()->setSwiperEffectMode(nativeNode, edgeEffect);
453     } else {
454         GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperEffectMode(nativeNode);
455     }
456     return panda::JSValueRef::Undefined(vm);
457 }
ResetSwiperEffectMode(ArkUIRuntimeCallInfo * runtimeCallInfo)458 ArkUINativeModuleValue SwiperBridge::ResetSwiperEffectMode(ArkUIRuntimeCallInfo* runtimeCallInfo)
459 {
460     EcmaVM* vm = runtimeCallInfo->GetVM();
461     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
462     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
463     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
464     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
465     GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperEffectMode(nativeNode);
466     return panda::JSValueRef::Undefined(vm);
467 }
SetSwiperCachedCount(ArkUIRuntimeCallInfo * runtimeCallInfo)468 ArkUINativeModuleValue SwiperBridge::SetSwiperCachedCount(ArkUIRuntimeCallInfo* runtimeCallInfo)
469 {
470     EcmaVM* vm = runtimeCallInfo->GetVM();
471     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
472     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
473     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
474     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
475     Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
476     if (valueArg->IsNumber()) {
477         int32_t cachedCount = valueArg->Int32Value(vm);
478         GetArkUINodeModifiers()->getSwiperModifier()->setSwiperCachedCount(nativeNode, cachedCount);
479     } else {
480         GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperCachedCount(nativeNode);
481     }
482     return panda::JSValueRef::Undefined(vm);
483 }
ResetSwiperCachedCount(ArkUIRuntimeCallInfo * runtimeCallInfo)484 ArkUINativeModuleValue SwiperBridge::ResetSwiperCachedCount(ArkUIRuntimeCallInfo* runtimeCallInfo)
485 {
486     EcmaVM* vm = runtimeCallInfo->GetVM();
487     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
488     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
489     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
490     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
491     GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperCachedCount(nativeNode);
492     return panda::JSValueRef::Undefined(vm);
493 }
SetSwiperIsShown(ArkUIRuntimeCallInfo * runtimeCallInfo)494 ArkUINativeModuleValue SwiperBridge::SetSwiperIsShown(ArkUIRuntimeCallInfo* runtimeCallInfo)
495 {
496     EcmaVM* vm = runtimeCallInfo->GetVM();
497     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
498     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
499     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
500     Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
501     bool isShown = valueArg->ToBoolean(vm)->Value();
502     GetArkUINodeModifiers()->getSwiperModifier()->setSwiperIsShown(nativeNode, isShown);
503     return panda::JSValueRef::Undefined(vm);
504 }
ResetSwiperIsShown(ArkUIRuntimeCallInfo * runtimeCallInfo)505 ArkUINativeModuleValue SwiperBridge::ResetSwiperIsShown(ArkUIRuntimeCallInfo* runtimeCallInfo)
506 {
507     EcmaVM* vm = runtimeCallInfo->GetVM();
508     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
509     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
510     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
511     GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperIsShown(nativeNode);
512     return panda::JSValueRef::Undefined(vm);
513 }
SetSwiperDisplayMode(ArkUIRuntimeCallInfo * runtimeCallInfo)514 ArkUINativeModuleValue SwiperBridge::SetSwiperDisplayMode(ArkUIRuntimeCallInfo* runtimeCallInfo)
515 {
516     EcmaVM* vm = runtimeCallInfo->GetVM();
517     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
518     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
519     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
520     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
521     Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
522     if (valueArg->IsNumber()) {
523         int32_t index = valueArg->Int32Value(vm);
524         GetArkUINodeModifiers()->getSwiperModifier()->setSwiperDisplayMode(nativeNode, index);
525     } else {
526         GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperDisplayMode(nativeNode);
527     }
528     return panda::JSValueRef::Undefined(vm);
529 }
ResetSwiperDisplayMode(ArkUIRuntimeCallInfo * runtimeCallInfo)530 ArkUINativeModuleValue SwiperBridge::ResetSwiperDisplayMode(ArkUIRuntimeCallInfo* runtimeCallInfo)
531 {
532     EcmaVM* vm = runtimeCallInfo->GetVM();
533     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
534     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
535     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
536     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
537     GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperDisplayMode(nativeNode);
538     return panda::JSValueRef::Undefined(vm);
539 }
SetSwiperItemSpace(ArkUIRuntimeCallInfo * runtimeCallInfo)540 ArkUINativeModuleValue SwiperBridge::SetSwiperItemSpace(ArkUIRuntimeCallInfo* runtimeCallInfo)
541 {
542     EcmaVM* vm = runtimeCallInfo->GetVM();
543     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
544     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
545     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
546     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
547     Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
548     Ace::CalcDimension itemSpace;
549     if (!ArkTSUtils::ParseJsDimensionVpNG(vm, valueArg, itemSpace) || LessNotEqual(itemSpace.Value(), 0.0)) {
550         itemSpace.SetValue(0.0);
551     }
552     int32_t itemSpaceUnit = static_cast<int32_t>(itemSpace.Unit());
553     GetArkUINodeModifiers()->getSwiperModifier()->setSwiperItemSpace(nativeNode, itemSpace.Value(), itemSpaceUnit);
554     return panda::JSValueRef::Undefined(vm);
555 }
ResetSwiperItemSpace(ArkUIRuntimeCallInfo * runtimeCallInfo)556 ArkUINativeModuleValue SwiperBridge::ResetSwiperItemSpace(ArkUIRuntimeCallInfo* runtimeCallInfo)
557 {
558     EcmaVM* vm = runtimeCallInfo->GetVM();
559     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
560     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
561     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
562     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
563     GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperItemSpace(nativeNode);
564     return panda::JSValueRef::Undefined(vm);
565 }
SetSwiperVertical(ArkUIRuntimeCallInfo * runtimeCallInfo)566 ArkUINativeModuleValue SwiperBridge::SetSwiperVertical(ArkUIRuntimeCallInfo* runtimeCallInfo)
567 {
568     EcmaVM* vm = runtimeCallInfo->GetVM();
569     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
570     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
571     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
572     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
573     Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
574     if (valueArg->IsBoolean()) {
575         bool isVertical = valueArg->ToBoolean(vm)->Value();
576         GetArkUINodeModifiers()->getSwiperModifier()->setSwiperVertical(nativeNode, isVertical);
577     } else {
578         GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperVertical(nativeNode);
579     }
580     return panda::JSValueRef::Undefined(vm);
581 }
ResetSwiperVertical(ArkUIRuntimeCallInfo * runtimeCallInfo)582 ArkUINativeModuleValue SwiperBridge::ResetSwiperVertical(ArkUIRuntimeCallInfo* runtimeCallInfo)
583 {
584     EcmaVM* vm = runtimeCallInfo->GetVM();
585     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
586     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
587     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
588     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
589     GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperVertical(nativeNode);
590     return panda::JSValueRef::Undefined(vm);
591 }
SetSwiperLoop(ArkUIRuntimeCallInfo * runtimeCallInfo)592 ArkUINativeModuleValue SwiperBridge::SetSwiperLoop(ArkUIRuntimeCallInfo* runtimeCallInfo)
593 {
594     EcmaVM* vm = runtimeCallInfo->GetVM();
595     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
596     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
597     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
598     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
599     Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
600     if (valueArg->IsBoolean()) {
601         bool loop = valueArg->ToBoolean(vm)->Value();
602         GetArkUINodeModifiers()->getSwiperModifier()->setSwiperLoop(nativeNode, loop);
603     } else {
604         GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperLoop(nativeNode);
605     }
606     return panda::JSValueRef::Undefined(vm);
607 }
ResetSwiperLoop(ArkUIRuntimeCallInfo * runtimeCallInfo)608 ArkUINativeModuleValue SwiperBridge::ResetSwiperLoop(ArkUIRuntimeCallInfo* runtimeCallInfo)
609 {
610     EcmaVM* vm = runtimeCallInfo->GetVM();
611     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
612     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
613     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
614     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
615     GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperLoop(nativeNode);
616     return panda::JSValueRef::Undefined(vm);
617 }
SetSwiperInterval(ArkUIRuntimeCallInfo * runtimeCallInfo)618 ArkUINativeModuleValue SwiperBridge::SetSwiperInterval(ArkUIRuntimeCallInfo* runtimeCallInfo)
619 {
620     EcmaVM* vm = runtimeCallInfo->GetVM();
621     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
622     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
623     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
624     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
625     Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
626     if (valueArg->IsNumber()) {
627         int32_t interval = valueArg->Int32Value(vm);
628         GetArkUINodeModifiers()->getSwiperModifier()->setSwiperInterval(nativeNode, interval);
629     } else {
630         GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperInterval(nativeNode);
631     }
632     return panda::JSValueRef::Undefined(vm);
633 }
ResetSwiperInterval(ArkUIRuntimeCallInfo * runtimeCallInfo)634 ArkUINativeModuleValue SwiperBridge::ResetSwiperInterval(ArkUIRuntimeCallInfo* runtimeCallInfo)
635 {
636     EcmaVM* vm = runtimeCallInfo->GetVM();
637     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
638     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
639     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
640     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
641     GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperInterval(nativeNode);
642     return panda::JSValueRef::Undefined(vm);
643 }
SetSwiperAutoPlay(ArkUIRuntimeCallInfo * runtimeCallInfo)644 ArkUINativeModuleValue SwiperBridge::SetSwiperAutoPlay(ArkUIRuntimeCallInfo* runtimeCallInfo)
645 {
646     EcmaVM* vm = runtimeCallInfo->GetVM();
647     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
648     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
649     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
650     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
651     Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
652     if (valueArg->IsBoolean()) {
653         bool autoPlay = valueArg->ToBoolean(vm)->Value();
654         GetArkUINodeModifiers()->getSwiperModifier()->setSwiperAutoPlay(nativeNode, autoPlay);
655     } else {
656         GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperAutoPlay(nativeNode);
657         return panda::JSValueRef::Undefined(vm);
658     }
659 
660     Local<JSValueRef> jsStopWhenTouchedArg = runtimeCallInfo->GetCallArgRef(STOP_WHEN_TOUCHED);
661     bool neddStopWhenTouched = true;
662     if (!jsStopWhenTouchedArg->IsNull() && !jsStopWhenTouchedArg->IsUndefined() && jsStopWhenTouchedArg->IsBoolean()) {
663         neddStopWhenTouched = jsStopWhenTouchedArg->ToBoolean(vm)->Value();
664     }
665     GetArkUINodeModifiers()->getSwiperModifier()->setSwiperStopWhenTouched(nativeNode, neddStopWhenTouched);
666     return panda::JSValueRef::Undefined(vm);
667 }
ResetSwiperAutoPlay(ArkUIRuntimeCallInfo * runtimeCallInfo)668 ArkUINativeModuleValue SwiperBridge::ResetSwiperAutoPlay(ArkUIRuntimeCallInfo* runtimeCallInfo)
669 {
670     EcmaVM* vm = runtimeCallInfo->GetVM();
671     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
672     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
673     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
674     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
675     GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperAutoPlay(nativeNode);
676     GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperStopWhenTouched(nativeNode);
677     return panda::JSValueRef::Undefined(vm);
678 }
SetSwiperIndex(ArkUIRuntimeCallInfo * runtimeCallInfo)679 ArkUINativeModuleValue SwiperBridge::SetSwiperIndex(ArkUIRuntimeCallInfo* runtimeCallInfo)
680 {
681     EcmaVM* vm = runtimeCallInfo->GetVM();
682     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
683     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
684     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
685     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
686     Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
687     if (valueArg->IsNumber()) {
688         int32_t index = valueArg->Int32Value(vm);
689         GetArkUINodeModifiers()->getSwiperModifier()->setSwiperIndex(nativeNode, index, DEFAULT_ANIMATION_MODE);
690     } else {
691         GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperIndex(nativeNode);
692     }
693     return panda::JSValueRef::Undefined(vm);
694 }
ResetSwiperIndex(ArkUIRuntimeCallInfo * runtimeCallInfo)695 ArkUINativeModuleValue SwiperBridge::ResetSwiperIndex(ArkUIRuntimeCallInfo* runtimeCallInfo)
696 {
697     EcmaVM* vm = runtimeCallInfo->GetVM();
698     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
699     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
700     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
701     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
702     GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperIndex(nativeNode);
703     return panda::JSValueRef::Undefined(vm);
704 }
GetStringByValueRef(const EcmaVM * vm,const Local<JSValueRef> & jsValue,RefPtr<ResourceObject> & resObj)705 std::string GetStringByValueRef(const EcmaVM* vm, const Local<JSValueRef>& jsValue, RefPtr<ResourceObject>& resObj)
706 {
707     std::string result = "-";
708     if (jsValue->IsUndefined()) {
709         return result;
710     }
711     CalcDimension calc;
712     result = ArkTSUtils::ParseJsDimension(vm, jsValue, calc, DimensionUnit::VP, resObj, true)
713                  ? (calc.Unit() == DimensionUnit::PERCENT
714                            ? (std::to_string(calc.Value() * DEFAULT_PERCENT_VALUE) + "%")
715                            : (std::to_string(calc.Value()) + GetDimensionUnitString(calc.Unit())))
716                  : "0.0_vp";
717     return result;
718 }
GetIntStringByValueRef(const EcmaVM * vm,const Local<JSValueRef> & jsValue)719 std::string GetIntStringByValueRef(const EcmaVM* vm, const Local<JSValueRef>& jsValue)
720 {
721     std::string result = "-";
722     if (jsValue->IsUndefined()) {
723         return result;
724     }
725     int32_t intValue;
726     result = ArkTSUtils::ParseJsInteger(vm, jsValue, intValue) ? std::to_string(intValue) : "0";
727     return result;
728 }
729 
ParseBottom(const EcmaVM * vm,const Local<JSValueRef> & jsValue,bool hasIgnoreSize,RefPtr<ResourceObject> & resObj)730 std::string ParseBottom(const EcmaVM* vm, const Local<JSValueRef>& jsValue, bool hasIgnoreSize,
731     RefPtr<ResourceObject>& resObj)
732 {
733     std::string bottom = "-";
734     if (jsValue->IsUndefined()) {
735         return bottom;
736     }
737     if (hasIgnoreSize) {
738         CalcDimension bottomcCalc;
739         bool parseOK =  ArkTSUtils::ParseJsLengthMetrics(vm, jsValue, bottomcCalc, resObj);
740         if (!parseOK) {
741             bottom = GetStringByValueRef(vm, jsValue, resObj);
742             return bottom;
743         } else {
744             bottomcCalc = bottomcCalc > 0.0_vp ? bottomcCalc : 0.0_vp;
745             bottom = bottomcCalc.ToString();
746             return bottom;
747         }
748     } else {
749         bottom = GetStringByValueRef(vm, jsValue, resObj);
750         return bottom;
751     }
752 }
753 
ParseIgrnoreSize(const EcmaVM * vm,const Local<JSValueRef> & jsValue,bool hasIgrnoreSize)754 std::optional<bool> ParseIgrnoreSize(const EcmaVM* vm, const Local<JSValueRef>& jsValue, bool hasIgrnoreSize)
755 {
756     std::optional<bool> ignoreSize;
757     if (!hasIgrnoreSize) {
758         return ignoreSize;
759     }
760     ignoreSize = false;
761     if (!jsValue->IsNull() && !jsValue->IsUndefined() && jsValue->IsBoolean()) {
762         ignoreSize = jsValue->ToBoolean(vm)->Value();
763     }
764     return ignoreSize;
765 }
766 
ParseSpace(const EcmaVM * vm,const Local<JSValueRef> & jsValue)767 std::string ParseSpace(const EcmaVM* vm, const Local<JSValueRef>& jsValue)
768 {
769     std::string result = "-";
770     if (jsValue->IsUndefined()) {
771         return result;
772     }
773     CalcDimension calc;
774     bool parseOK =  ArkTSUtils::ParseJsLengthMetrics(vm, jsValue, calc);
775     calc = (parseOK && !(calc < 0.0_vp) && calc.Unit() != DimensionUnit::PERCENT) ?
776         calc : 8.0_vp;
777     return calc.ToString();
778 }
779 
GetSpaceAndBottom(ArkUIRuntimeCallInfo * runtimeCallInfo,EcmaVM * vm,std::string & bottom,std::string & spaceAndIgnoreSize,RefPtr<ResourceObject> & resObj)780 void GetSpaceAndBottom(ArkUIRuntimeCallInfo* runtimeCallInfo, EcmaVM* vm, std::string& bottom,
781     std::string& spaceAndIgnoreSize, RefPtr<ResourceObject>& resObj)
782 {
783     Local<JSValueRef> bottomArg = runtimeCallInfo->GetCallArgRef(DOT_INDICATOR_BOTTOM);
784     Local<JSValueRef> spaceArg = runtimeCallInfo->GetCallArgRef(DOT_INDICATOR_SPACE);
785     Local<JSValueRef> ignoreSizeArg = runtimeCallInfo->GetCallArgRef(DOT_INDICATOR_IGNORE_SIZE);
786     Local<JSValueRef> setIgnoreSizeArg = runtimeCallInfo->GetCallArgRef(DOT_INDICATOR_SET_IGNORE_SIZE);
787 
788     auto hasIgnoreSize = (setIgnoreSizeArg->IsBoolean() && setIgnoreSizeArg->ToBoolean(vm)->Value()) ? true : false;
789     std::optional<bool> ignoreSize = ParseIgrnoreSize(vm, ignoreSizeArg, hasIgnoreSize);
790     std::string ignoreSizeStr = "-";
791     if (ignoreSize.has_value()) {
792         ignoreSizeStr = ignoreSize.value()  ? "1" : "0";
793     }
794 
795     std::string setIgnoreSizeStr = "-";
796     if (!setIgnoreSizeArg->IsUndefined()) {
797         setIgnoreSizeStr = setIgnoreSizeArg->ToBoolean(vm)->Value() ? "1" : "0";
798     }
799 
800     bottom = ParseBottom(vm, bottomArg, hasIgnoreSize, resObj);
801     std::string space = ParseSpace(vm, spaceArg);
802     spaceAndIgnoreSize =  space + "|" + ignoreSizeStr + "|" + setIgnoreSizeStr;
803 }
804 
GetSwiperDotIndicator(ArkUIRuntimeCallInfo * runtimeCallInfo,EcmaVM * vm,std::vector<RefPtr<ResourceObject>> & resObjs,ArkUINodeHandle nativeNode)805 std::string GetSwiperDotIndicator(ArkUIRuntimeCallInfo* runtimeCallInfo, EcmaVM* vm,
806     std::vector<RefPtr<ResourceObject>>& resObjs, ArkUINodeHandle nativeNode)
807 {
808     Local<JSValueRef> itemWidthArg = runtimeCallInfo->GetCallArgRef(DOT_INDICATOR_ITEM_WIDTH);
809     Local<JSValueRef> itemHeightArg = runtimeCallInfo->GetCallArgRef(DOT_INDICATOR_ITEM_HEIGHT);
810     Local<JSValueRef> selectedItemWidthArg = runtimeCallInfo->GetCallArgRef(DOT_INDICATOR_SELECTED_ITEM_WIDTH);
811     Local<JSValueRef> selectedItemHeightArg = runtimeCallInfo->GetCallArgRef(DOT_INDICATOR_SELECTED_ITEM_HEIGHT);
812     Local<JSValueRef> maskArg = runtimeCallInfo->GetCallArgRef(DOT_INDICATOR_MASK);
813     Local<JSValueRef> colorArg = runtimeCallInfo->GetCallArgRef(DOT_INDICATOR_COLOR);
814     Local<JSValueRef> selectedColorArg = runtimeCallInfo->GetCallArgRef(DOT_INDICATOR_SELECTED_COLOR);
815     Local<JSValueRef> leftArg = runtimeCallInfo->GetCallArgRef(DOT_INDICATOR_LEFT);
816     Local<JSValueRef> topArg = runtimeCallInfo->GetCallArgRef(DOT_INDICATOR_TOP);
817     Local<JSValueRef> rightArg = runtimeCallInfo->GetCallArgRef(DOT_INDICATOR_RIGHT);
818 
819     CalcDimension calc;
820     std::string itemWidth = ArkTSUtils::ParseJsDimension(vm, itemWidthArg, calc, DimensionUnit::VP,
821         resObjs.at(DOT_INDICATOR_RESOURCE_ITEM_WIDTH), false)
822         ? std::to_string(calc.Value()) + GetDimensionUnitString(calc.Unit()) : "-";
823     std::string itemHeight = ArkTSUtils::ParseJsDimension(vm, itemHeightArg, calc, DimensionUnit::VP,
824         resObjs.at(DOT_INDICATOR_RESOURCE_ITEM_HEIGHT), false)
825         ? std::to_string(calc.Value()) + GetDimensionUnitString(calc.Unit()) : "-";
826     std::string selectedItemWidth =
827         ArkTSUtils::ParseJsDimension(vm, selectedItemWidthArg, calc, DimensionUnit::VP,
828             resObjs.at(DOT_INDICATOR_RESOURCE_SELECTED_ITEM_WIDTH), false)
829             ? std::to_string(calc.Value()) + GetDimensionUnitString(calc.Unit()) : "-";
830     std::string selectedItemHeight =
831         ArkTSUtils::ParseJsDimension(vm, selectedItemHeightArg, calc, DimensionUnit::VP,
832             resObjs.at(DOT_INDICATOR_RESOURCE_SELECTED_ITEM_HEIGHT), false)
833             ? std::to_string(calc.Value()) + GetDimensionUnitString(calc.Unit()) : "-";
834     std::string mask = "2";
835     if (!maskArg->IsUndefined()) {
836         mask = maskArg->ToBoolean(vm)->Value() ? "1" : "0";
837     }
838     Color color;
839     auto nodeInfo = ArkTSUtils::MakeNativeNodeInfo(nativeNode);
840     std::string colorStr = ArkTSUtils::ParseJsColorAlpha(vm, colorArg, color,
841         resObjs.at(DOT_INDICATOR_RESOURCE_COLOR), nodeInfo) ? std::to_string(color.GetValue()) : "-";
842     std::string selectedColor = ArkTSUtils::ParseJsColorAlpha(vm, selectedColorArg, color,
843         resObjs.at(DOT_INDICATOR_RESOURCE_SELECTED_COLOR), nodeInfo) ? std::to_string(color.GetValue()) : "-";
844     std::string left = GetStringByValueRef(vm, leftArg, resObjs.at(INDICATOR_RESOURCE_LEFT));
845     std::string top = GetStringByValueRef(vm, topArg, resObjs.at(INDICATOR_RESOURCE_TOP));
846     std::string right = GetStringByValueRef(vm, rightArg, resObjs.at(INDICATOR_RESOURCE_RIGHT));
847     Local<JSValueRef> maxDisplayCountArg = runtimeCallInfo->GetCallArgRef(DOT_INDICATOR_MAX_DISPLAY_COUNT);
848     auto maxDisplayCount = GetIntStringByValueRef(vm, maxDisplayCountArg);
849     std::string bottom = "-";
850     std::string spaceAndIgnoreSize = "-";
851     GetSpaceAndBottom(runtimeCallInfo, vm, bottom, spaceAndIgnoreSize, resObjs.at(INDICATOR_RESOURCE_BOTTOM));
852     std::string indicatorStr = itemWidth + "|" + itemHeight + "|" + selectedItemWidth + "|" +
853                                selectedItemHeight + "|" + mask + "|" + colorStr + "|" + selectedColor + "|" + left +
854                                "|" + top + "|" + right + "|" + bottom + "|" + maxDisplayCount + "|" +
855                                spaceAndIgnoreSize;
856     return indicatorStr;
857 }
GetSwiperDigitIndicator(ArkUIRuntimeCallInfo * runtimeCallInfo,EcmaVM * vm,std::vector<RefPtr<ResourceObject>> & resObjs,ArkUINodeHandle nativeNode)858 std::string GetSwiperDigitIndicator(ArkUIRuntimeCallInfo* runtimeCallInfo, EcmaVM* vm,
859     std::vector<RefPtr<ResourceObject>>& resObjs, ArkUINodeHandle nativeNode)
860 {
861     Local<JSValueRef> fontColorArg = runtimeCallInfo->GetCallArgRef(DIGIT_INDICATOR_FONT_COLOR);
862     Local<JSValueRef> selectedFontColorArg = runtimeCallInfo->GetCallArgRef(DIGIT_INDICATOR_SELECTED_FONT_COLOR);
863     Local<JSValueRef> digitFontSizeArg = runtimeCallInfo->GetCallArgRef(DIGIT_INDICATOR_DIGIT_FONT_SIZE);
864     Local<JSValueRef> digitFontWeightArg = runtimeCallInfo->GetCallArgRef(DIGIT_INDICATOR_DIGIT_FONT_WEIGHT);
865     Local<JSValueRef> selectedDigitFontSizeArg =
866         runtimeCallInfo->GetCallArgRef(DIGIT_INDICATOR_SELECTED_DIGIT_FONT_SIZE);
867     Local<JSValueRef> selectedDigitFontWeightArg =
868         runtimeCallInfo->GetCallArgRef(DIGIT_INDICATOR_SELECTED_DIGIT_FONT_WEIGHT);
869     Local<JSValueRef> leftArg = runtimeCallInfo->GetCallArgRef(DIGIT_INDICATOR_LEFT);
870     Local<JSValueRef> topArg = runtimeCallInfo->GetCallArgRef(DIGIT_INDICATOR_TOP);
871     Local<JSValueRef> rightArg = runtimeCallInfo->GetCallArgRef(DIGIT_INDICATOR_RIGHT);
872     Local<JSValueRef> bottomArg = runtimeCallInfo->GetCallArgRef(DIGIT_INDICATOR_BOTTOM);
873     Local<JSValueRef> ignoreSizeArg = runtimeCallInfo->GetCallArgRef(DIGIT_INDICATOR_IGNORE_SIZE);
874     Local<JSValueRef> setIgnoreSizeArg = runtimeCallInfo->GetCallArgRef(DIGIT_INDICATOR_SET_IGNORE_SIZE);
875     Color color;
876     CalcDimension calc;
877     auto nodeInfo = ArkTSUtils::MakeNativeNodeInfo(nativeNode);
878     std::string fontColor = ArkTSUtils::ParseJsColorAlpha(vm, fontColorArg, color,
879         resObjs.at(DIGIT_INDICATOR_RESOURCE_FONT_COLOR), nodeInfo) ? std::to_string(color.GetValue()) : "-";
880     std::string selectedFontColor = ArkTSUtils::ParseJsColorAlpha(vm, selectedFontColorArg, color,
881         resObjs.at(DIGIT_INDICATOR_RESOURCE_FONT_SELECTED_COLOR), nodeInfo) ? std::to_string(color.GetValue()) : "-";
882     std::string digitFontSize = ArkTSUtils::ParseJsDimension(vm, digitFontSizeArg, calc, DimensionUnit::FP,
883         resObjs.at(DIGIT_INDICATOR_RESOURCE_FONT_SIZE), false)
884         ? std::to_string(calc.Value()) + GetDimensionUnitString(calc.Unit()) : "-";
885     std::string digitFontWeight = digitFontWeightArg->ToString(vm)->ToString(vm);
886     std::string selectedDigitFontSize = ArkTSUtils::ParseJsDimension(vm, selectedDigitFontSizeArg, calc,
887         DimensionUnit::FP, resObjs.at(DIGIT_INDICATOR_RESOURCE_SELECTED_FONT_SIZE), false)
888         ? std::to_string(calc.Value()) + GetDimensionUnitString(calc.Unit()) : "-";
889     std::string selectedDigitFontWeight = selectedDigitFontWeightArg->ToString(vm)->ToString(vm);
890     std::string left = GetStringByValueRef(vm, leftArg, resObjs.at(INDICATOR_RESOURCE_LEFT));
891     std::string top = GetStringByValueRef(vm, topArg, resObjs.at(INDICATOR_RESOURCE_TOP));
892     std::string right = GetStringByValueRef(vm, rightArg, resObjs.at(INDICATOR_RESOURCE_RIGHT));
893 
894     std::string setIgnoreSize = "-";
895     if (!setIgnoreSizeArg->IsUndefined()) {
896         setIgnoreSize = setIgnoreSizeArg->ToBoolean(vm)->Value() ? "1" : "0";
897     }
898 
899     auto hasIgnoreSize = (setIgnoreSizeArg->IsBoolean() && setIgnoreSizeArg->ToBoolean(vm)->Value()) ? true : false;
900     std::optional<bool> ignoreSize = ParseIgrnoreSize(vm, ignoreSizeArg, hasIgnoreSize);
901     std::string ignoreSizeStr = "-";
902     if (ignoreSize.has_value()) {
903         ignoreSizeStr = ignoreSize.value()  ? "1" : "0";
904     }
905     std::string bottom = ParseBottom(vm, bottomArg, hasIgnoreSize, resObjs.at(INDICATOR_RESOURCE_BOTTOM));
906     std::string indicatorStr = fontColor + "|" + selectedFontColor + "|" + digitFontSize + "|" + digitFontWeight +
907                    "|" + selectedDigitFontSize + "|" + selectedDigitFontWeight + "|" + left + "|" + top + "|" + right +
908                    "|" + bottom + "|" + ignoreSizeStr + "|" + setIgnoreSize;
909     return indicatorStr;
910 }
SetSwiperIndicator(ArkUIRuntimeCallInfo * runtimeCallInfo)911 ArkUINativeModuleValue SwiperBridge::SetSwiperIndicator(ArkUIRuntimeCallInfo* runtimeCallInfo)
912 {
913     EcmaVM* vm = runtimeCallInfo->GetVM();
914     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
915     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
916     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
917     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
918     Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
919     auto frameNode = reinterpret_cast<FrameNode*>(nativeNode);
920     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
921 
922     std::string type = valueArg->ToString(vm)->ToString(vm);
923     std::string indicatorStr = "";
924     std::vector<RefPtr<ResourceObject>> resObjs;
925     resObjs.resize(INDICATOR_RESOURCE_VECTOR_LENGTH);
926     if (type == "boolean") {
927         Local<JSValueRef> indicatorArg = runtimeCallInfo->GetCallArgRef(INDICATOR_VALUE_INDEX);
928         std::string indicator = indicatorArg->ToBoolean(vm)->Value() ? "1" : "0";
929         indicatorStr = type + "|" + indicator;
930     } else if (type == "ArkDotIndicator") {
931         indicatorStr = type + "|" + GetSwiperDotIndicator(runtimeCallInfo, vm, resObjs, nativeNode);
932     } else if (type == "ArkDigitIndicator") {
933         indicatorStr = type + "|" + GetSwiperDigitIndicator(runtimeCallInfo, vm, resObjs, nativeNode);
934     } else if (type == "IndicatorComponentController") {
935         Framework::JsiCallbackInfo info = Framework::JsiCallbackInfo(runtimeCallInfo);
936         Framework::JSIndicatorController* jsController =
937             Framework::JSRef<Framework::JSObject>::Cast(info[INDICATOR_VALUE_INDEX])
938                 ->Unwrap<Framework::JSIndicatorController>();
939         if (jsController) {
940             auto targetNode = AceType::Claim(frameNode);
941             jsController->SetSwiperNodeBySwiper(targetNode);
942         }
943         indicatorStr = "IndicatorComponentController|";
944     } else {
945         indicatorStr = "boolean|1";
946     }
947     if (SystemProperties::ConfigChangePerform()) {
948         GetArkUINodeModifiers()->getSwiperModifier()->setSwiperIndicatorRaw(nativeNode, indicatorStr.c_str(),
949             static_cast<void*>(&resObjs));
950     } else {
951         GetArkUINodeModifiers()->getSwiperModifier()->setSwiperIndicator(nativeNode, indicatorStr.c_str());
952     }
953     return panda::JSValueRef::Undefined(vm);
954 }
ResetSwiperIndicator(ArkUIRuntimeCallInfo * runtimeCallInfo)955 ArkUINativeModuleValue SwiperBridge::ResetSwiperIndicator(ArkUIRuntimeCallInfo* runtimeCallInfo)
956 {
957     EcmaVM* vm = runtimeCallInfo->GetVM();
958     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
959     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
960     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
961     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
962     GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperIndicator(nativeNode);
963     return panda::JSValueRef::Undefined(vm);
964 }
SetSwiperDuration(ArkUIRuntimeCallInfo * runtimeCallInfo)965 ArkUINativeModuleValue SwiperBridge::SetSwiperDuration(ArkUIRuntimeCallInfo* runtimeCallInfo)
966 {
967     EcmaVM* vm = runtimeCallInfo->GetVM();
968     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
969     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
970     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
971     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
972     Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
973     if (valueArg->IsNumber()) {
974         int32_t duration = valueArg->Int32Value(vm);
975         GetArkUINodeModifiers()->getSwiperModifier()->setSwiperDuration(nativeNode, duration);
976     } else {
977         GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperDuration(nativeNode);
978     }
979     return panda::JSValueRef::Undefined(vm);
980 }
981 
ResetSwiperDuration(ArkUIRuntimeCallInfo * runtimeCallInfo)982 ArkUINativeModuleValue SwiperBridge::ResetSwiperDuration(ArkUIRuntimeCallInfo* runtimeCallInfo)
983 {
984     EcmaVM* vm = runtimeCallInfo->GetVM();
985     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
986     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
987     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
988     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
989     GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperDuration(nativeNode);
990     return panda::JSValueRef::Undefined(vm);
991 }
992 
SetSwiperEnabled(ArkUIRuntimeCallInfo * runtimeCallInfo)993 ArkUINativeModuleValue SwiperBridge::SetSwiperEnabled(ArkUIRuntimeCallInfo* runtimeCallInfo)
994 {
995     EcmaVM* vm = runtimeCallInfo->GetVM();
996     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
997     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
998     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
999     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
1000     Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
1001     if (valueArg->IsBoolean()) {
1002         bool enabled = valueArg->ToBoolean(vm)->Value();
1003         GetArkUINodeModifiers()->getCommonModifier()->setEnabled(nativeNode, enabled);
1004         GetArkUINodeModifiers()->getSwiperModifier()->setSwiperEnabled(nativeNode, enabled);
1005     } else {
1006         GetArkUINodeModifiers()->getCommonModifier()->resetEnabled(nativeNode);
1007         GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperEnabled(nativeNode);
1008     }
1009     return panda::JSValueRef::Undefined(vm);
1010 }
1011 
ResetSwiperEnabled(ArkUIRuntimeCallInfo * runtimeCallInfo)1012 ArkUINativeModuleValue SwiperBridge::ResetSwiperEnabled(ArkUIRuntimeCallInfo* runtimeCallInfo)
1013 {
1014     EcmaVM* vm = runtimeCallInfo->GetVM();
1015     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1016     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
1017     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
1018     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
1019     GetArkUINodeModifiers()->getCommonModifier()->resetEnabled(nativeNode);
1020     GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperEnabled(nativeNode);
1021     return panda::JSValueRef::Undefined(vm);
1022 }
1023 
SetSwiperOnChange(ArkUIRuntimeCallInfo * runtimeCallInfo)1024 ArkUINativeModuleValue SwiperBridge::SetSwiperOnChange(ArkUIRuntimeCallInfo* runtimeCallInfo)
1025 {
1026     EcmaVM* vm = runtimeCallInfo->GetVM();
1027     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
1028     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
1029     Local<JSValueRef> callbackArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
1030     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
1031     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1032     if (callbackArg->IsUndefined() || callbackArg->IsNull() || !callbackArg->IsFunction(vm)) {
1033         GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperOnChange(nativeNode);
1034         return panda::JSValueRef::Undefined(vm);
1035     }
1036     auto frameNode = reinterpret_cast<FrameNode*>(nativeNode);
1037     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
1038     panda::Local<panda::FunctionRef> func = callbackArg->ToObject(vm);
1039     std::function<void(const BaseEventInfo* info)> callback =
1040         [vm, frameNode, func = panda::CopyableGlobal(vm, func)](const BaseEventInfo* info) {
1041         panda::LocalScope pandaScope(vm);
1042         panda::TryCatch trycatch(vm);
1043         PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode));
1044         const auto* swiperInfo = TypeInfoHelper::DynamicCast<SwiperChangeEvent>(info);
1045         if (!swiperInfo) {
1046             TAG_LOGW(AceLogTag::ACE_SWIPER, "Swiper onChange callback execute failed.");
1047             return;
1048         }
1049         panda::Local<panda::NumberRef> indexParam = panda::NumberRef::New(vm, swiperInfo->GetIndex());
1050         panda::Local<panda::JSValueRef> params[1] = { indexParam }; // 1: Array length
1051         func->Call(vm, func.ToLocal(), params, 1); // 1: Array length
1052     };
1053     GetArkUINodeModifiers()->getSwiperModifier()->setSwiperOnChange(nativeNode, reinterpret_cast<void*>(&callback));
1054     return panda::JSValueRef::Undefined(vm);
1055 }
1056 
ResetSwiperOnChange(ArkUIRuntimeCallInfo * runtimeCallInfo)1057 ArkUINativeModuleValue SwiperBridge::ResetSwiperOnChange(ArkUIRuntimeCallInfo* runtimeCallInfo)
1058 {
1059     EcmaVM* vm = runtimeCallInfo->GetVM();
1060     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
1061     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
1062     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
1063     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1064     GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperOnChange(nativeNode);
1065     return panda::JSValueRef::Undefined(vm);
1066 }
1067 
SetSwiperOnSelected(ArkUIRuntimeCallInfo * runtimeCallInfo)1068 ArkUINativeModuleValue SwiperBridge::SetSwiperOnSelected(ArkUIRuntimeCallInfo* runtimeCallInfo)
1069 {
1070     EcmaVM* vm = runtimeCallInfo->GetVM();
1071     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
1072     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
1073     Local<JSValueRef> callbackArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
1074     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1075     if (callbackArg->IsUndefined() || callbackArg->IsNull() || !callbackArg->IsFunction(vm)) {
1076         GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperOnSelected(nativeNode);
1077         return panda::JSValueRef::Undefined(vm);
1078     }
1079     auto frameNode = reinterpret_cast<FrameNode*>(nativeNode);
1080     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
1081     panda::Local<panda::FunctionRef> func = callbackArg->ToObject(vm);
1082     std::function<void(const BaseEventInfo* info)> callback =
1083         [vm, frameNode, func = panda::CopyableGlobal(vm, func)](const BaseEventInfo* info) {
1084         panda::LocalScope pandaScope(vm);
1085         panda::TryCatch trycatch(vm);
1086         PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode));
1087         const auto* swiperInfo = TypeInfoHelper::DynamicCast<SwiperChangeEvent>(info);
1088         if (!swiperInfo) {
1089             TAG_LOGW(AceLogTag::ACE_SWIPER, "Swiper onSelected callback execute failed.");
1090             return;
1091         }
1092         panda::Local<panda::NumberRef> indexParam = panda::NumberRef::New(vm, swiperInfo->GetIndex());
1093         panda::Local<panda::JSValueRef> params[1] = { indexParam }; // 1: Array length
1094         func->Call(vm, func.ToLocal(), params, 1); // 1: Array length
1095     };
1096     GetArkUINodeModifiers()->getSwiperModifier()->setSwiperOnSelected(nativeNode, reinterpret_cast<void*>(&callback));
1097     return panda::JSValueRef::Undefined(vm);
1098 }
1099 
ResetSwiperOnSelected(ArkUIRuntimeCallInfo * runtimeCallInfo)1100 ArkUINativeModuleValue SwiperBridge::ResetSwiperOnSelected(ArkUIRuntimeCallInfo* runtimeCallInfo)
1101 {
1102     EcmaVM* vm = runtimeCallInfo->GetVM();
1103     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
1104     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
1105     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1106     GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperOnSelected(nativeNode);
1107     return panda::JSValueRef::Undefined(vm);
1108 }
1109 
SetSwiperOnAnimationStart(ArkUIRuntimeCallInfo * runtimeCallInfo)1110 ArkUINativeModuleValue SwiperBridge::SetSwiperOnAnimationStart(ArkUIRuntimeCallInfo* runtimeCallInfo)
1111 {
1112     EcmaVM* vm = runtimeCallInfo->GetVM();
1113     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
1114     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
1115     Local<JSValueRef> callbackArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
1116     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
1117     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1118     if (callbackArg->IsUndefined() || callbackArg->IsNull() || !callbackArg->IsFunction(vm)) {
1119         GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperOnAnimationStart(nativeNode);
1120         return panda::JSValueRef::Undefined(vm);
1121     }
1122     auto frameNode = reinterpret_cast<FrameNode*>(nativeNode);
1123     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
1124     panda::Local<panda::FunctionRef> func = callbackArg->ToObject(vm);
1125     std::function<void(int32_t, int32_t, const AnimationCallbackInfo&)> callback =
1126         [vm, frameNode, func = panda::CopyableGlobal(vm, func)](
1127         int32_t index, int32_t targetIndex, const AnimationCallbackInfo& extraInfo) {
1128         panda::LocalScope pandaScope(vm);
1129         panda::TryCatch trycatch(vm);
1130         PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode));
1131         panda::Local<panda::NumberRef> indexParam = panda::NumberRef::New(vm, index);
1132         panda::Local<panda::NumberRef> targetIndexParam = panda::NumberRef::New(vm, targetIndex);
1133         const char* keys[] = {"currentOffset", "targetOffset", "velocity"};
1134         Local<JSValueRef> values[] = { panda::NumberRef::New(vm, extraInfo.currentOffset.value_or(0.0f)),
1135             panda::NumberRef::New(vm, extraInfo.targetOffset.value_or(0.0f)),
1136             panda::NumberRef::New(vm, extraInfo.velocity.value_or(0.0f)) };
1137         auto eventObject = panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keys), keys, values);
1138         panda::Local<panda::JSValueRef> params[3] = { indexParam, targetIndexParam, eventObject }; // 3: Array length
1139         func->Call(vm, func.ToLocal(), params, 3); // 3: Array length
1140     };
1141     GetArkUINodeModifiers()->getSwiperModifier()->setSwiperOnAnimationStart(nativeNode,
1142         reinterpret_cast<void*>(&callback));
1143     return panda::JSValueRef::Undefined(vm);
1144 }
1145 
ResetSwiperOnAnimationStart(ArkUIRuntimeCallInfo * runtimeCallInfo)1146 ArkUINativeModuleValue SwiperBridge::ResetSwiperOnAnimationStart(ArkUIRuntimeCallInfo* runtimeCallInfo)
1147 {
1148     EcmaVM* vm = runtimeCallInfo->GetVM();
1149     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
1150     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1151     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
1152     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1153     GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperOnAnimationStart(nativeNode);
1154     return panda::JSValueRef::Undefined(vm);
1155 }
1156 
SetSwiperOnAnimationEnd(ArkUIRuntimeCallInfo * runtimeCallInfo)1157 ArkUINativeModuleValue SwiperBridge::SetSwiperOnAnimationEnd(ArkUIRuntimeCallInfo* runtimeCallInfo)
1158 {
1159     EcmaVM* vm = runtimeCallInfo->GetVM();
1160     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
1161     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
1162     Local<JSValueRef> callbackArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
1163     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
1164     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1165     if (callbackArg->IsUndefined() || callbackArg->IsNull() || !callbackArg->IsFunction(vm)) {
1166         GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperOnAnimationEnd(nativeNode);
1167         return panda::JSValueRef::Undefined(vm);
1168     }
1169     auto frameNode = reinterpret_cast<FrameNode*>(nativeNode);
1170     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
1171     panda::Local<panda::FunctionRef> func = callbackArg->ToObject(vm);
1172     std::function<void(int32_t, const AnimationCallbackInfo&)> callback = [vm, frameNode,
1173         func = panda::CopyableGlobal(vm, func)](int32_t index, const AnimationCallbackInfo& extraInfo) {
1174         panda::LocalScope pandaScope(vm);
1175         panda::TryCatch trycatch(vm);
1176         PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode));
1177         panda::Local<panda::NumberRef> indexParam = panda::NumberRef::New(vm, index);
1178         const char* keys[] = {"currentOffset", "targetOffset", "velocity"};
1179         Local<JSValueRef> values[] = { panda::NumberRef::New(vm, extraInfo.currentOffset.value()),
1180             panda::NumberRef::New(vm, 0),
1181             panda::NumberRef::New(vm, 0) };
1182         auto eventObject = panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keys), keys, values);
1183         panda::Local<panda::JSValueRef> params[2] = { indexParam, eventObject }; // 2: Array length
1184         func->Call(vm, func.ToLocal(), params, 2); // 2: Array length
1185     };
1186     GetArkUINodeModifiers()->getSwiperModifier()->setSwiperOnAnimationEnd(nativeNode,
1187         reinterpret_cast<void*>(&callback));
1188     return panda::JSValueRef::Undefined(vm);
1189 }
1190 
ResetSwiperOnAnimationEnd(ArkUIRuntimeCallInfo * runtimeCallInfo)1191 ArkUINativeModuleValue SwiperBridge::ResetSwiperOnAnimationEnd(ArkUIRuntimeCallInfo* runtimeCallInfo)
1192 {
1193     EcmaVM* vm = runtimeCallInfo->GetVM();
1194     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
1195     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1196     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
1197     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1198     GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperOnAnimationEnd(nativeNode);
1199     return panda::JSValueRef::Undefined(vm);
1200 }
1201 
SetSwiperOnGestureSwipe(ArkUIRuntimeCallInfo * runtimeCallInfo)1202 ArkUINativeModuleValue SwiperBridge::SetSwiperOnGestureSwipe(ArkUIRuntimeCallInfo* runtimeCallInfo)
1203 {
1204     EcmaVM* vm = runtimeCallInfo->GetVM();
1205     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
1206     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
1207     Local<JSValueRef> callbackArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
1208     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
1209     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1210     if (callbackArg->IsUndefined() || callbackArg->IsNull() || !callbackArg->IsFunction(vm)) {
1211         GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperOnGestureSwipe(nativeNode);
1212         return panda::JSValueRef::Undefined(vm);
1213     }
1214     auto frameNode = reinterpret_cast<FrameNode*>(nativeNode);
1215     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
1216     panda::Local<panda::FunctionRef> func = callbackArg->ToObject(vm);
1217     std::function<void(int32_t, const AnimationCallbackInfo&)> callback = [vm, frameNode,
1218         func = panda::CopyableGlobal(vm, func)](int32_t index, const AnimationCallbackInfo& extraInfo) {
1219         panda::LocalScope pandaScope(vm);
1220         panda::TryCatch trycatch(vm);
1221         PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode));
1222         panda::Local<panda::NumberRef> indexParam = panda::NumberRef::New(vm, index);
1223         const char* keys[] = {"currentOffset", "targetOffset", "velocity"};
1224         Local<JSValueRef> values[] = { panda::NumberRef::New(vm, extraInfo.currentOffset.value()),
1225             panda::NumberRef::New(vm, 0),
1226             panda::NumberRef::New(vm, 0) };
1227         auto eventObject = panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keys), keys, values);
1228         panda::Local<panda::JSValueRef> params[2] = { indexParam, eventObject }; // 2: Array length
1229         func->Call(vm, func.ToLocal(), params, 2); // 2: Array length
1230     };
1231     GetArkUINodeModifiers()->getSwiperModifier()->setSwiperOnGestureSwipe(nativeNode,
1232         reinterpret_cast<void*>(&callback));
1233     return panda::JSValueRef::Undefined(vm);
1234 }
1235 
ResetSwiperOnGestureSwipe(ArkUIRuntimeCallInfo * runtimeCallInfo)1236 ArkUINativeModuleValue SwiperBridge::ResetSwiperOnGestureSwipe(ArkUIRuntimeCallInfo* runtimeCallInfo)
1237 {
1238     EcmaVM* vm = runtimeCallInfo->GetVM();
1239     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
1240     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1241     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
1242     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1243     GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperOnGestureSwipe(nativeNode);
1244     return panda::JSValueRef::Undefined(vm);
1245 }
1246 
SetSwiperOnUnselected(ArkUIRuntimeCallInfo * runtimeCallInfo)1247 ArkUINativeModuleValue SwiperBridge::SetSwiperOnUnselected(ArkUIRuntimeCallInfo* runtimeCallInfo)
1248 {
1249     EcmaVM* vm = runtimeCallInfo->GetVM();
1250     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
1251     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
1252     Local<JSValueRef> callbackArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
1253     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1254     if (callbackArg->IsUndefined() || callbackArg->IsNull() || !callbackArg->IsFunction(vm)) {
1255         GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperOnUnselected(nativeNode);
1256         return panda::JSValueRef::Undefined(vm);
1257     }
1258     auto frameNode = reinterpret_cast<FrameNode*>(nativeNode);
1259     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
1260     panda::Local<panda::FunctionRef> func = callbackArg->ToObject(vm);
1261     std::function<void(const BaseEventInfo* info)> callback =
1262         [vm, frameNode, func = panda::CopyableGlobal(vm, func)](const BaseEventInfo* info) {
1263         panda::LocalScope pandaScope(vm);
1264         panda::TryCatch trycatch(vm);
1265         PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode));
1266         const auto* swiperInfo = TypeInfoHelper::DynamicCast<SwiperChangeEvent>(info);
1267         if (!swiperInfo) {
1268             TAG_LOGW(AceLogTag::ACE_SWIPER, "Swiper OnUnselected callback execute failed.");
1269             return;
1270         }
1271         panda::Local<panda::NumberRef> indexParam = panda::NumberRef::New(vm, swiperInfo->GetIndex());
1272         panda::Local<panda::JSValueRef> params[1] = { indexParam }; // 1: Array length
1273         func->Call(vm, func.ToLocal(), params, 1); // 1: Array length
1274     };
1275     GetArkUINodeModifiers()->getSwiperModifier()->setSwiperOnUnselected(nativeNode, reinterpret_cast<void*>(&callback));
1276     return panda::JSValueRef::Undefined(vm);
1277 }
1278 
ResetSwiperOnUnselected(ArkUIRuntimeCallInfo * runtimeCallInfo)1279 ArkUINativeModuleValue SwiperBridge::ResetSwiperOnUnselected(ArkUIRuntimeCallInfo* runtimeCallInfo)
1280 {
1281     EcmaVM* vm = runtimeCallInfo->GetVM();
1282     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
1283     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
1284     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1285     GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperOnUnselected(nativeNode);
1286     return panda::JSValueRef::Undefined(vm);
1287 }
1288 
SetSwiperCustomContentTransition(ArkUIRuntimeCallInfo * runtimeCallInfo)1289 ArkUINativeModuleValue SwiperBridge::SetSwiperCustomContentTransition(ArkUIRuntimeCallInfo* runtimeCallInfo)
1290 {
1291     EcmaVM* vm = runtimeCallInfo->GetVM();
1292     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
1293     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
1294     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
1295     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1296     auto* frameNode = reinterpret_cast<FrameNode*>(nativeNode);
1297     using namespace OHOS::Ace::Framework;
1298     JsiCallbackInfo info = JsiCallbackInfo(runtimeCallInfo);
1299     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
1300     if (info.Length() < 2 || !info[1]->IsObject()) { // 2: Array length
1301         return panda::JSValueRef::Undefined(vm);
1302     }
1303 
1304     SwiperContentAnimatedTransition transitionInfo;
1305     auto transitionObj = JSRef<JSObject>::Cast(info[1]);
1306     JSRef<JSVal> timeoutProperty = transitionObj->GetProperty("timeout");
1307     if (timeoutProperty->IsNumber()) {
1308         auto timeout = timeoutProperty->ToNumber<int32_t>();
1309         transitionInfo.timeout = timeout < 0 ? 0 : timeout;
1310     } else {
1311         transitionInfo.timeout = 0;
1312     }
1313 
1314     JSRef<JSVal> transition = transitionObj->GetProperty("transition");
1315     if (transition->IsFunction()) {
1316         auto jsOnTransition =
1317             AceType::MakeRefPtr<JsSwiperFunction>(JSRef<JSFunc>::Cast(transition));
1318         auto onTransition = [execCtx = info.GetExecutionContext(), func = std::move(jsOnTransition)](
1319                                 const RefPtr<SwiperContentTransitionProxy>& proxy) {
1320             JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
1321             ACE_SCORING_EVENT("Swiper.customContentTransition");
1322             func->Execute(proxy);
1323         };
1324         transitionInfo.transition = std::move(onTransition);
1325     }
1326     SwiperModelNG::SetCustomContentTransition(frameNode, transitionInfo);
1327     return panda::JSValueRef::Undefined(vm);
1328 }
1329 
ResetSwiperCustomContentTransition(ArkUIRuntimeCallInfo * runtimeCallInfo)1330 ArkUINativeModuleValue SwiperBridge::ResetSwiperCustomContentTransition(ArkUIRuntimeCallInfo* runtimeCallInfo)
1331 {
1332     EcmaVM* vm = runtimeCallInfo->GetVM();
1333     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
1334     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
1335     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
1336     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1337     auto* frameNode = reinterpret_cast<FrameNode*>(nativeNode);
1338     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
1339     SwiperContentAnimatedTransition transitionInfo;
1340     SwiperModelNG::SetCustomContentTransition(frameNode, transitionInfo);
1341     return panda::JSValueRef::Undefined(vm);
1342 }
1343 
SetOnContentDidScroll(ArkUIRuntimeCallInfo * runtimeCallInfo)1344 ArkUINativeModuleValue SwiperBridge::SetOnContentDidScroll(ArkUIRuntimeCallInfo* runtimeCallInfo)
1345 {
1346     EcmaVM* vm = runtimeCallInfo->GetVM();
1347     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
1348     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
1349     Local<JSValueRef> callbackArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
1350     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
1351     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1352     if (callbackArg->IsUndefined() || callbackArg->IsNull() || !callbackArg->IsFunction(vm)) {
1353         GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperOnContentDidScroll(nativeNode);
1354         return panda::JSValueRef::Undefined(vm);
1355     }
1356     auto frameNode = reinterpret_cast<FrameNode*>(nativeNode);
1357     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
1358     panda::Local<panda::FunctionRef> func = callbackArg->ToObject(vm);
1359     std::function<void(int32_t, int32_t, float_t, float_t)> callback = [vm, frameNode,
1360         func = panda::CopyableGlobal(vm, func)](int32_t selectedIndex, int32_t index,
1361         float position, float mainAxisLength) {
1362         panda::LocalScope pandaScope(vm);
1363         panda::TryCatch trycatch(vm);
1364         PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode));
1365         panda::Local<panda::NumberRef> selectedIndexParam = panda::NumberRef::New(vm, selectedIndex);
1366         panda::Local<panda::NumberRef> indexParam = panda::NumberRef::New(vm, index);
1367         panda::Local<panda::NumberRef> positionParam = panda::NumberRef::New(vm, position);
1368         panda::Local<panda::NumberRef> mainAxisLengthParam = panda::NumberRef::New(vm, mainAxisLength);
1369         panda::Local<panda::JSValueRef> params[4] = { selectedIndexParam, indexParam, // 4: Array length
1370             positionParam, mainAxisLengthParam };
1371         func->Call(vm, func.ToLocal(), params, 4); // 4: Array length
1372     };
1373     GetArkUINodeModifiers()->getSwiperModifier()->setSwiperOnContentDidScroll(nativeNode,
1374         reinterpret_cast<void*>(&callback));
1375     return panda::JSValueRef::Undefined(vm);
1376 }
1377 
ResetOnContentDidScroll(ArkUIRuntimeCallInfo * runtimeCallInfo)1378 ArkUINativeModuleValue SwiperBridge::ResetOnContentDidScroll(ArkUIRuntimeCallInfo* runtimeCallInfo)
1379 {
1380     EcmaVM* vm = runtimeCallInfo->GetVM();
1381     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
1382     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1383     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
1384     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1385     GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperOnContentDidScroll(nativeNode);
1386     return panda::JSValueRef::Undefined(vm);
1387 }
1388 
SetSwiperPageFlipMode(ArkUIRuntimeCallInfo * runtimeCallInfo)1389 ArkUINativeModuleValue SwiperBridge::SetSwiperPageFlipMode(ArkUIRuntimeCallInfo* runtimeCallInfo)
1390 {
1391     EcmaVM* vm = runtimeCallInfo->GetVM();
1392     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1393     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
1394     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
1395     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
1396     Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
1397     if (valueArg->IsNumber()) {
1398         int32_t pageFlipMode = valueArg->Int32Value(vm);
1399         GetArkUINodeModifiers()->getSwiperModifier()->setSwiperPageFlipMode(nativeNode, pageFlipMode);
1400     } else {
1401         GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperPageFlipMode(nativeNode);
1402     }
1403     return panda::JSValueRef::Undefined(vm);
1404 }
1405 
ResetSwiperPageFlipMode(ArkUIRuntimeCallInfo * runtimeCallInfo)1406 ArkUINativeModuleValue SwiperBridge::ResetSwiperPageFlipMode(ArkUIRuntimeCallInfo* runtimeCallInfo)
1407 {
1408     EcmaVM* vm = runtimeCallInfo->GetVM();
1409     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1410     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
1411     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
1412     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
1413     GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperPageFlipMode(nativeNode);
1414     return panda::JSValueRef::Undefined(vm);
1415 }
1416 
SetSwiperOnContentWillScroll(ArkUIRuntimeCallInfo * runtimeCallInfo)1417 ArkUINativeModuleValue SwiperBridge::SetSwiperOnContentWillScroll(ArkUIRuntimeCallInfo* runtimeCallInfo)
1418 {
1419     EcmaVM* vm = runtimeCallInfo->GetVM();
1420     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
1421     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
1422     Local<JSValueRef> callbackArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
1423     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
1424     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1425     if (callbackArg->IsUndefined() || callbackArg->IsNull() || !callbackArg->IsFunction(vm)) {
1426         GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperOnContentWillScroll(nativeNode);
1427         return panda::JSValueRef::Undefined(vm);
1428     }
1429     auto frameNode = reinterpret_cast<FrameNode*>(nativeNode);
1430     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
1431     panda::Local<panda::FunctionRef> func = callbackArg->ToObject(vm);
1432     std::function<bool(const SwiperContentWillScrollResult&)> callback =
1433         [vm, frameNode, func = panda::CopyableGlobal(vm, func)](const SwiperContentWillScrollResult& result) -> bool {
1434         panda::LocalScope pandaScope(vm);
1435         panda::TryCatch trycatch(vm);
1436         PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode));
1437         const char* keys[] = { "currentIndex", "comingIndex", "offset" };
1438         Local<JSValueRef> values[] = { panda::NumberRef::New(vm, result.currentIndex),
1439             panda::NumberRef::New(vm, result.comingIndex), panda::NumberRef::New(vm, result.offset) };
1440         auto eventObject = panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keys), keys, values);
1441         panda::Local<panda::JSValueRef> params[1] = { eventObject };
1442         auto ret = func->Call(vm, func.ToLocal(), params, 1);
1443         if (ret->IsBoolean()) {
1444             return ret->ToBoolean(vm)->Value();
1445         }
1446         return true;
1447     };
1448     GetArkUINodeModifiers()->getSwiperModifier()->setSwiperOnContentWillScroll(
1449         nativeNode, reinterpret_cast<bool*>(&callback));
1450     return panda::JSValueRef::Undefined(vm);
1451 }
1452 
ResetSwiperOnContentWillScroll(ArkUIRuntimeCallInfo * runtimeCallInfo)1453 ArkUINativeModuleValue SwiperBridge::ResetSwiperOnContentWillScroll(ArkUIRuntimeCallInfo* runtimeCallInfo)
1454 {
1455     EcmaVM* vm = runtimeCallInfo->GetVM();
1456     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
1457     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1458     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
1459     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1460     GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperOnContentWillScroll(nativeNode);
1461     return panda::JSValueRef::Undefined(vm);
1462 }
1463 
SetSwiperMaintainVisibleContentPosition(ArkUIRuntimeCallInfo * runtimeCallInfo)1464 ArkUINativeModuleValue SwiperBridge::SetSwiperMaintainVisibleContentPosition(ArkUIRuntimeCallInfo* runtimeCallInfo)
1465 {
1466     EcmaVM* vm = runtimeCallInfo->GetVM();
1467     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1468     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
1469     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
1470     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
1471     Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
1472     if (valueArg->IsBoolean()) {
1473         bool value = valueArg->ToBoolean(vm)->Value();
1474         GetArkUINodeModifiers()->getSwiperModifier()->setMaintainVisibleContentPosition(nativeNode, value);
1475     } else {
1476         GetArkUINodeModifiers()->getSwiperModifier()->resetMaintainVisibleContentPosition(nativeNode);
1477     }
1478     return panda::JSValueRef::Undefined(vm);
1479 }
1480 
ReSetSwiperMaintainVisibleContentPosition(ArkUIRuntimeCallInfo * runtimeCallInfo)1481 ArkUINativeModuleValue SwiperBridge::ReSetSwiperMaintainVisibleContentPosition(ArkUIRuntimeCallInfo* runtimeCallInfo)
1482 {
1483     EcmaVM* vm = runtimeCallInfo->GetVM();
1484     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1485     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
1486     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
1487     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
1488     GetArkUINodeModifiers()->getSwiperModifier()->resetMaintainVisibleContentPosition(nativeNode);
1489     return panda::JSValueRef::Undefined(vm);
1490 }
1491 
SetSwiperOnScrollStateChanged(ArkUIRuntimeCallInfo * runtimeCallInfo)1492 ArkUINativeModuleValue SwiperBridge::SetSwiperOnScrollStateChanged(ArkUIRuntimeCallInfo* runtimeCallInfo)
1493 {
1494     EcmaVM* vm = runtimeCallInfo->GetVM();
1495     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
1496     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
1497     Local<JSValueRef> callbackArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
1498     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1499     if (!callbackArg->IsFunction(vm)) {
1500         GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperOnScrollStateChanged(nativeNode);
1501         return panda::JSValueRef::Undefined(vm);
1502     }
1503     auto frameNode = reinterpret_cast<FrameNode*>(nativeNode);
1504     CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
1505     panda::Local<panda::FunctionRef> func = callbackArg->ToObject(vm);
1506     std::function<void(const BaseEventInfo* info)> callback =
1507         [vm, frameNode, func = panda::CopyableGlobal(vm, func)](const BaseEventInfo* info) {
1508         panda::LocalScope pandaScope(vm);
1509         panda::TryCatch trycatch(vm);
1510         PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode));
1511         const auto* scrollStateInfo = TypeInfoHelper::DynamicCast<SwiperChangeEvent>(info);
1512         if (!scrollStateInfo) {
1513             TAG_LOGW(AceLogTag::ACE_SWIPER, "scrollStateInfo invalid, OnScrollStateChanged failed.");
1514             return;
1515         }
1516         panda::Local<panda::NumberRef> indexParam = panda::NumberRef::New(vm, scrollStateInfo->GetIndex());
1517         panda::Local<panda::JSValueRef> params[1] = { indexParam };
1518         func->Call(vm, func.ToLocal(), params, 1);
1519     };
1520     GetArkUINodeModifiers()->getSwiperModifier()->setSwiperOnScrollStateChanged(
1521         nativeNode, reinterpret_cast<void*>(&callback));
1522     return panda::JSValueRef::Undefined(vm);
1523 }
1524 
ResetSwiperOnScrollStateChanged(ArkUIRuntimeCallInfo * runtimeCallInfo)1525 ArkUINativeModuleValue SwiperBridge::ResetSwiperOnScrollStateChanged(ArkUIRuntimeCallInfo* runtimeCallInfo)
1526 {
1527     EcmaVM* vm = runtimeCallInfo->GetVM();
1528     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1529     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
1530     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
1531     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
1532     GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperOnScrollStateChanged(nativeNode);
1533     return panda::JSValueRef::Undefined(vm);
1534 }
1535 } // namespace OHOS::Ace::NG
1536