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