1 /*
2 * Copyright (c) 2024 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
16 #include "swiper_helper.h"
17
18 #include "base/log/dump_log.h"
19 #include "core/pipeline/base/constants.h"
20
21 namespace OHOS::Ace::NG {
InitSwiperController(const RefPtr<SwiperController> & controller,const WeakPtr<SwiperPattern> & weak)22 void SwiperHelper::InitSwiperController(const RefPtr<SwiperController>& controller, const WeakPtr<SwiperPattern>& weak)
23 {
24 CHECK_NULL_VOID(controller);
25 controller->SetSwipeToImpl([weak](int32_t index, bool reverse) {
26 auto swiper = weak.Upgrade();
27 CHECK_NULL_VOID(swiper);
28 swiper->SwipeTo(index);
29 });
30
31 controller->SetSwipeToWithoutAnimationImpl([weak](int32_t index) {
32 auto swiper = weak.Upgrade();
33 CHECK_NULL_VOID(swiper);
34 swiper->SwipeToWithoutAnimation(index);
35 });
36
37 controller->SetShowNextImpl([weak]() {
38 auto swiper = weak.Upgrade();
39 CHECK_NULL_VOID(swiper);
40 auto swiperNode = swiper->GetHost();
41 CHECK_NULL_VOID(swiperNode);
42 TAG_LOGI(AceLogTag::ACE_SWIPER, "Swiper ShowNext, id:%{public}d", swiperNode->GetId());
43 swiper->ResetAnimationParam();
44 swiper->ShowNext();
45 });
46
47 controller->SetShowPrevImpl([weak]() {
48 auto swiper = weak.Upgrade();
49 CHECK_NULL_VOID(swiper);
50 auto swiperNode = swiper->GetHost();
51 CHECK_NULL_VOID(swiperNode);
52 TAG_LOGI(AceLogTag::ACE_SWIPER, "Swiper ShowPrevious, id:%{public}d", swiperNode->GetId());
53 swiper->ResetAnimationParam();
54 swiper->ShowPrevious();
55 });
56
57 controller->SetChangeIndexImpl([weak](int32_t index, bool useAnimation) {
58 auto swiper = weak.Upgrade();
59 CHECK_NULL_VOID(swiper);
60 TAG_LOGI(AceLogTag::ACE_SWIPER, "Swiper ChangeIndex %{public}d, useAnimation:%{public}d, id:%{public}d", index,
61 useAnimation, swiper->GetId());
62 swiper->ChangeIndex(index, useAnimation);
63 });
64
65 SetChangeIndexWithModeImpl(controller, weak);
66
67 controller->SetFinishImpl([weak]() {
68 auto swiper = weak.Upgrade();
69 CHECK_NULL_VOID(swiper);
70 TAG_LOGI(AceLogTag::ACE_SWIPER, "Swiper user finish animation id:%{public}d", swiper->GetId());
71 swiper->FinishAnimation();
72 });
73
74 controller->SetPreloadItemsImpl([weak](const std::set<int32_t>& indexSet) {
75 auto swiper = weak.Upgrade();
76 CHECK_NULL_VOID(swiper);
77 swiper->PreloadItems(indexSet);
78 });
79 }
80
SetChangeIndexWithModeImpl(const RefPtr<SwiperController> & controller,const WeakPtr<SwiperPattern> & weak)81 void SwiperHelper::SetChangeIndexWithModeImpl(const RefPtr<SwiperController>& controller,
82 const WeakPtr<SwiperPattern>& weak)
83 {
84 CHECK_NULL_VOID(controller);
85 controller->SetChangeIndexWithModeImpl([weak](int32_t index, SwiperAnimationMode animationMode) {
86 auto swiper = weak.Upgrade();
87 CHECK_NULL_VOID(swiper);
88 TAG_LOGI(AceLogTag::ACE_SWIPER, "Swiper ChangeIndex %{public}d, animationMode:%{public}d",
89 index, animationMode);
90 swiper->ChangeIndex(index, animationMode);
91 });
92 }
93
SaveDigitIndicatorIgnoreSize(const SwiperPattern & swiper,const std::shared_ptr<SwiperDigitalParameters> & digitalParams,RefPtr<SwiperIndicatorLayoutProperty> & indicatorProps,bool isSidebarMiddle,bool isShowArrow)94 void SwiperHelper::SaveDigitIndicatorIgnoreSize(const SwiperPattern& swiper,
95 const std::shared_ptr<SwiperDigitalParameters>& digitalParams,
96 RefPtr<SwiperIndicatorLayoutProperty>& indicatorProps, bool isSidebarMiddle, bool isShowArrow)
97 {
98 CHECK_NULL_VOID(digitalParams);
99 auto axis = swiper.GetDirection();
100 bool hasBottomValue = digitalParams->dimBottom.has_value() ? true : false;
101 bool ignoreSizeForHorizontal = (axis == Axis::HORIZONTAL) && (!hasBottomValue ||
102 (hasBottomValue && digitalParams->dimBottom == 0.0_vp));
103 bool ignoreSizeForVertical = (axis == Axis::VERTICAL) && hasBottomValue &&
104 (digitalParams->dimBottom == 0.0_vp) && (!isShowArrow || (isShowArrow && isSidebarMiddle));
105 if (digitalParams->ignoreSizeValue.has_value() && (ignoreSizeForHorizontal || ignoreSizeForVertical)) {
106 indicatorProps->UpdateIgnoreSize(digitalParams->ignoreSizeValue.value());
107 } else {
108 indicatorProps->UpdateIgnoreSize(false);
109 }
110 }
111
SaveDigitIndicatorProperty(const RefPtr<FrameNode> & indicatorNode,SwiperPattern & swiper)112 void SwiperHelper::SaveDigitIndicatorProperty(const RefPtr<FrameNode>& indicatorNode, SwiperPattern& swiper)
113 {
114 CHECK_NULL_VOID(indicatorNode);
115 auto indicatorProps = indicatorNode->GetLayoutProperty<SwiperIndicatorLayoutProperty>();
116 CHECK_NULL_VOID(indicatorProps);
117 auto pipeline = PipelineBase::GetCurrentContext();
118 CHECK_NULL_VOID(pipeline);
119 const auto theme = pipeline->GetTheme<SwiperIndicatorTheme>();
120 const auto digitalParams = swiper.GetSwiperDigitalParameters();
121 CHECK_NULL_VOID(digitalParams);
122 indicatorProps->ResetIndicatorLayoutStyle();
123 if (digitalParams->dimLeft.has_value()) {
124 indicatorProps->UpdateLeft(digitalParams->dimLeft.value());
125 }
126 if (digitalParams->dimTop.has_value()) {
127 indicatorProps->UpdateTop(digitalParams->dimTop.value());
128 }
129 if (digitalParams->dimRight.has_value()) {
130 indicatorProps->UpdateRight(digitalParams->dimRight.value());
131 }
132 if (digitalParams->dimBottom.has_value()) {
133 indicatorProps->UpdateBottom(digitalParams->dimBottom.value());
134 }
135 indicatorProps->UpdateFontColor(
136 digitalParams->fontColor.value_or(theme->GetDigitalIndicatorTextStyle().GetTextColor()));
137 indicatorProps->UpdateSelectedFontColor(
138 digitalParams->selectedFontColor.value_or(theme->GetDigitalIndicatorTextStyle().GetTextColor()));
139 indicatorProps->UpdateFontSize(
140 digitalParams->fontSize.value_or(theme->GetDigitalIndicatorTextStyle().GetFontSize()));
141 indicatorProps->UpdateSelectedFontSize(
142 digitalParams->selectedFontSize.value_or(theme->GetDigitalIndicatorTextStyle().GetFontSize()));
143 indicatorProps->UpdateFontWeight(
144 digitalParams->fontWeight.value_or(theme->GetDigitalIndicatorTextStyle().GetFontWeight()));
145 indicatorProps->UpdateSelectedFontWeight(
146 digitalParams->selectedFontWeight.value_or(theme->GetDigitalIndicatorTextStyle().GetFontWeight()));
147 auto props = swiper.GetLayoutProperty<SwiperLayoutProperty>();
148 CHECK_NULL_VOID(props);
149 auto isSidebarMiddle = props->GetIsSidebarMiddleValue(false);
150 auto isShowArrow = props->GetDisplayArrowValue(false);
151 SaveDigitIndicatorIgnoreSize(swiper, digitalParams, indicatorProps, isSidebarMiddle, isShowArrow);
152 props->UpdateLeft(digitalParams->dimLeft.value_or(0.0_vp));
153 props->UpdateTop(digitalParams->dimTop.value_or(0.0_vp));
154 props->UpdateRight(digitalParams->dimRight.value_or(0.0_vp));
155 props->UpdateBottom(digitalParams->dimBottom.value_or(0.0_vp));
156 swiper.SetDigitStartAndEndProperty(indicatorNode);
157 }
158
SaveDotIndicatorProperty(const RefPtr<FrameNode> & indicatorNode,SwiperPattern & swiper)159 void SwiperHelper::SaveDotIndicatorProperty(const RefPtr<FrameNode>& indicatorNode, SwiperPattern& swiper)
160 {
161 CHECK_NULL_VOID(indicatorNode);
162 auto indicatorProps = indicatorNode->GetLayoutProperty<SwiperIndicatorLayoutProperty>();
163 CHECK_NULL_VOID(indicatorProps);
164 const auto params = swiper.GetSwiperParameters();
165 CHECK_NULL_VOID(params);
166 indicatorProps->ResetIndicatorLayoutStyle();
167 if (params->dimLeft.has_value()) {
168 indicatorProps->UpdateLeft(params->dimLeft.value());
169 }
170 if (params->dimTop.has_value()) {
171 indicatorProps->UpdateTop(params->dimTop.value());
172 }
173 if (params->dimRight.has_value()) {
174 indicatorProps->UpdateRight(params->dimRight.value());
175 }
176 if (params->dimBottom.has_value()) {
177 indicatorProps->UpdateBottom(params->dimBottom.value());
178 }
179 if (params->dimSpace.has_value()) {
180 indicatorProps->UpdateSpace(params->dimSpace.value());
181 }
182 if (params->ignoreSizeValue.has_value()) {
183 indicatorProps->UpdateIgnoreSize(params->ignoreSizeValue.value());
184 } else {
185 indicatorProps->UpdateIgnoreSize(false);
186 }
187 const bool isRtl = swiper.GetNonAutoLayoutDirection() == TextDirection::RTL;
188 if (params->dimStart.has_value()) {
189 auto dimValue = params->dimStart.value();
190 isRtl ? indicatorProps->UpdateRight(dimValue) : indicatorProps->UpdateLeft(dimValue);
191 } else if (params->dimEnd.has_value()) {
192 auto dimValue = params->dimEnd.value();
193 isRtl ? indicatorProps->UpdateLeft(dimValue) : indicatorProps->UpdateRight(dimValue);
194 }
195
196 swiper.UpdatePaintProperty(indicatorNode);
197 }
198
199 namespace {
DumpPanDirection(const PanDirection & pan)200 void DumpPanDirection(const PanDirection& pan)
201 {
202 switch (pan.type) {
203 case PanDirection::NONE: {
204 DumpLog::GetInstance().AddDesc("PanDirection:NONE");
205 break;
206 }
207 case PanDirection::LEFT: {
208 DumpLog::GetInstance().AddDesc("PanDirection:LEFT");
209 break;
210 }
211 case PanDirection::RIGHT: {
212 DumpLog::GetInstance().AddDesc("PanDirection:RIGHT");
213 break;
214 }
215 case PanDirection::HORIZONTAL: {
216 DumpLog::GetInstance().AddDesc("PanDirection:HORIZONTAL");
217 break;
218 }
219 case PanDirection::UP: {
220 DumpLog::GetInstance().AddDesc("PanDirection:UP");
221 break;
222 }
223 case PanDirection::DOWN: {
224 DumpLog::GetInstance().AddDesc("PanDirection:DOWN");
225 break;
226 }
227 case PanDirection::VERTICAL: {
228 DumpLog::GetInstance().AddDesc("PanDirection:VERTICAL");
229 break;
230 }
231 case PanDirection::ALL: {
232 DumpLog::GetInstance().AddDesc("PanDirection:ALL");
233 break;
234 }
235 default: {
236 break;
237 }
238 }
239 }
240
DumpDirection(Axis direction)241 void DumpDirection(Axis direction)
242 {
243 switch (direction) {
244 case Axis::NONE: {
245 DumpLog::GetInstance().AddDesc("Axis:NONE");
246 break;
247 }
248 case Axis::HORIZONTAL: {
249 DumpLog::GetInstance().AddDesc("Axis:HORIZONTAL");
250 break;
251 }
252 case Axis::FREE: {
253 DumpLog::GetInstance().AddDesc("Axis:FREE");
254 break;
255 }
256 case Axis::VERTICAL: {
257 DumpLog::GetInstance().AddDesc("Axis:VERTICAL");
258 break;
259 }
260 default: {
261 break;
262 }
263 }
264 }
265
DumpIndicatorType(const std::optional<SwiperIndicatorType> & type)266 void DumpIndicatorType(const std::optional<SwiperIndicatorType>& type)
267 {
268 if (type.has_value()) {
269 switch (type.value()) {
270 case SwiperIndicatorType::DOT: {
271 DumpLog::GetInstance().AddDesc("SwiperIndicatorType:DOT");
272 break;
273 }
274 case SwiperIndicatorType::DIGIT: {
275 DumpLog::GetInstance().AddDesc("SwiperIndicatorType:DIGIT");
276 break;
277 }
278 case SwiperIndicatorType::ARC_DOT: {
279 DumpLog::GetInstance().AddDesc("SwiperIndicatorType:ARC_DOT");
280 break;
281 }
282 default: {
283 break;
284 }
285 }
286 } else {
287 DumpLog::GetInstance().AddDesc("lastSwiperIndicatorType:null");
288 }
289 }
290
DumpItemPosition(const SwiperLayoutAlgorithm::PositionMap & positions)291 void DumpItemPosition(const SwiperLayoutAlgorithm::PositionMap& positions)
292 {
293 for (const auto& item : positions) {
294 DumpLog::GetInstance().AddDesc(std::string("id:")
295 .append(std::to_string(item.first))
296 .append(",startPos:")
297 .append(std::to_string(item.second.startPos))
298 .append(",endPos:" + std::to_string(item.second.endPos)));
299 }
300 }
301 } // namespace
302
DumpAdvanceInfo(SwiperPattern & swiper)303 void SwiperHelper::DumpAdvanceInfo(SwiperPattern& swiper)
304 {
305 DumpInfoAddPositionDesc(swiper);
306 DumpInfoAddGestureDesc(swiper);
307 DumpIndicatorType(swiper.lastSwiperIndicatorType_);
308 DumpInfoAddAnimationDesc(swiper);
309 if (!swiper.itemPosition_.empty()) {
310 DumpLog::GetInstance().AddDesc("-----------start print itemPosition------------");
311 DumpItemPosition(swiper.itemPosition_);
312 DumpLog::GetInstance().AddDesc("-----------end print itemPosition------------");
313 }
314 if (!swiper.itemPositionInAnimation_.empty()) {
315 DumpLog::GetInstance().AddDesc("-----------start print itemPositionInAnimation------------");
316 DumpItemPosition(swiper.itemPositionInAnimation_);
317 DumpLog::GetInstance().AddDesc("-----------end print itemPositionInAnimation------------");
318 }
319 DumpPanDirection(swiper.panDirection_);
320 DumpDirection(swiper.direction_);
321 swiper.IsDisableSwipe() ? DumpLog::GetInstance().AddDesc("disableSwipe:true")
322 : DumpLog::GetInstance().AddDesc("disableSwipe:false");
323 swiper.GetNonAutoLayoutDirection() == TextDirection::RTL ? DumpLog::GetInstance().AddDesc("TextDirection::RTL")
324 : DumpLog::GetInstance().AddDesc("TextDirection::LTR");
325 }
326
DumpInfoAddPositionDesc(SwiperPattern & swiper)327 void SwiperHelper::DumpInfoAddPositionDesc(SwiperPattern& swiper)
328 {
329 swiper.crossMatchChild_ ? DumpLog::GetInstance().AddDesc("crossMatchChild:true")
330 : DumpLog::GetInstance().AddDesc("crossMatchChild:false");
331 swiper.uiCastJumpIndex_.has_value()
332 ? DumpLog::GetInstance().AddDesc("uiCastJumpIndex:" + std::to_string(swiper.uiCastJumpIndex_.value()))
333 : DumpLog::GetInstance().AddDesc("uiCastJumpIndex:null");
334 swiper.jumpIndex_.has_value()
335 ? DumpLog::GetInstance().AddDesc("jumpIndex:" + std::to_string(swiper.jumpIndex_.value()))
336 : DumpLog::GetInstance().AddDesc("jumpIndex:null");
337 swiper.targetIndex_.has_value()
338 ? DumpLog::GetInstance().AddDesc("targetIndex:" + std::to_string(swiper.targetIndex_.value()))
339 : DumpLog::GetInstance().AddDesc("targetIndex:null");
340 swiper.pauseTargetIndex_.has_value()
341 ? DumpLog::GetInstance().AddDesc("pauseTargetIndex:" + std::to_string(swiper.pauseTargetIndex_.value()))
342 : DumpLog::GetInstance().AddDesc("pauseTargetIndex:null");
343 DumpLog::GetInstance().AddDesc("currentIndex:" + std::to_string(swiper.currentIndex_));
344 DumpLog::GetInstance().AddDesc("oldIndex:" + std::to_string(swiper.oldIndex_));
345 DumpLog::GetInstance().AddDesc("currentOffset:" + std::to_string(swiper.currentOffset_));
346 DumpLog::GetInstance().AddDesc("fadeOffset:" + std::to_string(swiper.fadeOffset_));
347 DumpLog::GetInstance().AddDesc("touchBottomRate:" + std::to_string(swiper.touchBottomRate_));
348 DumpLog::GetInstance().AddDesc("currentIndexOffset:" + std::to_string(swiper.currentIndexOffset_));
349 DumpLog::GetInstance().AddDesc("gestureSwipeIndex:" + std::to_string(swiper.gestureSwipeIndex_));
350 DumpLog::GetInstance().AddDesc("currentFirstIndex:" + std::to_string(swiper.currentFirstIndex_));
351 DumpLog::GetInstance().AddDesc("startMainPos:" + std::to_string(swiper.startMainPos_));
352 DumpLog::GetInstance().AddDesc("endMainPos:" + std::to_string(swiper.endMainPos_));
353 DumpLog::GetInstance().AddDesc("contentMainSize:" + std::to_string(swiper.contentMainSize_));
354 DumpLog::GetInstance().AddDesc("contentCrossSize:" + std::to_string(swiper.contentCrossSize_));
355 }
356
DumpInfoAddGestureDesc(SwiperPattern & swiper)357 void SwiperHelper::DumpInfoAddGestureDesc(SwiperPattern& swiper)
358 {
359 swiper.isLastIndicatorFocused_ ? DumpLog::GetInstance().AddDesc("isLastIndicatorFocused:true")
360 : DumpLog::GetInstance().AddDesc("isLastIndicatorFocused:false");
361 swiper.moveDirection_ ? DumpLog::GetInstance().AddDesc("moveDirection:true")
362 : DumpLog::GetInstance().AddDesc("moveDirection:false");
363 swiper.indicatorDoingAnimation_ ? DumpLog::GetInstance().AddDesc("indicatorDoingAnimation:true")
364 : DumpLog::GetInstance().AddDesc("indicatorDoingAnimation:false");
365 swiper.hasVisibleChangeRegistered_ ? DumpLog::GetInstance().AddDesc("hasVisibleChangeRegistered:true")
366 : DumpLog::GetInstance().AddDesc("hasVisibleChangeRegistered:false");
367 swiper.isVisible_ ? DumpLog::GetInstance().AddDesc("isVisible:true")
368 : DumpLog::GetInstance().AddDesc("isVisible:false");
369 swiper.isVisibleArea_ ? DumpLog::GetInstance().AddDesc("isVisibleArea:true")
370 : DumpLog::GetInstance().AddDesc("isVisibleArea:false");
371 swiper.isWindowShow_ ? DumpLog::GetInstance().AddDesc("isWindowShow:true")
372 : DumpLog::GetInstance().AddDesc("isWindowShow:false");
373 swiper.isCustomSize_ ? DumpLog::GetInstance().AddDesc("IsCustomSize:true")
374 : DumpLog::GetInstance().AddDesc("IsCustomSize:false");
375 swiper.indicatorIsBoolean_ ? DumpLog::GetInstance().AddDesc("indicatorIsBoolean:true")
376 : DumpLog::GetInstance().AddDesc("indicatorIsBoolean:false");
377 swiper.isAtHotRegion_ ? DumpLog::GetInstance().AddDesc("isAtHotRegion:true")
378 : DumpLog::GetInstance().AddDesc("isAtHotRegion:false");
379 swiper.isDragging_ ? DumpLog::GetInstance().AddDesc("isDragging:true")
380 : DumpLog::GetInstance().AddDesc("isDragging:false");
381 swiper.isTouchDown_ ? DumpLog::GetInstance().AddDesc("isTouchDown:true")
382 : DumpLog::GetInstance().AddDesc("isTouchDown:false");
383 swiper.isIndicatorLongPress_ ? DumpLog::GetInstance().AddDesc("isIndicatorLongPress:true")
384 : DumpLog::GetInstance().AddDesc("isIndicatorLongPress:false");
385 swiper.preLoop_.has_value() ? DumpLog::GetInstance().AddDesc("preLoop:" + std::to_string(swiper.preLoop_.value()))
386 : DumpLog::GetInstance().AddDesc("preLoop:null");
387 swiper.indicatorId_.has_value()
388 ? DumpLog::GetInstance().AddDesc("indicatorId:" + std::to_string(swiper.indicatorId_.value()))
389 : DumpLog::GetInstance().AddDesc("indicatorId:null");
390 swiper.leftButtonId_.has_value()
391 ? DumpLog::GetInstance().AddDesc("leftButtonId:" + std::to_string(swiper.leftButtonId_.value()))
392 : DumpLog::GetInstance().AddDesc("leftButtonId:null");
393 swiper.rightButtonId_.has_value()
394 ? DumpLog::GetInstance().AddDesc("rightButtonId:" + std::to_string(swiper.rightButtonId_.value()))
395 : DumpLog::GetInstance().AddDesc("rightButtonId:null");
396 }
397
DumpInfoAddAnimationDesc(SwiperPattern & swiper)398 void SwiperHelper::DumpInfoAddAnimationDesc(SwiperPattern& swiper)
399 {
400 swiper.isFinishAnimation_ ? DumpLog::GetInstance().AddDesc("isFinishAnimation:true")
401 : DumpLog::GetInstance().AddDesc("isFinishAnimation:false");
402 swiper.mainSizeIsMeasured_ ? DumpLog::GetInstance().AddDesc("mainSizeIsMeasured:true")
403 : DumpLog::GetInstance().AddDesc("mainSizeIsMeasured:false");
404 swiper.propertyAnimationIsRunning_ ? DumpLog::GetInstance().AddDesc("usePropertyAnimation:true")
405 : DumpLog::GetInstance().AddDesc("usePropertyAnimation:false");
406 swiper.isUserFinish_ ? DumpLog::GetInstance().AddDesc("isUserFinish:true")
407 : DumpLog::GetInstance().AddDesc("isUserFinish:false");
408 swiper.isVoluntarilyClear_ ? DumpLog::GetInstance().AddDesc("isVoluntarilyClear:true")
409 : DumpLog::GetInstance().AddDesc("isVoluntarilyClear:false");
410 swiper.stopIndicatorAnimation_ ? DumpLog::GetInstance().AddDesc("stopIndicatorAnimation:true")
411 : DumpLog::GetInstance().AddDesc("stopIndicatorAnimation:false");
412 swiper.isTouchPad_ ? DumpLog::GetInstance().AddDesc("isTouchPad:true")
413 : DumpLog::GetInstance().AddDesc("isTouchPad:false");
414 swiper.surfaceChangedCallbackId_.has_value()
415 ? DumpLog::GetInstance().AddDesc("surfaceChangedCallbackId:"
416 + std::to_string(swiper.surfaceChangedCallbackId_.value()))
417 : DumpLog::GetInstance().AddDesc("surfaceChangedCallbackId:null");
418 swiper.velocity_.has_value()
419 ? DumpLog::GetInstance().AddDesc("velocity:" + std::to_string(swiper.velocity_.value()))
420 : DumpLog::GetInstance().AddDesc("velocity:null");
421 swiper.GetCurveIncludeMotion()
422 ? DumpLog::GetInstance().AddDesc("curve:" + swiper.GetCurveIncludeMotion()->ToString())
423 : DumpLog::GetInstance().AddDesc("curve:null");
424 DumpLog::GetInstance().AddDesc("currentDelta:" + std::to_string(swiper.currentDelta_));
425 DumpLog::GetInstance().AddDesc("propertyAnimationIndex:" + std::to_string(swiper.propertyAnimationIndex_));
426 DumpLog::GetInstance().AddDesc("mainDeltaSum:" + std::to_string(swiper.mainDeltaSum_));
427 }
428
GetDotIndicatorStyle(const std::shared_ptr<SwiperParameters> & params)429 std::string SwiperHelper::GetDotIndicatorStyle(const std::shared_ptr<SwiperParameters>& params)
430 {
431 CHECK_NULL_RETURN(params, "");
432 auto jsonValue = JsonUtil::Create(true);
433 CHECK_NULL_RETURN(jsonValue, "");
434 jsonValue->Put("left", params->dimLeft.value_or(0.0_vp).ToString().c_str());
435 jsonValue->Put("top", params->dimTop.value_or(0.0_vp).ToString().c_str());
436 jsonValue->Put("right", params->dimRight.value_or(0.0_vp).ToString().c_str());
437 jsonValue->Put("bottom", params->dimBottom.value_or(0.0_vp).ToString().c_str());
438 jsonValue->Put("itemWidth", params->itemWidth.value_or(6.0_vp).ToString().c_str());
439 jsonValue->Put("itemHeight", params->itemHeight.value_or(6.0_vp).ToString().c_str());
440 jsonValue->Put("selectedItemWidth", params->selectedItemWidth.value_or(12.0_vp).ToString().c_str());
441 jsonValue->Put("selectedItemHeight", params->selectedItemHeight.value_or(6.0_vp).ToString().c_str());
442 jsonValue->Put(
443 "selectedColor", params->selectedColorVal.value_or(Color::FromString("#ff007dff")).ColorToString().c_str());
444 jsonValue->Put("color", params->colorVal.value_or(Color::FromString("#19182431")).ColorToString().c_str());
445 jsonValue->Put("mask", params->maskValue.value_or(false) ? "true" : "false");
446 jsonValue->Put(
447 "maxDisplayCount", (params->maxDisplayCountVal.has_value()) ? params->maxDisplayCountVal.value() : 0);
448 jsonValue->Put("space", params->dimSpace.value_or(8.0_vp).ToString().c_str());
449 jsonValue->Put("ignoreSize", params->ignoreSizeValue.value_or(false) ? "true" : "false");
450 return jsonValue->ToString();
451 }
452
GetDigitIndicatorStyle(const std::shared_ptr<SwiperDigitalParameters> & params)453 std::string SwiperHelper::GetDigitIndicatorStyle(const std::shared_ptr<SwiperDigitalParameters>& params)
454 {
455 CHECK_NULL_RETURN(params, "");
456 auto jsonValue = JsonUtil::Create(true);
457 CHECK_NULL_RETURN(jsonValue, "");
458 auto pipeline = PipelineBase::GetCurrentContext();
459 CHECK_NULL_RETURN(pipeline, "");
460 auto theme = pipeline->GetTheme<SwiperIndicatorTheme>();
461 CHECK_NULL_RETURN(theme, "");
462 jsonValue->Put("left", params->dimLeft.value_or(0.0_vp).ToString().c_str());
463 jsonValue->Put("top", params->dimTop.value_or(0.0_vp).ToString().c_str());
464 jsonValue->Put("right", params->dimRight.value_or(0.0_vp).ToString().c_str());
465 jsonValue->Put("bottom", params->dimBottom.value_or(0.0_vp).ToString().c_str());
466 jsonValue->Put(
467 "fontSize", params->fontSize.value_or(theme->GetDigitalIndicatorTextStyle().GetFontSize()).ToString().c_str());
468 jsonValue->Put("fontColor",
469 params->fontColor.value_or(theme->GetDigitalIndicatorTextStyle().GetTextColor()).ColorToString().c_str());
470 jsonValue->Put(
471 "fontWeight", V2::ConvertWrapFontWeightToStirng(params->fontWeight.value_or(FontWeight::NORMAL)).c_str());
472 jsonValue->Put("selectedFontSize",
473 params->selectedFontSize.value_or(theme->GetDigitalIndicatorTextStyle().GetFontSize()).ToString().c_str());
474 jsonValue->Put(
475 "selectedFontColor", params->selectedFontColor.value_or(theme->GetDigitalIndicatorTextStyle().GetTextColor())
476 .ColorToString()
477 .c_str());
478 jsonValue->Put("selectedFontWeight",
479 V2::ConvertWrapFontWeightToStirng(params->selectedFontWeight.value_or(FontWeight::NORMAL)).c_str());
480 jsonValue->Put("ignoreSize", params->ignoreSizeValue.value_or(false) ? "true" : "false");
481 return jsonValue->ToString();
482 }
483
CalculateFriction(float gamma)484 float SwiperHelper::CalculateFriction(float gamma)
485 {
486 if (LessOrEqual(gamma, 0.0f)) {
487 return 1.0f;
488 }
489 if (GreatOrEqual(gamma, 1.0f)) {
490 gamma = 1.0f;
491 }
492 constexpr float scrollRatio = 0.72f;
493 const float coefficient = ACE_E / (1.0f - ACE_E);
494 auto fx = (gamma + coefficient) * (log(ACE_E - (ACE_E - 1.0f) * gamma) - 1.0f);
495 return scrollRatio * fx / gamma;
496 }
497 } // namespace OHOS::Ace::NG
498