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 "core/interfaces/native/node/node_swiper_modifier.h"
16
17 #include <vector>
18 #include "node_model.h"
19
20 #include "base/error/error_code.h"
21 #include "base/geometry/axis.h"
22 #include "base/log/log_wrapper.h"
23 #include "base/memory/type_info_base.h"
24 #include "base/utils/string_utils.h"
25 #include "base/utils/utils.h"
26 #include "bridge/common/utils/utils.h"
27 #include "core/animation/curve.h"
28 #include "core/components/swiper/swiper_component.h"
29 #include "core/components/swiper/swiper_indicator_theme.h"
30 #include "core/components_ng/base/frame_node.h"
31 #include "core/components_ng/pattern/swiper/swiper_model_ng.h"
32 #include "core/interfaces/arkoala/arkoala_api.h"
33 #include "core/interfaces/native/node/node_adapter_impl.h"
34 #include "core/interfaces/native/node/node_api.h"
35 #include "core/pipeline/base/element_register.h"
36 #include "core/pipeline/pipeline_base.h"
37
38 namespace OHOS::Ace::NG {
39 namespace {
40 constexpr int32_t DEFAULT_INTERVAL = 3000;
41 constexpr int32_t DEFAULT_DURATION = 400;
42 constexpr int32_t DEFAULT_CACHED_COUNT = 1;
43 constexpr int32_t DEFAULT_DISPLAY_COUNT = 1;
44 constexpr bool DEFAULT_SWIPE_BY_GROUP = false;
45 constexpr bool DEFAULT_AUTO_PLAY = false;
46 constexpr bool DEFAULT_LOOP = true;
47 constexpr bool DEAFULT_DISABLE_SWIPE = false;
48 constexpr int32_t ARROW_IS_SHOW_BACKGROUND = 1;
49 constexpr int32_t ARROW_IS_SIDE_BAR_MIDDLE = 2;
50 constexpr int32_t ARROW_BACKGROUND_SIZE = 3;
51 constexpr int32_t ARROW_BACKGROUND_COLOR = 4;
52 constexpr int32_t ARROW_SIZE = 5;
53 constexpr int32_t ARROW_COLOR = 6;
54 constexpr int32_t DISPLAY_ARROW_UNDEFINED = 3;
55 constexpr int32_t DISPLAY_ARROW_OBJECT = 2;
56 constexpr int32_t DISPLAY_ARROW_TRUE = 1;
57 constexpr int32_t DISPLAY_ARROW_FALSE = 0;
58 constexpr int32_t DISPLAY_ARROW_VALUE = 0;
59 constexpr int32_t DISPLAY_ARROW_IS_HOVER_SHOW_INDEX = 7;
60 constexpr int32_t DISPLAY_ARROW_IS_HOVER_SHOW_UNDEFINED = 2;
61 constexpr int32_t INDICATOR_TYPE_INDEX = 0;
62 constexpr int32_t INDICATOR_VALUE = 1;
63 constexpr int32_t DIGIT_INDICATOR_FONT_COLOR = 1;
64 constexpr int32_t DIGIT_INDICATOR_SELECTED_FONT_COLOR = 2;
65 constexpr int32_t DIGIT_INDICATOR_DIGIT_FONT_SIZE = 3;
66 constexpr int32_t DIGIT_INDICATOR_DIGIT_FONT_WEIGHT = 4;
67 constexpr int32_t DIGIT_INDICATOR_SELECTED_DIGIT_FONT_SIZE = 5;
68 constexpr int32_t DIGIT_INDICATOR_SELECTED_DIGIT_FONT_WEIGHT = 6;
69 constexpr int32_t DIGIT_INDICATOR_LEFT = 7;
70 constexpr int32_t DIGIT_INDICATOR_TOP = 8;
71 constexpr int32_t DIGIT_INDICATOR_RIGHT = 9;
72 constexpr int32_t DIGIT_INDICATOR_BOTTOM = 10;
73 constexpr int32_t DOT_INDICATOR_ITEM_WIDTH = 1;
74 constexpr int32_t DOT_INDICATOR_ITEM_HEIGHT = 2;
75 constexpr int32_t DOT_INDICATOR_SELECTED_ITEM_WIDTH = 3;
76 constexpr int32_t DOT_INDICATOR_SELECTED_ITEM_HEIGHT = 4;
77 constexpr int32_t DOT_INDICATOR_MASK = 5;
78 constexpr int32_t DOT_INDICATOR_COLOR = 6;
79 constexpr int32_t DOT_INDICATOR_SELECTED_COLOR = 7;
80 constexpr int32_t DOT_INDICATOR_LEFT = 8;
81 constexpr int32_t DOT_INDICATOR_TOP = 9;
82 constexpr int32_t DOT_INDICATOR_RIGHT = 10;
83 constexpr int32_t DOT_INDICATOR_BOTTOM = 11;
84 constexpr int32_t DOT_INDICATOR_MAX_DISPLAY_COUNT = 12;
85 constexpr int32_t DOT_INDICATOR_INFO_SIZE = 12;
86 constexpr int32_t NUM_0 = 0;
87 constexpr int32_t NUM_1 = 1;
88 constexpr int32_t NUM_2 = 2;
89 constexpr int32_t NUM_3 = 3;
90 constexpr int32_t NUM_4 = 4;
91 constexpr float ANIMATION_INFO_DEFAULT = 0.0f;
92 constexpr float ARROW_SIZE_COEFFICIENT = 0.75f;
93 const int32_t ERROR_INT_CODE = -1;
94 constexpr float ZERO_F = 0.0f;
95
96 const std::vector<SwiperDisplayMode> DISPLAY_MODE = { SwiperDisplayMode::STRETCH, SwiperDisplayMode::AUTO_LINEAR };
97 const std::vector<EdgeEffect> EDGE_EFFECT = { EdgeEffect::SPRING, EdgeEffect::FADE, EdgeEffect::NONE };
98 const std::vector<SwiperIndicatorType> INDICATOR_TYPE = { SwiperIndicatorType::DOT, SwiperIndicatorType::DIGIT };
99 const std::vector<OHOS::Ace::RefPtr<OHOS::Ace::Curve>> CURVES = {
100 OHOS::Ace::Curves::LINEAR,
101 OHOS::Ace::Curves::EASE,
102 OHOS::Ace::Curves::EASE_IN,
103 OHOS::Ace::Curves::EASE_OUT,
104 OHOS::Ace::Curves::EASE_IN_OUT,
105 OHOS::Ace::Curves::FAST_OUT_SLOW_IN,
106 OHOS::Ace::Curves::LINEAR_OUT_SLOW_IN,
107 OHOS::Ace::Curves::FAST_OUT_LINEAR_IN,
108 OHOS::Ace::Curves::EXTREME_DECELERATION,
109 OHOS::Ace::Curves::SHARP,
110 OHOS::Ace::Curves::RHYTHM,
111 OHOS::Ace::Curves::SMOOTH,
112 OHOS::Ace::Curves::FRICTION,
113 };
SetArrowBackgroundInfo(SwiperArrowParameters & swiperArrowParameters,RefPtr<SwiperIndicatorTheme> & swiperIndicatorTheme,const std::vector<std::string> & arrowInfo)114 void SetArrowBackgroundInfo(SwiperArrowParameters& swiperArrowParameters,
115 RefPtr<SwiperIndicatorTheme>& swiperIndicatorTheme, const std::vector<std::string>& arrowInfo)
116 {
117 auto backgroundSizeValue = arrowInfo[ARROW_BACKGROUND_SIZE] == "-" ? "" : arrowInfo[ARROW_BACKGROUND_SIZE];
118 auto backgroundColorValue = arrowInfo[ARROW_BACKGROUND_COLOR] == "-" ? "" : arrowInfo[ARROW_BACKGROUND_COLOR];
119 auto arrowSizeValue = arrowInfo[ARROW_SIZE] == "-" ? "" : arrowInfo[ARROW_SIZE];
120 auto arrowColorValue = arrowInfo[ARROW_COLOR] == "-" ? "" : arrowInfo[ARROW_COLOR];
121 bool parseOk = false;
122 CalcDimension dimension;
123 Color color;
124 if (swiperArrowParameters.isSidebarMiddle.value()) {
125 dimension = StringUtils::StringToCalcDimension(backgroundSizeValue, false, DimensionUnit::VP);
126 swiperArrowParameters.backgroundSize =
127 GreatNotEqual(dimension.ConvertToVp(), 0.0) && !(dimension.Unit() == DimensionUnit::PERCENT)
128 ? dimension
129 : swiperIndicatorTheme->GetBigArrowBackgroundSize();
130 parseOk = Color::ParseColorString(backgroundColorValue, color);
131 swiperArrowParameters.backgroundColor = parseOk ? color : swiperIndicatorTheme->GetBigArrowBackgroundColor();
132 if (swiperArrowParameters.isShowBackground.value()) {
133 swiperArrowParameters.arrowSize = swiperArrowParameters.backgroundSize.value() * ARROW_SIZE_COEFFICIENT;
134 } else {
135 parseOk = StringUtils::StringToCalcDimensionNG(arrowSizeValue, dimension, false, DimensionUnit::VP);
136 swiperArrowParameters.arrowSize =
137 parseOk && GreatNotEqual(dimension.ConvertToVp(), 0.0) && !(dimension.Unit() == DimensionUnit::PERCENT)
138 ? dimension
139 : swiperIndicatorTheme->GetBigArrowSize();
140 swiperArrowParameters.backgroundSize = swiperArrowParameters.arrowSize;
141 }
142 parseOk = Color::ParseColorString(arrowColorValue, color);
143 swiperArrowParameters.arrowColor = parseOk ? color : swiperIndicatorTheme->GetBigArrowColor();
144 } else {
145 dimension = StringUtils::StringToCalcDimension(backgroundSizeValue, false, DimensionUnit::VP);
146 swiperArrowParameters.backgroundSize =
147 GreatNotEqual(dimension.ConvertToVp(), 0.0) && !(dimension.Unit() == DimensionUnit::PERCENT)
148 ? dimension
149 : swiperIndicatorTheme->GetSmallArrowBackgroundSize();
150 parseOk = Color::ParseColorString(backgroundColorValue, color);
151 swiperArrowParameters.backgroundColor = parseOk ? color : swiperIndicatorTheme->GetSmallArrowBackgroundColor();
152 if (swiperArrowParameters.isShowBackground.value()) {
153 swiperArrowParameters.arrowSize = swiperArrowParameters.backgroundSize.value() * ARROW_SIZE_COEFFICIENT;
154 } else {
155 parseOk = StringUtils::StringToCalcDimensionNG(arrowSizeValue, dimension, false, DimensionUnit::VP);
156 swiperArrowParameters.arrowSize =
157 parseOk && GreatNotEqual(dimension.ConvertToVp(), 0.0) && !(dimension.Unit() == DimensionUnit::PERCENT)
158 ? dimension
159 : swiperIndicatorTheme->GetSmallArrowSize();
160 swiperArrowParameters.backgroundSize = swiperArrowParameters.arrowSize;
161 }
162 parseOk = Color::ParseColorString(arrowColorValue, color);
163 swiperArrowParameters.arrowColor = parseOk ? color : swiperIndicatorTheme->GetSmallArrowColor();
164 }
165 }
166
GetArrowInfo(const std::vector<std::string> & arrowInfo,SwiperArrowParameters & swiperArrowParameters)167 bool GetArrowInfo(const std::vector<std::string>& arrowInfo, SwiperArrowParameters& swiperArrowParameters)
168 {
169 auto isShowBackgroundValue = arrowInfo[ARROW_IS_SHOW_BACKGROUND];
170 auto isSidebarMiddleValue = arrowInfo[ARROW_IS_SIDE_BAR_MIDDLE];
171
172 auto pipelineContext = PipelineBase::GetCurrentContextSafely();
173 CHECK_NULL_RETURN(pipelineContext, false);
174 auto swiperIndicatorTheme = pipelineContext->GetTheme<SwiperIndicatorTheme>();
175 CHECK_NULL_RETURN(swiperIndicatorTheme, false);
176 if (isShowBackgroundValue == "2") {
177 swiperArrowParameters.isShowBackground = swiperIndicatorTheme->GetIsShowArrowBackground();
178 } else {
179 swiperArrowParameters.isShowBackground = isShowBackgroundValue == "1" ? true : false;
180 }
181 if (isSidebarMiddleValue == "2") {
182 swiperArrowParameters.isSidebarMiddle = swiperIndicatorTheme->GetIsSidebarMiddle();
183 } else {
184 swiperArrowParameters.isSidebarMiddle = isSidebarMiddleValue == "1" ? true : false;
185 }
186 SetArrowBackgroundInfo(swiperArrowParameters, swiperIndicatorTheme, arrowInfo);
187 return true;
188 }
189
GetInfoFromVectorByIndex(const std::vector<std::string> & dotIndicatorInfo,int32_t index)190 std::string GetInfoFromVectorByIndex(const std::vector<std::string>& dotIndicatorInfo, int32_t index)
191 {
192 auto dotIndicatorInfoSize = dotIndicatorInfo.size();
193 return dotIndicatorInfoSize < DOT_INDICATOR_INFO_SIZE
194 ? ""
195 : (dotIndicatorInfo[index] == "-" ? "" : dotIndicatorInfo[index]);
196 }
197
ParseIndicatorDimension(const std::string & value)198 std::optional<Dimension> ParseIndicatorDimension(const std::string& value)
199 {
200 std::optional<Dimension> indicatorDimension;
201 if (value.empty()) {
202 return indicatorDimension;
203 }
204 CalcDimension dimPosition = StringUtils::StringToCalcDimension(value, false, DimensionUnit::VP);
205 indicatorDimension = LessNotEqual(dimPosition.ConvertToPx(), 0.0f) ? 0.0_vp : dimPosition;
206 return indicatorDimension;
207 }
208
ParseMaxDisplayCount(const std::vector<std::string> & dotIndicatorInfo,SwiperParameters & swiperParameters)209 void ParseMaxDisplayCount(const std::vector<std::string>& dotIndicatorInfo, SwiperParameters& swiperParameters)
210 {
211 auto maxDisplayCount = GetInfoFromVectorByIndex(dotIndicatorInfo, DOT_INDICATOR_MAX_DISPLAY_COUNT);
212 if (maxDisplayCount.empty()) {
213 return;
214 }
215
216 swiperParameters.maxDisplayCountVal = StringUtils::StringToInt(maxDisplayCount);
217 }
218
GetDotIndicatorInfo(FrameNode * frameNode,const std::vector<std::string> & dotIndicatorInfo)219 SwiperParameters GetDotIndicatorInfo(FrameNode* frameNode, const std::vector<std::string>& dotIndicatorInfo)
220 {
221 auto itemWidthValue = GetInfoFromVectorByIndex(dotIndicatorInfo, DOT_INDICATOR_ITEM_WIDTH);
222 auto itemHeightValue = GetInfoFromVectorByIndex(dotIndicatorInfo, DOT_INDICATOR_ITEM_HEIGHT);
223 auto selectedItemWidthValue = GetInfoFromVectorByIndex(dotIndicatorInfo, DOT_INDICATOR_SELECTED_ITEM_WIDTH);
224 auto selectedItemHeightValue = GetInfoFromVectorByIndex(dotIndicatorInfo, DOT_INDICATOR_SELECTED_ITEM_HEIGHT);
225 auto maskValue = GetInfoFromVectorByIndex(dotIndicatorInfo, DOT_INDICATOR_MASK);
226 auto colorValue = GetInfoFromVectorByIndex(dotIndicatorInfo, DOT_INDICATOR_COLOR);
227 auto selectedColorValue = GetInfoFromVectorByIndex(dotIndicatorInfo, DOT_INDICATOR_SELECTED_COLOR);
228 CHECK_NULL_RETURN(frameNode, SwiperParameters());
229 auto pipelineContext = frameNode->GetContext();
230 CHECK_NULL_RETURN(pipelineContext, SwiperParameters());
231 auto swiperIndicatorTheme = pipelineContext->GetTheme<SwiperIndicatorTheme>();
232 CHECK_NULL_RETURN(swiperIndicatorTheme, SwiperParameters());
233 bool parseOk = false;
234 SwiperParameters swiperParameters;
235 auto leftValue = GetInfoFromVectorByIndex(dotIndicatorInfo, DOT_INDICATOR_LEFT);
236 auto topValue = GetInfoFromVectorByIndex(dotIndicatorInfo, DOT_INDICATOR_TOP);
237 auto rightValue = GetInfoFromVectorByIndex(dotIndicatorInfo, DOT_INDICATOR_RIGHT);
238 auto bottomValue = GetInfoFromVectorByIndex(dotIndicatorInfo, DOT_INDICATOR_BOTTOM);
239 swiperParameters.dimLeft = ParseIndicatorDimension(leftValue);
240 swiperParameters.dimTop = ParseIndicatorDimension(topValue);
241 swiperParameters.dimRight = ParseIndicatorDimension(rightValue);
242 swiperParameters.dimBottom = ParseIndicatorDimension(bottomValue);
243 CalcDimension dimPosition = StringUtils::StringToCalcDimension(itemWidthValue, false, DimensionUnit::VP);
244 auto defaultSize = swiperIndicatorTheme->GetSize();
245 bool parseItemWOk = !itemWidthValue.empty() && dimPosition.Unit() != DimensionUnit::PERCENT;
246 swiperParameters.itemWidth = (parseItemWOk && (dimPosition > 0.0_vp)) ? dimPosition : defaultSize;
247 dimPosition = StringUtils::StringToCalcDimension(itemHeightValue, false, DimensionUnit::VP);
248 bool parseItemHOk = !itemHeightValue.empty() && dimPosition.Unit() != DimensionUnit::PERCENT;
249 swiperParameters.itemHeight = (parseItemHOk && (dimPosition > 0.0_vp)) ? dimPosition : defaultSize;
250 dimPosition = StringUtils::StringToCalcDimension(selectedItemWidthValue, false, DimensionUnit::VP);
251 bool parseSeleItemWOk = !selectedItemWidthValue.empty() && dimPosition.Unit() != DimensionUnit::PERCENT;
252 swiperParameters.selectedItemWidth = (parseSeleItemWOk && (dimPosition > 0.0_vp)) ? dimPosition : defaultSize;
253 dimPosition = StringUtils::StringToCalcDimension(selectedItemHeightValue, false, DimensionUnit::VP);
254 bool parseSeleItemHOk = !selectedItemHeightValue.empty() && dimPosition.Unit() != DimensionUnit::PERCENT;
255 swiperParameters.selectedItemHeight = (parseSeleItemHOk && (dimPosition > 0.0_vp)) ? dimPosition : defaultSize;
256 if (!parseSeleItemWOk && !parseSeleItemHOk && !parseItemWOk && !parseItemHOk) {
257 SwiperModelNG::SetIsIndicatorCustomSize(frameNode, false);
258 } else {
259 SwiperModelNG::SetIsIndicatorCustomSize(frameNode, true);
260 }
261 if (maskValue != "2") {
262 swiperParameters.maskValue = (maskValue == "1" ? true : false);
263 }
264 Color colorVal;
265 parseOk = Color::ParseColorString(colorValue, colorVal);
266 swiperParameters.colorVal = parseOk ? colorVal : swiperIndicatorTheme->GetColor();
267 parseOk = Color::ParseColorString(selectedColorValue, colorVal);
268 swiperParameters.selectedColorVal = parseOk ? colorVal : swiperIndicatorTheme->GetSelectedColor();
269
270 ParseMaxDisplayCount(dotIndicatorInfo, swiperParameters);
271
272 return swiperParameters;
273 }
274
ParseIndicatorCommonDimension(const ArkUIOptionalFloat attribute,DimensionUnit unit)275 std::optional<Dimension> ParseIndicatorCommonDimension(const ArkUIOptionalFloat attribute, DimensionUnit unit)
276 {
277 std::optional<Dimension> indicatorDimension;
278 if (!attribute.isSet) {
279 return indicatorDimension;
280 }
281 CalcDimension dimPosition = CalcDimension(attribute.value, unit);
282 indicatorDimension = LessNotEqual(dimPosition.ConvertToPx(), 0.0f) ? 0.0_vp : dimPosition;
283 return indicatorDimension;
284 }
285
286
ParseIndicatorAttribute(std::optional<Dimension> dim,bool & hasValue,float & value)287 void ParseIndicatorAttribute(std::optional<Dimension> dim, bool& hasValue, float& value)
288 {
289 hasValue = dim.has_value();
290 if (hasValue) {
291 value = dim.value().Value();
292 } else {
293 value = ZERO_F;
294 }
295 }
296
GetDotIndicatorProps(FrameNode * frameNode,ArkUISwiperIndicator * indicator)297 SwiperParameters GetDotIndicatorProps(FrameNode* frameNode, ArkUISwiperIndicator* indicator)
298 {
299 CHECK_NULL_RETURN(frameNode, SwiperParameters());
300 auto pipelineContext = frameNode->GetContext();
301 CHECK_NULL_RETURN(pipelineContext, SwiperParameters());
302 auto swiperIndicatorTheme = pipelineContext->GetTheme<SwiperIndicatorTheme>();
303 CHECK_NULL_RETURN(swiperIndicatorTheme, SwiperParameters());
304 SwiperParameters swiperParameters;
305 DimensionUnit unit = static_cast<DimensionUnit>(indicator->dimUnit);
306 swiperParameters.dimLeft = ParseIndicatorCommonDimension(indicator->dimLeft, unit);
307 swiperParameters.dimTop = ParseIndicatorCommonDimension(indicator->dimTop, unit);
308 swiperParameters.dimRight = ParseIndicatorCommonDimension(indicator->dimRight, unit);
309 swiperParameters.dimBottom = ParseIndicatorCommonDimension(indicator->dimBottom, unit);
310 auto defaultSize = swiperIndicatorTheme->GetSize();
311
312 CalcDimension dimPosition = Dimension(indicator->itemWidth.value, unit);
313 bool parseItemWOk = indicator->itemWidth.isSet && dimPosition.Unit() != DimensionUnit::PERCENT;
314 swiperParameters.itemWidth = (parseItemWOk && (dimPosition > 0.0_vp)) ? dimPosition : defaultSize;
315 dimPosition = Dimension(indicator->itemHeight.value, unit);
316 bool parseItemHOk = indicator->itemHeight.isSet && dimPosition.Unit() != DimensionUnit::PERCENT;
317 swiperParameters.itemHeight = (parseItemHOk && (dimPosition > 0.0_vp)) ? dimPosition : defaultSize;
318 dimPosition = Dimension(indicator->selectedItemWidth.value, unit);
319 bool parseSelectedItemWOk = indicator->selectedItemWidth.isSet && dimPosition.Unit() != DimensionUnit::PERCENT;
320 swiperParameters.selectedItemWidth = (parseSelectedItemWOk && (dimPosition > 0.0_vp)) ? dimPosition : defaultSize;
321 dimPosition = Dimension(indicator->selectedItemHeight.value, unit);
322 bool parseSelectedItemHOk = indicator->selectedItemHeight.isSet && dimPosition.Unit() != DimensionUnit::PERCENT;
323 swiperParameters.selectedItemHeight = (parseSelectedItemHOk && (dimPosition > 0.0_vp)) ? dimPosition : defaultSize;
324 if (!parseSelectedItemWOk && !parseSelectedItemHOk && !parseItemWOk && !parseItemHOk) {
325 SwiperModelNG::SetIsIndicatorCustomSize(frameNode, false);
326 } else {
327 SwiperModelNG::SetIsIndicatorCustomSize(frameNode, true);
328 }
329 swiperParameters.maskValue = indicator->maskValue.value == 1 ? true : false;
330 swiperParameters.colorVal =
331 indicator->colorValue.isSet == 1 ? Color(indicator->colorValue.value) : swiperIndicatorTheme->GetColor();
332 swiperParameters.selectedColorVal = indicator->selectedColorValue.isSet == 1 ?
333 Color(indicator->selectedColorValue.value) : swiperIndicatorTheme->GetSelectedColor();
334 swiperParameters.maxDisplayCountVal = indicator->maxDisplayCount.isSet == 1 ?
335 indicator->maxDisplayCount.value : NUM_0;
336 return swiperParameters;
337 }
338
GetFontContent(const std::string & size,const std::string & weight,bool isSelected,SwiperDigitalParameters & digitalParameters)339 void GetFontContent(
340 const std::string& size, const std::string& weight, bool isSelected, SwiperDigitalParameters& digitalParameters)
341 {
342 auto pipelineContext = PipelineBase::GetCurrentContextSafely();
343 CHECK_NULL_VOID(pipelineContext);
344 auto swiperIndicatorTheme = pipelineContext->GetTheme<SwiperIndicatorTheme>();
345 CHECK_NULL_VOID(swiperIndicatorTheme);
346 CalcDimension fontSize = StringUtils::StringToCalcDimension(size, false, DimensionUnit::VP);
347 if (LessOrEqual(fontSize.Value(), 0.0) || fontSize.Unit() == DimensionUnit::PERCENT) {
348 fontSize = swiperIndicatorTheme->GetDigitalIndicatorTextStyle().GetFontSize();
349 }
350 if (isSelected) {
351 digitalParameters.selectedFontSize = fontSize;
352 } else {
353 digitalParameters.fontSize = fontSize;
354 }
355 if (!weight.empty()) {
356 if (isSelected) {
357 digitalParameters.selectedFontWeight = StringUtils::StringToFontWeight(weight, FontWeight::NORMAL);
358 } else {
359 digitalParameters.fontWeight = StringUtils::StringToFontWeight(weight, FontWeight::NORMAL);
360 }
361 } else {
362 if (isSelected) {
363 digitalParameters.selectedFontWeight = swiperIndicatorTheme->GetDigitalIndicatorTextStyle().GetFontWeight();
364 } else {
365 digitalParameters.fontWeight = swiperIndicatorTheme->GetDigitalIndicatorTextStyle().GetFontWeight();
366 }
367 }
368 }
369
GetDigitIndicatorInfo(const std::vector<std::string> & digitIndicatorInfo)370 SwiperDigitalParameters GetDigitIndicatorInfo(const std::vector<std::string>& digitIndicatorInfo)
371 {
372 auto dotLeftValue = digitIndicatorInfo[DIGIT_INDICATOR_LEFT] == "-" ? "" : digitIndicatorInfo[DIGIT_INDICATOR_LEFT];
373 auto dotTopValue = digitIndicatorInfo[DIGIT_INDICATOR_TOP] == "-" ? "" : digitIndicatorInfo[DIGIT_INDICATOR_TOP];
374 auto dotRightValue =
375 digitIndicatorInfo[DIGIT_INDICATOR_RIGHT] == "-" ? "" : digitIndicatorInfo[DIGIT_INDICATOR_RIGHT];
376 auto dotBottomValue =
377 digitIndicatorInfo[DIGIT_INDICATOR_BOTTOM] == "-" ? "" : digitIndicatorInfo[DIGIT_INDICATOR_BOTTOM];
378 auto fontColorValue =
379 digitIndicatorInfo[DIGIT_INDICATOR_FONT_COLOR] == "-" ? "" : digitIndicatorInfo[DIGIT_INDICATOR_FONT_COLOR];
380 auto selectedFontColorValue = digitIndicatorInfo[DIGIT_INDICATOR_SELECTED_FONT_COLOR] == "-"
381 ? ""
382 : digitIndicatorInfo[DIGIT_INDICATOR_SELECTED_FONT_COLOR];
383 auto digitFontSize = digitIndicatorInfo[DIGIT_INDICATOR_DIGIT_FONT_SIZE] == "-"
384 ? ""
385 : digitIndicatorInfo[DIGIT_INDICATOR_DIGIT_FONT_SIZE];
386 auto digitFontWeight = digitIndicatorInfo[DIGIT_INDICATOR_DIGIT_FONT_WEIGHT] == "-"
387 ? ""
388 : digitIndicatorInfo[DIGIT_INDICATOR_DIGIT_FONT_WEIGHT];
389 auto selectedDigitFontSize = digitIndicatorInfo[DIGIT_INDICATOR_SELECTED_DIGIT_FONT_SIZE] == "-"
390 ? ""
391 : digitIndicatorInfo[DIGIT_INDICATOR_SELECTED_DIGIT_FONT_SIZE];
392 auto selectedDigitFontWeight = digitIndicatorInfo[DIGIT_INDICATOR_SELECTED_DIGIT_FONT_WEIGHT] == "-"
393 ? ""
394 : digitIndicatorInfo[DIGIT_INDICATOR_SELECTED_DIGIT_FONT_WEIGHT];
395 auto pipelineContext = PipelineBase::GetCurrentContextSafely();
396 CHECK_NULL_RETURN(pipelineContext, SwiperDigitalParameters());
397 auto swiperIndicatorTheme = pipelineContext->GetTheme<SwiperIndicatorTheme>();
398 CHECK_NULL_RETURN(swiperIndicatorTheme, SwiperDigitalParameters());
399 bool parseOk = false;
400 SwiperDigitalParameters digitalParameters;
401 digitalParameters.dimLeft = ParseIndicatorDimension(dotLeftValue);
402 digitalParameters.dimTop = ParseIndicatorDimension(dotTopValue);
403 digitalParameters.dimRight = ParseIndicatorDimension(dotRightValue);
404 digitalParameters.dimBottom = ParseIndicatorDimension(dotBottomValue);
405 Color fontColor;
406 parseOk = Color::ParseColorString(fontColorValue, fontColor);
407 digitalParameters.fontColor =
408 parseOk ? fontColor : swiperIndicatorTheme->GetDigitalIndicatorTextStyle().GetTextColor();
409 parseOk = Color::ParseColorString(selectedFontColorValue, fontColor);
410 digitalParameters.selectedFontColor =
411 parseOk ? fontColor : swiperIndicatorTheme->GetDigitalIndicatorTextStyle().GetTextColor();
412 GetFontContent(digitFontSize, digitFontWeight, false, digitalParameters);
413 GetFontContent(selectedDigitFontSize, selectedDigitFontWeight, true, digitalParameters);
414 return digitalParameters;
415 }
416
SetIndicatorInteractive(ArkUINodeHandle node,ArkUI_Bool value)417 void SetIndicatorInteractive(ArkUINodeHandle node, ArkUI_Bool value)
418 {
419 auto* frameNode = reinterpret_cast<FrameNode*>(node);
420 CHECK_NULL_VOID(frameNode);
421 SwiperModelNG::SetIndicatorInteractive(frameNode, static_cast<bool>(value));
422 }
423
ResetIndicatorInteractive(ArkUINodeHandle node)424 void ResetIndicatorInteractive(ArkUINodeHandle node)
425 {
426 auto* frameNode = reinterpret_cast<FrameNode*>(node);
427 CHECK_NULL_VOID(frameNode);
428 SwiperModelNG::SetIndicatorInteractive(frameNode, true);
429 }
430
GetIndicatorInteractive(ArkUINodeHandle node)431 ArkUI_Int32 GetIndicatorInteractive(ArkUINodeHandle node)
432 {
433 auto* frameNode = reinterpret_cast<FrameNode*>(node);
434 CHECK_NULL_RETURN(frameNode, ERROR_INT_CODE);
435 return static_cast<ArkUI_Int32>(SwiperModelNG::GetIndicatorInteractive(frameNode));
436 }
437
SetSwiperNextMargin(ArkUINodeHandle node,ArkUI_Float32 nextMarginValue,ArkUI_Int32 nextMarginUnit,ArkUI_Bool ignoreBlank)438 void SetSwiperNextMargin(
439 ArkUINodeHandle node, ArkUI_Float32 nextMarginValue, ArkUI_Int32 nextMarginUnit, ArkUI_Bool ignoreBlank)
440 {
441 auto* frameNode = reinterpret_cast<FrameNode*>(node);
442 CHECK_NULL_VOID(frameNode);
443 SwiperModelNG::SetNextMargin(
444 frameNode, CalcDimension(nextMarginValue, (DimensionUnit)nextMarginUnit), static_cast<bool>(ignoreBlank));
445 }
446
ResetSwiperNextMargin(ArkUINodeHandle node)447 void ResetSwiperNextMargin(ArkUINodeHandle node)
448 {
449 auto* frameNode = reinterpret_cast<FrameNode*>(node);
450 CHECK_NULL_VOID(frameNode);
451 CalcDimension value(0.0, DimensionUnit::VP);
452 SwiperModelNG::SetNextMargin(frameNode, value);
453 }
454
SetSwiperPrevMargin(ArkUINodeHandle node,ArkUI_Float32 prevMarginValue,ArkUI_Int32 prevMarginUnit,ArkUI_Bool ignoreBlank)455 void SetSwiperPrevMargin(
456 ArkUINodeHandle node, ArkUI_Float32 prevMarginValue, ArkUI_Int32 prevMarginUnit, ArkUI_Bool ignoreBlank)
457 {
458 auto* frameNode = reinterpret_cast<FrameNode*>(node);
459 CHECK_NULL_VOID(frameNode);
460 SwiperModelNG::SetPreviousMargin(
461 frameNode, CalcDimension(prevMarginValue, (DimensionUnit)prevMarginUnit), static_cast<bool>(ignoreBlank));
462 }
463
ResetSwiperPrevMargin(ArkUINodeHandle node)464 void ResetSwiperPrevMargin(ArkUINodeHandle node)
465 {
466 auto* frameNode = reinterpret_cast<FrameNode*>(node);
467 CHECK_NULL_VOID(frameNode);
468 CalcDimension value(0.0, DimensionUnit::VP);
469 SwiperModelNG::SetPreviousMargin(frameNode, value);
470 }
471
SetSwiperDisplayCount(ArkUINodeHandle node,ArkUI_CharPtr displayCountChar,ArkUI_CharPtr displayCountType)472 void SetSwiperDisplayCount(ArkUINodeHandle node, ArkUI_CharPtr displayCountChar, ArkUI_CharPtr displayCountType)
473 {
474 auto* frameNode = reinterpret_cast<FrameNode*>(node);
475 CHECK_NULL_VOID(frameNode);
476 std::string displayCountValue = std::string(displayCountChar);
477 std::string type = std::string(displayCountType);
478 if (type == "string" && displayCountValue == "auto") {
479 SwiperModelNG::SetDisplayMode(frameNode, SwiperDisplayMode::AUTO_LINEAR);
480 SwiperModelNG::ResetDisplayCount(frameNode);
481 } else if (type == "number" && StringUtils::StringToInt(displayCountValue) > 0) {
482 SwiperModelNG::SetDisplayCount(frameNode, StringUtils::StringToInt(displayCountValue));
483 } else if (type == "object") {
484 if (displayCountValue.empty()) {
485 return;
486 }
487 CalcDimension minSizeValue = StringUtils::StringToCalcDimension(displayCountValue, false, DimensionUnit::VP);
488 if (LessNotEqual(minSizeValue.Value(), 0.0)) {
489 minSizeValue.SetValue(0.0);
490 }
491 SwiperModelNG::SetMinSize(frameNode, minSizeValue);
492 } else {
493 SwiperModelNG::SetDisplayCount(frameNode, DEFAULT_DISPLAY_COUNT);
494 }
495 }
496
ResetSwiperDisplayCount(ArkUINodeHandle node)497 void ResetSwiperDisplayCount(ArkUINodeHandle node)
498 {
499 auto* frameNode = reinterpret_cast<FrameNode*>(node);
500 CHECK_NULL_VOID(frameNode);
501 SwiperModelNG::SetDisplayCount(frameNode, DEFAULT_DISPLAY_COUNT);
502 }
503
SetSwiperSwipeByGroup(ArkUINodeHandle node,ArkUI_Bool swipeByGroup)504 void SetSwiperSwipeByGroup(ArkUINodeHandle node, ArkUI_Bool swipeByGroup)
505 {
506 auto* frameNode = reinterpret_cast<FrameNode*>(node);
507 CHECK_NULL_VOID(frameNode);
508 SwiperModelNG::SetSwipeByGroup(frameNode, swipeByGroup);
509 }
510
ResetSwiperSwipeByGroup(ArkUINodeHandle node)511 void ResetSwiperSwipeByGroup(ArkUINodeHandle node)
512 {
513 auto* frameNode = reinterpret_cast<FrameNode*>(node);
514 CHECK_NULL_VOID(frameNode);
515 SwiperModelNG::SetSwipeByGroup(frameNode, DEFAULT_SWIPE_BY_GROUP);
516 }
517
SetSwiperDisplayArrow(ArkUINodeHandle node,ArkUI_CharPtr displayArrowStr)518 void SetSwiperDisplayArrow(ArkUINodeHandle node, ArkUI_CharPtr displayArrowStr)
519 {
520 auto* frameNode = reinterpret_cast<FrameNode*>(node);
521 CHECK_NULL_VOID(frameNode);
522 std::vector<std::string> res;
523 std::string displayArrowValues = std::string(displayArrowStr);
524 StringUtils::StringSplitter(displayArrowValues, '|', res);
525 int32_t displayArrowValue = StringUtils::StringToInt(res[DISPLAY_ARROW_VALUE]);
526 if (displayArrowValue == DISPLAY_ARROW_UNDEFINED) {
527 SwiperModelNG::SetDisplayArrow(frameNode, false);
528 return;
529 } else if (displayArrowValue == DISPLAY_ARROW_OBJECT) {
530 SwiperArrowParameters swiperArrowParameters;
531 if (!GetArrowInfo(res, swiperArrowParameters)) {
532 SwiperModelNG::SetDisplayArrow(frameNode, false);
533 return;
534 }
535 SwiperModelNG::SetArrowStyle(frameNode, swiperArrowParameters);
536 SwiperModelNG::SetDisplayArrow(frameNode, true);
537 } else if (displayArrowValue == DISPLAY_ARROW_TRUE) {
538 auto pipelineContext = frameNode->GetContext();
539 CHECK_NULL_VOID(pipelineContext);
540 auto swiperIndicatorTheme = pipelineContext->GetTheme<SwiperIndicatorTheme>();
541 CHECK_NULL_VOID(swiperIndicatorTheme);
542 SwiperArrowParameters swiperArrowParameters;
543 swiperArrowParameters.isShowBackground = swiperIndicatorTheme->GetIsShowArrowBackground();
544 swiperArrowParameters.isSidebarMiddle = swiperIndicatorTheme->GetIsSidebarMiddle();
545 swiperArrowParameters.backgroundSize = swiperIndicatorTheme->GetSmallArrowBackgroundSize();
546 swiperArrowParameters.backgroundColor = swiperIndicatorTheme->GetSmallArrowBackgroundColor();
547 swiperArrowParameters.arrowSize = swiperIndicatorTheme->GetSmallArrowSize();
548 swiperArrowParameters.arrowColor = swiperIndicatorTheme->GetSmallArrowColor();
549 SwiperModelNG::SetArrowStyle(frameNode, swiperArrowParameters);
550 SwiperModelNG::SetDisplayArrow(frameNode, true);
551 } else if (displayArrowValue == DISPLAY_ARROW_FALSE) {
552 SwiperModelNG::SetDisplayArrow(frameNode, false);
553 return;
554 } else {
555 SwiperModelNG::SetDisplayArrow(frameNode, false);
556 return;
557 }
558 int32_t isHoverShow = StringUtils::StringToInt(res[DISPLAY_ARROW_IS_HOVER_SHOW_INDEX]);
559 if (isHoverShow != DISPLAY_ARROW_IS_HOVER_SHOW_UNDEFINED) {
560 SwiperModelNG::SetHoverShow(frameNode, isHoverShow == 1 ? true : false);
561 } else {
562 SwiperModelNG::SetHoverShow(frameNode, false);
563 }
564 }
565
ResetSwiperDisplayArrow(ArkUINodeHandle node)566 void ResetSwiperDisplayArrow(ArkUINodeHandle node)
567 {
568 auto* frameNode = reinterpret_cast<FrameNode*>(node);
569 CHECK_NULL_VOID(frameNode);
570 SwiperModelNG::SetDisplayArrow(frameNode, false);
571 }
572
SetSwiperCurve(ArkUINodeHandle node,ArkUI_CharPtr curveChar)573 void SetSwiperCurve(ArkUINodeHandle node, ArkUI_CharPtr curveChar)
574 {
575 auto* frameNode = reinterpret_cast<FrameNode*>(node);
576 CHECK_NULL_VOID(frameNode);
577 RefPtr<Curve> curve = Curves::LINEAR;
578 curve = Framework::CreateCurve(curveChar);
579 SwiperModelNG::SetCurve(frameNode, curve);
580 }
581
ResetSwiperCurve(ArkUINodeHandle node)582 void ResetSwiperCurve(ArkUINodeHandle node)
583 {
584 auto* frameNode = reinterpret_cast<FrameNode*>(node);
585 CHECK_NULL_VOID(frameNode);
586 RefPtr<Curve> curve = Curves::LINEAR;
587 SwiperModelNG::SetCurve(frameNode, curve);
588 }
589
SetSwiperDisableSwipe(ArkUINodeHandle node,ArkUI_Bool disableSwipe)590 void SetSwiperDisableSwipe(ArkUINodeHandle node, ArkUI_Bool disableSwipe)
591 {
592 auto* frameNode = reinterpret_cast<FrameNode*>(node);
593 CHECK_NULL_VOID(frameNode);
594 SwiperModelNG::SetDisableSwipe(frameNode, disableSwipe);
595 }
596
ResetSwiperDisableSwipe(ArkUINodeHandle node)597 void ResetSwiperDisableSwipe(ArkUINodeHandle node)
598 {
599 auto* frameNode = reinterpret_cast<FrameNode*>(node);
600 CHECK_NULL_VOID(frameNode);
601 SwiperModelNG::SetDisableSwipe(frameNode, DEAFULT_DISABLE_SWIPE);
602 }
603
SetSwiperEffectMode(ArkUINodeHandle node,ArkUI_Int32 edgeEffect)604 void SetSwiperEffectMode(ArkUINodeHandle node, ArkUI_Int32 edgeEffect)
605 {
606 auto* frameNode = reinterpret_cast<FrameNode*>(node);
607 CHECK_NULL_VOID(frameNode);
608 if (edgeEffect < 0 || edgeEffect >= static_cast<int32_t>(EDGE_EFFECT.size())) {
609 return;
610 }
611 SwiperModelNG::SetEdgeEffect(frameNode, EDGE_EFFECT[edgeEffect]);
612 }
613
ResetSwiperEffectMode(ArkUINodeHandle node)614 void ResetSwiperEffectMode(ArkUINodeHandle node)
615 {
616 auto* frameNode = reinterpret_cast<FrameNode*>(node);
617 CHECK_NULL_VOID(frameNode);
618 SwiperModelNG::SetEdgeEffect(frameNode, EdgeEffect::SPRING);
619 }
620
SetSwiperCachedCount(ArkUINodeHandle node,ArkUI_Int32 cachedCount)621 void SetSwiperCachedCount(ArkUINodeHandle node, ArkUI_Int32 cachedCount)
622 {
623 auto* frameNode = reinterpret_cast<FrameNode*>(node);
624 CHECK_NULL_VOID(frameNode);
625 if (cachedCount < 0) {
626 cachedCount = DEFAULT_CACHED_COUNT;
627 }
628 SwiperModelNG::SetCachedCount(frameNode, cachedCount);
629 }
630
ResetSwiperCachedCount(ArkUINodeHandle node)631 void ResetSwiperCachedCount(ArkUINodeHandle node)
632 {
633 auto* frameNode = reinterpret_cast<FrameNode*>(node);
634 CHECK_NULL_VOID(frameNode);
635 int32_t value = DEFAULT_CACHED_COUNT;
636 SwiperModelNG::SetCachedCount(frameNode, value);
637 }
638
SetSwiperDisplayMode(ArkUINodeHandle node,ArkUI_Int32 displayMode)639 void SetSwiperDisplayMode(ArkUINodeHandle node, ArkUI_Int32 displayMode)
640 {
641 auto* frameNode = reinterpret_cast<FrameNode*>(node);
642 CHECK_NULL_VOID(frameNode);
643 if (displayMode < 0 || displayMode >= static_cast<int32_t>(DISPLAY_MODE.size())) {
644 return;
645 }
646 SwiperModelNG::SetDisplayMode(frameNode, DISPLAY_MODE[displayMode]);
647 }
648
ResetSwiperDisplayMode(ArkUINodeHandle node)649 void ResetSwiperDisplayMode(ArkUINodeHandle node)
650 {
651 auto* frameNode = reinterpret_cast<FrameNode*>(node);
652 CHECK_NULL_VOID(frameNode);
653 SwiperModelNG::SetDisplayMode(frameNode, SwiperDisplayMode::STRETCH);
654 }
655
SetSwiperItemSpace(ArkUINodeHandle node,ArkUI_Float32 itemSpaceValue,ArkUI_Int32 itemSpaceUnit)656 void SetSwiperItemSpace(ArkUINodeHandle node, ArkUI_Float32 itemSpaceValue, ArkUI_Int32 itemSpaceUnit)
657 {
658 auto* frameNode = reinterpret_cast<FrameNode*>(node);
659 CHECK_NULL_VOID(frameNode);
660 SwiperModelNG::SetItemSpace(frameNode, CalcDimension(itemSpaceValue, (DimensionUnit)itemSpaceUnit));
661 }
662
ResetSwiperItemSpace(ArkUINodeHandle node)663 void ResetSwiperItemSpace(ArkUINodeHandle node)
664 {
665 auto* frameNode = reinterpret_cast<FrameNode*>(node);
666 CHECK_NULL_VOID(frameNode);
667 CalcDimension value(0.0, DimensionUnit::VP);
668 SwiperModelNG::SetItemSpace(frameNode, value);
669 }
670
SetSwiperVertical(ArkUINodeHandle node,ArkUI_Bool isVertical)671 void SetSwiperVertical(ArkUINodeHandle node, ArkUI_Bool isVertical)
672 {
673 auto* frameNode = reinterpret_cast<FrameNode*>(node);
674 CHECK_NULL_VOID(frameNode);
675 SwiperModelNG::SetDirection(frameNode, isVertical ? Axis::VERTICAL : Axis::HORIZONTAL);
676 }
677
ResetSwiperVertical(ArkUINodeHandle node)678 void ResetSwiperVertical(ArkUINodeHandle node)
679 {
680 auto* frameNode = reinterpret_cast<FrameNode*>(node);
681 CHECK_NULL_VOID(frameNode);
682 SwiperModelNG::SetDirection(frameNode, Axis::HORIZONTAL);
683 }
684
SetSwiperLoop(ArkUINodeHandle node,ArkUI_Bool loop)685 void SetSwiperLoop(ArkUINodeHandle node, ArkUI_Bool loop)
686 {
687 auto* frameNode = reinterpret_cast<FrameNode*>(node);
688 CHECK_NULL_VOID(frameNode);
689 SwiperModelNG::SetLoop(frameNode, loop);
690 }
691
ResetSwiperLoop(ArkUINodeHandle node)692 void ResetSwiperLoop(ArkUINodeHandle node)
693 {
694 auto* frameNode = reinterpret_cast<FrameNode*>(node);
695 CHECK_NULL_VOID(frameNode);
696 SwiperModelNG::SetLoop(frameNode, DEFAULT_LOOP);
697 }
698
SetSwiperInterval(ArkUINodeHandle node,ArkUI_Int32 interval)699 void SetSwiperInterval(ArkUINodeHandle node, ArkUI_Int32 interval)
700 {
701 auto* frameNode = reinterpret_cast<FrameNode*>(node);
702 CHECK_NULL_VOID(frameNode);
703 if (interval < 0) {
704 interval = DEFAULT_INTERVAL;
705 }
706 SwiperModelNG::SetAutoPlayInterval(frameNode, interval);
707 }
708
ResetSwiperInterval(ArkUINodeHandle node)709 void ResetSwiperInterval(ArkUINodeHandle node)
710 {
711 auto* frameNode = reinterpret_cast<FrameNode*>(node);
712 CHECK_NULL_VOID(frameNode);
713 SwiperModelNG::SetAutoPlayInterval(frameNode, DEFAULT_INTERVAL);
714 }
715
SetSwiperAutoPlay(ArkUINodeHandle node,ArkUI_Bool autoPlay)716 void SetSwiperAutoPlay(ArkUINodeHandle node, ArkUI_Bool autoPlay)
717 {
718 auto* frameNode = reinterpret_cast<FrameNode*>(node);
719 CHECK_NULL_VOID(frameNode);
720 SwiperModelNG::SetAutoPlay(frameNode, autoPlay);
721 }
722
ResetSwiperAutoPlay(ArkUINodeHandle node)723 void ResetSwiperAutoPlay(ArkUINodeHandle node)
724 {
725 auto* frameNode = reinterpret_cast<FrameNode*>(node);
726 CHECK_NULL_VOID(frameNode);
727 SwiperModelNG::SetAutoPlay(frameNode, DEFAULT_AUTO_PLAY);
728 }
729
SetSwiperIndex(ArkUINodeHandle node,ArkUI_Int32 index)730 void SetSwiperIndex(ArkUINodeHandle node, ArkUI_Int32 index)
731 {
732 auto* frameNode = reinterpret_cast<FrameNode*>(node);
733 CHECK_NULL_VOID(frameNode);
734 index = index < 0 ? 0 : index;
735 SwiperModelNG::SetIndex(frameNode, index);
736 }
737
ResetSwiperIndex(ArkUINodeHandle node)738 void ResetSwiperIndex(ArkUINodeHandle node)
739 {
740 auto* frameNode = reinterpret_cast<FrameNode*>(node);
741 CHECK_NULL_VOID(frameNode);
742 uint32_t value = 0;
743 SwiperModelNG::SetIndex(frameNode, value);
744 }
745
SetSwiperIndicator(ArkUINodeHandle node,ArkUI_CharPtr indicatorStr)746 void SetSwiperIndicator(ArkUINodeHandle node, ArkUI_CharPtr indicatorStr)
747 {
748 auto* frameNode = reinterpret_cast<FrameNode*>(node);
749 CHECK_NULL_VOID(frameNode);
750 std::vector<std::string> res;
751 std::string indicatorValues = std::string(indicatorStr);
752 StringUtils::StringSplitter(indicatorValues, '|', res);
753 std::string type = res[INDICATOR_TYPE_INDEX];
754 if (type == "ArkDigitIndicator") {
755 SwiperModelNG::SetIndicatorIsBoolean(frameNode, false);
756 SwiperDigitalParameters digitalParameters = GetDigitIndicatorInfo(res);
757 SwiperModelNG::SetDigitIndicatorStyle(frameNode, digitalParameters);
758 SwiperModelNG::SetIndicatorType(frameNode, SwiperIndicatorType::DIGIT);
759 } else if (type == "ArkDotIndicator") {
760 SwiperModelNG::SetIndicatorIsBoolean(frameNode, false);
761 SwiperParameters swiperParameters = GetDotIndicatorInfo(frameNode, res);
762 SwiperModelNG::SetDotIndicatorStyle(frameNode, swiperParameters);
763 SwiperModelNG::SetIndicatorType(frameNode, SwiperIndicatorType::DOT);
764 } else {
765 SwiperParameters swiperParameters = GetDotIndicatorInfo(frameNode, res);
766 SwiperModelNG::SetDotIndicatorStyle(frameNode, swiperParameters);
767 SwiperModelNG::SetIndicatorType(frameNode, SwiperIndicatorType::DOT);
768 }
769 if (type == "boolean") {
770 int32_t indicator = StringUtils::StringToInt(res[INDICATOR_VALUE]);
771 bool showIndicator = indicator == 1 ? true : false;
772 SwiperModelNG::SetShowIndicator(frameNode, showIndicator);
773 } else {
774 SwiperModelNG::SetShowIndicator(frameNode, true);
775 }
776 }
777
ResetSwiperIndicator(ArkUINodeHandle node)778 void ResetSwiperIndicator(ArkUINodeHandle node)
779 {
780 auto* frameNode = reinterpret_cast<FrameNode*>(node);
781 CHECK_NULL_VOID(frameNode);
782 SwiperModelNG::SetShowIndicator(frameNode, true);
783 }
784
SetSwiperDuration(ArkUINodeHandle node,ArkUI_Float32 duration)785 void SetSwiperDuration(ArkUINodeHandle node, ArkUI_Float32 duration)
786 {
787 auto* frameNode = reinterpret_cast<FrameNode*>(node);
788 CHECK_NULL_VOID(frameNode);
789 if (duration < 0) {
790 duration = DEFAULT_DURATION;
791 }
792 SwiperModelNG::SetDuration(frameNode, duration);
793 }
794
ResetSwiperDuration(ArkUINodeHandle node)795 void ResetSwiperDuration(ArkUINodeHandle node)
796 {
797 auto* frameNode = reinterpret_cast<FrameNode*>(node);
798 CHECK_NULL_VOID(frameNode);
799 uint32_t value = DEFAULT_DURATION;
800 SwiperModelNG::SetDuration(frameNode, value);
801 }
802
SetSwiperEnabled(ArkUINodeHandle node,ArkUI_Bool enabled)803 void SetSwiperEnabled(ArkUINodeHandle node, ArkUI_Bool enabled)
804 {
805 auto* frameNode = reinterpret_cast<FrameNode*>(node);
806 CHECK_NULL_VOID(frameNode);
807 SwiperModelNG::SetEnabled(frameNode, enabled);
808 }
809
ResetSwiperEnabled(ArkUINodeHandle node)810 void ResetSwiperEnabled(ArkUINodeHandle node)
811 {
812 auto* frameNode = reinterpret_cast<FrameNode*>(node);
813 CHECK_NULL_VOID(frameNode);
814 SwiperModelNG::SetEnabled(frameNode, false);
815 }
816
GetSwiperLoop(ArkUINodeHandle node)817 ArkUI_Int32 GetSwiperLoop(ArkUINodeHandle node)
818 {
819 auto* frameNode = reinterpret_cast<FrameNode*>(node);
820 CHECK_NULL_RETURN(frameNode, ERROR_INT_CODE);
821 return static_cast<ArkUI_Int32>(SwiperModelNG::GetLoop(frameNode));
822 }
823
GetSwiperAutoPlay(ArkUINodeHandle node)824 ArkUI_Int32 GetSwiperAutoPlay(ArkUINodeHandle node)
825 {
826 auto* frameNode = reinterpret_cast<FrameNode*>(node);
827 CHECK_NULL_RETURN(frameNode, ERROR_INT_CODE);
828 return static_cast<ArkUI_Int32>(SwiperModelNG::GetAutoPlay(frameNode));
829 }
830
GetSwiperIndex(ArkUINodeHandle node)831 ArkUI_Int32 GetSwiperIndex(ArkUINodeHandle node)
832 {
833 auto* frameNode = reinterpret_cast<FrameNode*>(node);
834 CHECK_NULL_RETURN(frameNode, ERROR_INT_CODE);
835 return static_cast<ArkUI_Int32>(SwiperModelNG::GetIndex(frameNode));
836 }
837
GetSwiperVertical(ArkUINodeHandle node)838 ArkUI_Int32 GetSwiperVertical(ArkUINodeHandle node)
839 {
840 auto* frameNode = reinterpret_cast<FrameNode*>(node);
841 CHECK_NULL_RETURN(frameNode, ERROR_INT_CODE);
842 return static_cast<ArkUI_Int32>(SwiperModelNG::GetDirection(frameNode) == Axis::VERTICAL ? true : false);
843 }
844
GetSwiperDuration(ArkUINodeHandle node)845 ArkUI_Float32 GetSwiperDuration(ArkUINodeHandle node)
846 {
847 auto* frameNode = reinterpret_cast<FrameNode*>(node);
848 CHECK_NULL_RETURN(frameNode, ERROR_INT_CODE);
849 return static_cast<ArkUI_Float32>(SwiperModelNG::GetDuration(frameNode));
850 }
851
GetSwiperDisplayCount(ArkUINodeHandle node)852 ArkUI_Int32 GetSwiperDisplayCount(ArkUINodeHandle node)
853 {
854 auto* frameNode = reinterpret_cast<FrameNode*>(node);
855 CHECK_NULL_RETURN(frameNode, ERROR_INT_CODE);
856 return SwiperModelNG::GetDisplayCount(frameNode);
857 }
858
GetSwiperInterval(ArkUINodeHandle node)859 ArkUI_Float32 GetSwiperInterval(ArkUINodeHandle node)
860 {
861 auto* frameNode = reinterpret_cast<FrameNode*>(node);
862 CHECK_NULL_RETURN(frameNode, ERROR_INT_CODE);
863 return static_cast<ArkUI_Float32>(SwiperModelNG::GetAutoPlayInterval(frameNode));
864 }
865
findCurveIndex(const RefPtr<Curve> curve)866 int32_t findCurveIndex(const RefPtr<Curve> curve)
867 {
868 CHECK_NULL_RETURN(curve, 0);
869 auto iterator = std::find(CURVES.begin(), CURVES.end(), curve);
870 if (iterator == CURVES.end()) {
871 return 0;
872 }
873 return iterator - CURVES.begin();
874 }
875
GetSwiperCurve(ArkUINodeHandle node)876 ArkUI_Int32 GetSwiperCurve(ArkUINodeHandle node)
877 {
878 auto* frameNode = reinterpret_cast<FrameNode*>(node);
879 CHECK_NULL_RETURN(frameNode, ERROR_INT_CODE);
880 return findCurveIndex(SwiperModelNG::GetCurve(frameNode));
881 }
882
GetSwiperDisableSwipe(ArkUINodeHandle node)883 ArkUI_Int32 GetSwiperDisableSwipe(ArkUINodeHandle node)
884 {
885 auto* frameNode = reinterpret_cast<FrameNode*>(node);
886 CHECK_NULL_RETURN(frameNode, ERROR_INT_CODE);
887 return static_cast<ArkUI_Int32>(SwiperModelNG::GetDisableSwipe(frameNode));
888 }
889
GetSwiperItemSpace(ArkUINodeHandle node)890 ArkUI_Float32 GetSwiperItemSpace(ArkUINodeHandle node)
891 {
892 auto* frameNode = reinterpret_cast<FrameNode*>(node);
893 CHECK_NULL_RETURN(frameNode, ERROR_INT_CODE);
894 return SwiperModelNG::GetItemSpace(frameNode);
895 }
896
GetSwiperShowIndicator(ArkUINodeHandle node)897 ArkUI_Int32 GetSwiperShowIndicator(ArkUINodeHandle node)
898 {
899 auto* frameNode = reinterpret_cast<FrameNode*>(node);
900 CHECK_NULL_RETURN(frameNode, ERROR_INT_CODE);
901 return static_cast<ArkUI_Int32>(SwiperModelNG::GetShowIndicator(frameNode));
902 }
903
GetSwiperShowDisplayArrow(ArkUINodeHandle node)904 ArkUI_Int32 GetSwiperShowDisplayArrow(ArkUINodeHandle node)
905 {
906 auto* frameNode = reinterpret_cast<FrameNode*>(node);
907 CHECK_NULL_RETURN(frameNode, ERROR_INT_CODE);
908 return static_cast<ArkUI_Int32>(SwiperModelNG::GetShowDisplayArrow(frameNode));
909 }
910
GetSwiperEffectMode(ArkUINodeHandle node)911 ArkUI_Int32 GetSwiperEffectMode(ArkUINodeHandle node)
912 {
913 auto* frameNode = reinterpret_cast<FrameNode*>(node);
914 CHECK_NULL_RETURN(frameNode, ERROR_INT_CODE);
915 return static_cast<ArkUI_Int32>(SwiperModelNG::GetEffectMode(frameNode));
916 }
917
SetNodeAdapter(ArkUINodeHandle node,ArkUINodeAdapterHandle handle)918 ArkUI_Int32 SetNodeAdapter(ArkUINodeHandle node, ArkUINodeAdapterHandle handle)
919 {
920 auto* frameNode = reinterpret_cast<FrameNode*>(node);
921 CHECK_NULL_RETURN(frameNode, ERROR_CODE_PARAM_INVALID);
922 auto totalChildCount = SwiperModelNG::RealTotalCount(frameNode);
923 if (totalChildCount > 0) {
924 return ERROR_CODE_NATIVE_IMPL_NODE_ADAPTER_CHILD_NODE_EXIST;
925 }
926 NodeAdapter::GetNodeAdapterAPI()->attachHostNode(handle, node);
927 return ERROR_CODE_NO_ERROR;
928 }
929
ResetNodeAdapter(ArkUINodeHandle node)930 void ResetNodeAdapter(ArkUINodeHandle node)
931 {
932 NodeAdapter::GetNodeAdapterAPI()->detachHostNode(node);
933 }
934
GetNodeAdapter(ArkUINodeHandle node)935 ArkUINodeAdapterHandle GetNodeAdapter(ArkUINodeHandle node)
936 {
937 return NodeAdapter::GetNodeAdapterAPI()->getNodeAdapter(node);
938 }
939
GetCachedCount(ArkUINodeHandle node)940 ArkUI_Int32 GetCachedCount(ArkUINodeHandle node)
941 {
942 auto* frameNode = reinterpret_cast<FrameNode*>(node);
943 CHECK_NULL_RETURN(frameNode, 1);
944 return SwiperModelNG::GetCachedCount(frameNode);
945 }
946
SetSwiperNestedScroll(ArkUINodeHandle node,ArkUI_Int32 (* values)[1])947 void SetSwiperNestedScroll(ArkUINodeHandle node, ArkUI_Int32 (*values)[1])
948 {
949 auto* frameNode = reinterpret_cast<FrameNode*>(node);
950 CHECK_NULL_VOID(frameNode);
951 SwiperModelNG::SetNestedScroll(frameNode, (*values)[0]);
952 }
953
ResetSwiperNestedScroll(ArkUINodeHandle node)954 void ResetSwiperNestedScroll(ArkUINodeHandle node)
955 {
956 auto* frameNode = reinterpret_cast<FrameNode*>(node);
957 CHECK_NULL_VOID(frameNode);
958 SwiperModelNG::SetNestedScroll(frameNode, 0);
959 }
960
GetSwiperNestedScroll(ArkUINodeHandle node)961 ArkUI_Int32 GetSwiperNestedScroll(ArkUINodeHandle node)
962 {
963 auto* frameNode = reinterpret_cast<FrameNode*>(node);
964 CHECK_NULL_RETURN(frameNode, ERROR_CODE_PARAM_INVALID);
965 return SwiperModelNG::GetNestedScroll(frameNode);
966 }
967
SetSwiperToIndex(ArkUINodeHandle node,ArkUI_Int32 (* values)[2])968 void SetSwiperToIndex(ArkUINodeHandle node, ArkUI_Int32 (*values)[2])
969 {
970 auto* frameNode = reinterpret_cast<FrameNode*>(node);
971 CHECK_NULL_VOID(frameNode);
972 SwiperModelNG::SetSwiperToIndex(frameNode, (*values)[0], (*values)[1]);
973 }
974
GetSwiperPrevMargin(ArkUINodeHandle node,ArkUI_Int32 unit,ArkUISwiperMarginOptions * options)975 void GetSwiperPrevMargin(ArkUINodeHandle node, ArkUI_Int32 unit, ArkUISwiperMarginOptions* options)
976 {
977 auto* frameNode = reinterpret_cast<FrameNode*>(node);
978 CHECK_NULL_VOID(frameNode);
979 CHECK_NULL_VOID(options);
980 SwiperMarginOptions marginOptions;
981 SwiperModelNG::GetPreviousMargin(frameNode, unit, &marginOptions);
982 options->margin = static_cast<ArkUI_Float32>(marginOptions.margin);
983 options->ignoreBlank = static_cast<ArkUI_Bool>(marginOptions.ignoreBlank);
984 }
985
GetSwiperNextMargin(ArkUINodeHandle node,ArkUI_Int32 unit,ArkUISwiperMarginOptions * options)986 void GetSwiperNextMargin(ArkUINodeHandle node, ArkUI_Int32 unit, ArkUISwiperMarginOptions* options)
987 {
988 auto* frameNode = reinterpret_cast<FrameNode*>(node);
989 CHECK_NULL_VOID(frameNode);
990 CHECK_NULL_VOID(options);
991 SwiperMarginOptions marginOptions;
992 SwiperModelNG::GetNextMargin(frameNode, unit, &marginOptions);
993 options->margin = static_cast<ArkUI_Float32>(marginOptions.margin);
994 options->ignoreBlank = static_cast<ArkUI_Bool>(marginOptions.ignoreBlank);
995 }
996
SetSwiperIndicatorStyle(ArkUINodeHandle node,ArkUISwiperIndicator * indicator)997 void SetSwiperIndicatorStyle(ArkUINodeHandle node, ArkUISwiperIndicator* indicator)
998 {
999 CHECK_NULL_VOID(indicator);
1000 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1001 CHECK_NULL_VOID(frameNode);
1002 if (indicator->type == ArkUISwiperIndicatorType::DOT) {
1003 SwiperModelNG::SetIndicatorIsBoolean(frameNode, false);
1004 SwiperParameters swiperParameters = GetDotIndicatorProps(frameNode, indicator);
1005 SwiperModelNG::SetDotIndicatorStyle(frameNode, swiperParameters);
1006 SwiperModelNG::SetIndicatorType(frameNode, SwiperIndicatorType::DOT);
1007 }
1008 SwiperModelNG::SetShowIndicator(frameNode, true);
1009 }
1010
GetSwiperIndicator(ArkUINodeHandle node,ArkUISwiperIndicator * props)1011 void GetSwiperIndicator(ArkUINodeHandle node, ArkUISwiperIndicator* props)
1012 {
1013 CHECK_NULL_VOID(props);
1014 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1015 CHECK_NULL_VOID(frameNode);
1016 int32_t type = SwiperModelNG::GetIndicatorType(frameNode);
1017 props->type = static_cast<ArkUISwiperIndicatorType>(type);
1018 auto params = SwiperModelNG::GetDotIndicator(frameNode);
1019 CHECK_NULL_VOID(params);
1020 bool hasValue = false;
1021 float value = ZERO_F;
1022 ParseIndicatorAttribute(params->dimLeft, hasValue, value);
1023 props->dimLeft = ArkUIOptionalFloat { hasValue, value };
1024 ParseIndicatorAttribute(params->dimTop, hasValue, value);
1025 props->dimTop = ArkUIOptionalFloat { hasValue, value };
1026 ParseIndicatorAttribute(params->dimRight, hasValue, value);
1027 props->dimRight = ArkUIOptionalFloat { hasValue, value };
1028 ParseIndicatorAttribute(params->dimBottom, hasValue, value);
1029 props->dimBottom = ArkUIOptionalFloat { hasValue, value };
1030 if (props->type == ArkUISwiperIndicatorType::DOT) {
1031 props->type = ArkUISwiperIndicatorType::DOT;
1032 ParseIndicatorAttribute(params->itemWidth, hasValue, value);
1033 props->itemWidth = ArkUIOptionalFloat { hasValue, value };
1034 ParseIndicatorAttribute(params->itemHeight, hasValue, value);
1035 props->itemHeight = ArkUIOptionalFloat { hasValue, value };
1036 ParseIndicatorAttribute(params->selectedItemWidth, hasValue, value);
1037 props->selectedItemWidth = ArkUIOptionalFloat { hasValue, value };
1038 ParseIndicatorAttribute(params->selectedItemHeight, hasValue, value);
1039 props->selectedItemHeight = ArkUIOptionalFloat { hasValue, value };
1040 props->maskValue = ArkUIOptionalInt { 1, params->maskValue.value_or(0) };
1041 props->colorValue = ArkUIOptionalUint { 1, params->colorVal.value().GetValue() };
1042 props->selectedColorValue = ArkUIOptionalUint { 1, params->selectedColorVal.value().GetValue() };
1043 props->maxDisplayCount = ArkUIOptionalInt { 1, params->maxDisplayCountVal.value() };
1044 }
1045 }
1046
GetSwiperController(ArkUINodeHandle node)1047 ArkUINodeHandle GetSwiperController(ArkUINodeHandle node)
1048 {
1049 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1050 CHECK_NULL_RETURN(frameNode, nullptr);
1051 auto controller = SwiperModelNG::GetSwiperController(frameNode);
1052 CHECK_NULL_RETURN(controller, nullptr);
1053 auto nodecontroller = reinterpret_cast<ArkUINodeHandle>(OHOS::Ace::AceType::RawPtr(controller));
1054 return nodecontroller;
1055 }
1056
SetSwiperOnChange(ArkUINodeHandle node,void * callback)1057 void SetSwiperOnChange(ArkUINodeHandle node, void* callback)
1058 {
1059 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1060 CHECK_NULL_VOID(frameNode);
1061 if (callback) {
1062 auto onEvent = reinterpret_cast<std::function<void(const BaseEventInfo*)>*>(callback);
1063 SwiperModelNG::SetOnChange(frameNode, std::move(*onEvent));
1064 } else {
1065 SwiperModelNG::SetOnChange(frameNode, nullptr);
1066 }
1067 }
1068
ResetSwiperOnChange(ArkUINodeHandle node)1069 void ResetSwiperOnChange(ArkUINodeHandle node)
1070 {
1071 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1072 CHECK_NULL_VOID(frameNode);
1073 SwiperModelNG::SetOnChange(frameNode, nullptr);
1074 }
1075
SetSwiperOnAnimationStart(ArkUINodeHandle node,void * callback)1076 void SetSwiperOnAnimationStart(ArkUINodeHandle node, void* callback)
1077 {
1078 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1079 CHECK_NULL_VOID(frameNode);
1080 if (callback) {
1081 auto onEvent = reinterpret_cast<std::function<void(int32_t, int32_t, const AnimationCallbackInfo&)>*>(callback);
1082 SwiperModelNG::SetOnAnimationStart(frameNode, std::move(*onEvent));
1083 } else {
1084 SwiperModelNG::SetOnAnimationStart(frameNode, nullptr);
1085 }
1086 }
1087
ResetSwiperOnAnimationStart(ArkUINodeHandle node)1088 void ResetSwiperOnAnimationStart(ArkUINodeHandle node)
1089 {
1090 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1091 CHECK_NULL_VOID(frameNode);
1092 SwiperModelNG::SetOnAnimationStart(frameNode, nullptr);
1093 }
1094
SetSwiperOnAnimationEnd(ArkUINodeHandle node,void * callback)1095 void SetSwiperOnAnimationEnd(ArkUINodeHandle node, void* callback)
1096 {
1097 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1098 CHECK_NULL_VOID(frameNode);
1099 if (callback) {
1100 auto onEvent = reinterpret_cast<std::function<void(int32_t, const AnimationCallbackInfo&)>*>(callback);
1101 SwiperModelNG::SetOnAnimationEnd(frameNode, std::move(*onEvent));
1102 } else {
1103 SwiperModelNG::SetOnAnimationEnd(frameNode, nullptr);
1104 }
1105 }
1106
ResetSwiperOnAnimationEnd(ArkUINodeHandle node)1107 void ResetSwiperOnAnimationEnd(ArkUINodeHandle node)
1108 {
1109 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1110 CHECK_NULL_VOID(frameNode);
1111 SwiperModelNG::SetOnAnimationEnd(frameNode, nullptr);
1112 }
1113
SetSwiperOnGestureSwipe(ArkUINodeHandle node,void * callback)1114 void SetSwiperOnGestureSwipe(ArkUINodeHandle node, void* callback)
1115 {
1116 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1117 CHECK_NULL_VOID(frameNode);
1118 if (callback) {
1119 auto onEvent = reinterpret_cast<std::function<void(int32_t, const AnimationCallbackInfo&)>*>(callback);
1120 SwiperModelNG::SetOnGestureSwipe(frameNode, std::move(*onEvent));
1121 } else {
1122 SwiperModelNG::SetOnGestureSwipe(frameNode, nullptr);
1123 }
1124 }
1125
ResetSwiperOnGestureSwipe(ArkUINodeHandle node)1126 void ResetSwiperOnGestureSwipe(ArkUINodeHandle node)
1127 {
1128 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1129 CHECK_NULL_VOID(frameNode);
1130 SwiperModelNG::SetOnGestureSwipe(frameNode, nullptr);
1131 }
1132
SetOnContentDidScroll(ArkUINodeHandle node,void * callback)1133 void SetOnContentDidScroll(ArkUINodeHandle node, void* callback)
1134 {
1135 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1136 CHECK_NULL_VOID(frameNode);
1137 if (callback) {
1138 auto onEvent = reinterpret_cast<std::function<void(int32_t, int32_t, float, float)>*>(callback);
1139 SwiperModelNG::SetOnContentDidScroll(frameNode, std::move(*onEvent));
1140 } else {
1141 SwiperModelNG::SetOnContentDidScroll(frameNode, nullptr);
1142 }
1143 }
1144
ResetOnContentDidScroll(ArkUINodeHandle node)1145 void ResetOnContentDidScroll(ArkUINodeHandle node)
1146 {
1147 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1148 CHECK_NULL_VOID(frameNode);
1149 SwiperModelNG::SetOnContentDidScroll(frameNode, nullptr);
1150 }
1151 } // namespace
1152
1153 namespace NodeModifier {
GetSwiperModifier()1154 const ArkUISwiperModifier* GetSwiperModifier()
1155 {
1156 static const ArkUISwiperModifier modifier = { SetSwiperNextMargin, ResetSwiperNextMargin, SetSwiperPrevMargin,
1157 ResetSwiperPrevMargin, SetSwiperDisplayCount, ResetSwiperDisplayCount, SetSwiperSwipeByGroup,
1158 ResetSwiperSwipeByGroup, SetSwiperDisplayArrow, ResetSwiperDisplayArrow, SetSwiperCurve, ResetSwiperCurve,
1159 SetSwiperDisableSwipe, ResetSwiperDisableSwipe, SetSwiperEffectMode, ResetSwiperEffectMode,
1160 SetSwiperCachedCount, ResetSwiperCachedCount, SetSwiperDisplayMode, ResetSwiperDisplayMode, SetSwiperItemSpace,
1161 ResetSwiperItemSpace, SetSwiperVertical, ResetSwiperVertical, SetSwiperLoop, ResetSwiperLoop, SetSwiperInterval,
1162 ResetSwiperInterval, SetSwiperAutoPlay, ResetSwiperAutoPlay, SetSwiperIndex, ResetSwiperIndex,
1163 SetSwiperIndicator, ResetSwiperIndicator, SetSwiperDuration, ResetSwiperDuration, SetSwiperEnabled,
1164 ResetSwiperEnabled, GetSwiperLoop, GetSwiperAutoPlay, GetSwiperIndex, GetSwiperVertical, GetSwiperDuration,
1165 GetSwiperDisplayCount, GetSwiperInterval, GetSwiperCurve, GetSwiperDisableSwipe, GetSwiperItemSpace,
1166 GetSwiperShowIndicator, GetSwiperShowDisplayArrow, GetSwiperEffectMode, SetIndicatorInteractive,
1167 ResetIndicatorInteractive, SetNodeAdapter, ResetNodeAdapter, GetNodeAdapter, GetCachedCount,
1168 SetSwiperNestedScroll, ResetSwiperNestedScroll, GetSwiperNestedScroll, SetSwiperToIndex, GetSwiperPrevMargin,
1169 GetSwiperNextMargin, SetSwiperIndicatorStyle, GetSwiperIndicator, GetSwiperController,
1170 SetSwiperOnChange, ResetSwiperOnChange, SetSwiperOnAnimationStart, ResetSwiperOnAnimationStart,
1171 SetSwiperOnAnimationEnd, ResetSwiperOnAnimationEnd, SetSwiperOnGestureSwipe, ResetSwiperOnGestureSwipe,
1172 SetOnContentDidScroll, ResetOnContentDidScroll,
1173 GetIndicatorInteractive };
1174 return &modifier;
1175 }
1176
GetCJUISwiperModifier()1177 const CJUISwiperModifier* GetCJUISwiperModifier()
1178 {
1179 static const CJUISwiperModifier modifier = { SetSwiperNextMargin, ResetSwiperNextMargin, SetSwiperPrevMargin,
1180 ResetSwiperPrevMargin, SetSwiperDisplayCount, ResetSwiperDisplayCount, SetSwiperSwipeByGroup,
1181 ResetSwiperSwipeByGroup, SetSwiperDisplayArrow, ResetSwiperDisplayArrow, SetSwiperCurve, ResetSwiperCurve,
1182 SetSwiperDisableSwipe, ResetSwiperDisableSwipe, SetSwiperEffectMode, ResetSwiperEffectMode,
1183 SetSwiperCachedCount, ResetSwiperCachedCount, SetSwiperDisplayMode, ResetSwiperDisplayMode, SetSwiperItemSpace,
1184 ResetSwiperItemSpace, SetSwiperVertical, ResetSwiperVertical, SetSwiperLoop, ResetSwiperLoop, SetSwiperInterval,
1185 ResetSwiperInterval, SetSwiperAutoPlay, ResetSwiperAutoPlay, SetSwiperIndex, ResetSwiperIndex,
1186 SetSwiperIndicator, ResetSwiperIndicator, SetSwiperDuration, ResetSwiperDuration, SetSwiperEnabled,
1187 ResetSwiperEnabled, GetSwiperLoop, GetSwiperAutoPlay, GetSwiperIndex, GetSwiperVertical, GetSwiperDuration,
1188 GetSwiperDisplayCount, GetSwiperInterval, GetSwiperCurve, GetSwiperDisableSwipe, GetSwiperItemSpace,
1189 GetSwiperShowIndicator, GetSwiperShowDisplayArrow, GetSwiperEffectMode, SetIndicatorInteractive,
1190 ResetIndicatorInteractive, SetNodeAdapter, ResetNodeAdapter, GetNodeAdapter, GetCachedCount,
1191 SetSwiperNestedScroll, ResetSwiperNestedScroll, GetSwiperNestedScroll, SetSwiperToIndex, GetSwiperPrevMargin,
1192 GetSwiperNextMargin, SetSwiperIndicatorStyle, GetSwiperIndicator, GetSwiperController,
1193 SetSwiperOnChange, ResetSwiperOnChange, SetSwiperOnAnimationStart, ResetSwiperOnAnimationStart,
1194 SetSwiperOnAnimationEnd, ResetSwiperOnAnimationEnd, SetSwiperOnGestureSwipe, ResetSwiperOnGestureSwipe };
1195 return &modifier;
1196 }
1197
SetSwiperChange(ArkUINodeHandle node,void * extraParam)1198 void SetSwiperChange(ArkUINodeHandle node, void* extraParam)
1199 {
1200 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1201 CHECK_NULL_VOID(frameNode);
1202 auto onEvent = [node, extraParam](const BaseEventInfo* info) {
1203 const auto* swiperInfo = TypeInfoHelper::DynamicCast<SwiperChangeEvent>(info);
1204 if (!swiperInfo) {
1205 LOGE("Swiper onChange callback execute failed.");
1206 return;
1207 }
1208 int32_t index = swiperInfo->GetIndex();
1209 ArkUINodeEvent event;
1210 event.kind = COMPONENT_ASYNC_EVENT;
1211 event.extraParam = reinterpret_cast<intptr_t>(extraParam);
1212 event.componentAsyncEvent.subKind = ON_SWIPER_CHANGE;
1213 event.componentAsyncEvent.data[NUM_0].i32 = index;
1214 SendArkUIAsyncEvent(&event);
1215 };
1216 SwiperModelNG::SetOnChange(frameNode, std::move(onEvent));
1217 }
1218
SetSwiperAnimationStart(ArkUINodeHandle node,void * extraParam)1219 void SetSwiperAnimationStart(ArkUINodeHandle node, void* extraParam)
1220 {
1221 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1222 CHECK_NULL_VOID(frameNode);
1223 auto onEvent = [node, extraParam](int32_t index, int32_t targetIndex, const AnimationCallbackInfo& info) {
1224 ArkUINodeEvent event;
1225 event.kind = COMPONENT_ASYNC_EVENT;
1226 event.extraParam = reinterpret_cast<intptr_t>(extraParam);
1227 event.componentAsyncEvent.subKind = ON_SWIPER_ANIMATION_START;
1228 event.componentAsyncEvent.data[NUM_0].i32 = index;
1229 event.componentAsyncEvent.data[NUM_1].i32 = targetIndex;
1230 event.componentAsyncEvent.data[NUM_2].f32 = info.currentOffset.value_or(ANIMATION_INFO_DEFAULT);
1231 event.componentAsyncEvent.data[NUM_3].f32 = info.targetOffset.value_or(ANIMATION_INFO_DEFAULT);
1232 event.componentAsyncEvent.data[NUM_4].f32 = info.velocity.value_or(ANIMATION_INFO_DEFAULT);
1233 SendArkUIAsyncEvent(&event);
1234 };
1235 SwiperModelNG::SetOnAnimationStart(frameNode, std::move(onEvent));
1236 }
1237
SetSwiperAnimationEnd(ArkUINodeHandle node,void * extraParam)1238 void SetSwiperAnimationEnd(ArkUINodeHandle node, void* extraParam)
1239 {
1240 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1241 CHECK_NULL_VOID(frameNode);
1242 auto onEvent = [node, extraParam](int32_t index, const AnimationCallbackInfo& info) {
1243 ArkUINodeEvent event;
1244 event.kind = COMPONENT_ASYNC_EVENT;
1245 event.extraParam = reinterpret_cast<intptr_t>(extraParam);
1246 event.componentAsyncEvent.subKind = ON_SWIPER_ANIMATION_END;
1247 event.componentAsyncEvent.data[NUM_0].i32 = index;
1248 event.componentAsyncEvent.data[NUM_1].f32 = info.currentOffset.value_or(ANIMATION_INFO_DEFAULT);
1249 SendArkUIAsyncEvent(&event);
1250 };
1251 SwiperModelNG::SetOnAnimationEnd(frameNode, std::move(onEvent));
1252 }
1253
SetSwiperGestureSwipe(ArkUINodeHandle node,void * extraParam)1254 void SetSwiperGestureSwipe(ArkUINodeHandle node, void* extraParam)
1255 {
1256 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1257 CHECK_NULL_VOID(frameNode);
1258 auto onEvent = [node, extraParam](int32_t index, const AnimationCallbackInfo& info) {
1259 ArkUINodeEvent event;
1260 event.kind = COMPONENT_ASYNC_EVENT;
1261 event.extraParam = reinterpret_cast<intptr_t>(extraParam);
1262 event.componentAsyncEvent.subKind = ON_SWIPER_GESTURE_SWIPE;
1263 event.componentAsyncEvent.data[NUM_0].i32 = index;
1264 event.componentAsyncEvent.data[NUM_1].f32 = info.currentOffset.value_or(ANIMATION_INFO_DEFAULT);
1265 SendArkUIAsyncEvent(&event);
1266 };
1267 SwiperModelNG::SetOnGestureSwipe(frameNode, std::move(onEvent));
1268 }
1269
SetSwiperOnContentDidScroll(ArkUINodeHandle node,void * extraParam)1270 void SetSwiperOnContentDidScroll(ArkUINodeHandle node, void* extraParam)
1271 {
1272 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1273 CHECK_NULL_VOID(frameNode);
1274 auto onEvent = [node, extraParam](int32_t selectedIndex, int32_t index, float position, float mainAxisLength) {
1275 ArkUINodeEvent event;
1276 event.kind = COMPONENT_ASYNC_EVENT;
1277 event.extraParam = reinterpret_cast<intptr_t>(extraParam);
1278 bool usePx = NodeModel::UsePXUnit(reinterpret_cast<ArkUI_Node*>(extraParam));
1279 double density = usePx ? 1 : PipelineBase::GetCurrentDensity();
1280 event.componentAsyncEvent.subKind = ON_SWIPER_DID_CONTENT_SCROLL;
1281 event.componentAsyncEvent.data[NUM_0].i32 = selectedIndex;
1282 event.componentAsyncEvent.data[NUM_1].i32 = index;
1283 event.componentAsyncEvent.data[NUM_2].f32 = position;
1284 event.componentAsyncEvent.data[NUM_3].f32 = mainAxisLength / density;
1285 SendArkUIAsyncEvent(&event);
1286 };
1287 SwiperModelNG::SetOnContentDidScroll(frameNode, std::move(onEvent));
1288 }
1289 } // namespace NodeModifier
1290 } // namespace OHOS::Ace::NG