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