• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #include "core/components_ng/pattern/swiper_indicator/indicator_common/swiper_arrow_pattern.h"
17 
18 #include "base/utils/utils.h"
19 #include "core/components/theme/icon_theme.h"
20 #include "core/components_ng/base/frame_node.h"
21 #include "core/components_ng/event/gesture_event_hub.h"
22 #include "core/components_ng/pattern/swiper/swiper_pattern.h"
23 #include "core/components_ng/pattern/text/text_pattern.h"
24 #include "core/components_v2/inspector/inspector_constants.h"
25 #include "core/pipeline_ng/pipeline_context.h"
26 
27 namespace OHOS::Ace::NG {
OnModifyDone()28 void SwiperArrowPattern::OnModifyDone()
29 {
30     Pattern::OnModifyDone();
31     if (isFirstCreate_) {
32         InitNavigationArrow();
33         auto swiperNode = GetSwiperNode();
34         CHECK_NULL_VOID(swiperNode);
35         auto swiperEventHub = swiperNode->GetEventHub<SwiperEventHub>();
36         CHECK_NULL_VOID(swiperEventHub);
37         auto layoutProperty = GetSwiperArrowLayoutProperty();
38         CHECK_NULL_VOID(layoutProperty);
39         InitSwiperChangeEvent(swiperEventHub);
40         index_ = layoutProperty->GetIndex().value_or(0);
41         isFirstCreate_ = false;
42         InitEvent();
43         InitOnKeyEvent();
44     } else {
45         UpdateArrowContent();
46     }
47     UpdateButtonNode(index_);
48     InitAccessibilityText();
49 }
50 
InitOnKeyEvent()51 void SwiperArrowPattern::InitOnKeyEvent()
52 {
53     auto host = GetHost();
54     CHECK_NULL_VOID(host);
55     auto focusHub = host->GetFocusHub();
56     CHECK_NULL_VOID(focusHub);
57     auto onKeyEvent = [wp = WeakClaim(this)](const KeyEvent& event) -> bool {
58         auto pattern = wp.Upgrade();
59         if (pattern) {
60             return pattern->OnKeyEvent(event);
61         }
62         return false;
63     };
64     focusHub->SetOnKeyEventInternal(std::move(onKeyEvent));
65 }
66 
OnKeyEvent(const KeyEvent & event)67 bool SwiperArrowPattern::OnKeyEvent(const KeyEvent& event)
68 {
69     if (event.action != KeyAction::DOWN) {
70         return false;
71     }
72 
73     if (event.code == KeyCode::KEY_ENTER || event.code == KeyCode::KEY_SPACE) {
74         OnClick();
75         return true;
76     }
77     return false;
78 }
79 
OnClick() const80 void SwiperArrowPattern::OnClick() const
81 {
82     auto swiperNode = GetSwiperNode();
83     CHECK_NULL_VOID(swiperNode);
84     auto swiperPattern = swiperNode->GetPattern<SwiperPattern>();
85     CHECK_NULL_VOID(swiperPattern);
86     auto swiperController = swiperPattern->GetSwiperController();
87     CHECK_NULL_VOID(swiperController);
88     auto host = GetHost();
89     CHECK_NULL_VOID(host);
90     if (host->GetTag() == V2::SWIPER_LEFT_ARROW_ETS_TAG) {
91         if (swiperPattern->IsHorizontalAndRightToLeft()) {
92             swiperController->ShowNext();
93         } else {
94             swiperController->ShowPrevious();
95         }
96         return;
97     }
98     if (host->GetTag() == V2::SWIPER_RIGHT_ARROW_ETS_TAG) {
99         if (swiperPattern->IsHorizontalAndRightToLeft()) {
100             swiperController->ShowPrevious();
101         } else {
102             swiperController->ShowNext();
103         }
104     }
105 }
106 
InitSwiperChangeEvent(const RefPtr<SwiperEventHub> & swiperEventHub)107 void SwiperArrowPattern::InitSwiperChangeEvent(const RefPtr<SwiperEventHub>& swiperEventHub)
108 {
109     ChangeEvent changeEvent = [weak = WeakClaim(this)](int32_t index) {
110         auto pattern = weak.Upgrade();
111         CHECK_NULL_VOID(pattern);
112         pattern->UpdateButtonNode(index);
113     };
114     if (swiperChangeEvent_) {
115         (*swiperChangeEvent_).swap(changeEvent);
116     } else {
117         swiperChangeEvent_ = std::make_shared<ChangeEvent>(std::move(changeEvent));
118         swiperEventHub->AddOnChangeEvent(swiperChangeEvent_);
119     }
120 }
121 
UpdateButtonNode(int32_t index)122 void SwiperArrowPattern::UpdateButtonNode(int32_t index)
123 {
124     index_ = index;
125     auto host = GetHost();
126     CHECK_NULL_VOID(host);
127     auto buttonNode = DynamicCast<FrameNode>(host->GetFirstChild());
128     CHECK_NULL_VOID(buttonNode);
129     auto symbolNode = DynamicCast<FrameNode>(buttonNode->GetFirstChild());
130     CHECK_NULL_VOID(symbolNode);
131     SetButtonVisible(isVisible_);
132     symbolNode->MarkModifyDone();
133 }
134 
InitEvent()135 void SwiperArrowPattern::InitEvent()
136 {
137     auto host = GetHost();
138     CHECK_NULL_VOID(host);
139     auto arrowGestureHub = host->GetOrCreateGestureEventHub();
140     CHECK_NULL_VOID(arrowGestureHub);
141     auto arrowClickCallback = [weak = WeakClaim(this)](const GestureEvent& info) {
142         auto pattern = weak.Upgrade();
143         CHECK_NULL_VOID(pattern);
144         pattern->ButtonClickEvent();
145     };
146     if (arrowClickListener_) {
147         arrowGestureHub->RemoveClickEvent(arrowClickListener_);
148     }
149     arrowClickListener_ = MakeRefPtr<ClickEvent>(std::move(arrowClickCallback));
150     arrowGestureHub->AddClickEvent(arrowClickListener_);
151 
152     auto buttonNode = DynamicCast<FrameNode>(host->GetFirstChild());
153     CHECK_NULL_VOID(buttonNode);
154 
155     auto buttonGestureHub = buttonNode->GetOrCreateGestureEventHub();
156     auto touchCallback = [weak = WeakClaim(this), weakButton = WeakClaim(RawPtr(buttonNode))](
157                              const TouchEventInfo& info) {
158         auto pattern = weak.Upgrade();
159         CHECK_NULL_VOID(pattern);
160         auto buttonNode = weakButton.Upgrade();
161         CHECK_NULL_VOID(buttonNode);
162         pattern->ButtonTouchEvent(buttonNode, info.GetTouches().front().GetTouchType());
163     };
164     buttonTouchListener_ = MakeRefPtr<TouchEventImpl>(std::move(touchCallback));
165     buttonGestureHub->AddTouchEvent(buttonTouchListener_);
166 
167     auto hoverCallback = [weak = WeakClaim(this), weakButton = WeakClaim(RawPtr(buttonNode))](bool isHovered) {
168         auto pattern = weak.Upgrade();
169         CHECK_NULL_VOID(pattern);
170         auto buttonNode = weakButton.Upgrade();
171         CHECK_NULL_VOID(buttonNode);
172         pattern->ButtonOnHover(buttonNode, isHovered);
173     };
174     buttonOnHoverListener_ = MakeRefPtr<InputEvent>(std::move(hoverCallback));
175     auto buttonInputHub = buttonNode->GetOrCreateInputEventHub();
176     buttonInputHub->AddOnHoverEvent(buttonOnHoverListener_);
177 }
178 
ButtonClickEvent()179 void SwiperArrowPattern::ButtonClickEvent()
180 {
181     auto swiperArrowLayoutProperty = GetSwiperArrowLayoutProperty();
182     CHECK_NULL_VOID(swiperArrowLayoutProperty);
183     if (!hoverOnClickFlag_ && swiperArrowLayoutProperty->GetHoverShowValue(false)) {
184         return;
185     }
186 
187     OnClick();
188 }
189 
InitAccessibilityText()190 void SwiperArrowPattern::InitAccessibilityText()
191 {
192     auto swiperNode = GetSwiperNode();
193     CHECK_NULL_VOID(swiperNode);
194     auto host = GetHost();
195     CHECK_NULL_VOID(host);
196     auto accessibilityProperty = host->GetAccessibilityProperty<AccessibilityProperty>();
197     CHECK_NULL_VOID(accessibilityProperty);
198     auto pipelineContext = host->GetContext();
199     CHECK_NULL_VOID(pipelineContext);
200     auto swiperIndicatorTheme = pipelineContext->GetTheme<SwiperIndicatorTheme>();
201     CHECK_NULL_VOID(swiperIndicatorTheme);
202     auto swiperPattern = swiperNode->GetPattern<SwiperPattern>();
203     CHECK_NULL_VOID(swiperPattern);
204     auto preAccessibilityText = swiperIndicatorTheme->GetPreAccessibilityText();
205     auto nextAccessibilityText = swiperIndicatorTheme->GetNextAccessibilityText();
206     if (host->GetTag() == V2::SWIPER_LEFT_ARROW_ETS_TAG) {
207         std::string accessibilityLeftText = "";
208         if (swiperPattern->IsHorizontalAndRightToLeft()) {
209             accessibilityLeftText = nextAccessibilityText;
210         } else {
211             accessibilityLeftText = preAccessibilityText;
212         }
213         accessibilityProperty->SetAccessibilityText(accessibilityLeftText);
214         accessibilityProperty->SetAccessibilityCustomRole("button");
215     }
216     if (host->GetTag() == V2::SWIPER_RIGHT_ARROW_ETS_TAG) {
217         std::string accessibilityRightText = "";
218         if (swiperPattern->IsHorizontalAndRightToLeft()) {
219             accessibilityRightText = preAccessibilityText;
220         } else {
221             accessibilityRightText = nextAccessibilityText;
222         }
223         accessibilityProperty->SetAccessibilityText(accessibilityRightText);
224         accessibilityProperty->SetAccessibilityCustomRole("button");
225     }
226 }
227 
InitNavigationArrow()228 void SwiperArrowPattern::InitNavigationArrow()
229 {
230     auto buttonNode = FrameNode::GetOrCreateFrameNode(V2::BUTTON_ETS_TAG,
231         ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<ButtonPattern>(); });
232     auto buttonAccessibilityProperty = buttonNode->GetAccessibilityProperty<AccessibilityProperty>();
233     CHECK_NULL_VOID(buttonAccessibilityProperty);
234     buttonAccessibilityProperty->SetAccessibilityLevel(AccessibilityProperty::Level::NO_STR);
235     auto buttonNodeFocusHub = buttonNode->GetFocusHub();
236     CHECK_NULL_VOID(buttonNodeFocusHub);
237     buttonNodeFocusHub->SetParentFocusable(false);
238     auto swiperArrowLayoutProperty = GetSwiperArrowLayoutProperty();
239     CHECK_NULL_VOID(swiperArrowLayoutProperty);
240     auto imageNode = FrameNode::CreateFrameNode(
241         V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<ImagePattern>());
242     if (SystemProperties::IsNeedSymbol()) {
243         imageNode = FrameNode::GetOrCreateFrameNode(V2::SYMBOL_ETS_TAG,
244             ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<TextPattern>(); });
245     }
246     auto host = GetHost();
247     CHECK_NULL_VOID(host);
248     auto renderContext = host->GetRenderContext();
249     CHECK_NULL_VOID(renderContext);
250     BorderRadiusProperty radius;
251     radius.SetRadius(swiperArrowLayoutProperty->GetBackgroundSizeValue());
252     renderContext->UpdateBorderRadius(radius);
253     host->AddChild(buttonNode);
254     buttonNode->AddChild(imageNode);
255     UpdateArrowContent();
256 
257     auto buttonLayoutProperty = buttonNode->GetLayoutProperty<ButtonLayoutProperty>();
258     CHECK_NULL_VOID(buttonLayoutProperty);
259     buttonLayoutProperty->UpdateType(ButtonType::CIRCLE);
260 }
261 
TotalCount() const262 int32_t SwiperArrowPattern::TotalCount() const
263 {
264     auto swiperNode = GetSwiperNode();
265     CHECK_NULL_RETURN(swiperNode, 0);
266     auto swiperPattern = swiperNode->GetPattern<SwiperPattern>();
267     CHECK_NULL_RETURN(swiperPattern, 0);
268     return swiperPattern->RealTotalCount() - 1;
269 }
270 
ButtonTouchEvent(RefPtr<FrameNode> buttonNode,TouchType touchType)271 void SwiperArrowPattern::ButtonTouchEvent(RefPtr<FrameNode> buttonNode, TouchType touchType)
272 {
273     auto swiperArrowLayoutProperty = GetSwiperArrowLayoutProperty();
274     CHECK_NULL_VOID(swiperArrowLayoutProperty);
275     const auto& renderContext = buttonNode->GetRenderContext();
276     CHECK_NULL_VOID(renderContext);
277     auto pipelineContext = PipelineBase::GetCurrentContext();
278     CHECK_NULL_VOID(pipelineContext);
279     auto swiperIndicatorTheme = pipelineContext->GetTheme<SwiperIndicatorTheme>();
280     CHECK_NULL_VOID(swiperIndicatorTheme);
281     Color backgroundColor;
282     if (touchType == TouchType::UP || touchType == TouchType::CANCEL) {
283         isTouch_ = false;
284         if (isHover_) {
285             backgroundColor = swiperIndicatorTheme->GetHoverArrowBackgroundColor();
286             renderContext->ResetBlendBgColor();
287             renderContext->BlendBgColor(backgroundColor);
288         } else {
289             renderContext->ResetBlendBgColor();
290         }
291     }
292     if (!hoverOnClickFlag_ && swiperArrowLayoutProperty->GetHoverShowValue(false)) {
293         return;
294     }
295     if (touchType == TouchType::DOWN) {
296         isTouch_ = true;
297         if (isHover_) {
298             backgroundColor = swiperIndicatorTheme->GetHoverArrowBackgroundColor().BlendColor(
299                 swiperIndicatorTheme->GetClickArrowBackgroundColor());
300         } else {
301             backgroundColor = swiperIndicatorTheme->GetClickArrowBackgroundColor();
302         }
303         renderContext->ResetBlendBgColor();
304         renderContext->BlendBgColor(backgroundColor);
305         if (SystemProperties::IsNeedSymbol()) {
306             RefPtr<FrameNode> symbolNode = DynamicCast<FrameNode>(buttonNode->GetFirstChild());
307             CHECK_NULL_VOID(symbolNode);
308             auto symbolLayoutProperty = symbolNode->GetLayoutProperty<TextLayoutProperty>();
309             CHECK_NULL_VOID(symbolLayoutProperty);
310             auto symbolEffectOptions = symbolLayoutProperty->GetSymbolEffectOptionsValue(SymbolEffectOptions());
311             symbolEffectOptions.SetEffectType(SymbolEffectType::BOUNCE);
312             symbolEffectOptions.SetIsTxtActive(true);
313             symbolEffectOptions.SetIsTxtActiveSource(1);
314             symbolLayoutProperty->UpdateSymbolEffectOptions(symbolEffectOptions);
315             symbolNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF);
316         }
317     }
318 }
319 
ButtonOnHover(RefPtr<FrameNode> buttonNode,bool isHovered)320 void SwiperArrowPattern::ButtonOnHover(RefPtr<FrameNode> buttonNode, bool isHovered)
321 {
322     CHECK_NULL_VOID(buttonNode);
323     hoverOnClickFlag_ = isHovered;
324     isHover_ = isHovered;
325     const auto& renderContext = buttonNode->GetRenderContext();
326     CHECK_NULL_VOID(renderContext);
327     auto pipelineContext = PipelineBase::GetCurrentContext();
328     CHECK_NULL_VOID(pipelineContext);
329     auto swiperIndicatorTheme = pipelineContext->GetTheme<SwiperIndicatorTheme>();
330     CHECK_NULL_VOID(swiperIndicatorTheme);
331     Color backgroundColor;
332 
333     auto swiperNode = GetSwiperNode();
334     CHECK_NULL_VOID(swiperNode);
335     auto swiperPattern = swiperNode->GetPattern<SwiperPattern>();
336     CHECK_NULL_VOID(swiperPattern);
337     auto swiperLayoutProperty = swiperPattern->GetLayoutProperty<SwiperLayoutProperty>();
338     CHECK_NULL_VOID(swiperLayoutProperty);
339     if (swiperLayoutProperty->GetHoverShowValue(false)) {
340         swiperPattern->ArrowHover(isHover_, HOVER_ARROW);
341     }
342     if (isHovered) {
343         if (isTouch_) {
344             backgroundColor = swiperIndicatorTheme->GetHoverArrowBackgroundColor().BlendColor(
345                 swiperIndicatorTheme->GetClickArrowBackgroundColor());
346         } else {
347             backgroundColor = swiperIndicatorTheme->GetHoverArrowBackgroundColor();
348         }
349         renderContext->ResetBlendBgColor();
350         renderContext->BlendBgColor(backgroundColor);
351     } else {
352         if (isTouch_) {
353             backgroundColor = swiperIndicatorTheme->GetClickArrowBackgroundColor();
354             renderContext->ResetBlendBgColor();
355             renderContext->BlendBgColor(backgroundColor);
356         } else {
357             renderContext->ResetBlendBgColor();
358         }
359     }
360 }
361 
CheckHoverStatus()362 std::tuple<bool, bool, bool> SwiperArrowPattern::CheckHoverStatus()
363 {
364     auto host = GetHost();
365     CHECK_NULL_RETURN(host, std::make_tuple(false, false, true));
366     auto swiperArrowLayoutProperty = host->GetLayoutProperty<SwiperArrowLayoutProperty>();
367     CHECK_NULL_RETURN(swiperArrowLayoutProperty, std::make_tuple(false, false, true));
368 
369     auto swiperNode = DynamicCast<FrameNode>(host->GetParent());
370     auto swiperPattern = swiperNode ? swiperNode->GetPattern<SwiperPattern>() : nullptr;
371     CHECK_NULL_RETURN(swiperPattern, std::make_tuple(false, false, true));
372 
373     auto displayCount = swiperPattern->GetDisplayCount();
374     bool leftArrowIsHidden = (index_ == 0);
375     bool rightArrowIsHidden = (index_ == swiperPattern->TotalCount() - displayCount);
376     if (Container::GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_EIGHTEEN) && swiperPattern->IsSwipeByGroup()) {
377         leftArrowIsHidden = (index_ < displayCount);
378         rightArrowIsHidden = (index_ >= swiperPattern->TotalCount() - displayCount);
379     }
380     if (swiperPattern->IsHorizontalAndRightToLeft()) {
381         std::swap(leftArrowIsHidden, rightArrowIsHidden);
382     }
383     auto isLeftArrow = host->GetTag() == V2::SWIPER_LEFT_ARROW_ETS_TAG;
384     auto isRightArrow = host->GetTag() == V2::SWIPER_RIGHT_ARROW_ETS_TAG;
385     auto isLoop = swiperArrowLayoutProperty->GetLoopValue(true);
386     auto needHideArrow = (((isLeftArrow && leftArrowIsHidden) || (isRightArrow && rightArrowIsHidden)) && !isLoop)
387         || (swiperPattern->RealTotalCount() <= displayCount);
388     auto isHoverShow = swiperArrowLayoutProperty->GetHoverShowValue(false);
389     auto isHoverNone = swiperPattern->IsHoverNone();
390     return std::make_tuple(needHideArrow, isHoverShow, isHoverNone);
391 }
392 
SetButtonVisible(bool visible)393 void SwiperArrowPattern::SetButtonVisible(bool visible)
394 {
395     isVisible_ = visible;
396     auto host = GetHost();
397     CHECK_NULL_VOID(host);
398     auto buttonNode = DynamicCast<FrameNode>(host->GetFirstChild());
399     CHECK_NULL_VOID(buttonNode);
400     auto buttonNodeGestureHub = buttonNode->GetOrCreateGestureEventHub();
401     CHECK_NULL_VOID(buttonNodeGestureHub);
402     const auto& renderContext = buttonNode->GetRenderContext();
403     CHECK_NULL_VOID(renderContext);
404     auto hostFocusHub = host->GetFocusHub();
405     CHECK_NULL_VOID(hostFocusHub);
406     auto arrowGestureHub = host->GetOrCreateGestureEventHub();
407     CHECK_NULL_VOID(arrowGestureHub);
408 
409     auto [needHideArrow, isHoverShow, isHoverNone] = CheckHoverStatus();
410     if (needHideArrow || isHoverShow) {
411         hostFocusHub->SetParentFocusable(false);
412         hostFocusHub->LostSelfFocus();
413         if (needHideArrow || isHoverNone) {
414             visible = false;
415         }
416     } else {
417         hostFocusHub->SetParentFocusable(true);
418         visible = true;
419     }
420     renderContext->SetVisible(visible);
421     // Set hit test mode BLOCK to make sure button respond to the touch events when visible.
422     arrowGestureHub->SetHitTestMode(visible ? HitTestMode::HTMBLOCK : HitTestMode::HTMTRANSPARENT);
423     if (arrowClickListener_) {
424         arrowGestureHub->RemoveClickEvent(arrowClickListener_);
425         if (visible) {
426             arrowGestureHub->AddClickEvent(arrowClickListener_);
427         }
428     }
429     auto accessibilityProperty = buttonNode->GetAccessibilityProperty<AccessibilityProperty>();
430     auto arrowAccessibilityProperty = host->GetAccessibilityProperty<AccessibilityProperty>();
431     if (accessibilityProperty) {
432         accessibilityProperty->SetAccessibilityLevel(
433             visible ? AccessibilityProperty::Level::AUTO : AccessibilityProperty::Level::NO_STR);
434         arrowAccessibilityProperty->SetAccessibilityLevel(
435             visible ? AccessibilityProperty::Level::AUTO : AccessibilityProperty::Level::NO_STR);
436     }
437 }
438 
UpdateArrowContentBySymbol(RefPtr<FrameNode> & buttonNode,RefPtr<SwiperArrowLayoutProperty> & swiperArrowLayoutProperty)439 void SwiperArrowPattern::UpdateArrowContentBySymbol(RefPtr<FrameNode>& buttonNode,
440     RefPtr<SwiperArrowLayoutProperty>& swiperArrowLayoutProperty)
441 {
442     RefPtr<FrameNode> symbolNode = DynamicCast<FrameNode>(buttonNode->GetFirstChild());
443     CHECK_NULL_VOID(symbolNode);
444     auto symbolLayoutProperty = symbolNode->GetLayoutProperty<TextLayoutProperty>();
445     CHECK_NULL_VOID(symbolLayoutProperty);
446     auto swiperLayoutProperty = GetSwiperArrowLayoutProperty();
447     CHECK_NULL_VOID(swiperLayoutProperty);
448     auto pipelineContext = PipelineBase::GetCurrentContext();
449     CHECK_NULL_VOID(pipelineContext);
450     auto swiperIndicatorTheme = pipelineContext->GetTheme<SwiperIndicatorTheme>();
451     CHECK_NULL_VOID(swiperIndicatorTheme);
452     bool isRtl = swiperLayoutProperty->GetNonAutoLayoutDirection() == TextDirection::RTL;
453     if (V2::SWIPER_LEFT_ARROW_ETS_TAG == GetHost()->GetTag()) {
454         if (swiperLayoutProperty->GetDirection().value_or(Axis::HORIZONTAL) == Axis::HORIZONTAL) {
455             symbolLayoutProperty->UpdateSymbolSourceInfo(SymbolSourceInfo(
456                 isRtl ? swiperIndicatorTheme->GetRightSymbolId() : swiperIndicatorTheme->GetLeftSymbolId()));
457         } else {
458             symbolLayoutProperty->UpdateSymbolSourceInfo(SymbolSourceInfo(swiperIndicatorTheme->GetUpSymbolId()));
459         }
460     } else if (V2::SWIPER_RIGHT_ARROW_ETS_TAG == GetHost()->GetTag()) {
461         if (swiperLayoutProperty->GetDirection().value_or(Axis::HORIZONTAL) == Axis::HORIZONTAL) {
462             symbolLayoutProperty->UpdateSymbolSourceInfo(SymbolSourceInfo(
463                 isRtl ? swiperIndicatorTheme->GetLeftSymbolId() : swiperIndicatorTheme->GetRightSymbolId()));
464         } else {
465             symbolLayoutProperty->UpdateSymbolSourceInfo(SymbolSourceInfo(swiperIndicatorTheme->GetDownSymbolId()));
466         }
467     }
468     symbolLayoutProperty->UpdateFontSize(swiperArrowLayoutProperty->GetArrowSizeValue());
469     symbolLayoutProperty->UpdateSymbolColorList({ swiperArrowLayoutProperty->GetArrowColorValue() });
470     if (!swiperArrowLayoutProperty->GetEnabledValue(true)) {
471         buttonNode->GetRenderContext()->UpdateBackgroundColor(
472             backgroundColor_.BlendOpacity(swiperIndicatorTheme->GetArrowDisabledAlpha()));
473         symbolLayoutProperty->UpdateSymbolColorList({ swiperArrowLayoutProperty->GetArrowColorValue().BlendOpacity(
474             swiperIndicatorTheme->GetArrowDisabledAlpha()) });
475     }
476     symbolNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF_AND_PARENT);
477     symbolNode->MarkModifyDone();
478 }
479 
UpdateArrowContentByImage(RefPtr<FrameNode> & buttonNode,RefPtr<SwiperArrowLayoutProperty> & swiperArrowLayoutProperty)480 void SwiperArrowPattern::UpdateArrowContentByImage(RefPtr<FrameNode>& buttonNode,
481     RefPtr<SwiperArrowLayoutProperty>& swiperArrowLayoutProperty)
482 {
483     RefPtr<FrameNode> imageNode = DynamicCast<FrameNode>(buttonNode->GetFirstChild());
484     CHECK_NULL_VOID(imageNode);
485     auto imageLayoutProperty = imageNode->GetLayoutProperty<ImageLayoutProperty>();
486     CHECK_NULL_VOID(imageLayoutProperty);
487     imageLayoutProperty->UpdateUserDefinedIdealSize(CalcSize(CalcLength(swiperArrowLayoutProperty->GetArrowSizeValue()),
488         CalcLength(swiperArrowLayoutProperty->GetArrowSizeValue())));
489     imageLayoutProperty->UpdateImageFit(ImageFit::FILL);
490     ImageSourceInfo imageSourceInfo;
491     auto swiperLayoutProperty = GetSwiperArrowLayoutProperty();
492     CHECK_NULL_VOID(swiperLayoutProperty);
493     if (V2::SWIPER_LEFT_ARROW_ETS_TAG == GetHost()->GetTag()) {
494         if (swiperLayoutProperty->GetDirection().value_or(Axis::HORIZONTAL) == Axis::HORIZONTAL) {
495             imageSourceInfo.SetResourceId(InternalResource::ResourceId::IC_PUBLIC_ARROW_LEFT_SVG);
496         } else {
497             imageSourceInfo.SetResourceId(InternalResource::ResourceId::IC_PUBLIC_ARROW_UP_SVG);
498         }
499     } else if (V2::SWIPER_RIGHT_ARROW_ETS_TAG == GetHost()->GetTag()) {
500         if (swiperLayoutProperty->GetDirection().value_or(Axis::HORIZONTAL) == Axis::HORIZONTAL) {
501             imageSourceInfo.SetResourceId(InternalResource::ResourceId::IC_PUBLIC_ARROW_RIGHT_SVG);
502         } else {
503             imageSourceInfo.SetResourceId(InternalResource::ResourceId::IC_PUBLIC_ARROW_DOWN_SVG);
504         }
505     }
506     imageSourceInfo.SetFillColor(swiperArrowLayoutProperty->GetArrowColorValue());
507     if (!swiperArrowLayoutProperty->GetEnabledValue(true)) {
508         auto pipelineContext = PipelineBase::GetCurrentContext();
509         CHECK_NULL_VOID(pipelineContext);
510         auto swiperIndicatorTheme = pipelineContext->GetTheme<SwiperIndicatorTheme>();
511         CHECK_NULL_VOID(swiperIndicatorTheme);
512         buttonNode->GetRenderContext()->UpdateBackgroundColor(
513             backgroundColor_.BlendOpacity(swiperIndicatorTheme->GetArrowDisabledAlpha()));
514         imageSourceInfo.SetFillColor(swiperArrowLayoutProperty->GetArrowColorValue().BlendOpacity(
515             swiperIndicatorTheme->GetArrowDisabledAlpha()));
516     }
517     imageLayoutProperty->UpdateImageSourceInfo(imageSourceInfo);
518     imageNode->MarkModifyDone();
519 }
520 
UpdateArrowContent()521 void SwiperArrowPattern::UpdateArrowContent()
522 {
523     auto swiperArrowLayoutProperty = GetSwiperArrowLayoutProperty();
524     CHECK_NULL_VOID(swiperArrowLayoutProperty);
525     auto host = GetHost();
526     CHECK_NULL_VOID(host);
527     auto buttonNode = DynamicCast<FrameNode>(host->GetFirstChild());
528     CHECK_NULL_VOID(buttonNode);
529     auto buttonRenderContext = buttonNode->GetRenderContext();
530     CHECK_NULL_VOID(buttonRenderContext);
531     buttonRenderContext->UpdateBackgroundColor(
532         swiperArrowLayoutProperty->GetIsShowBackgroundValue(false)
533             ? swiperArrowLayoutProperty->GetBackgroundColorValue(backgroundColor_)
534             : Color::TRANSPARENT);
535     auto buttonLayoutProperty = buttonNode->GetLayoutProperty<ButtonLayoutProperty>();
536     CHECK_NULL_VOID(buttonLayoutProperty);
537     buttonLayoutProperty->UpdateUserDefinedIdealSize(
538         CalcSize(CalcLength(swiperArrowLayoutProperty->GetBackgroundSizeValue()),
539             CalcLength(swiperArrowLayoutProperty->GetBackgroundSizeValue())));
540     backgroundColor_ = buttonRenderContext->GetBackgroundColorValue(Color::TRANSPARENT);
541     if (SystemProperties::IsNeedSymbol()) {
542         UpdateArrowContentBySymbol(buttonNode, swiperArrowLayoutProperty);
543     } else {
544         UpdateArrowContentByImage(buttonNode, swiperArrowLayoutProperty);
545     }
546 }
547 
DumpAdvanceInfo()548 void SwiperArrowPattern::DumpAdvanceInfo()
549 {
550     DumpLog::GetInstance().AddDesc("index:" + std::to_string(index_));
551     isTouch_ ? DumpLog::GetInstance().AddDesc("isTouch:true") : DumpLog::GetInstance().AddDesc("isTouch:false");
552     isHover_ ? DumpLog::GetInstance().AddDesc("isHover:true") : DumpLog::GetInstance().AddDesc("isHover:false");
553     hoverOnClickFlag_ ? DumpLog::GetInstance().AddDesc("hoverOnClickFlag:true")
554                       : DumpLog::GetInstance().AddDesc("hoverOnClickFlag:false");
555 }
556 
DumpAdvanceInfo(std::unique_ptr<JsonValue> & json)557 void SwiperArrowPattern::DumpAdvanceInfo(std::unique_ptr<JsonValue>& json)
558 {
559     json->Put("index", index_);
560     json->Put("isTouch", isTouch_);
561     json->Put("isHover", isHover_);
562     json->Put("hoverOnClickFlag", hoverOnClickFlag_);
563 }
564 
GetSwiperPattern() const565 RefPtr<SwiperPattern> SwiperArrowPattern::GetSwiperPattern() const
566 {
567     auto swiperNode = GetSwiperNode();
568     CHECK_NULL_RETURN(swiperNode, nullptr);
569     return swiperNode->GetPattern<SwiperPattern>();
570 }
571 } // namespace OHOS::Ace::NG
572