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