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 "node_model.h"
18
19 #include "bridge/common/utils/utils.h"
20 #include "core/components/swiper/swiper_component.h"
21 #include "core/components_ng/pattern/swiper/swiper_model_ng.h"
22 #include "core/interfaces/native/node/node_adapter_impl.h"
23
24 namespace OHOS::Ace::NG {
25 namespace {
26 constexpr int32_t DEFAULT_INTERVAL = 3000;
27 constexpr int32_t DEFAULT_DURATION = 400;
28 constexpr int32_t DEFAULT_CACHED_COUNT = 1;
29 constexpr int32_t DEFAULT_DISPLAY_COUNT = 1;
30 constexpr bool DEFAULT_SWIPE_BY_GROUP = false;
31 constexpr bool DEFAULT_CACHED_IS_SHOWN = false;
32 constexpr bool DEFAULT_AUTO_PLAY = false;
33 constexpr bool DEFAULT_LOOP = true;
34 constexpr bool DEAFULT_DISABLE_SWIPE = false;
35 constexpr int32_t ARROW_IS_SHOW_BACKGROUND = 1;
36 constexpr int32_t ARROW_IS_SIDE_BAR_MIDDLE = 2;
37 constexpr int32_t ARROW_BACKGROUND_SIZE = 3;
38 constexpr int32_t ARROW_BACKGROUND_COLOR = 4;
39 constexpr int32_t ARROW_SIZE = 5;
40 constexpr int32_t ARROW_COLOR = 6;
41 constexpr int32_t DISPLAY_ARROW_OBJECT = 2;
42 constexpr int32_t DISPLAY_ARROW_TRUE = 1;
43 constexpr int32_t DISPLAY_ARROW_VALUE = 0;
44 constexpr int32_t DISPLAY_ARROW_IS_HOVER_SHOW_INDEX = 7;
45 constexpr int32_t DISPLAY_ARROW_CAPI = 8;
46 constexpr int32_t DISPLAY_ARROW_IS_HOVER_SHOW_UNDEFINED = 2;
47 constexpr int32_t INDICATOR_TYPE_INDEX = 0;
48 constexpr int32_t INDICATOR_VALUE = 1;
49 constexpr int32_t DIGIT_INDICATOR_FONT_COLOR = 1;
50 constexpr int32_t DIGIT_INDICATOR_SELECTED_FONT_COLOR = 2;
51 constexpr int32_t DIGIT_INDICATOR_DIGIT_FONT_SIZE = 3;
52 constexpr int32_t DIGIT_INDICATOR_DIGIT_FONT_WEIGHT = 4;
53 constexpr int32_t DIGIT_INDICATOR_SELECTED_DIGIT_FONT_SIZE = 5;
54 constexpr int32_t DIGIT_INDICATOR_SELECTED_DIGIT_FONT_WEIGHT = 6;
55 constexpr int32_t DIGIT_INDICATOR_LEFT = 7;
56 constexpr int32_t DIGIT_INDICATOR_TOP = 8;
57 constexpr int32_t DIGIT_INDICATOR_RIGHT = 9;
58 constexpr int32_t DIGIT_INDICATOR_BOTTOM = 10;
59 constexpr int32_t DIGIT_INDICATOR_IGNORE_SIZE = 11;
60 constexpr int32_t DIGIT_INDICATOR_SET_IGNORE_SIZE = 12;
61 constexpr int32_t DOT_INDICATOR_ITEM_WIDTH = 1;
62 constexpr int32_t DOT_INDICATOR_ITEM_HEIGHT = 2;
63 constexpr int32_t DOT_INDICATOR_SELECTED_ITEM_WIDTH = 3;
64 constexpr int32_t DOT_INDICATOR_SELECTED_ITEM_HEIGHT = 4;
65 constexpr int32_t DOT_INDICATOR_MASK = 5;
66 constexpr int32_t DOT_INDICATOR_COLOR = 6;
67 constexpr int32_t DOT_INDICATOR_SELECTED_COLOR = 7;
68 constexpr int32_t DOT_INDICATOR_LEFT = 8;
69 constexpr int32_t DOT_INDICATOR_TOP = 9;
70 constexpr int32_t DOT_INDICATOR_RIGHT = 10;
71 constexpr int32_t DOT_INDICATOR_BOTTOM = 11;
72 constexpr int32_t DOT_INDICATOR_MAX_DISPLAY_COUNT = 12;
73 constexpr int32_t DOT_INDICATOR_INFO_SIZE = 12;
74 constexpr int32_t DOT_INDICATOR_SPACE = 13;
75 constexpr int32_t DOT_INDICATOR_IGNORE_SIZE = 14;
76 constexpr int32_t DOT_INDICATOR_SET_IGNORE_SIZE = 15;
77 constexpr int32_t NUM_0 = 0;
78 constexpr int32_t NUM_1 = 1;
79 constexpr int32_t NUM_2 = 2;
80 constexpr int32_t NUM_3 = 3;
81 constexpr int32_t NUM_4 = 4;
82 constexpr float ANIMATION_INFO_DEFAULT = 0.0f;
83 constexpr float ARROW_SIZE_COEFFICIENT = 0.75f;
84 const int32_t ERROR_INT_CODE = -1;
85 constexpr float ZERO_F = 0.0f;
86 constexpr bool DEFAULT_STOP_WHEN_TOUCHED = true;
87
88 const std::vector<SwiperDisplayMode> DISPLAY_MODE = { SwiperDisplayMode::STRETCH, SwiperDisplayMode::AUTO_LINEAR };
89 const std::vector<EdgeEffect> EDGE_EFFECT = { EdgeEffect::SPRING, EdgeEffect::FADE, EdgeEffect::NONE };
90 const std::vector<SwiperIndicatorType> INDICATOR_TYPE = { SwiperIndicatorType::DOT, SwiperIndicatorType::DIGIT };
91 const std::vector<SwiperAnimationMode> ANIMATION_MODE = { SwiperAnimationMode::NO_ANIMATION,
92 SwiperAnimationMode::DEFAULT_ANIMATION, SwiperAnimationMode::FAST_ANIMATION };
93 const std::vector<OHOS::Ace::RefPtr<OHOS::Ace::Curve>> CURVES = {
94 OHOS::Ace::Curves::LINEAR,
95 OHOS::Ace::Curves::EASE,
96 OHOS::Ace::Curves::EASE_IN,
97 OHOS::Ace::Curves::EASE_OUT,
98 OHOS::Ace::Curves::EASE_IN_OUT,
99 OHOS::Ace::Curves::FAST_OUT_SLOW_IN,
100 OHOS::Ace::Curves::LINEAR_OUT_SLOW_IN,
101 OHOS::Ace::Curves::FAST_OUT_LINEAR_IN,
102 OHOS::Ace::Curves::EXTREME_DECELERATION,
103 OHOS::Ace::Curves::SHARP,
104 OHOS::Ace::Curves::RHYTHM,
105 OHOS::Ace::Curves::SMOOTH,
106 OHOS::Ace::Curves::FRICTION,
107 };
SetArrowBackgroundInfo(SwiperArrowParameters & swiperArrowParameters,RefPtr<SwiperIndicatorTheme> & swiperIndicatorTheme,const std::vector<std::string> & arrowInfo)108 void SetArrowBackgroundInfo(SwiperArrowParameters& swiperArrowParameters,
109 RefPtr<SwiperIndicatorTheme>& swiperIndicatorTheme, const std::vector<std::string>& arrowInfo)
110 {
111 auto backgroundSizeValue = arrowInfo[ARROW_BACKGROUND_SIZE] == "-" ? "" : arrowInfo[ARROW_BACKGROUND_SIZE];
112 auto backgroundColorValue = arrowInfo[ARROW_BACKGROUND_COLOR] == "-" ? "" : arrowInfo[ARROW_BACKGROUND_COLOR];
113 auto arrowSizeValue = arrowInfo[ARROW_SIZE] == "-" ? "" : arrowInfo[ARROW_SIZE];
114 auto arrowColorValue = arrowInfo[ARROW_COLOR] == "-" ? "" : arrowInfo[ARROW_COLOR];
115 bool parseOk = false;
116 CalcDimension dimension;
117 Color color;
118 if (swiperArrowParameters.isSidebarMiddle.value()) {
119 dimension = StringUtils::StringToCalcDimension(backgroundSizeValue, false, DimensionUnit::VP);
120 swiperArrowParameters.backgroundSize =
121 GreatNotEqual(dimension.ConvertToVp(), 0.0) && !(dimension.Unit() == DimensionUnit::PERCENT)
122 ? dimension
123 : swiperIndicatorTheme->GetBigArrowBackgroundSize();
124 parseOk = Color::ParseColorString(backgroundColorValue, color);
125 swiperArrowParameters.backgroundColor = parseOk ? color : swiperIndicatorTheme->GetBigArrowBackgroundColor();
126 if (swiperArrowParameters.isShowBackground.value()) {
127 swiperArrowParameters.arrowSize = swiperArrowParameters.backgroundSize.value() * ARROW_SIZE_COEFFICIENT;
128 } else {
129 parseOk = StringUtils::StringToCalcDimensionNG(arrowSizeValue, dimension, false, DimensionUnit::VP);
130 swiperArrowParameters.arrowSize =
131 parseOk && GreatNotEqual(dimension.ConvertToVp(), 0.0) && !(dimension.Unit() == DimensionUnit::PERCENT)
132 ? dimension
133 : swiperIndicatorTheme->GetBigArrowSize();
134 swiperArrowParameters.backgroundSize = swiperArrowParameters.arrowSize;
135 }
136 parseOk = Color::ParseColorString(arrowColorValue, color);
137 swiperArrowParameters.arrowColor = parseOk ? color : swiperIndicatorTheme->GetBigArrowColor();
138 } else {
139 dimension = StringUtils::StringToCalcDimension(backgroundSizeValue, false, DimensionUnit::VP);
140 swiperArrowParameters.backgroundSize =
141 GreatNotEqual(dimension.ConvertToVp(), 0.0) && !(dimension.Unit() == DimensionUnit::PERCENT)
142 ? dimension
143 : swiperIndicatorTheme->GetSmallArrowBackgroundSize();
144 parseOk = Color::ParseColorString(backgroundColorValue, color);
145 swiperArrowParameters.backgroundColor = parseOk ? color : swiperIndicatorTheme->GetSmallArrowBackgroundColor();
146 if (swiperArrowParameters.isShowBackground.value()) {
147 swiperArrowParameters.arrowSize = swiperArrowParameters.backgroundSize.value() * ARROW_SIZE_COEFFICIENT;
148 } else {
149 parseOk = StringUtils::StringToCalcDimensionNG(arrowSizeValue, dimension, false, DimensionUnit::VP);
150 swiperArrowParameters.arrowSize =
151 parseOk && GreatNotEqual(dimension.ConvertToVp(), 0.0) && !(dimension.Unit() == DimensionUnit::PERCENT)
152 ? dimension
153 : swiperIndicatorTheme->GetSmallArrowSize();
154 swiperArrowParameters.backgroundSize = swiperArrowParameters.arrowSize;
155 }
156 parseOk = Color::ParseColorString(arrowColorValue, color);
157 swiperArrowParameters.arrowColor = parseOk ? color : swiperIndicatorTheme->GetSmallArrowColor();
158 }
159 }
160
GetArrowInfo(const std::vector<std::string> & arrowInfo,SwiperArrowParameters & swiperArrowParameters)161 bool GetArrowInfo(const std::vector<std::string>& arrowInfo, SwiperArrowParameters& swiperArrowParameters)
162 {
163 auto isShowBackgroundValue = arrowInfo[ARROW_IS_SHOW_BACKGROUND];
164 auto isSidebarMiddleValue = arrowInfo[ARROW_IS_SIDE_BAR_MIDDLE];
165
166 auto pipelineContext = PipelineBase::GetCurrentContextSafely();
167 CHECK_NULL_RETURN(pipelineContext, false);
168 auto swiperIndicatorTheme = pipelineContext->GetTheme<SwiperIndicatorTheme>();
169 CHECK_NULL_RETURN(swiperIndicatorTheme, false);
170 if (isShowBackgroundValue == "2") {
171 swiperArrowParameters.isShowBackground = swiperIndicatorTheme->GetIsShowArrowBackground();
172 } else {
173 swiperArrowParameters.isShowBackground = isShowBackgroundValue == "1" ? true : false;
174 }
175 if (isSidebarMiddleValue == "2") {
176 swiperArrowParameters.isSidebarMiddle = swiperIndicatorTheme->GetIsSidebarMiddle();
177 } else {
178 swiperArrowParameters.isSidebarMiddle = isSidebarMiddleValue == "1" ? true : false;
179 }
180 SetArrowBackgroundInfo(swiperArrowParameters, swiperIndicatorTheme, arrowInfo);
181 return true;
182 }
183
GetInfoFromVectorByIndex(const std::vector<std::string> & dotIndicatorInfo,int32_t index)184 std::string GetInfoFromVectorByIndex(const std::vector<std::string>& dotIndicatorInfo, int32_t index)
185 {
186 auto dotIndicatorInfoSize = dotIndicatorInfo.size();
187 return dotIndicatorInfoSize < DOT_INDICATOR_INFO_SIZE
188 ? ""
189 : (dotIndicatorInfo[index] == "-" ? "" : dotIndicatorInfo[index]);
190 }
191
ParseIndicatorDimension(const std::string & value)192 std::optional<Dimension> ParseIndicatorDimension(const std::string& value)
193 {
194 std::optional<Dimension> indicatorDimension;
195 if (value.empty()) {
196 return indicatorDimension;
197 }
198 CalcDimension dimPosition = StringUtils::StringToCalcDimension(value, false, DimensionUnit::VP);
199 indicatorDimension = LessNotEqual(dimPosition.ConvertToPx(), 0.0f) ? 0.0_vp : dimPosition;
200 return indicatorDimension;
201 }
202
ParseMaxDisplayCount(const std::vector<std::string> & dotIndicatorInfo,SwiperParameters & swiperParameters)203 void ParseMaxDisplayCount(const std::vector<std::string>& dotIndicatorInfo, SwiperParameters& swiperParameters)
204 {
205 auto maxDisplayCount = GetInfoFromVectorByIndex(dotIndicatorInfo, DOT_INDICATOR_MAX_DISPLAY_COUNT);
206 if (maxDisplayCount.empty()) {
207 return;
208 }
209
210 swiperParameters.maxDisplayCountVal = StringUtils::StringToInt(maxDisplayCount);
211 }
212
ParseDotIndicatorSize(FrameNode * frameNode,const std::vector<std::string> & dotIndicatorInfo,const RefPtr<SwiperIndicatorTheme> & swiperIndicatorTheme,SwiperParameters & swiperParameters)213 void ParseDotIndicatorSize(FrameNode* frameNode, const std::vector<std::string>& dotIndicatorInfo,
214 const RefPtr<SwiperIndicatorTheme>& swiperIndicatorTheme, SwiperParameters& swiperParameters)
215 {
216 CHECK_NULL_VOID(frameNode);
217 CHECK_NULL_VOID(swiperIndicatorTheme);
218 auto itemWidthValue = GetInfoFromVectorByIndex(dotIndicatorInfo, DOT_INDICATOR_ITEM_WIDTH);
219 auto itemHeightValue = GetInfoFromVectorByIndex(dotIndicatorInfo, DOT_INDICATOR_ITEM_HEIGHT);
220 auto selectedItemWidthValue = GetInfoFromVectorByIndex(dotIndicatorInfo, DOT_INDICATOR_SELECTED_ITEM_WIDTH);
221 auto selectedItemHeightValue = GetInfoFromVectorByIndex(dotIndicatorInfo, DOT_INDICATOR_SELECTED_ITEM_HEIGHT);
222 CalcDimension dimPosition = StringUtils::StringToCalcDimension(itemWidthValue, false, DimensionUnit::VP);
223 auto defaultSize = swiperIndicatorTheme->GetSize();
224 bool parseItemWOk = !itemWidthValue.empty() && dimPosition.Unit() != DimensionUnit::PERCENT;
225 swiperParameters.itemWidth = (parseItemWOk && (dimPosition > 0.0_vp)) ? dimPosition : defaultSize;
226 dimPosition = StringUtils::StringToCalcDimension(itemHeightValue, false, DimensionUnit::VP);
227 bool parseItemHOk = !itemHeightValue.empty() && dimPosition.Unit() != DimensionUnit::PERCENT;
228 swiperParameters.itemHeight = (parseItemHOk && (dimPosition > 0.0_vp)) ? dimPosition : defaultSize;
229 dimPosition = StringUtils::StringToCalcDimension(selectedItemWidthValue, false, DimensionUnit::VP);
230 bool parseSeleItemWOk = !selectedItemWidthValue.empty() && dimPosition.Unit() != DimensionUnit::PERCENT;
231 swiperParameters.selectedItemWidth = (parseSeleItemWOk && (dimPosition > 0.0_vp)) ? dimPosition : defaultSize;
232 dimPosition = StringUtils::StringToCalcDimension(selectedItemHeightValue, false, DimensionUnit::VP);
233 bool parseSeleItemHOk = !selectedItemHeightValue.empty() && dimPosition.Unit() != DimensionUnit::PERCENT;
234 swiperParameters.selectedItemHeight = (parseSeleItemHOk && (dimPosition > 0.0_vp)) ? dimPosition : defaultSize;
235 if (!parseSeleItemWOk && !parseSeleItemHOk && !parseItemWOk && !parseItemHOk) {
236 SwiperModelNG::SetIsIndicatorCustomSize(frameNode, false);
237 } else {
238 SwiperModelNG::SetIsIndicatorCustomSize(frameNode, true);
239 }
240 }
241
GetDotIndicatorSpaceAndIgnoreSize(const std::vector<std::string> & dotIndicatorInfo,const RefPtr<SwiperIndicatorTheme> & swiperIndicatorTheme,SwiperParameters & swiperParameters)242 void GetDotIndicatorSpaceAndIgnoreSize(const std::vector<std::string>& dotIndicatorInfo,
243 const RefPtr<SwiperIndicatorTheme>& swiperIndicatorTheme, SwiperParameters& swiperParameters)
244 {
245 CHECK_NULL_VOID(swiperIndicatorTheme);
246 auto spaceValue = GetInfoFromVectorByIndex(dotIndicatorInfo, DOT_INDICATOR_SPACE);
247 auto ignoreSize = GetInfoFromVectorByIndex(dotIndicatorInfo, DOT_INDICATOR_IGNORE_SIZE);
248 auto setIgnoreSize = GetInfoFromVectorByIndex(dotIndicatorInfo, DOT_INDICATOR_SET_IGNORE_SIZE);
249
250 CalcDimension dimPosition = StringUtils::StringToCalcDimension(spaceValue, false, DimensionUnit::VP);
251 bool parseSpaceOk = !spaceValue.empty() && dimPosition.Unit() != DimensionUnit::PERCENT;
252 auto defaultSpaceSize = swiperIndicatorTheme->GetIndicatorDotItemSpace();
253 swiperParameters.dimSpace = (parseSpaceOk && !(dimPosition < 0.0_vp)) ? dimPosition : defaultSpaceSize;
254
255 swiperParameters.ignoreSizeValue = (ignoreSize == "1" ? true : false);
256 swiperParameters.setIgnoreSizeValue = (setIgnoreSize == "1" ? true : false);
257 }
258
GetDotIndicatorInfo(FrameNode * frameNode,const std::vector<std::string> & dotIndicatorInfo)259 SwiperParameters GetDotIndicatorInfo(FrameNode* frameNode, const std::vector<std::string>& dotIndicatorInfo)
260 {
261 auto maskValue = GetInfoFromVectorByIndex(dotIndicatorInfo, DOT_INDICATOR_MASK);
262 auto colorValue = GetInfoFromVectorByIndex(dotIndicatorInfo, DOT_INDICATOR_COLOR);
263 auto selectedColorValue = GetInfoFromVectorByIndex(dotIndicatorInfo, DOT_INDICATOR_SELECTED_COLOR);
264 CHECK_NULL_RETURN(frameNode, SwiperParameters());
265 auto pipelineContext = frameNode->GetContext();
266 CHECK_NULL_RETURN(pipelineContext, SwiperParameters());
267 auto swiperIndicatorTheme = pipelineContext->GetTheme<SwiperIndicatorTheme>();
268 CHECK_NULL_RETURN(swiperIndicatorTheme, SwiperParameters());
269 bool parseOk = false;
270 SwiperParameters swiperParameters;
271 auto leftValue = GetInfoFromVectorByIndex(dotIndicatorInfo, DOT_INDICATOR_LEFT);
272 auto topValue = GetInfoFromVectorByIndex(dotIndicatorInfo, DOT_INDICATOR_TOP);
273 auto rightValue = GetInfoFromVectorByIndex(dotIndicatorInfo, DOT_INDICATOR_RIGHT);
274 auto bottomValue = GetInfoFromVectorByIndex(dotIndicatorInfo, DOT_INDICATOR_BOTTOM);
275 swiperParameters.dimLeft = ParseIndicatorDimension(leftValue);
276 swiperParameters.dimTop = ParseIndicatorDimension(topValue);
277 swiperParameters.dimRight = ParseIndicatorDimension(rightValue);
278 swiperParameters.dimBottom = ParseIndicatorDimension(bottomValue);
279 if (maskValue != "2") {
280 swiperParameters.maskValue = (maskValue == "1" ? true : false);
281 }
282 Color colorVal;
283 parseOk = Color::ParseColorString(colorValue, colorVal);
284 swiperParameters.colorVal = parseOk ? colorVal : swiperIndicatorTheme->GetColor();
285 parseOk = Color::ParseColorString(selectedColorValue, colorVal);
286 swiperParameters.selectedColorVal = parseOk ? colorVal : swiperIndicatorTheme->GetSelectedColor();
287 ParseDotIndicatorSize(frameNode, dotIndicatorInfo, swiperIndicatorTheme, swiperParameters);
288 GetDotIndicatorSpaceAndIgnoreSize(dotIndicatorInfo, swiperIndicatorTheme, swiperParameters);
289 ParseMaxDisplayCount(dotIndicatorInfo, swiperParameters);
290
291 return swiperParameters;
292 }
293
ParseIndicatorCommonDimension(const ArkUIOptionalFloat attribute,DimensionUnit unit)294 std::optional<Dimension> ParseIndicatorCommonDimension(const ArkUIOptionalFloat attribute, DimensionUnit unit)
295 {
296 std::optional<Dimension> indicatorDimension;
297 if (!attribute.isSet) {
298 return indicatorDimension;
299 }
300 CalcDimension dimPosition = CalcDimension(attribute.value, unit);
301 indicatorDimension = LessNotEqual(dimPosition.ConvertToPx(), 0.0f) ? 0.0_vp : dimPosition;
302 return indicatorDimension;
303 }
304
305
ParseIndicatorAttribute(std::optional<Dimension> dim,bool & hasValue,float & value)306 void ParseIndicatorAttribute(std::optional<Dimension> dim, bool& hasValue, float& value)
307 {
308 hasValue = dim.has_value();
309 if (hasValue) {
310 value = dim.value().Value();
311 } else {
312 value = ZERO_F;
313 }
314 }
315
GetDotIndicatorProps(FrameNode * frameNode,ArkUISwiperIndicator * indicator)316 SwiperParameters GetDotIndicatorProps(FrameNode* frameNode, ArkUISwiperIndicator* indicator)
317 {
318 CHECK_NULL_RETURN(frameNode, SwiperParameters());
319 auto pipelineContext = frameNode->GetContext();
320 CHECK_NULL_RETURN(pipelineContext, SwiperParameters());
321 auto swiperIndicatorTheme = pipelineContext->GetTheme<SwiperIndicatorTheme>();
322 CHECK_NULL_RETURN(swiperIndicatorTheme, SwiperParameters());
323 SwiperParameters swiperParameters;
324 DimensionUnit unit = static_cast<DimensionUnit>(indicator->dimUnit);
325 swiperParameters.dimLeft = ParseIndicatorCommonDimension(indicator->dimLeft, unit);
326 swiperParameters.dimTop = ParseIndicatorCommonDimension(indicator->dimTop, unit);
327 swiperParameters.dimRight = ParseIndicatorCommonDimension(indicator->dimRight, unit);
328 swiperParameters.dimBottom = ParseIndicatorCommonDimension(indicator->dimBottom, unit);
329 auto defaultSize = swiperIndicatorTheme->GetSize();
330
331 CalcDimension dimPosition = Dimension(indicator->itemWidth.value, unit);
332 bool parseItemWOk = indicator->itemWidth.isSet && dimPosition.Unit() != DimensionUnit::PERCENT;
333 swiperParameters.itemWidth = (parseItemWOk && (dimPosition > 0.0_vp)) ? dimPosition : defaultSize;
334 dimPosition = Dimension(indicator->itemHeight.value, unit);
335 bool parseItemHOk = indicator->itemHeight.isSet && dimPosition.Unit() != DimensionUnit::PERCENT;
336 swiperParameters.itemHeight = (parseItemHOk && (dimPosition > 0.0_vp)) ? dimPosition : defaultSize;
337 dimPosition = Dimension(indicator->selectedItemWidth.value, unit);
338 bool parseSelectedItemWOk = indicator->selectedItemWidth.isSet && dimPosition.Unit() != DimensionUnit::PERCENT;
339 swiperParameters.selectedItemWidth = (parseSelectedItemWOk && (dimPosition > 0.0_vp)) ? dimPosition : defaultSize;
340 dimPosition = Dimension(indicator->selectedItemHeight.value, unit);
341 bool parseSelectedItemHOk = indicator->selectedItemHeight.isSet && dimPosition.Unit() != DimensionUnit::PERCENT;
342 swiperParameters.selectedItemHeight = (parseSelectedItemHOk && (dimPosition > 0.0_vp)) ? dimPosition : defaultSize;
343
344 auto defaultSpace = swiperIndicatorTheme->GetIndicatorDotItemSpace();
345 dimPosition = Dimension(indicator->dimSpace.value, unit);
346 bool parseSpaceOk = indicator->dimSpace.isSet && dimPosition.Unit() != DimensionUnit::PERCENT;
347 swiperParameters.dimSpace = (parseSpaceOk && !(dimPosition < 0.0_vp)) ? dimPosition : defaultSpace;
348
349 if (!parseSelectedItemWOk && !parseSelectedItemHOk && !parseItemWOk && !parseItemHOk) {
350 SwiperModelNG::SetIsIndicatorCustomSize(frameNode, false);
351 } else {
352 SwiperModelNG::SetIsIndicatorCustomSize(frameNode, true);
353 }
354 swiperParameters.maskValue = indicator->maskValue.value == 1 ? true : false;
355 swiperParameters.colorVal =
356 indicator->colorValue.isSet == 1 ? Color(indicator->colorValue.value) : swiperIndicatorTheme->GetColor();
357 swiperParameters.selectedColorVal = indicator->selectedColorValue.isSet == 1 ?
358 Color(indicator->selectedColorValue.value) : swiperIndicatorTheme->GetSelectedColor();
359 swiperParameters.maxDisplayCountVal = indicator->maxDisplayCount.isSet == 1 ?
360 indicator->maxDisplayCount.value : NUM_0;
361 swiperParameters.ignoreSizeValue = indicator->ignoreSizeValue.value == 1 ? true : false;
362 return swiperParameters;
363 }
364
GetDigitIndicatorProps(FrameNode * frameNode,ArkUISwiperDigitIndicator * indicator)365 SwiperDigitalParameters GetDigitIndicatorProps(FrameNode* frameNode, ArkUISwiperDigitIndicator* indicator)
366 {
367 CHECK_NULL_RETURN(frameNode, SwiperDigitalParameters());
368 auto pipelineContext = frameNode->GetContext();
369 CHECK_NULL_RETURN(pipelineContext, SwiperDigitalParameters());
370 auto swiperIndicatorTheme = pipelineContext->GetTheme<SwiperIndicatorTheme>();
371 CHECK_NULL_RETURN(swiperIndicatorTheme, SwiperDigitalParameters());
372 SwiperDigitalParameters swiperDigitalParameters;
373 DimensionUnit unit = static_cast<DimensionUnit>(indicator->dimUnit);
374 swiperDigitalParameters.dimLeft = ParseIndicatorCommonDimension(indicator->dimLeft, unit);
375 swiperDigitalParameters.dimTop = ParseIndicatorCommonDimension(indicator->dimTop, unit);
376 swiperDigitalParameters.dimRight = ParseIndicatorCommonDimension(indicator->dimRight, unit);
377 swiperDigitalParameters.dimBottom = ParseIndicatorCommonDimension(indicator->dimBottom, unit);
378
379 swiperDigitalParameters.fontColor = indicator->fontColor.isSet == 1
380 ? Color(indicator->fontColor.value)
381 : swiperIndicatorTheme->GetDigitalIndicatorTextStyle().GetTextColor();
382 swiperDigitalParameters.selectedFontColor =
383 indicator->selectedFontColor.isSet == 1 ? Color(indicator->selectedFontColor.value)
384 : swiperIndicatorTheme->GetDigitalIndicatorTextStyle().GetTextColor();
385 auto digitFontSize = ParseIndicatorCommonDimension(indicator->fontSize, unit);
386 swiperDigitalParameters.fontSize = indicator->fontSize.isSet == 1 && (digitFontSize > 0.0_vp)
387 ? digitFontSize
388 : swiperIndicatorTheme->GetDigitalIndicatorTextStyle().GetFontSize();
389
390 auto digitSelectedFontSize = ParseIndicatorCommonDimension(indicator->selectedFontSize, unit);
391 swiperDigitalParameters.selectedFontSize =
392 indicator->selectedFontSize.isSet == 1 && (digitSelectedFontSize > 0.0_vp)
393 ? digitSelectedFontSize
394 : swiperIndicatorTheme->GetDigitalIndicatorTextStyle().GetFontSize();
395
396 swiperDigitalParameters.fontWeight = indicator->fontWeight.isSet == 1
397 ? FontWeight(indicator->fontWeight.value)
398 : swiperIndicatorTheme->GetDigitalIndicatorTextStyle().GetFontWeight();
399 swiperDigitalParameters.selectedFontWeight =
400 indicator->selectedFontWeight.isSet == 1 ? FontWeight(indicator->selectedFontWeight.value)
401 : swiperIndicatorTheme->GetDigitalIndicatorTextStyle().GetFontWeight();
402 swiperDigitalParameters.ignoreSizeValue = indicator->ignoreSizeValue.value == 1 ? true : false;
403 return swiperDigitalParameters;
404 }
405
GetFontContent(const std::string & size,const std::string & weight,bool isSelected,SwiperDigitalParameters & digitalParameters)406 void GetFontContent(
407 const std::string& size, const std::string& weight, bool isSelected, SwiperDigitalParameters& digitalParameters)
408 {
409 auto pipelineContext = PipelineBase::GetCurrentContextSafely();
410 CHECK_NULL_VOID(pipelineContext);
411 auto swiperIndicatorTheme = pipelineContext->GetTheme<SwiperIndicatorTheme>();
412 CHECK_NULL_VOID(swiperIndicatorTheme);
413 CalcDimension fontSize = StringUtils::StringToCalcDimension(size, false, DimensionUnit::VP);
414 if (LessOrEqual(fontSize.Value(), 0.0) || fontSize.Unit() == DimensionUnit::PERCENT) {
415 fontSize = swiperIndicatorTheme->GetDigitalIndicatorTextStyle().GetFontSize();
416 }
417 if (isSelected) {
418 digitalParameters.selectedFontSize = fontSize;
419 } else {
420 digitalParameters.fontSize = fontSize;
421 }
422 if (!weight.empty()) {
423 if (isSelected) {
424 digitalParameters.selectedFontWeight = StringUtils::StringToFontWeight(weight, FontWeight::NORMAL);
425 } else {
426 digitalParameters.fontWeight = StringUtils::StringToFontWeight(weight, FontWeight::NORMAL);
427 }
428 } else {
429 if (isSelected) {
430 digitalParameters.selectedFontWeight = swiperIndicatorTheme->GetDigitalIndicatorTextStyle().GetFontWeight();
431 } else {
432 digitalParameters.fontWeight = swiperIndicatorTheme->GetDigitalIndicatorTextStyle().GetFontWeight();
433 }
434 }
435 }
436
ParseDigitIndicatorBottomAndIgnoreSize(const std::vector<std::string> & digitIndicatorInfo,SwiperDigitalParameters & digitalParameters)437 void ParseDigitIndicatorBottomAndIgnoreSize(const std::vector<std::string>& digitIndicatorInfo,
438 SwiperDigitalParameters& digitalParameters)
439 {
440 auto digitBottomValue =
441 digitIndicatorInfo[DIGIT_INDICATOR_BOTTOM] == "-" ? "" : digitIndicatorInfo[DIGIT_INDICATOR_BOTTOM];
442 auto ignoreSize = digitIndicatorInfo[DIGIT_INDICATOR_IGNORE_SIZE] == "-" ? "" :
443 digitIndicatorInfo[DIGIT_INDICATOR_IGNORE_SIZE];
444
445 auto setIgnoreSize = digitIndicatorInfo[DIGIT_INDICATOR_SET_IGNORE_SIZE] == "-" ? "" :
446 digitIndicatorInfo[DIGIT_INDICATOR_SET_IGNORE_SIZE];
447
448 auto bottom = ParseIndicatorDimension(digitBottomValue);
449 digitalParameters.dimBottom = bottom;
450 if (!bottom.has_value() || (bottom.has_value() && (bottom.value() == 0.0_vp))) {
451 digitalParameters.ignoreSizeValue = (ignoreSize == "1" ? true : false);
452 } else {
453 digitalParameters.ignoreSizeValue = false;
454 }
455 }
456
GetDigitIndicatorInfo(const std::vector<std::string> & digitIndicatorInfo)457 SwiperDigitalParameters GetDigitIndicatorInfo(const std::vector<std::string>& digitIndicatorInfo)
458 {
459 auto dotLeftValue = digitIndicatorInfo[DIGIT_INDICATOR_LEFT] == "-" ? "" : digitIndicatorInfo[DIGIT_INDICATOR_LEFT];
460 auto dotTopValue = digitIndicatorInfo[DIGIT_INDICATOR_TOP] == "-" ? "" : digitIndicatorInfo[DIGIT_INDICATOR_TOP];
461 auto dotRightValue =
462 digitIndicatorInfo[DIGIT_INDICATOR_RIGHT] == "-" ? "" : digitIndicatorInfo[DIGIT_INDICATOR_RIGHT];
463 auto fontColorValue =
464 digitIndicatorInfo[DIGIT_INDICATOR_FONT_COLOR] == "-" ? "" : digitIndicatorInfo[DIGIT_INDICATOR_FONT_COLOR];
465 auto selectedFontColorValue = digitIndicatorInfo[DIGIT_INDICATOR_SELECTED_FONT_COLOR] == "-"
466 ? ""
467 : digitIndicatorInfo[DIGIT_INDICATOR_SELECTED_FONT_COLOR];
468 auto digitFontSize = digitIndicatorInfo[DIGIT_INDICATOR_DIGIT_FONT_SIZE] == "-"
469 ? ""
470 : digitIndicatorInfo[DIGIT_INDICATOR_DIGIT_FONT_SIZE];
471 auto digitFontWeight = digitIndicatorInfo[DIGIT_INDICATOR_DIGIT_FONT_WEIGHT] == "-"
472 ? ""
473 : digitIndicatorInfo[DIGIT_INDICATOR_DIGIT_FONT_WEIGHT];
474 auto selectedDigitFontSize = digitIndicatorInfo[DIGIT_INDICATOR_SELECTED_DIGIT_FONT_SIZE] == "-"
475 ? ""
476 : digitIndicatorInfo[DIGIT_INDICATOR_SELECTED_DIGIT_FONT_SIZE];
477 auto selectedDigitFontWeight = digitIndicatorInfo[DIGIT_INDICATOR_SELECTED_DIGIT_FONT_WEIGHT] == "-"
478 ? ""
479 : digitIndicatorInfo[DIGIT_INDICATOR_SELECTED_DIGIT_FONT_WEIGHT];
480
481 auto pipelineContext = PipelineBase::GetCurrentContextSafely();
482 CHECK_NULL_RETURN(pipelineContext, SwiperDigitalParameters());
483 auto swiperIndicatorTheme = pipelineContext->GetTheme<SwiperIndicatorTheme>();
484 CHECK_NULL_RETURN(swiperIndicatorTheme, SwiperDigitalParameters());
485 bool parseOk = false;
486 SwiperDigitalParameters digitalParameters;
487 digitalParameters.dimLeft = ParseIndicatorDimension(dotLeftValue);
488 digitalParameters.dimTop = ParseIndicatorDimension(dotTopValue);
489 digitalParameters.dimRight = ParseIndicatorDimension(dotRightValue);
490
491 Color fontColor;
492 parseOk = Color::ParseColorString(fontColorValue, fontColor);
493 digitalParameters.fontColor =
494 parseOk ? fontColor : swiperIndicatorTheme->GetDigitalIndicatorTextStyle().GetTextColor();
495 parseOk = Color::ParseColorString(selectedFontColorValue, fontColor);
496 digitalParameters.selectedFontColor =
497 parseOk ? fontColor : swiperIndicatorTheme->GetDigitalIndicatorTextStyle().GetTextColor();
498 ParseDigitIndicatorBottomAndIgnoreSize(digitIndicatorInfo, digitalParameters);
499 GetFontContent(digitFontSize, digitFontWeight, false, digitalParameters);
500 GetFontContent(selectedDigitFontSize, selectedDigitFontWeight, true, digitalParameters);
501 return digitalParameters;
502 }
503
SetIndicatorInteractive(ArkUINodeHandle node,ArkUI_Bool value)504 void SetIndicatorInteractive(ArkUINodeHandle node, ArkUI_Bool value)
505 {
506 auto* frameNode = reinterpret_cast<FrameNode*>(node);
507 CHECK_NULL_VOID(frameNode);
508 SwiperModelNG::SetIndicatorInteractive(frameNode, static_cast<bool>(value));
509 }
510
ResetIndicatorInteractive(ArkUINodeHandle node)511 void ResetIndicatorInteractive(ArkUINodeHandle node)
512 {
513 auto* frameNode = reinterpret_cast<FrameNode*>(node);
514 CHECK_NULL_VOID(frameNode);
515 SwiperModelNG::SetIndicatorInteractive(frameNode, true);
516 }
517
GetIndicatorInteractive(ArkUINodeHandle node)518 ArkUI_Int32 GetIndicatorInteractive(ArkUINodeHandle node)
519 {
520 auto* frameNode = reinterpret_cast<FrameNode*>(node);
521 CHECK_NULL_RETURN(frameNode, ERROR_INT_CODE);
522 return static_cast<ArkUI_Int32>(SwiperModelNG::GetIndicatorInteractive(frameNode));
523 }
524
SetSwiperNextMargin(ArkUINodeHandle node,ArkUI_Float32 nextMarginValue,ArkUI_Int32 nextMarginUnit,ArkUI_Bool ignoreBlank)525 void SetSwiperNextMargin(
526 ArkUINodeHandle node, ArkUI_Float32 nextMarginValue, ArkUI_Int32 nextMarginUnit, ArkUI_Bool ignoreBlank)
527 {
528 auto* frameNode = reinterpret_cast<FrameNode*>(node);
529 CHECK_NULL_VOID(frameNode);
530 SwiperModelNG::SetNextMargin(
531 frameNode, CalcDimension(nextMarginValue, (DimensionUnit)nextMarginUnit), static_cast<bool>(ignoreBlank));
532 }
533
ResetSwiperNextMargin(ArkUINodeHandle node)534 void ResetSwiperNextMargin(ArkUINodeHandle node)
535 {
536 auto* frameNode = reinterpret_cast<FrameNode*>(node);
537 CHECK_NULL_VOID(frameNode);
538 CalcDimension value(0.0, DimensionUnit::VP);
539 SwiperModelNG::SetNextMargin(frameNode, value);
540 }
541
SetSwiperMinSize(ArkUINodeHandle node,ArkUI_Float32 minSizeValue,ArkUI_Int32 minSizeUnitt)542 void SetSwiperMinSize(ArkUINodeHandle node, ArkUI_Float32 minSizeValue, ArkUI_Int32 minSizeUnitt)
543 {
544 auto* frameNode = reinterpret_cast<FrameNode*>(node);
545 CHECK_NULL_VOID(frameNode);
546 SwiperModelNG::SetMinSize(frameNode, CalcDimension(minSizeValue, (DimensionUnit)minSizeUnitt));
547 }
548
ResetSwiperMinSize(ArkUINodeHandle node)549 void ResetSwiperMinSize(ArkUINodeHandle node)
550 {
551 auto* frameNode = reinterpret_cast<FrameNode*>(node);
552 CHECK_NULL_VOID(frameNode);
553 CalcDimension value(0.0, DimensionUnit::VP);
554 SwiperModelNG::SetMinSize(frameNode, value);
555 }
556
SetSwiperPrevMargin(ArkUINodeHandle node,ArkUI_Float32 prevMarginValue,ArkUI_Int32 prevMarginUnit,ArkUI_Bool ignoreBlank)557 void SetSwiperPrevMargin(
558 ArkUINodeHandle node, ArkUI_Float32 prevMarginValue, ArkUI_Int32 prevMarginUnit, ArkUI_Bool ignoreBlank)
559 {
560 auto* frameNode = reinterpret_cast<FrameNode*>(node);
561 CHECK_NULL_VOID(frameNode);
562 SwiperModelNG::SetPreviousMargin(
563 frameNode, CalcDimension(prevMarginValue, (DimensionUnit)prevMarginUnit), static_cast<bool>(ignoreBlank));
564 }
565
ResetSwiperPrevMargin(ArkUINodeHandle node)566 void ResetSwiperPrevMargin(ArkUINodeHandle node)
567 {
568 auto* frameNode = reinterpret_cast<FrameNode*>(node);
569 CHECK_NULL_VOID(frameNode);
570 CalcDimension value(0.0, DimensionUnit::VP);
571 SwiperModelNG::SetPreviousMargin(frameNode, value);
572 }
573
SetSwiperDisplayCount(ArkUINodeHandle node,ArkUI_CharPtr displayCountChar,ArkUI_CharPtr displayCountType)574 void SetSwiperDisplayCount(ArkUINodeHandle node, ArkUI_CharPtr displayCountChar, ArkUI_CharPtr displayCountType)
575 {
576 auto* frameNode = reinterpret_cast<FrameNode*>(node);
577 CHECK_NULL_VOID(frameNode);
578 std::string displayCountValue = std::string(displayCountChar);
579 std::string type = std::string(displayCountType);
580 if (type == "string" && displayCountValue == "auto") {
581 SwiperModelNG::SetDisplayMode(frameNode, SwiperDisplayMode::AUTO_LINEAR);
582 SwiperModelNG::ResetDisplayCount(frameNode);
583 } else if (type == "number" && StringUtils::StringToInt(displayCountValue) > 0) {
584 SwiperModelNG::SetDisplayCount(frameNode, StringUtils::StringToInt(displayCountValue));
585 } else if (type == "object") {
586 if (displayCountValue.empty()) {
587 return;
588 }
589 CalcDimension minSizeValue = StringUtils::StringToCalcDimension(displayCountValue, false, DimensionUnit::VP);
590 if (LessNotEqual(minSizeValue.Value(), 0.0)) {
591 minSizeValue.SetValue(0.0);
592 }
593 SwiperModelNG::SetMinSize(frameNode, minSizeValue);
594 } else {
595 SwiperModelNG::SetDisplayCount(frameNode, DEFAULT_DISPLAY_COUNT);
596 }
597 }
598
ResetSwiperDisplayCount(ArkUINodeHandle node)599 void ResetSwiperDisplayCount(ArkUINodeHandle node)
600 {
601 auto* frameNode = reinterpret_cast<FrameNode*>(node);
602 CHECK_NULL_VOID(frameNode);
603 SwiperModelNG::SetDisplayCount(frameNode, DEFAULT_DISPLAY_COUNT);
604 }
605
SetSwiperSwipeByGroup(ArkUINodeHandle node,ArkUI_Bool swipeByGroup)606 void SetSwiperSwipeByGroup(ArkUINodeHandle node, ArkUI_Bool swipeByGroup)
607 {
608 auto* frameNode = reinterpret_cast<FrameNode*>(node);
609 CHECK_NULL_VOID(frameNode);
610 SwiperModelNG::SetSwipeByGroup(frameNode, swipeByGroup);
611 }
612
ResetSwiperSwipeByGroup(ArkUINodeHandle node)613 void ResetSwiperSwipeByGroup(ArkUINodeHandle node)
614 {
615 auto* frameNode = reinterpret_cast<FrameNode*>(node);
616 CHECK_NULL_VOID(frameNode);
617 SwiperModelNG::SetSwipeByGroup(frameNode, DEFAULT_SWIPE_BY_GROUP);
618 }
619
InitSwiperArrowParameters(SwiperArrowParameters & swiperArrowParameters,RefPtr<SwiperIndicatorTheme> swiperIndicatorTheme)620 void InitSwiperArrowParameters(
621 SwiperArrowParameters& swiperArrowParameters, RefPtr<SwiperIndicatorTheme> swiperIndicatorTheme)
622 {
623 swiperArrowParameters.isShowBackground = swiperIndicatorTheme->GetIsShowArrowBackground();
624 swiperArrowParameters.isSidebarMiddle = swiperIndicatorTheme->GetIsSidebarMiddle();
625 swiperArrowParameters.backgroundSize = swiperIndicatorTheme->GetSmallArrowBackgroundSize();
626 swiperArrowParameters.backgroundColor = swiperIndicatorTheme->GetSmallArrowBackgroundColor();
627 swiperArrowParameters.arrowSize = swiperIndicatorTheme->GetSmallArrowSize();
628 swiperArrowParameters.arrowColor = swiperIndicatorTheme->GetSmallArrowColor();
629 }
630
VectorStringToInt(std::vector<std::string> & vectorStr,int32_t index)631 int32_t VectorStringToInt(std::vector<std::string>& vectorStr, int32_t index)
632 {
633 int32_t value = 0;
634 if (index < vectorStr.size()) {
635 value = StringUtils::StringToInt(vectorStr[index]);
636 }
637 return value;
638 }
639
SetSwiperDisplayArrow(ArkUINodeHandle node,ArkUI_CharPtr displayArrowStr)640 void SetSwiperDisplayArrow(ArkUINodeHandle node, ArkUI_CharPtr displayArrowStr)
641 {
642 auto* frameNode = reinterpret_cast<FrameNode*>(node);
643 CHECK_NULL_VOID(frameNode);
644 std::vector<std::string> res;
645 std::string displayArrowValues = std::string(displayArrowStr);
646 StringUtils::StringSplitter(displayArrowValues, '|', res);
647 int32_t displayArrowValue = VectorStringToInt(res, DISPLAY_ARROW_VALUE);
648 int32_t displayArrowCAPI = VectorStringToInt(res, DISPLAY_ARROW_CAPI);
649 if (displayArrowValue == DISPLAY_ARROW_OBJECT) {
650 SwiperArrowParameters swiperArrowParameters;
651 if (!GetArrowInfo(res, swiperArrowParameters)) {
652 SwiperModelNG::SetDisplayArrow(frameNode, false);
653 return;
654 }
655 SwiperModelNG::SetArrowStyle(frameNode, swiperArrowParameters);
656 SwiperModelNG::SetDisplayArrow(frameNode, true);
657 } else if (displayArrowValue == DISPLAY_ARROW_TRUE) {
658 if (displayArrowCAPI == 1) {
659 SwiperArrowParameters swiperArrowParameters;
660 if (!GetArrowInfo(res, swiperArrowParameters)) {
661 SwiperModelNG::SetDisplayArrow(frameNode, false);
662 return;
663 }
664 SwiperModelNG::SetArrowStyle(frameNode, swiperArrowParameters);
665 SwiperModelNG::SetDisplayArrow(frameNode, true);
666 } else {
667 auto pipelineContext = frameNode->GetContext();
668 CHECK_NULL_VOID(pipelineContext);
669 auto swiperIndicatorTheme = pipelineContext->GetTheme<SwiperIndicatorTheme>();
670 CHECK_NULL_VOID(swiperIndicatorTheme);
671 SwiperArrowParameters swiperArrowParameters;
672 InitSwiperArrowParameters(swiperArrowParameters, swiperIndicatorTheme);
673 SwiperModelNG::SetArrowStyle(frameNode, swiperArrowParameters);
674 SwiperModelNG::SetDisplayArrow(frameNode, true);
675 }
676 } else {
677 SwiperModelNG::SetDisplayArrow(frameNode, false);
678 return;
679 }
680 int32_t isHoverShow = VectorStringToInt(res, DISPLAY_ARROW_IS_HOVER_SHOW_INDEX);
681 if (isHoverShow != DISPLAY_ARROW_IS_HOVER_SHOW_UNDEFINED) {
682 SwiperModelNG::SetHoverShow(frameNode, isHoverShow == 1 ? true : false);
683 } else {
684 SwiperModelNG::SetHoverShow(frameNode, false);
685 }
686 }
687
ResetSwiperDisplayArrow(ArkUINodeHandle node)688 void ResetSwiperDisplayArrow(ArkUINodeHandle node)
689 {
690 auto* frameNode = reinterpret_cast<FrameNode*>(node);
691 CHECK_NULL_VOID(frameNode);
692 SwiperModelNG::ResetArrowStyle(frameNode);
693 SwiperModelNG::SetDisplayArrow(frameNode, false);
694 }
695
SetSwiperCurve(ArkUINodeHandle node,ArkUI_CharPtr curveChar)696 void SetSwiperCurve(ArkUINodeHandle node, ArkUI_CharPtr curveChar)
697 {
698 auto* frameNode = reinterpret_cast<FrameNode*>(node);
699 CHECK_NULL_VOID(frameNode);
700 RefPtr<Curve> curve = Curves::LINEAR;
701 curve = Framework::CreateCurve(curveChar);
702 SwiperModelNG::SetCurve(frameNode, curve);
703 }
704
ResetSwiperCurve(ArkUINodeHandle node)705 void ResetSwiperCurve(ArkUINodeHandle node)
706 {
707 auto* frameNode = reinterpret_cast<FrameNode*>(node);
708 CHECK_NULL_VOID(frameNode);
709 RefPtr<Curve> curve = Curves::LINEAR;
710 SwiperModelNG::SetCurve(frameNode, curve);
711 }
712
SetSwiperDisableSwipe(ArkUINodeHandle node,ArkUI_Bool disableSwipe)713 void SetSwiperDisableSwipe(ArkUINodeHandle node, ArkUI_Bool disableSwipe)
714 {
715 auto* frameNode = reinterpret_cast<FrameNode*>(node);
716 CHECK_NULL_VOID(frameNode);
717 SwiperModelNG::SetDisableSwipe(frameNode, disableSwipe);
718 }
719
ResetSwiperDisableSwipe(ArkUINodeHandle node)720 void ResetSwiperDisableSwipe(ArkUINodeHandle node)
721 {
722 auto* frameNode = reinterpret_cast<FrameNode*>(node);
723 CHECK_NULL_VOID(frameNode);
724 SwiperModelNG::SetDisableSwipe(frameNode, DEAFULT_DISABLE_SWIPE);
725 }
726
SetSwiperEffectMode(ArkUINodeHandle node,ArkUI_Int32 edgeEffect)727 void SetSwiperEffectMode(ArkUINodeHandle node, ArkUI_Int32 edgeEffect)
728 {
729 auto* frameNode = reinterpret_cast<FrameNode*>(node);
730 CHECK_NULL_VOID(frameNode);
731 if (edgeEffect < 0 || edgeEffect >= static_cast<int32_t>(EDGE_EFFECT.size())) {
732 return;
733 }
734 SwiperModelNG::SetEdgeEffect(frameNode, EDGE_EFFECT[edgeEffect]);
735 }
736
ResetSwiperEffectMode(ArkUINodeHandle node)737 void ResetSwiperEffectMode(ArkUINodeHandle node)
738 {
739 auto* frameNode = reinterpret_cast<FrameNode*>(node);
740 CHECK_NULL_VOID(frameNode);
741 SwiperModelNG::SetEdgeEffect(frameNode, EdgeEffect::SPRING);
742 }
743
SetSwiperCachedCount(ArkUINodeHandle node,ArkUI_Int32 cachedCount)744 void SetSwiperCachedCount(ArkUINodeHandle node, ArkUI_Int32 cachedCount)
745 {
746 auto* frameNode = reinterpret_cast<FrameNode*>(node);
747 CHECK_NULL_VOID(frameNode);
748 if (cachedCount < 0) {
749 cachedCount = DEFAULT_CACHED_COUNT;
750 }
751 SwiperModelNG::SetCachedCount(frameNode, cachedCount);
752 }
753
ResetSwiperCachedCount(ArkUINodeHandle node)754 void ResetSwiperCachedCount(ArkUINodeHandle node)
755 {
756 auto* frameNode = reinterpret_cast<FrameNode*>(node);
757 CHECK_NULL_VOID(frameNode);
758 int32_t value = DEFAULT_CACHED_COUNT;
759 SwiperModelNG::SetCachedCount(frameNode, value);
760 }
761
SetSwiperIsShown(ArkUINodeHandle node,ArkUI_Bool isShown)762 void SetSwiperIsShown(ArkUINodeHandle node, ArkUI_Bool isShown)
763 {
764 auto* frameNode = reinterpret_cast<FrameNode*>(node);
765 CHECK_NULL_VOID(frameNode);
766 SwiperModelNG::SetCachedIsShown(frameNode, isShown);
767 }
768
ResetSwiperIsShown(ArkUINodeHandle node)769 void ResetSwiperIsShown(ArkUINodeHandle node)
770 {
771 auto* frameNode = reinterpret_cast<FrameNode*>(node);
772 CHECK_NULL_VOID(frameNode);
773 SwiperModelNG::SetCachedIsShown(frameNode, DEFAULT_CACHED_IS_SHOWN);
774 }
775
GetSwiperCachedIsShown(ArkUINodeHandle node)776 ArkUI_Int32 GetSwiperCachedIsShown(ArkUINodeHandle node)
777 {
778 auto* frameNode = reinterpret_cast<FrameNode*>(node);
779 CHECK_NULL_RETURN(frameNode, ERROR_INT_CODE);
780 return static_cast<ArkUI_Int32>(SwiperModelNG::GetCachedIsShown(frameNode));
781 }
782
SetSwiperDisplayMode(ArkUINodeHandle node,ArkUI_Int32 displayMode)783 void SetSwiperDisplayMode(ArkUINodeHandle node, ArkUI_Int32 displayMode)
784 {
785 auto* frameNode = reinterpret_cast<FrameNode*>(node);
786 CHECK_NULL_VOID(frameNode);
787 if (displayMode < 0 || displayMode >= static_cast<int32_t>(DISPLAY_MODE.size())) {
788 return;
789 }
790 SwiperModelNG::SetDisplayMode(frameNode, DISPLAY_MODE[displayMode]);
791 }
792
ResetSwiperDisplayMode(ArkUINodeHandle node)793 void ResetSwiperDisplayMode(ArkUINodeHandle node)
794 {
795 auto* frameNode = reinterpret_cast<FrameNode*>(node);
796 CHECK_NULL_VOID(frameNode);
797 SwiperModelNG::SetDisplayMode(frameNode, SwiperDisplayMode::STRETCH);
798 }
799
SetSwiperItemSpace(ArkUINodeHandle node,ArkUI_Float32 itemSpaceValue,ArkUI_Int32 itemSpaceUnit)800 void SetSwiperItemSpace(ArkUINodeHandle node, ArkUI_Float32 itemSpaceValue, ArkUI_Int32 itemSpaceUnit)
801 {
802 auto* frameNode = reinterpret_cast<FrameNode*>(node);
803 CHECK_NULL_VOID(frameNode);
804 SwiperModelNG::SetItemSpace(frameNode, CalcDimension(itemSpaceValue, (DimensionUnit)itemSpaceUnit));
805 }
806
ResetSwiperItemSpace(ArkUINodeHandle node)807 void ResetSwiperItemSpace(ArkUINodeHandle node)
808 {
809 auto* frameNode = reinterpret_cast<FrameNode*>(node);
810 CHECK_NULL_VOID(frameNode);
811 CalcDimension value(0.0, DimensionUnit::VP);
812 SwiperModelNG::SetItemSpace(frameNode, value);
813 }
814
SetSwiperVertical(ArkUINodeHandle node,ArkUI_Bool isVertical)815 void SetSwiperVertical(ArkUINodeHandle node, ArkUI_Bool isVertical)
816 {
817 auto* frameNode = reinterpret_cast<FrameNode*>(node);
818 CHECK_NULL_VOID(frameNode);
819 SwiperModelNG::SetDirection(frameNode, isVertical ? Axis::VERTICAL : Axis::HORIZONTAL);
820 }
821
ResetSwiperVertical(ArkUINodeHandle node)822 void ResetSwiperVertical(ArkUINodeHandle node)
823 {
824 auto* frameNode = reinterpret_cast<FrameNode*>(node);
825 CHECK_NULL_VOID(frameNode);
826 SwiperModelNG::SetDirection(frameNode, Axis::HORIZONTAL);
827 }
828
SetSwiperLoop(ArkUINodeHandle node,ArkUI_Bool loop)829 void SetSwiperLoop(ArkUINodeHandle node, ArkUI_Bool loop)
830 {
831 auto* frameNode = reinterpret_cast<FrameNode*>(node);
832 CHECK_NULL_VOID(frameNode);
833 SwiperModelNG::SetLoop(frameNode, loop);
834 }
835
ResetSwiperLoop(ArkUINodeHandle node)836 void ResetSwiperLoop(ArkUINodeHandle node)
837 {
838 auto* frameNode = reinterpret_cast<FrameNode*>(node);
839 CHECK_NULL_VOID(frameNode);
840 SwiperModelNG::SetLoop(frameNode, DEFAULT_LOOP);
841 }
842
SetSwiperInterval(ArkUINodeHandle node,ArkUI_Int32 interval)843 void SetSwiperInterval(ArkUINodeHandle node, ArkUI_Int32 interval)
844 {
845 auto* frameNode = reinterpret_cast<FrameNode*>(node);
846 CHECK_NULL_VOID(frameNode);
847 if (interval < 0) {
848 interval = DEFAULT_INTERVAL;
849 }
850 SwiperModelNG::SetAutoPlayInterval(frameNode, interval);
851 }
852
ResetSwiperInterval(ArkUINodeHandle node)853 void ResetSwiperInterval(ArkUINodeHandle node)
854 {
855 auto* frameNode = reinterpret_cast<FrameNode*>(node);
856 CHECK_NULL_VOID(frameNode);
857 SwiperModelNG::SetAutoPlayInterval(frameNode, DEFAULT_INTERVAL);
858 }
859
SetSwiperAutoPlay(ArkUINodeHandle node,ArkUI_Bool autoPlay)860 void SetSwiperAutoPlay(ArkUINodeHandle node, ArkUI_Bool autoPlay)
861 {
862 auto* frameNode = reinterpret_cast<FrameNode*>(node);
863 CHECK_NULL_VOID(frameNode);
864 SwiperModelNG::SetAutoPlay(frameNode, autoPlay);
865 }
866
ResetSwiperAutoPlay(ArkUINodeHandle node)867 void ResetSwiperAutoPlay(ArkUINodeHandle node)
868 {
869 auto* frameNode = reinterpret_cast<FrameNode*>(node);
870 CHECK_NULL_VOID(frameNode);
871 SwiperModelNG::SetAutoPlay(frameNode, DEFAULT_AUTO_PLAY);
872 }
873
SetSwiperStopWhenTouched(ArkUINodeHandle node,ArkUI_Bool stopWhenTouched)874 void SetSwiperStopWhenTouched(ArkUINodeHandle node, ArkUI_Bool stopWhenTouched)
875 {
876 auto* frameNode = reinterpret_cast<FrameNode*>(node);
877 CHECK_NULL_VOID(frameNode);
878
879 SwiperAutoPlayOptions swiperAutoPlayOptions;
880 swiperAutoPlayOptions.stopWhenTouched = stopWhenTouched;
881 SwiperModelNG::SetAutoPlayOptions(frameNode, swiperAutoPlayOptions);
882 }
883
ResetSwiperStopWhenTouched(ArkUINodeHandle node)884 void ResetSwiperStopWhenTouched(ArkUINodeHandle node)
885 {
886 auto* frameNode = reinterpret_cast<FrameNode*>(node);
887 CHECK_NULL_VOID(frameNode);
888 SwiperAutoPlayOptions swiperAutoPlayOptions;
889 swiperAutoPlayOptions.stopWhenTouched = DEFAULT_STOP_WHEN_TOUCHED;
890 SwiperModelNG::SetAutoPlayOptions(frameNode, swiperAutoPlayOptions);
891 }
892
SetSwiperIndex(ArkUINodeHandle node,ArkUI_Int32 index,ArkUI_Int32 animationMode)893 void SetSwiperIndex(ArkUINodeHandle node, ArkUI_Int32 index, ArkUI_Int32 animationMode)
894 {
895 auto* frameNode = reinterpret_cast<FrameNode*>(node);
896 CHECK_NULL_VOID(frameNode);
897 index = index < 0 ? 0 : index;
898 if (animationMode <= static_cast<int32_t>(SwiperAnimationMode::NO_ANIMATION) ||
899 animationMode >= static_cast<int32_t>(ANIMATION_MODE.size())) {
900 SwiperModelNG::SetIndex(frameNode, index);
901 return;
902 }
903 SwiperModelNG::SetSwiperToIndex(frameNode, index, static_cast<SwiperAnimationMode>(animationMode));
904 }
905
ResetSwiperIndex(ArkUINodeHandle node)906 void ResetSwiperIndex(ArkUINodeHandle node)
907 {
908 auto* frameNode = reinterpret_cast<FrameNode*>(node);
909 CHECK_NULL_VOID(frameNode);
910 uint32_t value = 0;
911 SwiperModelNG::SetIndex(frameNode, value);
912 }
913
SetSwiperIndicator(ArkUINodeHandle node,ArkUI_CharPtr indicatorStr)914 void SetSwiperIndicator(ArkUINodeHandle node, ArkUI_CharPtr indicatorStr)
915 {
916 auto* frameNode = reinterpret_cast<FrameNode*>(node);
917 CHECK_NULL_VOID(frameNode);
918 std::vector<std::string> res;
919 std::string indicatorValues = std::string(indicatorStr);
920 StringUtils::StringSplitter(indicatorValues, '|', res);
921 std::string type = res[INDICATOR_TYPE_INDEX];
922 if (type == "IndicatorComponentController") {
923 SwiperModelNG::SetBindIndicator(frameNode, true);
924 return;
925 }
926 if (type == "ArkDigitIndicator") {
927 SwiperModelNG::SetIndicatorIsBoolean(frameNode, false);
928 SwiperDigitalParameters digitalParameters = GetDigitIndicatorInfo(res);
929 SwiperModelNG::SetDigitIndicatorStyle(frameNode, digitalParameters);
930 SwiperModelNG::SetIndicatorType(frameNode, SwiperIndicatorType::DIGIT);
931 } else if (type == "ArkDotIndicator") {
932 SwiperModelNG::SetIndicatorIsBoolean(frameNode, false);
933 SwiperParameters swiperParameters = GetDotIndicatorInfo(frameNode, res);
934 SwiperModelNG::SetDotIndicatorStyle(frameNode, swiperParameters);
935 SwiperModelNG::SetIndicatorType(frameNode, SwiperIndicatorType::DOT);
936 } else {
937 SwiperParameters swiperParameters = GetDotIndicatorInfo(frameNode, res);
938 SwiperModelNG::SetDotIndicatorStyle(frameNode, swiperParameters);
939 SwiperModelNG::SetIndicatorType(frameNode, SwiperIndicatorType::DOT);
940 }
941 if (type == "boolean") {
942 int32_t indicator = StringUtils::StringToInt(res[INDICATOR_VALUE]);
943 bool showIndicator = indicator == 1 ? true : false;
944 SwiperModelNG::SetShowIndicator(frameNode, showIndicator);
945 } else {
946 SwiperModelNG::SetShowIndicator(frameNode, true);
947 }
948 }
949
ResetSwiperIndicator(ArkUINodeHandle node)950 void ResetSwiperIndicator(ArkUINodeHandle node)
951 {
952 auto* frameNode = reinterpret_cast<FrameNode*>(node);
953 CHECK_NULL_VOID(frameNode);
954 SwiperModelNG::ResetIndicatorStyle(frameNode);
955 SwiperModelNG::SetShowIndicator(frameNode, true);
956 }
957
SetSwiperDuration(ArkUINodeHandle node,ArkUI_Float32 duration)958 void SetSwiperDuration(ArkUINodeHandle node, ArkUI_Float32 duration)
959 {
960 auto* frameNode = reinterpret_cast<FrameNode*>(node);
961 CHECK_NULL_VOID(frameNode);
962 if (duration < 0) {
963 duration = DEFAULT_DURATION;
964 }
965 SwiperModelNG::SetDuration(frameNode, duration);
966 }
967
ResetSwiperDuration(ArkUINodeHandle node)968 void ResetSwiperDuration(ArkUINodeHandle node)
969 {
970 auto* frameNode = reinterpret_cast<FrameNode*>(node);
971 CHECK_NULL_VOID(frameNode);
972 uint32_t value = DEFAULT_DURATION;
973 SwiperModelNG::SetDuration(frameNode, value);
974 }
975
SetSwiperEnabled(ArkUINodeHandle node,ArkUI_Bool enabled)976 void SetSwiperEnabled(ArkUINodeHandle node, ArkUI_Bool enabled)
977 {
978 auto* frameNode = reinterpret_cast<FrameNode*>(node);
979 CHECK_NULL_VOID(frameNode);
980 SwiperModelNG::SetEnabled(frameNode, enabled);
981 }
982
ResetSwiperEnabled(ArkUINodeHandle node)983 void ResetSwiperEnabled(ArkUINodeHandle node)
984 {
985 auto* frameNode = reinterpret_cast<FrameNode*>(node);
986 CHECK_NULL_VOID(frameNode);
987 SwiperModelNG::SetEnabled(frameNode, false);
988 }
989
GetSwiperLoop(ArkUINodeHandle node)990 ArkUI_Int32 GetSwiperLoop(ArkUINodeHandle node)
991 {
992 auto* frameNode = reinterpret_cast<FrameNode*>(node);
993 CHECK_NULL_RETURN(frameNode, ERROR_INT_CODE);
994 return static_cast<ArkUI_Int32>(SwiperModelNG::GetLoop(frameNode));
995 }
996
GetSwiperAutoPlay(ArkUINodeHandle node)997 ArkUI_Int32 GetSwiperAutoPlay(ArkUINodeHandle node)
998 {
999 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1000 CHECK_NULL_RETURN(frameNode, ERROR_INT_CODE);
1001 return static_cast<ArkUI_Int32>(SwiperModelNG::GetAutoPlay(frameNode));
1002 }
1003
GetSwiperStopWhenTouched(ArkUINodeHandle node)1004 ArkUI_Int32 GetSwiperStopWhenTouched(ArkUINodeHandle node)
1005 {
1006 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1007 CHECK_NULL_RETURN(frameNode, ERROR_INT_CODE);
1008 return static_cast<ArkUI_Int32>(SwiperModelNG::GetAutoPlayOptions(frameNode).stopWhenTouched);
1009 }
1010
GetSwiperIndex(ArkUINodeHandle node)1011 ArkUI_Int32 GetSwiperIndex(ArkUINodeHandle node)
1012 {
1013 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1014 CHECK_NULL_RETURN(frameNode, ERROR_INT_CODE);
1015 return static_cast<ArkUI_Int32>(SwiperModelNG::GetIndex(frameNode));
1016 }
1017
GetSwiperVertical(ArkUINodeHandle node)1018 ArkUI_Int32 GetSwiperVertical(ArkUINodeHandle node)
1019 {
1020 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1021 CHECK_NULL_RETURN(frameNode, ERROR_INT_CODE);
1022 return static_cast<ArkUI_Int32>(SwiperModelNG::GetDirection(frameNode) == Axis::VERTICAL ? true : false);
1023 }
1024
GetSwiperDuration(ArkUINodeHandle node)1025 ArkUI_Float32 GetSwiperDuration(ArkUINodeHandle node)
1026 {
1027 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1028 CHECK_NULL_RETURN(frameNode, ERROR_INT_CODE);
1029 return static_cast<ArkUI_Float32>(SwiperModelNG::GetDuration(frameNode));
1030 }
1031
GetSwiperDisplayCount(ArkUINodeHandle node)1032 ArkUI_Int32 GetSwiperDisplayCount(ArkUINodeHandle node)
1033 {
1034 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1035 CHECK_NULL_RETURN(frameNode, ERROR_INT_CODE);
1036 return SwiperModelNG::GetDisplayCount(frameNode);
1037 }
1038
GetSwiperSwipeByGroup(ArkUINodeHandle node)1039 ArkUI_Int32 GetSwiperSwipeByGroup(ArkUINodeHandle node)
1040 {
1041 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1042 CHECK_NULL_RETURN(frameNode, ERROR_INT_CODE);
1043 return static_cast<ArkUI_Int32>(SwiperModelNG::GetSwipeByGroup(frameNode));
1044 }
1045
GetSwiperInterval(ArkUINodeHandle node)1046 ArkUI_Float32 GetSwiperInterval(ArkUINodeHandle node)
1047 {
1048 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1049 CHECK_NULL_RETURN(frameNode, ERROR_INT_CODE);
1050 return static_cast<ArkUI_Float32>(SwiperModelNG::GetAutoPlayInterval(frameNode));
1051 }
1052
findCurveIndex(const RefPtr<Curve> curve)1053 int32_t findCurveIndex(const RefPtr<Curve> curve)
1054 {
1055 CHECK_NULL_RETURN(curve, 0);
1056 auto iterator = std::find(CURVES.begin(), CURVES.end(), curve);
1057 if (iterator == CURVES.end()) {
1058 return 0;
1059 }
1060 return iterator - CURVES.begin();
1061 }
1062
GetSwiperCurve(ArkUINodeHandle node)1063 ArkUI_Int32 GetSwiperCurve(ArkUINodeHandle node)
1064 {
1065 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1066 CHECK_NULL_RETURN(frameNode, ERROR_INT_CODE);
1067 return findCurveIndex(SwiperModelNG::GetCurve(frameNode));
1068 }
1069
GetSwiperDisableSwipe(ArkUINodeHandle node)1070 ArkUI_Int32 GetSwiperDisableSwipe(ArkUINodeHandle node)
1071 {
1072 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1073 CHECK_NULL_RETURN(frameNode, ERROR_INT_CODE);
1074 return static_cast<ArkUI_Int32>(SwiperModelNG::GetDisableSwipe(frameNode));
1075 }
1076
GetSwiperItemSpace(ArkUINodeHandle node)1077 ArkUI_Float32 GetSwiperItemSpace(ArkUINodeHandle node)
1078 {
1079 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1080 CHECK_NULL_RETURN(frameNode, ERROR_INT_CODE);
1081 return SwiperModelNG::GetItemSpace(frameNode);
1082 }
1083
GetSwiperShowIndicator(ArkUINodeHandle node)1084 ArkUI_Int32 GetSwiperShowIndicator(ArkUINodeHandle node)
1085 {
1086 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1087 CHECK_NULL_RETURN(frameNode, ERROR_INT_CODE);
1088 return static_cast<ArkUI_Int32>(SwiperModelNG::GetShowIndicator(frameNode));
1089 }
1090
GetSwiperShowDisplayArrow(ArkUINodeHandle node)1091 ArkUI_Int32 GetSwiperShowDisplayArrow(ArkUINodeHandle node)
1092 {
1093 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1094 CHECK_NULL_RETURN(frameNode, ERROR_INT_CODE);
1095 return static_cast<ArkUI_Int32>(SwiperModelNG::GetShowDisplayArrow(frameNode));
1096 }
1097
SetSwiperArrowStyle(ArkUISwiperArrowStyle & arrowStyle,SwiperArrowParameters & swiperArrowParameters,RefPtr<SwiperIndicatorTheme> swiperIndicatorTheme)1098 void SetSwiperArrowStyle(ArkUISwiperArrowStyle& arrowStyle, SwiperArrowParameters& swiperArrowParameters,
1099 RefPtr<SwiperIndicatorTheme> swiperIndicatorTheme)
1100 {
1101 Dimension defaultBackGroundSize;
1102 Color defaultBackGroundColor;
1103 Dimension defaultArrowSize;
1104 if (arrowStyle.showSidebarMiddle.value) {
1105 defaultBackGroundSize = swiperIndicatorTheme->GetBigArrowBackgroundSize();
1106 defaultBackGroundColor = swiperIndicatorTheme->GetBigArrowBackgroundColor();
1107 defaultArrowSize = swiperIndicatorTheme->GetBigArrowSize();
1108 } else {
1109 defaultBackGroundSize = swiperIndicatorTheme->GetSmallArrowBackgroundSize();
1110 defaultBackGroundColor = swiperIndicatorTheme->GetSmallArrowBackgroundColor();
1111 defaultArrowSize = swiperIndicatorTheme->GetSmallArrowSize();
1112 }
1113 if (swiperArrowParameters.backgroundSize.has_value()) {
1114 arrowStyle.backgroundSize.value = swiperArrowParameters.backgroundSize.value().Value();
1115 arrowStyle.backgroundSize.isSet = 1;
1116 } else {
1117 arrowStyle.backgroundSize.value = defaultBackGroundSize.Value();
1118 }
1119 if (swiperArrowParameters.backgroundColor.has_value()) {
1120 arrowStyle.backgroundColor.value = swiperArrowParameters.backgroundColor.value().GetValue();
1121 arrowStyle.backgroundColor.isSet = 1;
1122 } else {
1123 arrowStyle.backgroundColor.value = defaultBackGroundColor.GetValue();
1124 }
1125 if (swiperArrowParameters.arrowSize.has_value()) {
1126 arrowStyle.arrowSize.value = swiperArrowParameters.arrowSize.value().Value();
1127 arrowStyle.arrowSize.isSet = 1;
1128 } else {
1129 arrowStyle.arrowSize.value = defaultArrowSize.Value();
1130 }
1131 if (swiperArrowParameters.arrowColor.has_value()) {
1132 arrowStyle.arrowColor.value = swiperArrowParameters.arrowColor.value().GetValue();
1133 arrowStyle.arrowColor.isSet = 1;
1134 } else {
1135 arrowStyle.arrowColor.value = 0x00182431;
1136 }
1137 }
1138
GetSwiperArrowStyle(ArkUINodeHandle node)1139 ArkUISwiperArrowStyle GetSwiperArrowStyle(ArkUINodeHandle node)
1140 {
1141 ArkUISwiperArrowStyle arrowStyle;
1142 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1143 CHECK_NULL_RETURN(frameNode, arrowStyle);
1144 SwiperArrowParameters swiperArrowParameters = SwiperModelNG::GetArrowStyle(frameNode);
1145 auto pipelineContext = PipelineBase::GetCurrentContext();
1146 CHECK_NULL_RETURN(pipelineContext, arrowStyle);
1147 auto swiperIndicatorTheme = pipelineContext->GetTheme<SwiperIndicatorTheme>();
1148 CHECK_NULL_RETURN(swiperIndicatorTheme, arrowStyle);
1149 if (swiperArrowParameters.isShowBackground.has_value()) {
1150 arrowStyle.showBackground.value = swiperArrowParameters.isShowBackground.value();
1151 arrowStyle.showBackground.isSet = 1;
1152 } else {
1153 arrowStyle.showBackground.value = 0;
1154 }
1155 if (swiperArrowParameters.isSidebarMiddle.has_value()) {
1156 arrowStyle.showSidebarMiddle.value = swiperArrowParameters.isSidebarMiddle.value();
1157 arrowStyle.showSidebarMiddle.isSet = 1;
1158 } else {
1159 arrowStyle.showSidebarMiddle.value = 0;
1160 }
1161
1162 SetSwiperArrowStyle(arrowStyle, swiperArrowParameters, swiperIndicatorTheme);
1163 return arrowStyle;
1164 }
1165
GetSwiperEffectMode(ArkUINodeHandle node)1166 ArkUI_Int32 GetSwiperEffectMode(ArkUINodeHandle node)
1167 {
1168 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1169 CHECK_NULL_RETURN(frameNode, ERROR_INT_CODE);
1170 return static_cast<ArkUI_Int32>(SwiperModelNG::GetEffectMode(frameNode));
1171 }
1172
GetSwiperDisplayMode(ArkUINodeHandle node)1173 ArkUI_CharPtr GetSwiperDisplayMode(ArkUINodeHandle node)
1174 {
1175 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1176 CHECK_NULL_RETURN(frameNode, "");
1177 auto type = "";
1178 if (SwiperModelNG::GetDisplayMode(frameNode) == SwiperDisplayMode::AUTO_LINEAR) {
1179 type = "auto";
1180 }
1181
1182 return type;
1183 }
1184
SetNodeAdapter(ArkUINodeHandle node,ArkUINodeAdapterHandle handle)1185 ArkUI_Int32 SetNodeAdapter(ArkUINodeHandle node, ArkUINodeAdapterHandle handle)
1186 {
1187 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1188 CHECK_NULL_RETURN(frameNode, ERROR_CODE_PARAM_INVALID);
1189 auto totalChildCount = SwiperModelNG::RealTotalCount(frameNode);
1190 if (totalChildCount > 0) {
1191 return ERROR_CODE_NATIVE_IMPL_NODE_ADAPTER_CHILD_NODE_EXIST;
1192 }
1193 NodeAdapter::GetNodeAdapterAPI()->attachHostNode(handle, node);
1194 return ERROR_CODE_NO_ERROR;
1195 }
1196
ResetNodeAdapter(ArkUINodeHandle node)1197 void ResetNodeAdapter(ArkUINodeHandle node)
1198 {
1199 NodeAdapter::GetNodeAdapterAPI()->detachHostNode(node);
1200 }
1201
GetNodeAdapter(ArkUINodeHandle node)1202 ArkUINodeAdapterHandle GetNodeAdapter(ArkUINodeHandle node)
1203 {
1204 return NodeAdapter::GetNodeAdapterAPI()->getNodeAdapter(node);
1205 }
1206
GetCachedCount(ArkUINodeHandle node)1207 ArkUI_Int32 GetCachedCount(ArkUINodeHandle node)
1208 {
1209 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1210 CHECK_NULL_RETURN(frameNode, 1);
1211 return SwiperModelNG::GetCachedCount(frameNode);
1212 }
1213
SetSwiperNestedScroll(ArkUINodeHandle node,ArkUI_Int32 (* values)[1])1214 void SetSwiperNestedScroll(ArkUINodeHandle node, ArkUI_Int32 (*values)[1])
1215 {
1216 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1217 CHECK_NULL_VOID(frameNode);
1218 SwiperModelNG::SetNestedScroll(frameNode, (*values)[0]);
1219 }
1220
ResetSwiperNestedScroll(ArkUINodeHandle node)1221 void ResetSwiperNestedScroll(ArkUINodeHandle node)
1222 {
1223 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1224 CHECK_NULL_VOID(frameNode);
1225 SwiperModelNG::SetNestedScroll(frameNode, 0);
1226 }
1227
GetSwiperNestedScroll(ArkUINodeHandle node)1228 ArkUI_Int32 GetSwiperNestedScroll(ArkUINodeHandle node)
1229 {
1230 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1231 CHECK_NULL_RETURN(frameNode, ERROR_CODE_PARAM_INVALID);
1232 return SwiperModelNG::GetNestedScroll(frameNode);
1233 }
1234
SetSwiperToIndex(ArkUINodeHandle node,ArkUI_Int32 (* values)[2])1235 void SetSwiperToIndex(ArkUINodeHandle node, ArkUI_Int32 (*values)[2])
1236 {
1237 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1238 CHECK_NULL_VOID(frameNode);
1239 SwiperModelNG::SetSwiperToIndex(frameNode, (*values)[0], (*values)[1]);
1240 }
1241
GetSwiperPrevMargin(ArkUINodeHandle node,ArkUI_Int32 unit,ArkUISwiperMarginOptions * options)1242 void GetSwiperPrevMargin(ArkUINodeHandle node, ArkUI_Int32 unit, ArkUISwiperMarginOptions* options)
1243 {
1244 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1245 CHECK_NULL_VOID(frameNode);
1246 CHECK_NULL_VOID(options);
1247 SwiperMarginOptions marginOptions;
1248 SwiperModelNG::GetPreviousMargin(frameNode, unit, &marginOptions);
1249 options->margin = static_cast<ArkUI_Float32>(marginOptions.margin);
1250 options->ignoreBlank = static_cast<ArkUI_Bool>(marginOptions.ignoreBlank);
1251 }
1252
GetSwiperMinSize(ArkUINodeHandle node)1253 ArkUI_Float32 GetSwiperMinSize(ArkUINodeHandle node)
1254 {
1255 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1256 CHECK_NULL_RETURN(frameNode, ERROR_INT_CODE);
1257 return SwiperModelNG::GetMinSize(frameNode);
1258 }
1259
GetSwiperNextMargin(ArkUINodeHandle node,ArkUI_Int32 unit,ArkUISwiperMarginOptions * options)1260 void GetSwiperNextMargin(ArkUINodeHandle node, ArkUI_Int32 unit, ArkUISwiperMarginOptions* options)
1261 {
1262 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1263 CHECK_NULL_VOID(frameNode);
1264 CHECK_NULL_VOID(options);
1265 SwiperMarginOptions marginOptions;
1266 SwiperModelNG::GetNextMargin(frameNode, unit, &marginOptions);
1267 options->margin = static_cast<ArkUI_Float32>(marginOptions.margin);
1268 options->ignoreBlank = static_cast<ArkUI_Bool>(marginOptions.ignoreBlank);
1269 }
1270
SetSwiperIndicatorStyle(ArkUINodeHandle node,ArkUISwiperIndicator * indicator)1271 void SetSwiperIndicatorStyle(ArkUINodeHandle node, ArkUISwiperIndicator* indicator)
1272 {
1273 CHECK_NULL_VOID(indicator);
1274 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1275 CHECK_NULL_VOID(frameNode);
1276 if (indicator->type == ArkUISwiperIndicatorType::DOT) {
1277 SwiperModelNG::SetIndicatorIsBoolean(frameNode, false);
1278 SwiperParameters swiperParameters = GetDotIndicatorProps(frameNode, indicator);
1279 SwiperModelNG::SetDotIndicatorStyle(frameNode, swiperParameters);
1280 SwiperModelNG::SetIndicatorType(frameNode, SwiperIndicatorType::DOT);
1281 }
1282 SwiperModelNG::SetShowIndicator(frameNode, true);
1283 }
1284
GetSwiperIndicator(ArkUINodeHandle node,ArkUISwiperIndicator * props)1285 void GetSwiperIndicator(ArkUINodeHandle node, ArkUISwiperIndicator* props)
1286 {
1287 CHECK_NULL_VOID(props);
1288 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1289 CHECK_NULL_VOID(frameNode);
1290 int32_t type = SwiperModelNG::GetIndicatorType(frameNode);
1291 props->type = static_cast<ArkUISwiperIndicatorType>(type);
1292 auto params = SwiperModelNG::GetDotIndicator(frameNode);
1293 CHECK_NULL_VOID(params);
1294 bool hasValue = false;
1295 float value = ZERO_F;
1296 ParseIndicatorAttribute(params->dimLeft, hasValue, value);
1297 props->dimLeft = ArkUIOptionalFloat { hasValue, value };
1298 ParseIndicatorAttribute(params->dimTop, hasValue, value);
1299 props->dimTop = ArkUIOptionalFloat { hasValue, value };
1300 ParseIndicatorAttribute(params->dimRight, hasValue, value);
1301 props->dimRight = ArkUIOptionalFloat { hasValue, value };
1302 ParseIndicatorAttribute(params->dimBottom, hasValue, value);
1303 props->dimBottom = ArkUIOptionalFloat { hasValue, value };
1304 props->ignoreSizeValue = ArkUIOptionalInt { 1, params->ignoreSizeValue.value_or(0) };
1305 if (props->type == ArkUISwiperIndicatorType::DOT) {
1306 props->type = ArkUISwiperIndicatorType::DOT;
1307 ParseIndicatorAttribute(params->itemWidth, hasValue, value);
1308 props->itemWidth = ArkUIOptionalFloat { hasValue, value };
1309 ParseIndicatorAttribute(params->itemHeight, hasValue, value);
1310 props->itemHeight = ArkUIOptionalFloat { hasValue, value };
1311 ParseIndicatorAttribute(params->selectedItemWidth, hasValue, value);
1312 props->selectedItemWidth = ArkUIOptionalFloat { hasValue, value };
1313 ParseIndicatorAttribute(params->selectedItemHeight, hasValue, value);
1314 props->selectedItemHeight = ArkUIOptionalFloat { hasValue, value };
1315 props->maskValue = ArkUIOptionalInt { 1, params->maskValue.value_or(0) };
1316 props->colorValue = ArkUIOptionalUint { 1, params->colorVal.value().GetValue() };
1317 props->selectedColorValue = ArkUIOptionalUint { 1, params->selectedColorVal.value().GetValue() };
1318 props->maxDisplayCount = ArkUIOptionalInt { 1, params->maxDisplayCountVal.value() };
1319 ParseIndicatorAttribute(params->dimSpace, hasValue, value);
1320 props->dimSpace = ArkUIOptionalFloat { hasValue, value };
1321 }
1322 }
1323
SetSwiperDigitIndicatorStyle(ArkUINodeHandle node,ArkUISwiperDigitIndicator * indicator)1324 void SetSwiperDigitIndicatorStyle(ArkUINodeHandle node, ArkUISwiperDigitIndicator* indicator)
1325 {
1326 CHECK_NULL_VOID(indicator);
1327 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1328 CHECK_NULL_VOID(frameNode);
1329 if (indicator->type == ArkUISwiperIndicatorType::DIGIT) {
1330 SwiperModelNG::SetIndicatorIsBoolean(frameNode, false);
1331 SwiperDigitalParameters swiperDigitParameters = GetDigitIndicatorProps(frameNode, indicator);
1332 SwiperModelNG::SetDigitIndicatorStyle(frameNode, swiperDigitParameters);
1333 SwiperModelNG::SetIndicatorType(frameNode, SwiperIndicatorType::DIGIT);
1334 }
1335 SwiperModelNG::SetShowIndicator(frameNode, true);
1336 }
1337
GetSwiperDigitIndicator(ArkUINodeHandle node,ArkUISwiperDigitIndicator * props)1338 void GetSwiperDigitIndicator(ArkUINodeHandle node, ArkUISwiperDigitIndicator* props)
1339 {
1340 CHECK_NULL_VOID(props);
1341 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1342 CHECK_NULL_VOID(frameNode);
1343 int32_t type = SwiperModelNG::GetIndicatorType(frameNode);
1344 props->type = static_cast<ArkUISwiperIndicatorType>(type);
1345 auto params = SwiperModelNG::GetDigitIndicator(frameNode);
1346 CHECK_NULL_VOID(params);
1347 bool hasValue = false;
1348 float value = ZERO_F;
1349 ParseIndicatorAttribute(params->dimLeft, hasValue, value);
1350 props->dimLeft = ArkUIOptionalFloat { hasValue, value };
1351 ParseIndicatorAttribute(params->dimTop, hasValue, value);
1352 props->dimTop = ArkUIOptionalFloat { hasValue, value };
1353 ParseIndicatorAttribute(params->dimRight, hasValue, value);
1354 props->dimRight = ArkUIOptionalFloat { hasValue, value };
1355 ParseIndicatorAttribute(params->dimBottom, hasValue, value);
1356 props->dimBottom = ArkUIOptionalFloat { hasValue, value };
1357 props->ignoreSizeValue = ArkUIOptionalInt { 1, params->ignoreSizeValue.value_or(0) };
1358 if (props->type == ArkUISwiperIndicatorType::DIGIT) {
1359 props->fontColor = ArkUIOptionalUint { 1, params->fontColor.value().GetValue() };
1360 props->selectedFontColor = ArkUIOptionalUint { 1, params->selectedFontColor.value().GetValue() };
1361 ParseIndicatorAttribute(params->fontSize, hasValue, value);
1362 props->fontSize = ArkUIOptionalFloat { hasValue, value };
1363 ParseIndicatorAttribute(params->selectedFontSize, hasValue, value);
1364 props->selectedFontSize = ArkUIOptionalFloat { hasValue, value };
1365 props->fontWeight = ArkUIOptionalUint { 1, static_cast<ArkUI_Uint32>(params->fontWeight.value()) };
1366 props->selectedFontWeight =
1367 ArkUIOptionalUint { 1, static_cast<ArkUI_Uint32>(params->selectedFontWeight.value()) };
1368 }
1369 }
1370
GetSwiperController(ArkUINodeHandle node)1371 ArkUINodeHandle GetSwiperController(ArkUINodeHandle node)
1372 {
1373 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1374 CHECK_NULL_RETURN(frameNode, nullptr);
1375 auto controller = SwiperModelNG::GetSwiperController(frameNode);
1376 CHECK_NULL_RETURN(controller, nullptr);
1377 auto nodecontroller = reinterpret_cast<ArkUINodeHandle>(OHOS::Ace::AceType::RawPtr(controller));
1378 return nodecontroller;
1379 }
1380
SetSwiperOnChange(ArkUINodeHandle node,void * callback)1381 void SetSwiperOnChange(ArkUINodeHandle node, void* callback)
1382 {
1383 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1384 CHECK_NULL_VOID(frameNode);
1385 if (callback) {
1386 auto onEvent = reinterpret_cast<std::function<void(const BaseEventInfo*)>*>(callback);
1387 SwiperModelNG::SetOnChange(frameNode, std::move(*onEvent));
1388 } else {
1389 SwiperModelNG::SetOnChange(frameNode, nullptr);
1390 }
1391 }
1392
ResetSwiperOnChange(ArkUINodeHandle node)1393 void ResetSwiperOnChange(ArkUINodeHandle node)
1394 {
1395 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1396 CHECK_NULL_VOID(frameNode);
1397 SwiperModelNG::SetOnChange(frameNode, nullptr);
1398 }
1399
SetSwiperOnSelected(ArkUINodeHandle node,void * callback)1400 void SetSwiperOnSelected(ArkUINodeHandle node, void* callback)
1401 {
1402 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1403 CHECK_NULL_VOID(frameNode);
1404 if (callback) {
1405 auto onEvent = reinterpret_cast<std::function<void(const BaseEventInfo*)>*>(callback);
1406 SwiperModelNG::SetOnSelected(frameNode, std::move(*onEvent));
1407 } else {
1408 SwiperModelNG::SetOnSelected(frameNode, nullptr);
1409 }
1410 }
1411
ResetSwiperOnSelected(ArkUINodeHandle node)1412 void ResetSwiperOnSelected(ArkUINodeHandle node)
1413 {
1414 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1415 CHECK_NULL_VOID(frameNode);
1416 SwiperModelNG::SetOnSelected(frameNode, nullptr);
1417 }
1418
SetSwiperOnUnselected(ArkUINodeHandle node,void * callback)1419 void SetSwiperOnUnselected(ArkUINodeHandle node, void* callback)
1420 {
1421 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1422 CHECK_NULL_VOID(frameNode);
1423 if (callback) {
1424 auto onEvent = reinterpret_cast<std::function<void(const BaseEventInfo*)>*>(callback);
1425 SwiperModelNG::SetOnUnselected(frameNode, std::move(*onEvent));
1426 } else {
1427 SwiperModelNG::SetOnUnselected(frameNode, nullptr);
1428 }
1429 }
1430
ResetSwiperOnUnselected(ArkUINodeHandle node)1431 void ResetSwiperOnUnselected(ArkUINodeHandle node)
1432 {
1433 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1434 CHECK_NULL_VOID(frameNode);
1435 SwiperModelNG::SetOnUnselected(frameNode, nullptr);
1436 }
1437
SetSwiperOnAnimationStart(ArkUINodeHandle node,void * callback)1438 void SetSwiperOnAnimationStart(ArkUINodeHandle node, void* callback)
1439 {
1440 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1441 CHECK_NULL_VOID(frameNode);
1442 if (callback) {
1443 auto onEvent = reinterpret_cast<std::function<void(int32_t, int32_t, const AnimationCallbackInfo&)>*>(callback);
1444 SwiperModelNG::SetOnAnimationStart(frameNode, std::move(*onEvent));
1445 } else {
1446 SwiperModelNG::SetOnAnimationStart(frameNode, nullptr);
1447 }
1448 }
1449
ResetSwiperOnAnimationStart(ArkUINodeHandle node)1450 void ResetSwiperOnAnimationStart(ArkUINodeHandle node)
1451 {
1452 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1453 CHECK_NULL_VOID(frameNode);
1454 SwiperModelNG::SetOnAnimationStart(frameNode, nullptr);
1455 }
1456
SetSwiperOnAnimationEnd(ArkUINodeHandle node,void * callback)1457 void SetSwiperOnAnimationEnd(ArkUINodeHandle node, void* callback)
1458 {
1459 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1460 CHECK_NULL_VOID(frameNode);
1461 if (callback) {
1462 auto onEvent = reinterpret_cast<std::function<void(int32_t, const AnimationCallbackInfo&)>*>(callback);
1463 SwiperModelNG::SetOnAnimationEnd(frameNode, std::move(*onEvent));
1464 } else {
1465 SwiperModelNG::SetOnAnimationEnd(frameNode, nullptr);
1466 }
1467 }
1468
ResetSwiperOnAnimationEnd(ArkUINodeHandle node)1469 void ResetSwiperOnAnimationEnd(ArkUINodeHandle node)
1470 {
1471 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1472 CHECK_NULL_VOID(frameNode);
1473 SwiperModelNG::SetOnAnimationEnd(frameNode, nullptr);
1474 }
1475
SetSwiperOnGestureSwipe(ArkUINodeHandle node,void * callback)1476 void SetSwiperOnGestureSwipe(ArkUINodeHandle node, void* callback)
1477 {
1478 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1479 CHECK_NULL_VOID(frameNode);
1480 if (callback) {
1481 auto onEvent = reinterpret_cast<std::function<void(int32_t, const AnimationCallbackInfo&)>*>(callback);
1482 SwiperModelNG::SetOnGestureSwipe(frameNode, std::move(*onEvent));
1483 } else {
1484 SwiperModelNG::SetOnGestureSwipe(frameNode, nullptr);
1485 }
1486 }
1487
ResetSwiperOnGestureSwipe(ArkUINodeHandle node)1488 void ResetSwiperOnGestureSwipe(ArkUINodeHandle node)
1489 {
1490 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1491 CHECK_NULL_VOID(frameNode);
1492 SwiperModelNG::SetOnGestureSwipe(frameNode, nullptr);
1493 }
1494
SetOnContentDidScroll(ArkUINodeHandle node,void * callback)1495 void SetOnContentDidScroll(ArkUINodeHandle node, void* callback)
1496 {
1497 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1498 CHECK_NULL_VOID(frameNode);
1499 if (callback) {
1500 auto onEvent = reinterpret_cast<std::function<void(int32_t, int32_t, float, float)>*>(callback);
1501 SwiperModelNG::SetOnContentDidScroll(frameNode, std::move(*onEvent));
1502 } else {
1503 SwiperModelNG::SetOnContentDidScroll(frameNode, nullptr);
1504 }
1505 }
1506
ResetOnContentDidScroll(ArkUINodeHandle node)1507 void ResetOnContentDidScroll(ArkUINodeHandle node)
1508 {
1509 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1510 CHECK_NULL_VOID(frameNode);
1511 SwiperModelNG::SetOnContentDidScroll(frameNode, nullptr);
1512 }
1513
SetSwiperPageFlipMode(ArkUINodeHandle node,ArkUI_Int32 pageFlipMode)1514 void SetSwiperPageFlipMode(ArkUINodeHandle node, ArkUI_Int32 pageFlipMode)
1515 {
1516 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1517 CHECK_NULL_VOID(frameNode);
1518 SwiperModelNG::SetPageFlipMode(frameNode, pageFlipMode);
1519 }
1520
ResetSwiperPageFlipMode(ArkUINodeHandle node)1521 void ResetSwiperPageFlipMode(ArkUINodeHandle node)
1522 {
1523 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1524 CHECK_NULL_VOID(frameNode);
1525 SwiperModelNG::SetPageFlipMode(frameNode, NUM_0);
1526 }
1527
GetSwiperSwiperPageFlipMode(ArkUINodeHandle node)1528 ArkUI_Int32 GetSwiperSwiperPageFlipMode(ArkUINodeHandle node)
1529 {
1530 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1531 CHECK_NULL_RETURN(frameNode, ERROR_CODE_PARAM_INVALID);
1532 return SwiperModelNG::GetPageFlipMode(frameNode);
1533 }
1534
SetSwiperOnContentWillScroll(ArkUINodeHandle node,bool * callback)1535 void SetSwiperOnContentWillScroll(ArkUINodeHandle node, bool* callback)
1536 {
1537 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1538 CHECK_NULL_VOID(frameNode);
1539 if (callback) {
1540 auto onEvent = reinterpret_cast<std::function<bool(const SwiperContentWillScrollResult&)>*>(callback);
1541 SwiperModelNG::SetOnContentWillScroll(frameNode, std::move(*onEvent));
1542 } else {
1543 SwiperModelNG::SetOnContentWillScroll(frameNode, nullptr);
1544 }
1545 }
1546
ResetSwiperOnContentWillScroll(ArkUINodeHandle node)1547 void ResetSwiperOnContentWillScroll(ArkUINodeHandle node)
1548 {
1549 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1550 CHECK_NULL_VOID(frameNode);
1551 SwiperModelNG::SetOnContentWillScroll(frameNode, nullptr);
1552 }
1553
GetIndicatorType(ArkUINodeHandle node)1554 ArkUISwiperIndicatorType GetIndicatorType(ArkUINodeHandle node)
1555 {
1556 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1557 CHECK_NULL_RETURN(frameNode, ArkUISwiperIndicatorType::DOT);
1558 return static_cast<ArkUISwiperIndicatorType>(SwiperModelNG::GetIndicatorType(frameNode));
1559 }
1560 } // namespace
1561
1562 namespace NodeModifier {
GetSwiperModifier()1563 const ArkUISwiperModifier* GetSwiperModifier()
1564 {
1565 CHECK_INITIALIZED_FIELDS_BEGIN(); // don't move this line
1566 static const ArkUISwiperModifier modifier = {
1567 .setSwiperNextMargin = SetSwiperNextMargin,
1568 .resetSwiperNextMargin = ResetSwiperNextMargin,
1569 .setSwiperPrevMargin = SetSwiperPrevMargin,
1570 .resetSwiperPrevMargin = ResetSwiperPrevMargin,
1571 .setSwiperDisplayCount = SetSwiperDisplayCount,
1572 .resetSwiperDisplayCount = ResetSwiperDisplayCount,
1573 .setSwiperSwipeByGroup = SetSwiperSwipeByGroup,
1574 .resetSwiperSwipeByGroup = ResetSwiperSwipeByGroup,
1575 .setSwiperDisplayArrow = SetSwiperDisplayArrow,
1576 .resetSwiperDisplayArrow = ResetSwiperDisplayArrow,
1577 .setSwiperCurve = SetSwiperCurve,
1578 .resetSwiperCurve = ResetSwiperCurve,
1579 .setSwiperDisableSwipe = SetSwiperDisableSwipe,
1580 .resetSwiperDisableSwipe = ResetSwiperDisableSwipe,
1581 .setSwiperEffectMode = SetSwiperEffectMode,
1582 .resetSwiperEffectMode = ResetSwiperEffectMode,
1583 .setSwiperCachedCount = SetSwiperCachedCount,
1584 .resetSwiperCachedCount = ResetSwiperCachedCount,
1585 .setSwiperIsShown = SetSwiperIsShown,
1586 .resetSwiperIsShown = ResetSwiperIsShown,
1587 .setSwiperDisplayMode = SetSwiperDisplayMode,
1588 .resetSwiperDisplayMode = ResetSwiperDisplayMode,
1589 .setSwiperItemSpace = SetSwiperItemSpace,
1590 .resetSwiperItemSpace = ResetSwiperItemSpace,
1591 .setSwiperVertical = SetSwiperVertical,
1592 .resetSwiperVertical = ResetSwiperVertical,
1593 .setSwiperLoop = SetSwiperLoop,
1594 .resetSwiperLoop = ResetSwiperLoop,
1595 .setSwiperInterval = SetSwiperInterval,
1596 .resetSwiperInterval = ResetSwiperInterval,
1597 .setSwiperAutoPlay = SetSwiperAutoPlay,
1598 .resetSwiperAutoPlay = ResetSwiperAutoPlay,
1599 .setSwiperStopWhenTouched = SetSwiperStopWhenTouched,
1600 .resetSwiperStopWhenTouched = ResetSwiperStopWhenTouched,
1601 .setSwiperIndex = SetSwiperIndex,
1602 .resetSwiperIndex = ResetSwiperIndex,
1603 .setSwiperIndicator = SetSwiperIndicator,
1604 .resetSwiperIndicator = ResetSwiperIndicator,
1605 .setSwiperDuration = SetSwiperDuration,
1606 .resetSwiperDuration = ResetSwiperDuration,
1607 .setSwiperEnabled = SetSwiperEnabled,
1608 .resetSwiperEnabled = ResetSwiperEnabled,
1609 .getSwiperLoop = GetSwiperLoop,
1610 .getSwiperAutoPlay = GetSwiperAutoPlay,
1611 .getSwiperStopWhenTouched = GetSwiperStopWhenTouched,
1612 .getSwiperIndex = GetSwiperIndex,
1613 .getSwiperVertical = GetSwiperVertical,
1614 .getSwiperDuration = GetSwiperDuration,
1615 .getSwiperDisplayCount = GetSwiperDisplayCount,
1616 .getSwiperCachedIsShown = GetSwiperCachedIsShown,
1617 .getSwiperInterval = GetSwiperInterval,
1618 .getSwiperCurve = GetSwiperCurve,
1619 .getSwiperDisableSwipe = GetSwiperDisableSwipe,
1620 .getSwiperItemSpace = GetSwiperItemSpace,
1621 .getSwiperShowIndicator = GetSwiperShowIndicator,
1622 .getSwiperShowDisplayArrow = GetSwiperShowDisplayArrow,
1623 .getSwiperEffectMode = GetSwiperEffectMode,
1624 .setIndicatorInteractive = SetIndicatorInteractive,
1625 .resetIndicatorInteractive = ResetIndicatorInteractive,
1626 .setNodeAdapter = SetNodeAdapter,
1627 .resetNodeAdapter = ResetNodeAdapter,
1628 .getNodeAdapter = GetNodeAdapter,
1629 .getCachedCount = GetCachedCount,
1630 .setSwiperNestedScroll = SetSwiperNestedScroll,
1631 .resetSwiperNestedScroll = ResetSwiperNestedScroll,
1632 .getSwiperNestedScroll = GetSwiperNestedScroll,
1633 .setSwiperToIndex = SetSwiperToIndex,
1634 .getSwiperPrevMargin = GetSwiperPrevMargin,
1635 .getSwiperNextMargin = GetSwiperNextMargin,
1636 .setSwiperIndicatorStyle = SetSwiperIndicatorStyle,
1637 .getSwiperIndicator = GetSwiperIndicator,
1638 .getSwiperController = GetSwiperController,
1639 .setSwiperOnChange = SetSwiperOnChange,
1640 .resetSwiperOnChange = ResetSwiperOnChange,
1641 .setSwiperOnUnselected = SetSwiperOnUnselected,
1642 .resetSwiperOnUnselected = ResetSwiperOnUnselected,
1643 .setSwiperOnAnimationStart = SetSwiperOnAnimationStart,
1644 .resetSwiperOnAnimationStart = ResetSwiperOnAnimationStart,
1645 .setSwiperOnAnimationEnd = SetSwiperOnAnimationEnd,
1646 .resetSwiperOnAnimationEnd = ResetSwiperOnAnimationEnd,
1647 .setSwiperOnGestureSwipe = SetSwiperOnGestureSwipe,
1648 .resetSwiperOnGestureSwipe = ResetSwiperOnGestureSwipe,
1649 .setSwiperOnContentDidScroll = SetOnContentDidScroll,
1650 .resetSwiperOnContentDidScroll = ResetOnContentDidScroll,
1651 .getIndicatorInteractive = GetIndicatorInteractive,
1652 .setSwiperPageFlipMode = SetSwiperPageFlipMode,
1653 .resetSwiperPageFlipMode = ResetSwiperPageFlipMode,
1654 .getSwiperPageFlipMode = GetSwiperSwiperPageFlipMode,
1655 .setSwiperOnContentWillScroll = SetSwiperOnContentWillScroll,
1656 .resetSwiperOnContentWillScroll = ResetSwiperOnContentWillScroll,
1657 .setSwiperOnSelected = SetSwiperOnSelected,
1658 .resetSwiperOnSelected = ResetSwiperOnSelected,
1659 .setSwiperMinSize = SetSwiperMinSize,
1660 .resetSwiperMinSize = ResetSwiperMinSize,
1661 .getSwiperMinSize = GetSwiperMinSize,
1662 .setSwiperDigitIndicatorStyle = SetSwiperDigitIndicatorStyle,
1663 .getSwiperDigitIndicator = GetSwiperDigitIndicator,
1664 .getIndicatorType = GetIndicatorType,
1665 .getSwiperSwipeByGroup = GetSwiperSwipeByGroup,
1666 .getSwiperDisplayMode = GetSwiperDisplayMode,
1667 .getSwiperArrowStyle = GetSwiperArrowStyle,
1668 };
1669 CHECK_INITIALIZED_FIELDS_END(modifier, 0, 0, 0); // don't move this line
1670 return &modifier;
1671 }
1672
GetCJUISwiperModifier()1673 const CJUISwiperModifier* GetCJUISwiperModifier()
1674 {
1675 CHECK_INITIALIZED_FIELDS_BEGIN(); // don't move this line
1676 static const CJUISwiperModifier modifier = {
1677 .setSwiperNextMargin = SetSwiperNextMargin,
1678 .resetSwiperNextMargin = ResetSwiperNextMargin,
1679 .setSwiperPrevMargin = SetSwiperPrevMargin,
1680 .resetSwiperPrevMargin = ResetSwiperPrevMargin,
1681 .setSwiperDisplayCount = SetSwiperDisplayCount,
1682 .resetSwiperDisplayCount = ResetSwiperDisplayCount,
1683 .setSwiperSwipeByGroup = SetSwiperSwipeByGroup,
1684 .resetSwiperSwipeByGroup = ResetSwiperSwipeByGroup,
1685 .setSwiperDisplayArrow = SetSwiperDisplayArrow,
1686 .resetSwiperDisplayArrow = ResetSwiperDisplayArrow,
1687 .setSwiperCurve = SetSwiperCurve,
1688 .resetSwiperCurve = ResetSwiperCurve,
1689 .setSwiperDisableSwipe = SetSwiperDisableSwipe,
1690 .resetSwiperDisableSwipe = ResetSwiperDisableSwipe,
1691 .setSwiperEffectMode = SetSwiperEffectMode,
1692 .resetSwiperEffectMode = ResetSwiperEffectMode,
1693 .setSwiperCachedCount = SetSwiperCachedCount,
1694 .resetSwiperCachedCount = ResetSwiperCachedCount,
1695 .setSwiperDisplayMode = SetSwiperDisplayMode,
1696 .resetSwiperDisplayMode = ResetSwiperDisplayMode,
1697 .setSwiperItemSpace = SetSwiperItemSpace,
1698 .resetSwiperItemSpace = ResetSwiperItemSpace,
1699 .setSwiperVertical = SetSwiperVertical,
1700 .resetSwiperVertical = ResetSwiperVertical,
1701 .setSwiperLoop = SetSwiperLoop,
1702 .resetSwiperLoop = ResetSwiperLoop,
1703 .setSwiperInterval = SetSwiperInterval,
1704 .resetSwiperInterval = ResetSwiperInterval,
1705 .setSwiperAutoPlay = SetSwiperAutoPlay,
1706 .resetSwiperAutoPlay = ResetSwiperAutoPlay,
1707 .setSwiperStopWhenTouched = SetSwiperStopWhenTouched,
1708 .resetSwiperStopWhenTouched = ResetSwiperStopWhenTouched,
1709 .setSwiperIndex = SetSwiperIndex,
1710 .resetSwiperIndex = ResetSwiperIndex,
1711 .setSwiperIndicator = SetSwiperIndicator,
1712 .resetSwiperIndicator = ResetSwiperIndicator,
1713 .setSwiperDuration = SetSwiperDuration,
1714 .resetSwiperDuration = ResetSwiperDuration,
1715 .setSwiperEnabled = SetSwiperEnabled,
1716 .resetSwiperEnabled = ResetSwiperEnabled,
1717 .getSwiperLoop = GetSwiperLoop,
1718 .getSwiperAutoPlay = GetSwiperAutoPlay,
1719 .getSwiperStopWhenTouched = GetSwiperStopWhenTouched,
1720 .getSwiperIndex = GetSwiperIndex,
1721 .getSwiperVertical = GetSwiperVertical,
1722 .getSwiperDuration = GetSwiperDuration,
1723 .getSwiperDisplayCount = GetSwiperDisplayCount,
1724 .getSwiperInterval = GetSwiperInterval,
1725 .getSwiperCurve = GetSwiperCurve,
1726 .getSwiperDisableSwipe = GetSwiperDisableSwipe,
1727 .getSwiperItemSpace = GetSwiperItemSpace,
1728 .getSwiperShowIndicator = GetSwiperShowIndicator,
1729 .getSwiperShowDisplayArrow = GetSwiperShowDisplayArrow,
1730 .getSwiperEffectMode = GetSwiperEffectMode,
1731 .setIndicatorInteractive = SetIndicatorInteractive,
1732 .resetIndicatorInteractive = ResetIndicatorInteractive,
1733 .setNodeAdapter = SetNodeAdapter,
1734 .resetNodeAdapter = ResetNodeAdapter,
1735 .getNodeAdapter = GetNodeAdapter,
1736 .getCachedCount = GetCachedCount,
1737 .setSwiperNestedScroll = SetSwiperNestedScroll,
1738 .resetSwiperNestedScroll = ResetSwiperNestedScroll,
1739 .getSwiperNestedScroll = GetSwiperNestedScroll,
1740 .setSwiperToIndex = SetSwiperToIndex,
1741 .getSwiperPrevMargin = GetSwiperPrevMargin,
1742 .getSwiperNextMargin = GetSwiperNextMargin,
1743 .setSwiperIndicatorStyle = SetSwiperIndicatorStyle,
1744 .getSwiperIndicator = GetSwiperIndicator,
1745 .getSwiperController = GetSwiperController,
1746 .setSwiperOnChange = SetSwiperOnChange,
1747 .resetSwiperOnChange = ResetSwiperOnChange,
1748 .setSwiperOnAnimationStart = SetSwiperOnAnimationStart,
1749 .resetSwiperOnAnimationStart = ResetSwiperOnAnimationStart,
1750 .setSwiperOnAnimationEnd = SetSwiperOnAnimationEnd,
1751 .resetSwiperOnAnimationEnd = ResetSwiperOnAnimationEnd,
1752 .setSwiperOnGestureSwipe = SetSwiperOnGestureSwipe,
1753 .resetSwiperOnGestureSwipe = ResetSwiperOnGestureSwipe,
1754 .setSwiperOnSelected = SetSwiperOnSelected,
1755 .resetSwiperOnSelected = ResetSwiperOnSelected,
1756 .setSwiperMinSize = SetSwiperMinSize,
1757 .resetSwiperMinSize = ResetSwiperMinSize,
1758 .getSwiperMinSize = GetSwiperMinSize,
1759 .setSwiperDigitIndicatorStyle = SetSwiperDigitIndicatorStyle,
1760 .getSwiperDigitIndicator = GetSwiperDigitIndicator,
1761 .getIndicatorType = GetIndicatorType,
1762 .getSwiperSwipeByGroup = GetSwiperSwipeByGroup,
1763 .getSwiperDisplayMode = GetSwiperDisplayMode,
1764 .getSwiperArrowStyle = GetSwiperArrowStyle,
1765 };
1766 CHECK_INITIALIZED_FIELDS_END(modifier, 0, 0, 0); // don't move this line
1767 return &modifier;
1768 }
1769
SetSwiperChange(ArkUINodeHandle node,void * extraParam)1770 void SetSwiperChange(ArkUINodeHandle node, void* extraParam)
1771 {
1772 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1773 CHECK_NULL_VOID(frameNode);
1774 auto onEvent = [node, extraParam](const BaseEventInfo* info) {
1775 const auto* swiperInfo = TypeInfoHelper::DynamicCast<SwiperChangeEvent>(info);
1776 if (!swiperInfo) {
1777 LOGE("Swiper onChange callback execute failed.");
1778 return;
1779 }
1780 int32_t index = swiperInfo->GetIndex();
1781 ArkUINodeEvent event;
1782 event.kind = COMPONENT_ASYNC_EVENT;
1783 event.extraParam = reinterpret_cast<intptr_t>(extraParam);
1784 event.componentAsyncEvent.subKind = ON_SWIPER_CHANGE;
1785 event.componentAsyncEvent.data[NUM_0].i32 = index;
1786 SendArkUISyncEvent(&event);
1787 };
1788 SwiperModelNG::SetOnChange(frameNode, std::move(onEvent));
1789 }
1790
SetSwiperSelected(ArkUINodeHandle node,void * extraParam)1791 void SetSwiperSelected(ArkUINodeHandle node, void* extraParam)
1792 {
1793 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1794 CHECK_NULL_VOID(frameNode);
1795 auto onEvent = [node, extraParam](const BaseEventInfo* info) {
1796 const auto* swiperInfo = TypeInfoHelper::DynamicCast<SwiperChangeEvent>(info);
1797 if (!swiperInfo) {
1798 LOGE("Swiper onSelected callback execute failed.");
1799 return;
1800 }
1801 int32_t index = swiperInfo->GetIndex();
1802 ArkUINodeEvent event;
1803 event.kind = COMPONENT_ASYNC_EVENT;
1804 event.extraParam = reinterpret_cast<intptr_t>(extraParam);
1805 event.componentAsyncEvent.subKind = ON_SWIPER_SELECTED;
1806 event.componentAsyncEvent.data[NUM_0].i32 = index;
1807 SendArkUISyncEvent(&event);
1808 };
1809 SwiperModelNG::SetOnSelected(frameNode, std::move(onEvent));
1810 }
1811
SetSwiperAnimationStart(ArkUINodeHandle node,void * extraParam)1812 void SetSwiperAnimationStart(ArkUINodeHandle node, void* extraParam)
1813 {
1814 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1815 CHECK_NULL_VOID(frameNode);
1816 auto onEvent = [node, extraParam](int32_t index, int32_t targetIndex, const AnimationCallbackInfo& info) {
1817 ArkUINodeEvent event;
1818 event.kind = COMPONENT_ASYNC_EVENT;
1819 event.extraParam = reinterpret_cast<intptr_t>(extraParam);
1820 event.componentAsyncEvent.subKind = ON_SWIPER_ANIMATION_START;
1821 event.componentAsyncEvent.data[NUM_0].i32 = index;
1822 event.componentAsyncEvent.data[NUM_1].i32 = targetIndex;
1823 event.componentAsyncEvent.data[NUM_2].f32 = info.currentOffset.value_or(ANIMATION_INFO_DEFAULT);
1824 event.componentAsyncEvent.data[NUM_3].f32 = info.targetOffset.value_or(ANIMATION_INFO_DEFAULT);
1825 event.componentAsyncEvent.data[NUM_4].f32 = info.velocity.value_or(ANIMATION_INFO_DEFAULT);
1826 SendArkUISyncEvent(&event);
1827 };
1828 SwiperModelNG::SetOnAnimationStart(frameNode, std::move(onEvent));
1829 }
1830
SetSwiperAnimationEnd(ArkUINodeHandle node,void * extraParam)1831 void SetSwiperAnimationEnd(ArkUINodeHandle node, void* extraParam)
1832 {
1833 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1834 CHECK_NULL_VOID(frameNode);
1835 auto onEvent = [node, extraParam](int32_t index, const AnimationCallbackInfo& info) {
1836 ArkUINodeEvent event;
1837 event.kind = COMPONENT_ASYNC_EVENT;
1838 event.extraParam = reinterpret_cast<intptr_t>(extraParam);
1839 event.componentAsyncEvent.subKind = ON_SWIPER_ANIMATION_END;
1840 event.componentAsyncEvent.data[NUM_0].i32 = index;
1841 event.componentAsyncEvent.data[NUM_1].f32 = info.currentOffset.value_or(ANIMATION_INFO_DEFAULT);
1842 SendArkUISyncEvent(&event);
1843 };
1844 SwiperModelNG::SetOnAnimationEnd(frameNode, std::move(onEvent));
1845 }
1846
SetSwiperGestureSwipe(ArkUINodeHandle node,void * extraParam)1847 void SetSwiperGestureSwipe(ArkUINodeHandle node, void* extraParam)
1848 {
1849 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1850 CHECK_NULL_VOID(frameNode);
1851 auto onEvent = [node, extraParam](int32_t index, const AnimationCallbackInfo& info) {
1852 ArkUINodeEvent event;
1853 event.kind = COMPONENT_ASYNC_EVENT;
1854 event.extraParam = reinterpret_cast<intptr_t>(extraParam);
1855 event.componentAsyncEvent.subKind = ON_SWIPER_GESTURE_SWIPE;
1856 event.componentAsyncEvent.data[NUM_0].i32 = index;
1857 event.componentAsyncEvent.data[NUM_1].f32 = info.currentOffset.value_or(ANIMATION_INFO_DEFAULT);
1858 SendArkUISyncEvent(&event);
1859 };
1860 SwiperModelNG::SetOnGestureSwipe(frameNode, std::move(onEvent));
1861 }
1862
SetSwiperOnContentDidScroll(ArkUINodeHandle node,void * extraParam)1863 void SetSwiperOnContentDidScroll(ArkUINodeHandle node, void* extraParam)
1864 {
1865 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1866 CHECK_NULL_VOID(frameNode);
1867 auto onEvent = [node, extraParam](int32_t selectedIndex, int32_t index, float position, float mainAxisLength) {
1868 ArkUINodeEvent event;
1869 event.kind = COMPONENT_ASYNC_EVENT;
1870 event.extraParam = reinterpret_cast<intptr_t>(extraParam);
1871 bool usePx = NodeModel::UsePXUnit(reinterpret_cast<ArkUI_Node*>(extraParam));
1872 double density = usePx ? 1 : PipelineBase::GetCurrentDensity();
1873 event.componentAsyncEvent.subKind = ON_SWIPER_DID_CONTENT_SCROLL;
1874 event.componentAsyncEvent.data[NUM_0].i32 = selectedIndex;
1875 event.componentAsyncEvent.data[NUM_1].i32 = index;
1876 event.componentAsyncEvent.data[NUM_2].f32 = position;
1877 event.componentAsyncEvent.data[NUM_3].f32 = mainAxisLength / density;
1878 SendArkUISyncEvent(&event);
1879 };
1880 SwiperModelNG::SetOnContentDidScroll(frameNode, std::move(onEvent));
1881 }
1882
SetSwiperUnselected(ArkUINodeHandle node,void * extraParam)1883 void SetSwiperUnselected(ArkUINodeHandle node, void* extraParam)
1884 {
1885 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1886 CHECK_NULL_VOID(frameNode);
1887 auto onEvent = [node, extraParam](const BaseEventInfo* info) {
1888 const auto* swiperInfo = TypeInfoHelper::DynamicCast<SwiperChangeEvent>(info);
1889 if (!swiperInfo) {
1890 LOGE("Swiper onUnselected callback execute failed.");
1891 return;
1892 }
1893 int32_t index = swiperInfo->GetIndex();
1894 ArkUINodeEvent event;
1895 event.kind = COMPONENT_ASYNC_EVENT;
1896 event.extraParam = reinterpret_cast<intptr_t>(extraParam);
1897 event.componentAsyncEvent.subKind = ON_SWIPER_UNSELECTED;
1898 event.componentAsyncEvent.data[NUM_0].i32 = index;
1899 SendArkUISyncEvent(&event);
1900 };
1901 SwiperModelNG::SetOnUnselected(frameNode, std::move(onEvent));
1902 }
1903
SetSwiperContentWillScroll(ArkUINodeHandle node,void * extraParam)1904 void SetSwiperContentWillScroll(ArkUINodeHandle node, void* extraParam)
1905 {
1906 auto* frameNode = reinterpret_cast<FrameNode*>(node);
1907 CHECK_NULL_VOID(frameNode);
1908 auto onEvent = [node, extraParam](const SwiperContentWillScrollResult& result) -> bool {
1909 ArkUINodeEvent event;
1910 event.kind = COMPONENT_ASYNC_EVENT;
1911 event.extraParam = reinterpret_cast<intptr_t>(extraParam);
1912 event.componentAsyncEvent.subKind = ON_SWIPER_CONTENT_WILL_SCROLL;
1913 event.componentAsyncEvent.data[NUM_0].i32 = result.currentIndex;
1914 event.componentAsyncEvent.data[NUM_1].i32 = result.comingIndex;
1915 event.componentAsyncEvent.data[NUM_2].f32 = result.offset;
1916 SendArkUISyncEvent(&event);
1917 auto ret = event.componentAsyncEvent.data[0].i32;
1918 if (ret == 0) {
1919 return false;
1920 }
1921 return true;
1922 };
1923 SwiperModelNG::SetOnContentWillScroll(frameNode, std::move(onEvent));
1924 }
1925 } // namespace NodeModifier
1926 } // namespace OHOS::Ace::NG
1927