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_native_common_bridge.h"
25 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h"
26 #include "bridge/declarative_frontend/engine/js_execution_scope_defines.h"
27 #include "bridge/declarative_frontend/engine/functions/js_swiper_function.h"
28 #include "bridge/declarative_frontend/engine/jsi/jsi_declarative_engine.h"
29 #include "bridge/declarative_frontend/jsview/js_indicator.h"
30 #include "bridge/declarative_frontend/jsview/js_swiper.h"
31 #include "bridge/declarative_frontend/jsview/models/swiper_model_impl.h"
32 #include "core/components_ng/pattern/swiper/swiper_model_ng.h"
33
34 namespace OHOS::Ace::NG {
35 namespace {
36 constexpr int32_t CALL_ARG_NODE_INDEX = 0;
37 constexpr int32_t CALL_ARG_VALUE_INDEX = 1;
38 constexpr int32_t CALL_ARG_TYPE_INDEX = 2;
39 constexpr int32_t DISPLAY_ARROW_VALUE = 1;
40 constexpr int32_t ARROW_IS_SHOW_BACKGROUND = 2;
41 constexpr int32_t ARROW_IS_SIDE_BAR_MIDDLE = 3;
42 constexpr int32_t ARROW_BACKGROUND_SIZE = 4;
43 constexpr int32_t ARROW_BACKGROUND_COLOR = 5;
44 constexpr int32_t ARROW_SIZE = 6;
45 constexpr int32_t ARROW_COLOR = 7;
46 constexpr int32_t DISPLAY_ARROW_IS_HOVER_SHOW_INDEX = 8;
47 constexpr int32_t INDICATOR_VALUE_INDEX = 2;
48 constexpr int32_t DIGIT_INDICATOR_FONT_COLOR = 2;
49 constexpr int32_t DIGIT_INDICATOR_SELECTED_FONT_COLOR = 3;
50 constexpr int32_t DIGIT_INDICATOR_DIGIT_FONT_SIZE = 4;
51 constexpr int32_t DIGIT_INDICATOR_DIGIT_FONT_WEIGHT = 5;
52 constexpr int32_t DIGIT_INDICATOR_SELECTED_DIGIT_FONT_SIZE = 6;
53 constexpr int32_t DIGIT_INDICATOR_SELECTED_DIGIT_FONT_WEIGHT = 7;
54 constexpr int32_t DIGIT_INDICATOR_LEFT = 8;
55 constexpr int32_t DIGIT_INDICATOR_TOP = 9;
56 constexpr int32_t DIGIT_INDICATOR_RIGHT = 10;
57 constexpr int32_t DIGIT_INDICATOR_BOTTOM = 11;
58 constexpr int32_t DOT_INDICATOR_ITEM_WIDTH = 2;
59 constexpr int32_t DOT_INDICATOR_ITEM_HEIGHT = 3;
60 constexpr int32_t DOT_INDICATOR_SELECTED_ITEM_WIDTH = 4;
61 constexpr int32_t DOT_INDICATOR_SELECTED_ITEM_HEIGHT = 5;
62 constexpr int32_t DOT_INDICATOR_MASK = 6;
63 constexpr int32_t DOT_INDICATOR_COLOR = 7;
64 constexpr int32_t DOT_INDICATOR_SELECTED_COLOR = 8;
65 constexpr int32_t DOT_INDICATOR_LEFT = 9;
66 constexpr int32_t DOT_INDICATOR_TOP = 10;
67 constexpr int32_t DOT_INDICATOR_RIGHT = 11;
68 constexpr int32_t DOT_INDICATOR_BOTTOM = 12;
69 constexpr int32_t DOT_INDICATOR_MAX_DISPLAY_COUNT = 13;
70 constexpr double DEFAULT_PERCENT_VALUE = 100.0;
71 constexpr int32_t DEFAULT_ANIMATION_MODE = 0;
72 } // namespace
73
SetSwiperInitialize(ArkUIRuntimeCallInfo * runtimeCallInfo)74 ArkUINativeModuleValue SwiperBridge::SetSwiperInitialize(ArkUIRuntimeCallInfo* runtimeCallInfo)
75 {
76 EcmaVM* vm = runtimeCallInfo->GetVM();
77 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
78 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
79 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
80
81 auto nodePtr = GetArkUINodeModifiers()->getSwiperModifier()->getSwiperController(nativeNode);
82 auto node = AceType::Claim(reinterpret_cast<OHOS::Ace::SwiperController*>(nodePtr));
83
84 Framework::JsiCallbackInfo info = Framework::JsiCallbackInfo(runtimeCallInfo);
85 Framework::JSSwiperController* jsController =
86 Framework::JSRef<Framework::JSObject>::Cast(info[1])->Unwrap<Framework::JSSwiperController>();
87 if (jsController) {
88 jsController->SetInstanceId(Container::CurrentId());
89 jsController->SetController(node);
90 }
91 return panda::JSValueRef::Undefined(vm);
92 }
ResetSwiperInitialize(ArkUIRuntimeCallInfo * runtimeCallInfo)93 ArkUINativeModuleValue SwiperBridge::ResetSwiperInitialize(ArkUIRuntimeCallInfo* runtimeCallInfo)
94 {
95 EcmaVM* vm = runtimeCallInfo->GetVM();
96 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
97 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
98 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
99 GetArkUINodeModifiers()->getSwiperModifier()->getSwiperController(nativeNode);
100 return panda::JSValueRef::Undefined(vm);
101 }
SetSwiperNextMargin(ArkUIRuntimeCallInfo * runtimeCallInfo)102 ArkUINativeModuleValue SwiperBridge::SetSwiperNextMargin(ArkUIRuntimeCallInfo* runtimeCallInfo)
103 {
104 EcmaVM* vm = runtimeCallInfo->GetVM();
105 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
106 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
107 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
108 Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
109 Ace::CalcDimension nextMargin;
110 if (valueArg->IsUndefined() || valueArg->IsNull() ||
111 !ArkTSUtils::ParseJsDimension(vm, valueArg, nextMargin, DimensionUnit::VP) ||
112 LessNotEqual(nextMargin.Value(), 0.0)) {
113 nextMargin.SetValue(0.0);
114 }
115 int32_t nextMarginUnit = static_cast<int32_t>(nextMargin.Unit());
116 GetArkUINodeModifiers()->getSwiperModifier()->setSwiperNextMargin(
117 nativeNode, nextMargin.Value(), nextMarginUnit, 0);
118 return panda::JSValueRef::Undefined(vm);
119 }
ResetSwiperNextMargin(ArkUIRuntimeCallInfo * runtimeCallInfo)120 ArkUINativeModuleValue SwiperBridge::ResetSwiperNextMargin(ArkUIRuntimeCallInfo* runtimeCallInfo)
121 {
122 EcmaVM* vm = runtimeCallInfo->GetVM();
123 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
124 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
125 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
126 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperNextMargin(nativeNode);
127 return panda::JSValueRef::Undefined(vm);
128 }
SetSwiperPrevMargin(ArkUIRuntimeCallInfo * runtimeCallInfo)129 ArkUINativeModuleValue SwiperBridge::SetSwiperPrevMargin(ArkUIRuntimeCallInfo* runtimeCallInfo)
130 {
131 EcmaVM* vm = runtimeCallInfo->GetVM();
132 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
133 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
134 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
135 Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
136 Ace::CalcDimension prevMargin;
137 if (valueArg->IsUndefined() || valueArg->IsNull() ||
138 !ArkTSUtils::ParseJsDimension(vm, valueArg, prevMargin, DimensionUnit::VP) ||
139 LessNotEqual(prevMargin.Value(), 0.0)) {
140 prevMargin.SetValue(0.0);
141 }
142 int32_t prevMarginUnit = static_cast<int32_t>(prevMargin.Unit());
143 GetArkUINodeModifiers()->getSwiperModifier()->setSwiperPrevMargin(
144 nativeNode, prevMargin.Value(), prevMarginUnit, 0);
145 return panda::JSValueRef::Undefined(vm);
146 }
ResetSwiperPrevMargin(ArkUIRuntimeCallInfo * runtimeCallInfo)147 ArkUINativeModuleValue SwiperBridge::ResetSwiperPrevMargin(ArkUIRuntimeCallInfo* runtimeCallInfo)
148 {
149 EcmaVM* vm = runtimeCallInfo->GetVM();
150 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
151 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
152 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
153 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperPrevMargin(nativeNode);
154 return panda::JSValueRef::Undefined(vm);
155 }
156
SetNestedScroll(ArkUIRuntimeCallInfo * runtimeCallInfo)157 ArkUINativeModuleValue SwiperBridge::SetNestedScroll(ArkUIRuntimeCallInfo* runtimeCallInfo)
158 {
159 EcmaVM* vm = runtimeCallInfo->GetVM();
160 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
161 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
162 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
163 Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
164 if (valueArg->IsNumber()) {
165 int32_t index = valueArg->Int32Value(vm);
166 int32_t values[1] = { 0 };
167 values[0] = index;
168 GetArkUINodeModifiers()->getSwiperModifier()->setSwiperNestedScroll(nativeNode, &values);
169 } else {
170 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperNestedScroll(nativeNode);
171 }
172 return panda::JSValueRef::Undefined(vm);
173 }
174
ResetNestedScroll(ArkUIRuntimeCallInfo * runtimeCallInfo)175 ArkUINativeModuleValue SwiperBridge::ResetNestedScroll(ArkUIRuntimeCallInfo* runtimeCallInfo)
176 {
177 EcmaVM* vm = runtimeCallInfo->GetVM();
178 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
179 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
180 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
181 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperNestedScroll(nativeNode);
182 return panda::JSValueRef::Undefined(vm);
183 }
184
SetIndicatorInteractive(ArkUIRuntimeCallInfo * runtimeCallInfo)185 ArkUINativeModuleValue SwiperBridge::SetIndicatorInteractive(ArkUIRuntimeCallInfo* runtimeCallInfo)
186 {
187 EcmaVM* vm = runtimeCallInfo->GetVM();
188 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
189 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
190 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
191 Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
192 bool interactive = valueArg->ToBoolean(vm)->Value();
193 GetArkUINodeModifiers()->getSwiperModifier()->setIndicatorInteractive(nativeNode, interactive);
194 return panda::JSValueRef::Undefined(vm);
195 }
196
ResetIndicatorInteractive(ArkUIRuntimeCallInfo * runtimeCallInfo)197 ArkUINativeModuleValue SwiperBridge::ResetIndicatorInteractive(ArkUIRuntimeCallInfo* runtimeCallInfo)
198 {
199 EcmaVM* vm = runtimeCallInfo->GetVM();
200 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
201 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
202 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
203 GetArkUINodeModifiers()->getSwiperModifier()->resetIndicatorInteractive(nativeNode);
204 return panda::JSValueRef::Undefined(vm);
205 }
206
SetSwiperDisplayCount(ArkUIRuntimeCallInfo * runtimeCallInfo)207 ArkUINativeModuleValue SwiperBridge::SetSwiperDisplayCount(ArkUIRuntimeCallInfo* runtimeCallInfo)
208 {
209 EcmaVM* vm = runtimeCallInfo->GetVM();
210 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
211 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
212 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
213 Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
214 if (valueArg->IsNumber() || valueArg->IsString(vm)) {
215 Local<JSValueRef> typeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_TYPE_INDEX);
216 std::string displayCountValue;
217 std::string type = typeArg->ToString(vm)->ToString(vm);
218 if (type == "number") {
219 displayCountValue = std::to_string(valueArg->Int32Value(vm));
220 } else {
221 displayCountValue = valueArg->ToString(vm)->ToString(vm);
222 }
223 GetArkUINodeModifiers()->getSwiperModifier()->setSwiperDisplayCount(
224 nativeNode, displayCountValue.c_str(), type.c_str());
225 } else {
226 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperDisplayCount(nativeNode);
227 }
228 return panda::JSValueRef::Undefined(vm);
229 }
ResetSwiperDisplayCount(ArkUIRuntimeCallInfo * runtimeCallInfo)230 ArkUINativeModuleValue SwiperBridge::ResetSwiperDisplayCount(ArkUIRuntimeCallInfo* runtimeCallInfo)
231 {
232 EcmaVM* vm = runtimeCallInfo->GetVM();
233 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
234 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
235 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
236 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperDisplayCount(nativeNode);
237 return panda::JSValueRef::Undefined(vm);
238 }
239
SetSwiperSwipeByGroup(ArkUIRuntimeCallInfo * runtimeCallInfo)240 ArkUINativeModuleValue SwiperBridge::SetSwiperSwipeByGroup(ArkUIRuntimeCallInfo* runtimeCallInfo)
241 {
242 EcmaVM* vm = runtimeCallInfo->GetVM();
243 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
244 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
245 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
246 Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
247 bool swipeByGroup = valueArg->ToBoolean(vm)->Value();
248 GetArkUINodeModifiers()->getSwiperModifier()->setSwiperSwipeByGroup(nativeNode, swipeByGroup);
249 return panda::JSValueRef::Undefined(vm);
250 }
251
ResetSwiperSwipeByGroup(ArkUIRuntimeCallInfo * runtimeCallInfo)252 ArkUINativeModuleValue SwiperBridge::ResetSwiperSwipeByGroup(ArkUIRuntimeCallInfo* runtimeCallInfo)
253 {
254 EcmaVM* vm = runtimeCallInfo->GetVM();
255 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
256 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
257 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
258 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperSwipeByGroup(nativeNode);
259 return panda::JSValueRef::Undefined(vm);
260 }
GetDimensionUnitString(DimensionUnit unit)261 std::string GetDimensionUnitString(DimensionUnit unit)
262 {
263 switch (unit) {
264 case DimensionUnit::VP:
265 return "vp";
266 case DimensionUnit::PX:
267 return "px";
268 case DimensionUnit::FP:
269 return "fp";
270 case DimensionUnit::CALC:
271 return "calc";
272 default:
273 return "px";
274 }
275 }
SetSwiperDisplayArrow(ArkUIRuntimeCallInfo * runtimeCallInfo)276 ArkUINativeModuleValue SwiperBridge::SetSwiperDisplayArrow(ArkUIRuntimeCallInfo* runtimeCallInfo)
277 {
278 EcmaVM* vm = runtimeCallInfo->GetVM();
279 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
280 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
281 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
282 Local<JSValueRef> displayArrowValue = runtimeCallInfo->GetCallArgRef(DISPLAY_ARROW_VALUE);
283 Local<JSValueRef> showBackground = runtimeCallInfo->GetCallArgRef(ARROW_IS_SHOW_BACKGROUND);
284 Local<JSValueRef> isSidebarMiddle = runtimeCallInfo->GetCallArgRef(ARROW_IS_SIDE_BAR_MIDDLE);
285 Local<JSValueRef> backgroundSize = runtimeCallInfo->GetCallArgRef(ARROW_BACKGROUND_SIZE);
286 Local<JSValueRef> backgroundColor = runtimeCallInfo->GetCallArgRef(ARROW_BACKGROUND_COLOR);
287 Local<JSValueRef> arrowSize = runtimeCallInfo->GetCallArgRef(ARROW_SIZE);
288 Local<JSValueRef> arrowColor = runtimeCallInfo->GetCallArgRef(ARROW_COLOR);
289 Local<JSValueRef> isHoverShow = runtimeCallInfo->GetCallArgRef(DISPLAY_ARROW_IS_HOVER_SHOW_INDEX);
290 std::string displayArrowValueStr = std::to_string(displayArrowValue->Int32Value(vm));
291 std::string showBackgroundStr = "2";
292 if (!showBackground->IsUndefined()) {
293 showBackgroundStr = showBackground->ToBoolean(vm)->Value() ? "1" : "0";
294 }
295 std::string isSidebarMiddleStr = "2";
296 if (!isSidebarMiddle->IsUndefined()) {
297 isSidebarMiddleStr = isSidebarMiddle->ToBoolean(vm)->Value() ? "1" : "0";
298 }
299 CalcDimension lengthValue;
300 Color color;
301 std::string backgroundSizeStr =
302 ArkTSUtils::ParseJsDimension(vm, backgroundSize, lengthValue, DimensionUnit::VP, false)
303 ? std::to_string(lengthValue.Value()) + GetDimensionUnitString(lengthValue.Unit())
304 : "-";
305 std::string backgroundColorStr =
306 ArkTSUtils::ParseJsColorAlpha(vm, backgroundColor, color) ? std::to_string(color.GetValue()) : "-";
307 std::string arrowSizeStr = ArkTSUtils::ParseJsDimensionNG(vm, arrowSize, lengthValue, DimensionUnit::VP, false)
308 ? std::to_string(lengthValue.Value()) + GetDimensionUnitString(lengthValue.Unit())
309 : "-";
310 std::string arrowColorStr =
311 ArkTSUtils::ParseJsColorAlpha(vm, arrowColor, color) ? std::to_string(color.GetValue()) : "-";
312 std::string isHoverShowStr = "2";
313 if (!isHoverShow->IsUndefined()) {
314 isHoverShowStr = isHoverShow->ToBoolean(vm)->Value() ? "1" : "0";
315 }
316 std::string displayArrowStr = displayArrowValueStr + "|" + showBackgroundStr + "|" + isSidebarMiddleStr + "|" +
317 backgroundSizeStr + "|" + backgroundColorStr + "|" + arrowSizeStr + "|" +
318 arrowColorStr + "|" + isHoverShowStr + "|";
319 GetArkUINodeModifiers()->getSwiperModifier()->setSwiperDisplayArrow(nativeNode, displayArrowStr.c_str());
320 return panda::JSValueRef::Undefined(vm);
321 }
ResetSwiperDisplayArrow(ArkUIRuntimeCallInfo * runtimeCallInfo)322 ArkUINativeModuleValue SwiperBridge::ResetSwiperDisplayArrow(ArkUIRuntimeCallInfo* runtimeCallInfo)
323 {
324 EcmaVM* vm = runtimeCallInfo->GetVM();
325 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
326 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
327 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
328 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperDisplayArrow(nativeNode);
329 return panda::JSValueRef::Undefined(vm);
330 }
SetSwiperCurve(ArkUIRuntimeCallInfo * runtimeCallInfo)331 ArkUINativeModuleValue SwiperBridge::SetSwiperCurve(ArkUIRuntimeCallInfo* runtimeCallInfo)
332 {
333 EcmaVM* vm = runtimeCallInfo->GetVM();
334 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
335 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
336 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
337 Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
338 if (valueArg->IsString(vm)) {
339 std::string curve = valueArg->ToString(vm)->ToString(vm);
340 GetArkUINodeModifiers()->getSwiperModifier()->setSwiperCurve(nativeNode, curve.c_str());
341 } else {
342 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperCurve(nativeNode);
343 }
344 return panda::JSValueRef::Undefined(vm);
345 }
ResetSwiperCurve(ArkUIRuntimeCallInfo * runtimeCallInfo)346 ArkUINativeModuleValue SwiperBridge::ResetSwiperCurve(ArkUIRuntimeCallInfo* runtimeCallInfo)
347 {
348 EcmaVM* vm = runtimeCallInfo->GetVM();
349 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
350 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
351 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
352 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperCurve(nativeNode);
353 return panda::JSValueRef::Undefined(vm);
354 }
SetSwiperDisableSwipe(ArkUIRuntimeCallInfo * runtimeCallInfo)355 ArkUINativeModuleValue SwiperBridge::SetSwiperDisableSwipe(ArkUIRuntimeCallInfo* runtimeCallInfo)
356 {
357 EcmaVM* vm = runtimeCallInfo->GetVM();
358 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
359 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
360 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
361 Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
362 if (valueArg->IsBoolean()) {
363 bool disableswipe = valueArg->ToBoolean(vm)->Value();
364 GetArkUINodeModifiers()->getSwiperModifier()->setSwiperDisableSwipe(nativeNode, disableswipe);
365 } else {
366 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperDisableSwipe(nativeNode);
367 }
368 return panda::JSValueRef::Undefined(vm);
369 }
ResetSwiperDisableSwipe(ArkUIRuntimeCallInfo * runtimeCallInfo)370 ArkUINativeModuleValue SwiperBridge::ResetSwiperDisableSwipe(ArkUIRuntimeCallInfo* runtimeCallInfo)
371 {
372 EcmaVM* vm = runtimeCallInfo->GetVM();
373 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
374 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
375 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
376 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperDisableSwipe(nativeNode);
377 return panda::JSValueRef::Undefined(vm);
378 }
SetSwiperEffectMode(ArkUIRuntimeCallInfo * runtimeCallInfo)379 ArkUINativeModuleValue SwiperBridge::SetSwiperEffectMode(ArkUIRuntimeCallInfo* runtimeCallInfo)
380 {
381 EcmaVM* vm = runtimeCallInfo->GetVM();
382 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
383 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
384 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
385 Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
386 if (valueArg->IsNumber()) {
387 auto edgeEffect = valueArg->Int32Value(vm);
388 GetArkUINodeModifiers()->getSwiperModifier()->setSwiperEffectMode(nativeNode, edgeEffect);
389 } else {
390 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperEffectMode(nativeNode);
391 }
392 return panda::JSValueRef::Undefined(vm);
393 }
ResetSwiperEffectMode(ArkUIRuntimeCallInfo * runtimeCallInfo)394 ArkUINativeModuleValue SwiperBridge::ResetSwiperEffectMode(ArkUIRuntimeCallInfo* runtimeCallInfo)
395 {
396 EcmaVM* vm = runtimeCallInfo->GetVM();
397 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
398 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
399 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
400 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperEffectMode(nativeNode);
401 return panda::JSValueRef::Undefined(vm);
402 }
SetSwiperCachedCount(ArkUIRuntimeCallInfo * runtimeCallInfo)403 ArkUINativeModuleValue SwiperBridge::SetSwiperCachedCount(ArkUIRuntimeCallInfo* runtimeCallInfo)
404 {
405 EcmaVM* vm = runtimeCallInfo->GetVM();
406 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
407 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
408 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
409 Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
410 if (valueArg->IsNumber()) {
411 int32_t cachedCount = valueArg->Int32Value(vm);
412 GetArkUINodeModifiers()->getSwiperModifier()->setSwiperCachedCount(nativeNode, cachedCount);
413 } else {
414 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperCachedCount(nativeNode);
415 }
416 return panda::JSValueRef::Undefined(vm);
417 }
ResetSwiperCachedCount(ArkUIRuntimeCallInfo * runtimeCallInfo)418 ArkUINativeModuleValue SwiperBridge::ResetSwiperCachedCount(ArkUIRuntimeCallInfo* runtimeCallInfo)
419 {
420 EcmaVM* vm = runtimeCallInfo->GetVM();
421 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
422 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
423 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
424 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperCachedCount(nativeNode);
425 return panda::JSValueRef::Undefined(vm);
426 }
SetSwiperIsShown(ArkUIRuntimeCallInfo * runtimeCallInfo)427 ArkUINativeModuleValue SwiperBridge::SetSwiperIsShown(ArkUIRuntimeCallInfo* runtimeCallInfo)
428 {
429 EcmaVM* vm = runtimeCallInfo->GetVM();
430 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
431 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
432 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
433 Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
434 bool isShown = valueArg->ToBoolean(vm)->Value();
435 GetArkUINodeModifiers()->getSwiperModifier()->setSwiperIsShown(nativeNode, isShown);
436 return panda::JSValueRef::Undefined(vm);
437 }
ResetSwiperIsShown(ArkUIRuntimeCallInfo * runtimeCallInfo)438 ArkUINativeModuleValue SwiperBridge::ResetSwiperIsShown(ArkUIRuntimeCallInfo* runtimeCallInfo)
439 {
440 EcmaVM* vm = runtimeCallInfo->GetVM();
441 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
442 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
443 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
444 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperIsShown(nativeNode);
445 return panda::JSValueRef::Undefined(vm);
446 }
SetSwiperDisplayMode(ArkUIRuntimeCallInfo * runtimeCallInfo)447 ArkUINativeModuleValue SwiperBridge::SetSwiperDisplayMode(ArkUIRuntimeCallInfo* runtimeCallInfo)
448 {
449 EcmaVM* vm = runtimeCallInfo->GetVM();
450 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
451 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
452 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
453 Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
454 if (valueArg->IsNumber()) {
455 int32_t index = valueArg->Int32Value(vm);
456 GetArkUINodeModifiers()->getSwiperModifier()->setSwiperDisplayMode(nativeNode, index);
457 } else {
458 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperDisplayMode(nativeNode);
459 }
460 return panda::JSValueRef::Undefined(vm);
461 }
ResetSwiperDisplayMode(ArkUIRuntimeCallInfo * runtimeCallInfo)462 ArkUINativeModuleValue SwiperBridge::ResetSwiperDisplayMode(ArkUIRuntimeCallInfo* runtimeCallInfo)
463 {
464 EcmaVM* vm = runtimeCallInfo->GetVM();
465 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
466 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
467 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
468 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperDisplayMode(nativeNode);
469 return panda::JSValueRef::Undefined(vm);
470 }
SetSwiperItemSpace(ArkUIRuntimeCallInfo * runtimeCallInfo)471 ArkUINativeModuleValue SwiperBridge::SetSwiperItemSpace(ArkUIRuntimeCallInfo* runtimeCallInfo)
472 {
473 EcmaVM* vm = runtimeCallInfo->GetVM();
474 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
475 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
476 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
477 Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
478 Ace::CalcDimension itemSpace;
479 if (!ArkTSUtils::ParseJsDimensionVpNG(vm, valueArg, itemSpace) || LessNotEqual(itemSpace.Value(), 0.0)) {
480 itemSpace.SetValue(0.0);
481 }
482 int32_t itemSpaceUnit = static_cast<int32_t>(itemSpace.Unit());
483 GetArkUINodeModifiers()->getSwiperModifier()->setSwiperItemSpace(nativeNode, itemSpace.Value(), itemSpaceUnit);
484 return panda::JSValueRef::Undefined(vm);
485 }
ResetSwiperItemSpace(ArkUIRuntimeCallInfo * runtimeCallInfo)486 ArkUINativeModuleValue SwiperBridge::ResetSwiperItemSpace(ArkUIRuntimeCallInfo* runtimeCallInfo)
487 {
488 EcmaVM* vm = runtimeCallInfo->GetVM();
489 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
490 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
491 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
492 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperItemSpace(nativeNode);
493 return panda::JSValueRef::Undefined(vm);
494 }
SetSwiperVertical(ArkUIRuntimeCallInfo * runtimeCallInfo)495 ArkUINativeModuleValue SwiperBridge::SetSwiperVertical(ArkUIRuntimeCallInfo* runtimeCallInfo)
496 {
497 EcmaVM* vm = runtimeCallInfo->GetVM();
498 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
499 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
500 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
501 Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
502 if (valueArg->IsBoolean()) {
503 bool isVertical = valueArg->ToBoolean(vm)->Value();
504 GetArkUINodeModifiers()->getSwiperModifier()->setSwiperVertical(nativeNode, isVertical);
505 } else {
506 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperVertical(nativeNode);
507 }
508 return panda::JSValueRef::Undefined(vm);
509 }
ResetSwiperVertical(ArkUIRuntimeCallInfo * runtimeCallInfo)510 ArkUINativeModuleValue SwiperBridge::ResetSwiperVertical(ArkUIRuntimeCallInfo* runtimeCallInfo)
511 {
512 EcmaVM* vm = runtimeCallInfo->GetVM();
513 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
514 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
515 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
516 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperVertical(nativeNode);
517 return panda::JSValueRef::Undefined(vm);
518 }
SetSwiperLoop(ArkUIRuntimeCallInfo * runtimeCallInfo)519 ArkUINativeModuleValue SwiperBridge::SetSwiperLoop(ArkUIRuntimeCallInfo* runtimeCallInfo)
520 {
521 EcmaVM* vm = runtimeCallInfo->GetVM();
522 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
523 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
524 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
525 Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
526 if (valueArg->IsBoolean()) {
527 bool loop = valueArg->ToBoolean(vm)->Value();
528 GetArkUINodeModifiers()->getSwiperModifier()->setSwiperLoop(nativeNode, loop);
529 } else {
530 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperLoop(nativeNode);
531 }
532 return panda::JSValueRef::Undefined(vm);
533 }
ResetSwiperLoop(ArkUIRuntimeCallInfo * runtimeCallInfo)534 ArkUINativeModuleValue SwiperBridge::ResetSwiperLoop(ArkUIRuntimeCallInfo* runtimeCallInfo)
535 {
536 EcmaVM* vm = runtimeCallInfo->GetVM();
537 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
538 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
539 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
540 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperLoop(nativeNode);
541 return panda::JSValueRef::Undefined(vm);
542 }
SetSwiperInterval(ArkUIRuntimeCallInfo * runtimeCallInfo)543 ArkUINativeModuleValue SwiperBridge::SetSwiperInterval(ArkUIRuntimeCallInfo* runtimeCallInfo)
544 {
545 EcmaVM* vm = runtimeCallInfo->GetVM();
546 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
547 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
548 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
549 Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
550 if (valueArg->IsNumber()) {
551 int32_t interval = valueArg->Int32Value(vm);
552 GetArkUINodeModifiers()->getSwiperModifier()->setSwiperInterval(nativeNode, interval);
553 } else {
554 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperInterval(nativeNode);
555 }
556 return panda::JSValueRef::Undefined(vm);
557 }
ResetSwiperInterval(ArkUIRuntimeCallInfo * runtimeCallInfo)558 ArkUINativeModuleValue SwiperBridge::ResetSwiperInterval(ArkUIRuntimeCallInfo* runtimeCallInfo)
559 {
560 EcmaVM* vm = runtimeCallInfo->GetVM();
561 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
562 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
563 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
564 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperInterval(nativeNode);
565 return panda::JSValueRef::Undefined(vm);
566 }
SetSwiperAutoPlay(ArkUIRuntimeCallInfo * runtimeCallInfo)567 ArkUINativeModuleValue SwiperBridge::SetSwiperAutoPlay(ArkUIRuntimeCallInfo* runtimeCallInfo)
568 {
569 EcmaVM* vm = runtimeCallInfo->GetVM();
570 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
571 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
572 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
573 Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
574 if (valueArg->IsBoolean()) {
575 bool autoPlay = valueArg->ToBoolean(vm)->Value();
576 GetArkUINodeModifiers()->getSwiperModifier()->setSwiperAutoPlay(nativeNode, autoPlay);
577 } else {
578 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperAutoPlay(nativeNode);
579 }
580 return panda::JSValueRef::Undefined(vm);
581 }
ResetSwiperAutoPlay(ArkUIRuntimeCallInfo * runtimeCallInfo)582 ArkUINativeModuleValue SwiperBridge::ResetSwiperAutoPlay(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 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
588 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperAutoPlay(nativeNode);
589 return panda::JSValueRef::Undefined(vm);
590 }
SetSwiperIndex(ArkUIRuntimeCallInfo * runtimeCallInfo)591 ArkUINativeModuleValue SwiperBridge::SetSwiperIndex(ArkUIRuntimeCallInfo* runtimeCallInfo)
592 {
593 EcmaVM* vm = runtimeCallInfo->GetVM();
594 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
595 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
596 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
597 Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
598 if (valueArg->IsNumber()) {
599 int32_t index = valueArg->Int32Value(vm);
600 GetArkUINodeModifiers()->getSwiperModifier()->setSwiperIndex(nativeNode, index, DEFAULT_ANIMATION_MODE);
601 } else {
602 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperIndex(nativeNode);
603 }
604 return panda::JSValueRef::Undefined(vm);
605 }
ResetSwiperIndex(ArkUIRuntimeCallInfo * runtimeCallInfo)606 ArkUINativeModuleValue SwiperBridge::ResetSwiperIndex(ArkUIRuntimeCallInfo* runtimeCallInfo)
607 {
608 EcmaVM* vm = runtimeCallInfo->GetVM();
609 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
610 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
611 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
612 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperIndex(nativeNode);
613 return panda::JSValueRef::Undefined(vm);
614 }
GetStringByValueRef(const EcmaVM * vm,const Local<JSValueRef> & jsValue)615 std::string GetStringByValueRef(const EcmaVM* vm, const Local<JSValueRef>& jsValue)
616 {
617 std::string result = "-";
618 if (jsValue->IsUndefined()) {
619 return result;
620 }
621 CalcDimension calc;
622 result = ArkTSUtils::ParseJsDimension(vm, jsValue, calc, DimensionUnit::VP, true)
623 ? (calc.Unit() == DimensionUnit::PERCENT
624 ? (std::to_string(calc.Value() * DEFAULT_PERCENT_VALUE) + "%")
625 : (std::to_string(calc.Value()) + GetDimensionUnitString(calc.Unit())))
626 : "0.0_vp";
627 return result;
628 }
GetIntStringByValueRef(const EcmaVM * vm,const Local<JSValueRef> & jsValue)629 std::string GetIntStringByValueRef(const EcmaVM* vm, const Local<JSValueRef>& jsValue)
630 {
631 std::string result = "-";
632 if (jsValue->IsUndefined()) {
633 return result;
634 }
635 int32_t intValue;
636 result = ArkTSUtils::ParseJsInteger(vm, jsValue, intValue) ? std::to_string(intValue) : "0";
637 return result;
638 }
GetSwiperDotIndicator(ArkUIRuntimeCallInfo * runtimeCallInfo,EcmaVM * vm)639 std::string GetSwiperDotIndicator(ArkUIRuntimeCallInfo* runtimeCallInfo, EcmaVM* vm)
640 {
641 Local<JSValueRef> itemWidthArg = runtimeCallInfo->GetCallArgRef(DOT_INDICATOR_ITEM_WIDTH);
642 Local<JSValueRef> itemHeightArg = runtimeCallInfo->GetCallArgRef(DOT_INDICATOR_ITEM_HEIGHT);
643 Local<JSValueRef> selectedItemWidthArg = runtimeCallInfo->GetCallArgRef(DOT_INDICATOR_SELECTED_ITEM_WIDTH);
644 Local<JSValueRef> selectedItemHeightArg = runtimeCallInfo->GetCallArgRef(DOT_INDICATOR_SELECTED_ITEM_HEIGHT);
645 Local<JSValueRef> maskArg = runtimeCallInfo->GetCallArgRef(DOT_INDICATOR_MASK);
646 Local<JSValueRef> colorArg = runtimeCallInfo->GetCallArgRef(DOT_INDICATOR_COLOR);
647 Local<JSValueRef> selectedColorArg = runtimeCallInfo->GetCallArgRef(DOT_INDICATOR_SELECTED_COLOR);
648 Local<JSValueRef> leftArg = runtimeCallInfo->GetCallArgRef(DOT_INDICATOR_LEFT);
649 Local<JSValueRef> topArg = runtimeCallInfo->GetCallArgRef(DOT_INDICATOR_TOP);
650 Local<JSValueRef> rightArg = runtimeCallInfo->GetCallArgRef(DOT_INDICATOR_RIGHT);
651 Local<JSValueRef> bottomArg = runtimeCallInfo->GetCallArgRef(DOT_INDICATOR_BOTTOM);
652 CalcDimension calc;
653 std::string itemWidth = ArkTSUtils::ParseJsDimension(vm, itemWidthArg, calc, DimensionUnit::VP, false)
654 ? std::to_string(calc.Value()) + GetDimensionUnitString(calc.Unit())
655 : "-";
656 std::string itemHeight = ArkTSUtils::ParseJsDimension(vm, itemHeightArg, calc, DimensionUnit::VP, false)
657 ? std::to_string(calc.Value()) + GetDimensionUnitString(calc.Unit())
658 : "-";
659 std::string selectedItemWidth =
660 ArkTSUtils::ParseJsDimension(vm, selectedItemWidthArg, calc, DimensionUnit::VP, false)
661 ? std::to_string(calc.Value()) + GetDimensionUnitString(calc.Unit())
662 : "-";
663 std::string selectedItemHeight =
664 ArkTSUtils::ParseJsDimension(vm, selectedItemHeightArg, calc, DimensionUnit::VP, false)
665 ? std::to_string(calc.Value()) + GetDimensionUnitString(calc.Unit())
666 : "-";
667 std::string mask = "2";
668 if (!maskArg->IsUndefined()) {
669 mask = maskArg->ToBoolean(vm)->Value() ? "1" : "0";
670 }
671 Color color;
672 std::string colorStr = ArkTSUtils::ParseJsColorAlpha(vm, colorArg, color) ? std::to_string(color.GetValue()) : "-";
673 std::string selectedColor =
674 ArkTSUtils::ParseJsColorAlpha(vm, selectedColorArg, color) ? std::to_string(color.GetValue()) : "-";
675 std::string left = GetStringByValueRef(vm, leftArg);
676 std::string top = GetStringByValueRef(vm, topArg);
677 std::string right = GetStringByValueRef(vm, rightArg);
678 std::string bottom = GetStringByValueRef(vm, bottomArg);
679 Local<JSValueRef> maxDisplayCountArg = runtimeCallInfo->GetCallArgRef(DOT_INDICATOR_MAX_DISPLAY_COUNT);
680 auto maxDisplayCount = GetIntStringByValueRef(vm, maxDisplayCountArg);
681 std::string indicatorStr = itemWidth + "|" + itemHeight + "|" + selectedItemWidth + "|" +
682 selectedItemHeight + "|" + mask + "|" + colorStr + "|" + selectedColor + "|" + left +
683 "|" + top + "|" + right + "|" + bottom + "|" + maxDisplayCount;
684 return indicatorStr;
685 }
GetSwiperDigitIndicator(ArkUIRuntimeCallInfo * runtimeCallInfo,EcmaVM * vm)686 std::string GetSwiperDigitIndicator(ArkUIRuntimeCallInfo* runtimeCallInfo, EcmaVM* vm)
687 {
688 Local<JSValueRef> fontColorArg = runtimeCallInfo->GetCallArgRef(DIGIT_INDICATOR_FONT_COLOR);
689 Local<JSValueRef> selectedFontColorArg = runtimeCallInfo->GetCallArgRef(DIGIT_INDICATOR_SELECTED_FONT_COLOR);
690 Local<JSValueRef> digitFontSizeArg = runtimeCallInfo->GetCallArgRef(DIGIT_INDICATOR_DIGIT_FONT_SIZE);
691 Local<JSValueRef> digitFontWeightArg = runtimeCallInfo->GetCallArgRef(DIGIT_INDICATOR_DIGIT_FONT_WEIGHT);
692 Local<JSValueRef> selectedDigitFontSizeArg =
693 runtimeCallInfo->GetCallArgRef(DIGIT_INDICATOR_SELECTED_DIGIT_FONT_SIZE);
694 Local<JSValueRef> selectedDigitFontWeightArg =
695 runtimeCallInfo->GetCallArgRef(DIGIT_INDICATOR_SELECTED_DIGIT_FONT_WEIGHT);
696 Local<JSValueRef> leftArg = runtimeCallInfo->GetCallArgRef(DIGIT_INDICATOR_LEFT);
697 Local<JSValueRef> topArg = runtimeCallInfo->GetCallArgRef(DIGIT_INDICATOR_TOP);
698 Local<JSValueRef> rightArg = runtimeCallInfo->GetCallArgRef(DIGIT_INDICATOR_RIGHT);
699 Local<JSValueRef> bottomArg = runtimeCallInfo->GetCallArgRef(DIGIT_INDICATOR_BOTTOM);
700 Color color;
701 CalcDimension calc;
702 std::string fontColor =
703 ArkTSUtils::ParseJsColorAlpha(vm, fontColorArg, color) ? std::to_string(color.GetValue()) : "-";
704 std::string selectedFontColor =
705 ArkTSUtils::ParseJsColorAlpha(vm, selectedFontColorArg, color) ? std::to_string(color.GetValue()) : "-";
706 std::string digitFontSize = ArkTSUtils::ParseJsDimension(vm, digitFontSizeArg, calc, DimensionUnit::FP, false)
707 ? std::to_string(calc.Value()) + GetDimensionUnitString(calc.Unit())
708 : "-";
709 std::string digitFontWeight = digitFontWeightArg->ToString(vm)->ToString(vm);
710 std::string selectedDigitFontSize =
711 ArkTSUtils::ParseJsDimension(vm, selectedDigitFontSizeArg, calc, DimensionUnit::FP, false)
712 ? std::to_string(calc.Value()) + GetDimensionUnitString(calc.Unit())
713 : "-";
714 std::string selectedDigitFontWeight = selectedDigitFontWeightArg->ToString(vm)->ToString(vm);
715 std::string left = GetStringByValueRef(vm, leftArg);
716 std::string top = GetStringByValueRef(vm, topArg);
717 std::string right = GetStringByValueRef(vm, rightArg);
718 std::string bottom = GetStringByValueRef(vm, bottomArg);
719 std::string indicatorStr = fontColor + "|" + selectedFontColor + "|" + digitFontSize + "|" + digitFontWeight +
720 "|" + selectedDigitFontSize + "|" + selectedDigitFontWeight + "|" + left + "|" + top + "|" + right +
721 "|" + bottom;
722 return indicatorStr;
723 }
SetSwiperIndicator(ArkUIRuntimeCallInfo * runtimeCallInfo)724 ArkUINativeModuleValue SwiperBridge::SetSwiperIndicator(ArkUIRuntimeCallInfo* runtimeCallInfo)
725 {
726 EcmaVM* vm = runtimeCallInfo->GetVM();
727 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
728 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
729 CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
730 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
731 Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
732 auto frameNode = reinterpret_cast<FrameNode*>(nativeNode);
733 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
734
735 std::string type = valueArg->ToString(vm)->ToString(vm);
736 std::string indicatorStr = "";
737 if (type == "boolean") {
738 Local<JSValueRef> indicatorArg = runtimeCallInfo->GetCallArgRef(INDICATOR_VALUE_INDEX);
739 std::string indicator = indicatorArg->ToBoolean(vm)->Value() ? "1" : "0";
740 indicatorStr = type + "|" + indicator;
741 } else if (type == "ArkDotIndicator") {
742 indicatorStr = type + "|" + GetSwiperDotIndicator(runtimeCallInfo, vm);
743 } else if (type == "ArkDigitIndicator") {
744 indicatorStr = type + "|" + GetSwiperDigitIndicator(runtimeCallInfo, vm);
745 } else if (type == "IndicatorComponentController") {
746 Framework::JsiCallbackInfo info = Framework::JsiCallbackInfo(runtimeCallInfo);
747 Framework::JSIndicatorController* jsController =
748 Framework::JSRef<Framework::JSObject>::Cast(info[INDICATOR_VALUE_INDEX])
749 ->Unwrap<Framework::JSIndicatorController>();
750 if (jsController) {
751 WeakPtr<NG::UINode> targetNode = AceType::WeakClaim(frameNode);
752 jsController->SetSwiperNode(targetNode);
753 }
754 indicatorStr = "IndicatorComponentController|";
755 } else {
756 indicatorStr = "boolean|1";
757 }
758 GetArkUINodeModifiers()->getSwiperModifier()->setSwiperIndicator(nativeNode, indicatorStr.c_str());
759 return panda::JSValueRef::Undefined(vm);
760 }
ResetSwiperIndicator(ArkUIRuntimeCallInfo * runtimeCallInfo)761 ArkUINativeModuleValue SwiperBridge::ResetSwiperIndicator(ArkUIRuntimeCallInfo* runtimeCallInfo)
762 {
763 EcmaVM* vm = runtimeCallInfo->GetVM();
764 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
765 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
766 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
767 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperIndicator(nativeNode);
768 return panda::JSValueRef::Undefined(vm);
769 }
SetSwiperDuration(ArkUIRuntimeCallInfo * runtimeCallInfo)770 ArkUINativeModuleValue SwiperBridge::SetSwiperDuration(ArkUIRuntimeCallInfo* runtimeCallInfo)
771 {
772 EcmaVM* vm = runtimeCallInfo->GetVM();
773 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
774 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
775 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
776 Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
777 if (valueArg->IsNumber()) {
778 int32_t duration = valueArg->Int32Value(vm);
779 GetArkUINodeModifiers()->getSwiperModifier()->setSwiperDuration(nativeNode, duration);
780 } else {
781 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperDuration(nativeNode);
782 }
783 return panda::JSValueRef::Undefined(vm);
784 }
785
ResetSwiperDuration(ArkUIRuntimeCallInfo * runtimeCallInfo)786 ArkUINativeModuleValue SwiperBridge::ResetSwiperDuration(ArkUIRuntimeCallInfo* runtimeCallInfo)
787 {
788 EcmaVM* vm = runtimeCallInfo->GetVM();
789 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
790 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
791 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
792 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperDuration(nativeNode);
793 return panda::JSValueRef::Undefined(vm);
794 }
795
SetSwiperEnabled(ArkUIRuntimeCallInfo * runtimeCallInfo)796 ArkUINativeModuleValue SwiperBridge::SetSwiperEnabled(ArkUIRuntimeCallInfo* runtimeCallInfo)
797 {
798 EcmaVM* vm = runtimeCallInfo->GetVM();
799 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
800 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
801 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
802 Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
803 if (valueArg->IsBoolean()) {
804 bool enabled = valueArg->ToBoolean(vm)->Value();
805 GetArkUINodeModifiers()->getCommonModifier()->setEnabled(nativeNode, enabled);
806 GetArkUINodeModifiers()->getSwiperModifier()->setSwiperEnabled(nativeNode, enabled);
807 } else {
808 GetArkUINodeModifiers()->getCommonModifier()->resetEnabled(nativeNode);
809 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperEnabled(nativeNode);
810 }
811 return panda::JSValueRef::Undefined(vm);
812 }
813
ResetSwiperEnabled(ArkUIRuntimeCallInfo * runtimeCallInfo)814 ArkUINativeModuleValue SwiperBridge::ResetSwiperEnabled(ArkUIRuntimeCallInfo* runtimeCallInfo)
815 {
816 EcmaVM* vm = runtimeCallInfo->GetVM();
817 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
818 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
819 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
820 GetArkUINodeModifiers()->getCommonModifier()->resetEnabled(nativeNode);
821 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperEnabled(nativeNode);
822 return panda::JSValueRef::Undefined(vm);
823 }
824
SetSwiperOnChange(ArkUIRuntimeCallInfo * runtimeCallInfo)825 ArkUINativeModuleValue SwiperBridge::SetSwiperOnChange(ArkUIRuntimeCallInfo* runtimeCallInfo)
826 {
827 EcmaVM* vm = runtimeCallInfo->GetVM();
828 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
829 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
830 Local<JSValueRef> callbackArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
831 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
832 if (callbackArg->IsUndefined() || callbackArg->IsNull() || !callbackArg->IsFunction(vm)) {
833 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperOnChange(nativeNode);
834 return panda::JSValueRef::Undefined(vm);
835 }
836 auto frameNode = reinterpret_cast<FrameNode*>(nativeNode);
837 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
838 panda::Local<panda::FunctionRef> func = callbackArg->ToObject(vm);
839 std::function<void(const BaseEventInfo* info)> callback =
840 [vm, frameNode, func = panda::CopyableGlobal(vm, func)](const BaseEventInfo* info) {
841 panda::LocalScope pandaScope(vm);
842 panda::TryCatch trycatch(vm);
843 PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode));
844 const auto* swiperInfo = TypeInfoHelper::DynamicCast<SwiperChangeEvent>(info);
845 if (!swiperInfo) {
846 TAG_LOGW(AceLogTag::ACE_SWIPER, "Swiper onChange callback execute failed.");
847 return;
848 }
849 panda::Local<panda::NumberRef> indexParam = panda::NumberRef::New(vm, swiperInfo->GetIndex());
850 panda::Local<panda::JSValueRef> params[1] = { indexParam }; // 1: Array length
851 func->Call(vm, func.ToLocal(), params, 1); // 1: Array length
852 };
853 GetArkUINodeModifiers()->getSwiperModifier()->setSwiperOnChange(nativeNode, reinterpret_cast<void*>(&callback));
854 return panda::JSValueRef::Undefined(vm);
855 }
856
ResetSwiperOnChange(ArkUIRuntimeCallInfo * runtimeCallInfo)857 ArkUINativeModuleValue SwiperBridge::ResetSwiperOnChange(ArkUIRuntimeCallInfo* runtimeCallInfo)
858 {
859 EcmaVM* vm = runtimeCallInfo->GetVM();
860 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
861 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
862 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
863 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperOnChange(nativeNode);
864 return panda::JSValueRef::Undefined(vm);
865 }
866
SetSwiperOnAnimationStart(ArkUIRuntimeCallInfo * runtimeCallInfo)867 ArkUINativeModuleValue SwiperBridge::SetSwiperOnAnimationStart(ArkUIRuntimeCallInfo* runtimeCallInfo)
868 {
869 EcmaVM* vm = runtimeCallInfo->GetVM();
870 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
871 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
872 Local<JSValueRef> callbackArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
873 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
874 if (callbackArg->IsUndefined() || callbackArg->IsNull() || !callbackArg->IsFunction(vm)) {
875 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperOnAnimationStart(nativeNode);
876 return panda::JSValueRef::Undefined(vm);
877 }
878 auto frameNode = reinterpret_cast<FrameNode*>(nativeNode);
879 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
880 panda::Local<panda::FunctionRef> func = callbackArg->ToObject(vm);
881 std::function<void(int32_t, int32_t, const AnimationCallbackInfo&)> callback =
882 [vm, frameNode, func = panda::CopyableGlobal(vm, func)](
883 int32_t index, int32_t targetIndex, const AnimationCallbackInfo& extraInfo) {
884 panda::LocalScope pandaScope(vm);
885 panda::TryCatch trycatch(vm);
886 PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode));
887 panda::Local<panda::NumberRef> indexParam = panda::NumberRef::New(vm, index);
888 panda::Local<panda::NumberRef> targetIndexParam = panda::NumberRef::New(vm, targetIndex);
889 const char* keys[] = {"currentOffset", "targetOffset", "velocity"};
890 Local<JSValueRef> values[] = { panda::NumberRef::New(vm, extraInfo.currentOffset.value()),
891 panda::NumberRef::New(vm, extraInfo.targetOffset.value()),
892 panda::NumberRef::New(vm, extraInfo.velocity.value()) };
893 auto eventObject = panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keys), keys, values);
894 panda::Local<panda::JSValueRef> params[3] = { indexParam, targetIndexParam, eventObject }; // 3: Array length
895 func->Call(vm, func.ToLocal(), params, 3); // 3: Array length
896 };
897 GetArkUINodeModifiers()->getSwiperModifier()->setSwiperOnAnimationStart(nativeNode,
898 reinterpret_cast<void*>(&callback));
899 return panda::JSValueRef::Undefined(vm);
900 }
901
ResetSwiperOnAnimationStart(ArkUIRuntimeCallInfo * runtimeCallInfo)902 ArkUINativeModuleValue SwiperBridge::ResetSwiperOnAnimationStart(ArkUIRuntimeCallInfo* runtimeCallInfo)
903 {
904 EcmaVM* vm = runtimeCallInfo->GetVM();
905 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
906 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
907 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
908 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperOnAnimationStart(nativeNode);
909 return panda::JSValueRef::Undefined(vm);
910 }
911
SetSwiperOnAnimationEnd(ArkUIRuntimeCallInfo * runtimeCallInfo)912 ArkUINativeModuleValue SwiperBridge::SetSwiperOnAnimationEnd(ArkUIRuntimeCallInfo* runtimeCallInfo)
913 {
914 EcmaVM* vm = runtimeCallInfo->GetVM();
915 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
916 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
917 Local<JSValueRef> callbackArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
918 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
919 if (callbackArg->IsUndefined() || callbackArg->IsNull() || !callbackArg->IsFunction(vm)) {
920 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperOnAnimationEnd(nativeNode);
921 return panda::JSValueRef::Undefined(vm);
922 }
923 auto frameNode = reinterpret_cast<FrameNode*>(nativeNode);
924 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
925 panda::Local<panda::FunctionRef> func = callbackArg->ToObject(vm);
926 std::function<void(int32_t, const AnimationCallbackInfo&)> callback = [vm, frameNode,
927 func = panda::CopyableGlobal(vm, func)](int32_t index, const AnimationCallbackInfo& extraInfo) {
928 panda::LocalScope pandaScope(vm);
929 panda::TryCatch trycatch(vm);
930 PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode));
931 panda::Local<panda::NumberRef> indexParam = panda::NumberRef::New(vm, index);
932 const char* keys[] = {"currentOffset", "targetOffset", "velocity"};
933 Local<JSValueRef> values[] = { panda::NumberRef::New(vm, extraInfo.currentOffset.value()),
934 panda::NumberRef::New(vm, 0),
935 panda::NumberRef::New(vm, 0) };
936 auto eventObject = panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keys), keys, values);
937 panda::Local<panda::JSValueRef> params[2] = { indexParam, eventObject }; // 2: Array length
938 func->Call(vm, func.ToLocal(), params, 2); // 2: Array length
939 };
940 GetArkUINodeModifiers()->getSwiperModifier()->setSwiperOnAnimationEnd(nativeNode,
941 reinterpret_cast<void*>(&callback));
942 return panda::JSValueRef::Undefined(vm);
943 }
944
ResetSwiperOnAnimationEnd(ArkUIRuntimeCallInfo * runtimeCallInfo)945 ArkUINativeModuleValue SwiperBridge::ResetSwiperOnAnimationEnd(ArkUIRuntimeCallInfo* runtimeCallInfo)
946 {
947 EcmaVM* vm = runtimeCallInfo->GetVM();
948 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
949 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
950 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
951 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperOnAnimationEnd(nativeNode);
952 return panda::JSValueRef::Undefined(vm);
953 }
954
SetSwiperOnGestureSwipe(ArkUIRuntimeCallInfo * runtimeCallInfo)955 ArkUINativeModuleValue SwiperBridge::SetSwiperOnGestureSwipe(ArkUIRuntimeCallInfo* runtimeCallInfo)
956 {
957 EcmaVM* vm = runtimeCallInfo->GetVM();
958 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
959 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
960 Local<JSValueRef> callbackArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
961 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
962 if (callbackArg->IsUndefined() || callbackArg->IsNull() || !callbackArg->IsFunction(vm)) {
963 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperOnGestureSwipe(nativeNode);
964 return panda::JSValueRef::Undefined(vm);
965 }
966 auto frameNode = reinterpret_cast<FrameNode*>(nativeNode);
967 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
968 panda::Local<panda::FunctionRef> func = callbackArg->ToObject(vm);
969 std::function<void(int32_t, const AnimationCallbackInfo&)> callback = [vm, frameNode,
970 func = panda::CopyableGlobal(vm, func)](int32_t index, const AnimationCallbackInfo& extraInfo) {
971 panda::LocalScope pandaScope(vm);
972 panda::TryCatch trycatch(vm);
973 PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode));
974 panda::Local<panda::NumberRef> indexParam = panda::NumberRef::New(vm, index);
975 const char* keys[] = {"currentOffset", "targetOffset", "velocity"};
976 Local<JSValueRef> values[] = { panda::NumberRef::New(vm, extraInfo.currentOffset.value()),
977 panda::NumberRef::New(vm, 0),
978 panda::NumberRef::New(vm, 0) };
979 auto eventObject = panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keys), keys, values);
980 panda::Local<panda::JSValueRef> params[2] = { indexParam, eventObject }; // 2: Array length
981 func->Call(vm, func.ToLocal(), params, 2); // 2: Array length
982 };
983 GetArkUINodeModifiers()->getSwiperModifier()->setSwiperOnGestureSwipe(nativeNode,
984 reinterpret_cast<void*>(&callback));
985 return panda::JSValueRef::Undefined(vm);
986 }
987
ResetSwiperOnGestureSwipe(ArkUIRuntimeCallInfo * runtimeCallInfo)988 ArkUINativeModuleValue SwiperBridge::ResetSwiperOnGestureSwipe(ArkUIRuntimeCallInfo* runtimeCallInfo)
989 {
990 EcmaVM* vm = runtimeCallInfo->GetVM();
991 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
992 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
993 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
994 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperOnGestureSwipe(nativeNode);
995 return panda::JSValueRef::Undefined(vm);
996 }
997
SetSwiperCustomContentTransition(ArkUIRuntimeCallInfo * runtimeCallInfo)998 ArkUINativeModuleValue SwiperBridge::SetSwiperCustomContentTransition(ArkUIRuntimeCallInfo* runtimeCallInfo)
999 {
1000 EcmaVM* vm = runtimeCallInfo->GetVM();
1001 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
1002 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
1003 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1004 auto* frameNode = reinterpret_cast<FrameNode*>(nativeNode);
1005 using namespace OHOS::Ace::Framework;
1006 JsiCallbackInfo info = JsiCallbackInfo(runtimeCallInfo);
1007 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
1008 if (info.Length() < 2 || !info[1]->IsObject()) { // 2: Array length
1009 return panda::JSValueRef::Undefined(vm);
1010 }
1011
1012 SwiperContentAnimatedTransition transitionInfo;
1013 auto transitionObj = JSRef<JSObject>::Cast(info[1]);
1014 JSRef<JSVal> timeoutProperty = transitionObj->GetProperty("timeout");
1015 if (timeoutProperty->IsNumber()) {
1016 auto timeout = timeoutProperty->ToNumber<int32_t>();
1017 transitionInfo.timeout = timeout < 0 ? 0 : timeout;
1018 } else {
1019 transitionInfo.timeout = 0;
1020 }
1021
1022 JSRef<JSVal> transition = transitionObj->GetProperty("transition");
1023 if (transition->IsFunction()) {
1024 auto jsOnTransition =
1025 AceType::MakeRefPtr<JsSwiperFunction>(JSRef<JSFunc>::Cast(transition));
1026 auto onTransition = [execCtx = info.GetExecutionContext(), func = std::move(jsOnTransition)](
1027 const RefPtr<SwiperContentTransitionProxy>& proxy) {
1028 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
1029 ACE_SCORING_EVENT("Swiper.customContentTransition");
1030 func->Execute(proxy);
1031 };
1032 transitionInfo.transition = std::move(onTransition);
1033 }
1034 SwiperModelNG::SetCustomContentTransition(frameNode, transitionInfo);
1035 return panda::JSValueRef::Undefined(vm);
1036 }
1037
ResetSwiperCustomContentTransition(ArkUIRuntimeCallInfo * runtimeCallInfo)1038 ArkUINativeModuleValue SwiperBridge::ResetSwiperCustomContentTransition(ArkUIRuntimeCallInfo* runtimeCallInfo)
1039 {
1040 EcmaVM* vm = runtimeCallInfo->GetVM();
1041 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
1042 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
1043 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1044 auto* frameNode = reinterpret_cast<FrameNode*>(nativeNode);
1045 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
1046 SwiperContentAnimatedTransition transitionInfo;
1047 SwiperModelNG::SetCustomContentTransition(frameNode, transitionInfo);
1048 return panda::JSValueRef::Undefined(vm);
1049 }
1050
SetOnContentDidScroll(ArkUIRuntimeCallInfo * runtimeCallInfo)1051 ArkUINativeModuleValue SwiperBridge::SetOnContentDidScroll(ArkUIRuntimeCallInfo* runtimeCallInfo)
1052 {
1053 EcmaVM* vm = runtimeCallInfo->GetVM();
1054 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
1055 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
1056 Local<JSValueRef> callbackArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
1057 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1058 if (callbackArg->IsUndefined() || callbackArg->IsNull() || !callbackArg->IsFunction(vm)) {
1059 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperOnContentDidScroll(nativeNode);
1060 return panda::JSValueRef::Undefined(vm);
1061 }
1062 auto frameNode = reinterpret_cast<FrameNode*>(nativeNode);
1063 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
1064 panda::Local<panda::FunctionRef> func = callbackArg->ToObject(vm);
1065 std::function<void(int32_t, int32_t, float_t, float_t)> callback = [vm, frameNode,
1066 func = panda::CopyableGlobal(vm, func)](int32_t selectedIndex, int32_t index,
1067 float position, float mainAxisLength) {
1068 panda::LocalScope pandaScope(vm);
1069 panda::TryCatch trycatch(vm);
1070 PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode));
1071 panda::Local<panda::NumberRef> selectedIndexParam = panda::NumberRef::New(vm, selectedIndex);
1072 panda::Local<panda::NumberRef> indexParam = panda::NumberRef::New(vm, index);
1073 panda::Local<panda::NumberRef> positionParam = panda::NumberRef::New(vm, position);
1074 panda::Local<panda::NumberRef> mainAxisLengthParam = panda::NumberRef::New(vm, mainAxisLength);
1075 panda::Local<panda::JSValueRef> params[4] = { selectedIndexParam, indexParam, // 4: Array length
1076 positionParam, mainAxisLengthParam };
1077 func->Call(vm, func.ToLocal(), params, 4); // 4: Array length
1078 };
1079 GetArkUINodeModifiers()->getSwiperModifier()->setSwiperOnContentDidScroll(nativeNode,
1080 reinterpret_cast<void*>(&callback));
1081 return panda::JSValueRef::Undefined(vm);
1082 }
1083
ResetOnContentDidScroll(ArkUIRuntimeCallInfo * runtimeCallInfo)1084 ArkUINativeModuleValue SwiperBridge::ResetOnContentDidScroll(ArkUIRuntimeCallInfo* runtimeCallInfo)
1085 {
1086 EcmaVM* vm = runtimeCallInfo->GetVM();
1087 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
1088 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1089 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1090 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperOnContentDidScroll(nativeNode);
1091 return panda::JSValueRef::Undefined(vm);
1092 }
1093
SetSwiperPageFlipMode(ArkUIRuntimeCallInfo * runtimeCallInfo)1094 ArkUINativeModuleValue SwiperBridge::SetSwiperPageFlipMode(ArkUIRuntimeCallInfo* runtimeCallInfo)
1095 {
1096 EcmaVM* vm = runtimeCallInfo->GetVM();
1097 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1098 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
1099 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
1100 Local<JSValueRef> valueArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
1101 if (valueArg->IsNumber()) {
1102 int32_t pageFlipMode = valueArg->Int32Value(vm);
1103 GetArkUINodeModifiers()->getSwiperModifier()->setSwiperPageFlipMode(nativeNode, pageFlipMode);
1104 } else {
1105 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperPageFlipMode(nativeNode);
1106 }
1107 return panda::JSValueRef::Undefined(vm);
1108 }
1109
ResetSwiperPageFlipMode(ArkUIRuntimeCallInfo * runtimeCallInfo)1110 ArkUINativeModuleValue SwiperBridge::ResetSwiperPageFlipMode(ArkUIRuntimeCallInfo* runtimeCallInfo)
1111 {
1112 EcmaVM* vm = runtimeCallInfo->GetVM();
1113 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
1114 Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
1115 auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
1116 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperPageFlipMode(nativeNode);
1117 return panda::JSValueRef::Undefined(vm);
1118 }
1119
SetSwiperOnContentWillScroll(ArkUIRuntimeCallInfo * runtimeCallInfo)1120 ArkUINativeModuleValue SwiperBridge::SetSwiperOnContentWillScroll(ArkUIRuntimeCallInfo* runtimeCallInfo)
1121 {
1122 EcmaVM* vm = runtimeCallInfo->GetVM();
1123 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
1124 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_NODE_INDEX);
1125 Local<JSValueRef> callbackArg = runtimeCallInfo->GetCallArgRef(CALL_ARG_VALUE_INDEX);
1126 CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
1127 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1128 if (callbackArg->IsUndefined() || callbackArg->IsNull() || !callbackArg->IsFunction(vm)) {
1129 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperOnContentWillScroll(nativeNode);
1130 return panda::JSValueRef::Undefined(vm);
1131 }
1132 auto frameNode = reinterpret_cast<FrameNode*>(nativeNode);
1133 CHECK_NULL_RETURN(frameNode, panda::JSValueRef::Undefined(vm));
1134 panda::Local<panda::FunctionRef> func = callbackArg->ToObject(vm);
1135 std::function<bool(const SwiperContentWillScrollResult&)> callback =
1136 [vm, frameNode, func = panda::CopyableGlobal(vm, func)](const SwiperContentWillScrollResult& result) -> bool {
1137 panda::LocalScope pandaScope(vm);
1138 panda::TryCatch trycatch(vm);
1139 PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode));
1140 const char* keys[] = { "currentIndex", "comingIndex", "offset" };
1141 Local<JSValueRef> values[] = { panda::NumberRef::New(vm, result.currentIndex),
1142 panda::NumberRef::New(vm, result.comingIndex), panda::NumberRef::New(vm, result.offset) };
1143 auto eventObject = panda::ObjectRef::NewWithNamedProperties(vm, ArraySize(keys), keys, values);
1144 panda::Local<panda::JSValueRef> params[1] = { eventObject };
1145 auto ret = func->Call(vm, func.ToLocal(), params, 1);
1146 if (ret->IsBoolean()) {
1147 return ret->ToBoolean(vm)->Value();
1148 }
1149 return true;
1150 };
1151 GetArkUINodeModifiers()->getSwiperModifier()->setSwiperOnContentWillScroll(
1152 nativeNode, reinterpret_cast<bool*>(&callback));
1153 return panda::JSValueRef::Undefined(vm);
1154 }
1155
ResetSwiperOnContentWillScroll(ArkUIRuntimeCallInfo * runtimeCallInfo)1156 ArkUINativeModuleValue SwiperBridge::ResetSwiperOnContentWillScroll(ArkUIRuntimeCallInfo* runtimeCallInfo)
1157 {
1158 EcmaVM* vm = runtimeCallInfo->GetVM();
1159 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
1160 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
1161 CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
1162 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
1163 GetArkUINodeModifiers()->getSwiperModifier()->resetSwiperOnContentWillScroll(nativeNode);
1164 return panda::JSValueRef::Undefined(vm);
1165 }
1166 } // namespace OHOS::Ace::NG