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