• 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->GetOrCreateEventHub<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     auto pattern = buttonNode->GetPattern<ButtonPattern>();
257     CHECK_NULL_VOID(pattern);
258     pattern->HandleBackgroundColor();
259     auto buttonLayoutProperty = buttonNode->GetLayoutProperty<ButtonLayoutProperty>();
260     CHECK_NULL_VOID(buttonLayoutProperty);
261     buttonLayoutProperty->UpdateType(ButtonType::CIRCLE);
262 }
263 
TotalCount() const264 int32_t SwiperArrowPattern::TotalCount() const
265 {
266     auto swiperNode = GetSwiperNode();
267     CHECK_NULL_RETURN(swiperNode, 0);
268     auto swiperPattern = swiperNode->GetPattern<SwiperPattern>();
269     CHECK_NULL_RETURN(swiperPattern, 0);
270     return swiperPattern->RealTotalCount() - 1;
271 }
272 
ButtonTouchEvent(RefPtr<FrameNode> buttonNode,TouchType touchType)273 void SwiperArrowPattern::ButtonTouchEvent(RefPtr<FrameNode> buttonNode, TouchType touchType)
274 {
275     auto swiperArrowLayoutProperty = GetSwiperArrowLayoutProperty();
276     CHECK_NULL_VOID(swiperArrowLayoutProperty);
277     const auto& renderContext = buttonNode->GetRenderContext();
278     CHECK_NULL_VOID(renderContext);
279     auto pipelineContext = PipelineBase::GetCurrentContext();
280     CHECK_NULL_VOID(pipelineContext);
281     auto swiperIndicatorTheme = pipelineContext->GetTheme<SwiperIndicatorTheme>();
282     CHECK_NULL_VOID(swiperIndicatorTheme);
283     Color backgroundColor;
284     if (touchType == TouchType::UP || touchType == TouchType::CANCEL) {
285         isTouch_ = false;
286         if (isHover_) {
287             backgroundColor = swiperIndicatorTheme->GetHoverArrowBackgroundColor();
288             renderContext->ResetBlendBgColor();
289             renderContext->BlendBgColor(backgroundColor);
290         } else {
291             renderContext->ResetBlendBgColor();
292         }
293     }
294     if (!hoverOnClickFlag_ && swiperArrowLayoutProperty->GetHoverShowValue(false)) {
295         return;
296     }
297     if (touchType == TouchType::DOWN) {
298         isTouch_ = true;
299         if (isHover_) {
300             backgroundColor = swiperIndicatorTheme->GetHoverArrowBackgroundColor().BlendColor(
301                 swiperIndicatorTheme->GetClickArrowBackgroundColor());
302         } else {
303             backgroundColor = swiperIndicatorTheme->GetClickArrowBackgroundColor();
304         }
305         renderContext->ResetBlendBgColor();
306         renderContext->BlendBgColor(backgroundColor);
307         if (SystemProperties::IsNeedSymbol()) {
308             RefPtr<FrameNode> symbolNode = DynamicCast<FrameNode>(buttonNode->GetFirstChild());
309             CHECK_NULL_VOID(symbolNode);
310             auto symbolLayoutProperty = symbolNode->GetLayoutProperty<TextLayoutProperty>();
311             CHECK_NULL_VOID(symbolLayoutProperty);
312             auto symbolEffectOptions = symbolLayoutProperty->GetSymbolEffectOptionsValue(SymbolEffectOptions());
313             symbolEffectOptions.SetEffectType(SymbolEffectType::BOUNCE);
314             symbolEffectOptions.SetIsTxtActive(true);
315             symbolEffectOptions.SetIsTxtActiveSource(1);
316             symbolLayoutProperty->UpdateSymbolEffectOptions(symbolEffectOptions);
317             symbolNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF);
318         }
319     }
320 }
321 
ButtonOnHover(RefPtr<FrameNode> buttonNode,bool isHovered)322 void SwiperArrowPattern::ButtonOnHover(RefPtr<FrameNode> buttonNode, bool isHovered)
323 {
324     CHECK_NULL_VOID(buttonNode);
325     hoverOnClickFlag_ = isHovered;
326     isHover_ = isHovered;
327     const auto& renderContext = buttonNode->GetRenderContext();
328     CHECK_NULL_VOID(renderContext);
329     auto pipelineContext = PipelineBase::GetCurrentContext();
330     CHECK_NULL_VOID(pipelineContext);
331     auto swiperIndicatorTheme = pipelineContext->GetTheme<SwiperIndicatorTheme>();
332     CHECK_NULL_VOID(swiperIndicatorTheme);
333     Color backgroundColor;
334 
335     auto swiperNode = GetSwiperNode();
336     CHECK_NULL_VOID(swiperNode);
337     auto swiperPattern = swiperNode->GetPattern<SwiperPattern>();
338     CHECK_NULL_VOID(swiperPattern);
339     auto swiperLayoutProperty = swiperPattern->GetLayoutProperty<SwiperLayoutProperty>();
340     CHECK_NULL_VOID(swiperLayoutProperty);
341     if (swiperLayoutProperty->GetHoverShowValue(false)) {
342         swiperPattern->ArrowHover(isHover_, HOVER_ARROW);
343     }
344     if (isHovered) {
345         if (isTouch_) {
346             backgroundColor = swiperIndicatorTheme->GetHoverArrowBackgroundColor().BlendColor(
347                 swiperIndicatorTheme->GetClickArrowBackgroundColor());
348         } else {
349             backgroundColor = swiperIndicatorTheme->GetHoverArrowBackgroundColor();
350         }
351         renderContext->ResetBlendBgColor();
352         renderContext->BlendBgColor(backgroundColor);
353     } else {
354         if (isTouch_) {
355             backgroundColor = swiperIndicatorTheme->GetClickArrowBackgroundColor();
356             renderContext->ResetBlendBgColor();
357             renderContext->BlendBgColor(backgroundColor);
358         } else {
359             renderContext->ResetBlendBgColor();
360         }
361     }
362 }
363 
SetLayoutDisplayCount(int32_t displayCount)364 void SwiperArrowPattern::SetLayoutDisplayCount(int32_t displayCount)
365 {
366     if (displayCount_ != displayCount) {
367         displayCount_ = displayCount;
368         SetButtonVisible(isVisible_);
369     }
370 }
371 
CheckHoverStatus()372 std::tuple<bool, bool, bool> SwiperArrowPattern::CheckHoverStatus()
373 {
374     auto host = GetHost();
375     CHECK_NULL_RETURN(host, std::make_tuple(false, false, true));
376     auto swiperArrowLayoutProperty = host->GetLayoutProperty<SwiperArrowLayoutProperty>();
377     CHECK_NULL_RETURN(swiperArrowLayoutProperty, std::make_tuple(false, false, true));
378 
379     auto swiperNode = DynamicCast<FrameNode>(host->GetParent());
380     auto swiperPattern = swiperNode ? swiperNode->GetPattern<SwiperPattern>() : nullptr;
381     CHECK_NULL_RETURN(swiperPattern, std::make_tuple(false, false, true));
382 
383     displayCount_ = swiperPattern->GetDisplayCount();
384     bool leftArrowIsHidden = (index_ == 0);
385     bool rightArrowIsHidden = (index_ == swiperPattern->TotalCount() - displayCount_);
386     if (!swiperPattern->IsAutoLinear() && swiperPattern->IsSwipeByGroup()) {
387         leftArrowIsHidden = (index_ < displayCount_);
388         rightArrowIsHidden = (index_ >= swiperPattern->TotalCount() - displayCount_);
389     }
390     if (swiperPattern->IsHorizontalAndRightToLeft()) {
391         std::swap(leftArrowIsHidden, rightArrowIsHidden);
392     }
393     auto isLeftArrow = host->GetTag() == V2::SWIPER_LEFT_ARROW_ETS_TAG;
394     auto isRightArrow = host->GetTag() == V2::SWIPER_RIGHT_ARROW_ETS_TAG;
395     auto isLoop = swiperArrowLayoutProperty->GetLoopValue(true);
396     auto needHideArrow = (((isLeftArrow && leftArrowIsHidden) || (isRightArrow && rightArrowIsHidden)) && !isLoop)
397         || (swiperPattern->RealTotalCount() <= displayCount_);
398     auto isHoverShow = swiperArrowLayoutProperty->GetHoverShowValue(false);
399     auto isHoverNone = swiperPattern->IsHoverNone();
400     return std::make_tuple(needHideArrow, isHoverShow, isHoverNone);
401 }
402 
SetButtonVisible(bool visible)403 void SwiperArrowPattern::SetButtonVisible(bool visible)
404 {
405     isVisible_ = visible;
406     auto host = GetHost();
407     CHECK_NULL_VOID(host);
408     auto buttonNode = DynamicCast<FrameNode>(host->GetFirstChild());
409     CHECK_NULL_VOID(buttonNode);
410     auto buttonNodeGestureHub = buttonNode->GetOrCreateGestureEventHub();
411     CHECK_NULL_VOID(buttonNodeGestureHub);
412     const auto& renderContext = buttonNode->GetRenderContext();
413     CHECK_NULL_VOID(renderContext);
414     auto hostFocusHub = host->GetFocusHub();
415     CHECK_NULL_VOID(hostFocusHub);
416     auto arrowGestureHub = host->GetOrCreateGestureEventHub();
417     CHECK_NULL_VOID(arrowGestureHub);
418 
419     auto [needHideArrow, isHoverShow, isHoverNone] = CheckHoverStatus();
420     if (needHideArrow || isHoverShow) {
421         hostFocusHub->SetParentFocusable(false);
422         hostFocusHub->LostSelfFocus();
423         if (needHideArrow || isHoverNone) {
424             visible = false;
425         }
426     } else {
427         hostFocusHub->SetParentFocusable(true);
428         visible = true;
429     }
430     renderContext->SetVisible(visible);
431     // Set hit test mode BLOCK to make sure button respond to the touch events when visible.
432     if (AceApplicationInfo::GetInstance().IsAccessibilityEnabled()) {
433         arrowGestureHub->SetHitTestMode(visible ? HitTestMode::HTMBLOCK : HitTestMode::HTMTRANSPARENT);
434     } else {
435         arrowGestureHub->SetHitTestMode(visible ? HitTestMode::HTMDEFAULT : HitTestMode::HTMTRANSPARENT);
436     }
437     if (arrowClickListener_) {
438         arrowGestureHub->RemoveClickEvent(arrowClickListener_);
439         if (visible) {
440             arrowGestureHub->AddClickEvent(arrowClickListener_);
441         }
442     }
443     auto accessibilityProperty = buttonNode->GetAccessibilityProperty<AccessibilityProperty>();
444     auto arrowAccessibilityProperty = host->GetAccessibilityProperty<AccessibilityProperty>();
445     auto swiperNode = GetSwiperNode();
446     CHECK_NULL_VOID(swiperNode);
447     CHECK_NULL_VOID(accessibilityProperty);
448     if (visible) {
449         accessibilityProperty->SetAccessibilityLevel(AccessibilityProperty::Level::AUTO);
450         arrowAccessibilityProperty->SetAccessibilityLevel(AccessibilityProperty::Level::AUTO);
451     } else {
452         accessibilityProperty->SetAccessibilityLevel(AccessibilityProperty::Level::NO_STR);
453         arrowAccessibilityProperty->SetAccessibilityLevel(AccessibilityProperty::Level::NO_STR);
454         auto isArrowFocus = arrowAccessibilityProperty->GetAccessibilityFocusState();
455         if (isArrowFocus) {
456             swiperNode->OnAccessibilityEvent(AccessibilityEventType::CHANGE);
457         }
458     }
459 }
460 
UpdateArrowContentBySymbol(RefPtr<FrameNode> & buttonNode,RefPtr<SwiperArrowLayoutProperty> & swiperArrowLayoutProperty)461 void SwiperArrowPattern::UpdateArrowContentBySymbol(RefPtr<FrameNode>& buttonNode,
462     RefPtr<SwiperArrowLayoutProperty>& swiperArrowLayoutProperty)
463 {
464     RefPtr<FrameNode> symbolNode = DynamicCast<FrameNode>(buttonNode->GetFirstChild());
465     CHECK_NULL_VOID(symbolNode);
466     auto symbolLayoutProperty = symbolNode->GetLayoutProperty<TextLayoutProperty>();
467     CHECK_NULL_VOID(symbolLayoutProperty);
468     auto swiperLayoutProperty = GetSwiperArrowLayoutProperty();
469     CHECK_NULL_VOID(swiperLayoutProperty);
470     auto pipelineContext = PipelineBase::GetCurrentContext();
471     CHECK_NULL_VOID(pipelineContext);
472     auto swiperIndicatorTheme = pipelineContext->GetTheme<SwiperIndicatorTheme>();
473     CHECK_NULL_VOID(swiperIndicatorTheme);
474     bool isRtl = swiperLayoutProperty->GetNonAutoLayoutDirection() == TextDirection::RTL;
475     if (V2::SWIPER_LEFT_ARROW_ETS_TAG == GetHost()->GetTag()) {
476         if (swiperLayoutProperty->GetDirection().value_or(Axis::HORIZONTAL) == Axis::HORIZONTAL) {
477             symbolLayoutProperty->UpdateSymbolSourceInfo(SymbolSourceInfo(
478                 isRtl ? swiperIndicatorTheme->GetRightSymbolId() : swiperIndicatorTheme->GetLeftSymbolId()));
479         } else {
480             symbolLayoutProperty->UpdateSymbolSourceInfo(SymbolSourceInfo(swiperIndicatorTheme->GetUpSymbolId()));
481         }
482     } else if (V2::SWIPER_RIGHT_ARROW_ETS_TAG == GetHost()->GetTag()) {
483         if (swiperLayoutProperty->GetDirection().value_or(Axis::HORIZONTAL) == Axis::HORIZONTAL) {
484             symbolLayoutProperty->UpdateSymbolSourceInfo(SymbolSourceInfo(
485                 isRtl ? swiperIndicatorTheme->GetLeftSymbolId() : swiperIndicatorTheme->GetRightSymbolId()));
486         } else {
487             symbolLayoutProperty->UpdateSymbolSourceInfo(SymbolSourceInfo(swiperIndicatorTheme->GetDownSymbolId()));
488         }
489     }
490     symbolLayoutProperty->UpdateFontSize(swiperArrowLayoutProperty->GetArrowSizeValue());
491     symbolLayoutProperty->UpdateSymbolColorList({ swiperArrowLayoutProperty->GetArrowColorValue() });
492     if (!swiperArrowLayoutProperty->GetEnabledValue(true)) {
493         buttonNode->GetRenderContext()->UpdateBackgroundColor(
494             backgroundColor_.BlendOpacity(swiperIndicatorTheme->GetArrowDisabledAlpha()));
495         symbolLayoutProperty->UpdateSymbolColorList({ swiperArrowLayoutProperty->GetArrowColorValue().BlendOpacity(
496             swiperIndicatorTheme->GetArrowDisabledAlpha()) });
497     }
498     symbolNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF_AND_PARENT);
499     symbolNode->MarkModifyDone();
500 }
501 
UpdateArrowContentByImage(RefPtr<FrameNode> & buttonNode,RefPtr<SwiperArrowLayoutProperty> & swiperArrowLayoutProperty)502 void SwiperArrowPattern::UpdateArrowContentByImage(RefPtr<FrameNode>& buttonNode,
503     RefPtr<SwiperArrowLayoutProperty>& swiperArrowLayoutProperty)
504 {
505     RefPtr<FrameNode> imageNode = DynamicCast<FrameNode>(buttonNode->GetFirstChild());
506     CHECK_NULL_VOID(imageNode);
507     auto imageLayoutProperty = imageNode->GetLayoutProperty<ImageLayoutProperty>();
508     CHECK_NULL_VOID(imageLayoutProperty);
509     imageLayoutProperty->UpdateUserDefinedIdealSize(CalcSize(CalcLength(swiperArrowLayoutProperty->GetArrowSizeValue()),
510         CalcLength(swiperArrowLayoutProperty->GetArrowSizeValue())));
511     imageLayoutProperty->UpdateImageFit(ImageFit::FILL);
512     ImageSourceInfo imageSourceInfo;
513     auto swiperLayoutProperty = GetSwiperArrowLayoutProperty();
514     CHECK_NULL_VOID(swiperLayoutProperty);
515     if (V2::SWIPER_LEFT_ARROW_ETS_TAG == GetHost()->GetTag()) {
516         if (swiperLayoutProperty->GetDirection().value_or(Axis::HORIZONTAL) == Axis::HORIZONTAL) {
517             imageSourceInfo.SetResourceId(InternalResource::ResourceId::IC_PUBLIC_ARROW_LEFT_SVG);
518         } else {
519             imageSourceInfo.SetResourceId(InternalResource::ResourceId::IC_PUBLIC_ARROW_UP_SVG);
520         }
521     } else if (V2::SWIPER_RIGHT_ARROW_ETS_TAG == GetHost()->GetTag()) {
522         if (swiperLayoutProperty->GetDirection().value_or(Axis::HORIZONTAL) == Axis::HORIZONTAL) {
523             imageSourceInfo.SetResourceId(InternalResource::ResourceId::IC_PUBLIC_ARROW_RIGHT_SVG);
524         } else {
525             imageSourceInfo.SetResourceId(InternalResource::ResourceId::IC_PUBLIC_ARROW_DOWN_SVG);
526         }
527     }
528     imageSourceInfo.SetFillColor(swiperArrowLayoutProperty->GetArrowColorValue());
529     if (!swiperArrowLayoutProperty->GetEnabledValue(true)) {
530         auto pipelineContext = PipelineBase::GetCurrentContext();
531         CHECK_NULL_VOID(pipelineContext);
532         auto swiperIndicatorTheme = pipelineContext->GetTheme<SwiperIndicatorTheme>();
533         CHECK_NULL_VOID(swiperIndicatorTheme);
534         buttonNode->GetRenderContext()->UpdateBackgroundColor(
535             backgroundColor_.BlendOpacity(swiperIndicatorTheme->GetArrowDisabledAlpha()));
536         imageSourceInfo.SetFillColor(swiperArrowLayoutProperty->GetArrowColorValue().BlendOpacity(
537             swiperIndicatorTheme->GetArrowDisabledAlpha()));
538     }
539     imageLayoutProperty->UpdateImageSourceInfo(imageSourceInfo);
540     imageNode->MarkModifyDone();
541 }
542 
UpdateArrowContent()543 void SwiperArrowPattern::UpdateArrowContent()
544 {
545     auto swiperArrowLayoutProperty = GetSwiperArrowLayoutProperty();
546     CHECK_NULL_VOID(swiperArrowLayoutProperty);
547     auto host = GetHost();
548     CHECK_NULL_VOID(host);
549     auto buttonNode = DynamicCast<FrameNode>(host->GetFirstChild());
550     CHECK_NULL_VOID(buttonNode);
551     auto buttonRenderContext = buttonNode->GetRenderContext();
552     CHECK_NULL_VOID(buttonRenderContext);
553     buttonRenderContext->UpdateBackgroundColor(
554         swiperArrowLayoutProperty->GetIsShowBackgroundValue(false)
555             ? swiperArrowLayoutProperty->GetBackgroundColorValue(backgroundColor_)
556             : Color::TRANSPARENT);
557     auto buttonLayoutProperty = buttonNode->GetLayoutProperty<ButtonLayoutProperty>();
558     CHECK_NULL_VOID(buttonLayoutProperty);
559     buttonLayoutProperty->UpdateUserDefinedIdealSize(
560         CalcSize(CalcLength(swiperArrowLayoutProperty->GetBackgroundSizeValue()),
561             CalcLength(swiperArrowLayoutProperty->GetBackgroundSizeValue())));
562     backgroundColor_ = buttonRenderContext->GetBackgroundColorValue(Color::TRANSPARENT);
563     if (SystemProperties::IsNeedSymbol()) {
564         UpdateArrowContentBySymbol(buttonNode, swiperArrowLayoutProperty);
565     } else {
566         UpdateArrowContentByImage(buttonNode, swiperArrowLayoutProperty);
567     }
568 }
569 
DumpAdvanceInfo()570 void SwiperArrowPattern::DumpAdvanceInfo()
571 {
572     DumpLog::GetInstance().AddDesc("index:" + std::to_string(index_));
573     isTouch_ ? DumpLog::GetInstance().AddDesc("isTouch:true") : DumpLog::GetInstance().AddDesc("isTouch:false");
574     isHover_ ? DumpLog::GetInstance().AddDesc("isHover:true") : DumpLog::GetInstance().AddDesc("isHover:false");
575     hoverOnClickFlag_ ? DumpLog::GetInstance().AddDesc("hoverOnClickFlag:true")
576                       : DumpLog::GetInstance().AddDesc("hoverOnClickFlag:false");
577 }
578 
DumpAdvanceInfo(std::unique_ptr<JsonValue> & json)579 void SwiperArrowPattern::DumpAdvanceInfo(std::unique_ptr<JsonValue>& json)
580 {
581     json->Put("index", index_);
582     json->Put("isTouch", isTouch_);
583     json->Put("isHover", isHover_);
584     json->Put("hoverOnClickFlag", hoverOnClickFlag_);
585 }
586 
GetSwiperPattern() const587 RefPtr<SwiperPattern> SwiperArrowPattern::GetSwiperPattern() const
588 {
589     auto swiperNode = GetSwiperNode();
590     CHECK_NULL_RETURN(swiperNode, nullptr);
591     return swiperNode->GetPattern<SwiperPattern>();
592 }
593 } // namespace OHOS::Ace::NG
594