• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TABS_TAB_BAR_PATTERN_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TABS_TAB_BAR_PATTERN_H
18 
19 #include <optional>
20 #include <unordered_map>
21 
22 #include "base/geometry/axis.h"
23 #include "base/memory/referenced.h"
24 #include "core/components/common/layout/constants.h"
25 #include "core/components/swiper/swiper_controller.h"
26 #include "core/components/tab_bar/tab_theme.h"
27 #include "core/components_ng/event/event_hub.h"
28 #include "core/components_ng/pattern/pattern.h"
29 #include "core/components_ng/pattern/swiper/swiper_pattern.h"
30 #include "core/components_ng/pattern/tabs/tab_bar_accessibility_property.h"
31 #include "core/components_ng/pattern/tabs/tab_bar_layout_algorithm.h"
32 #include "core/components_ng/pattern/tabs/tab_bar_layout_property.h"
33 #include "core/components_ng/pattern/tabs/tab_bar_paint_method.h"
34 #include "core/components_ng/pattern/tabs/tab_bar_paint_property.h"
35 #include "core/components_ng/pattern/tabs/tab_content_model.h"
36 #include "core/event/mouse_event.h"
37 #include "core/components_ng/pattern/tabs/tab_content_transition_proxy.h"
38 #include "frameworks/core/components_ng/event/focus_hub.h"
39 
40 namespace OHOS::Ace::NG {
41 class InspectorFilter;
42 class TextLayoutProperty;
43 
44 const auto TabBarPhysicalCurve = AceType::MakeRefPtr<InterpolatingSpring>(-1.0f, 1.0f, 228.0f, 30.f);
45 
46 using TabBarBuilderFunc = std::function<void()>;
47 class TabBarParam : public virtual Referenced {
48 public:
TabBarParam(const std::string & textParam,const std::string & iconParam,TabBarBuilderFunc && builderParam)49     TabBarParam(const std::string& textParam, const std::string& iconParam, TabBarBuilderFunc&& builderParam)
50         : text_(textParam), icon_(iconParam), builder_(std::move(builderParam)) {};
51 
GetIcon()52     const std::string& GetIcon() const
53     {
54         return icon_;
55     }
56 
SetIcon(const std::string & icon)57     void SetIcon(const std::string& icon)
58     {
59         icon_ = icon;
60     }
61 
GetText()62     const std::string& GetText() const
63     {
64         return text_;
65     }
66 
SetText(const std::string & text)67     void SetText(const std::string& text)
68     {
69         text_ = text;
70     }
71 
GetSymbol()72     const std::optional<TabBarSymbol>& GetSymbol() const
73     {
74         return symbol_;
75     }
76 
SetSymbol(const std::optional<TabBarSymbol> & symbol)77     void SetSymbol(const std::optional<TabBarSymbol>& symbol)
78     {
79         symbol_ = symbol;
80     }
81 
HasBuilder()82     bool HasBuilder() const
83     {
84         return builder_ != nullptr;
85     }
86 
SetBuilder(TabBarBuilderFunc && builderParam)87     void SetBuilder(TabBarBuilderFunc&& builderParam)
88     {
89         builder_ = std::move(builderParam);
90     }
91 
ExecuteBuilder()92     void ExecuteBuilder() const
93     {
94         if (builder_ != nullptr) {
95             builder_();
96         }
97     }
98 
SetTabBarStyle(TabBarStyle tabBarStyle)99     void SetTabBarStyle(TabBarStyle tabBarStyle)
100     {
101         tabBarStyle_ = tabBarStyle;
102     }
103 
GetTabBarStyle()104     TabBarStyle GetTabBarStyle() const
105     {
106         return tabBarStyle_;
107     }
108 
SetCustomNode(FrameNode * node)109     void SetCustomNode(FrameNode* node)
110     {
111         node_ = node;
112     }
113 
HasContent()114     bool HasContent() const
115     {
116         return !content_.Invalid();
117     }
118 
SetContent(const WeakPtr<NG::UINode> & content)119     void SetContent(const WeakPtr<NG::UINode>& content)
120     {
121         content_ = content;
122     }
123 
GetContent()124     const WeakPtr<NG::UINode>& GetContent() const
125     {
126         return content_;
127     }
128 
129 private:
130     std::string text_;
131     std::string icon_;
132     std::optional<TabBarSymbol> symbol_;
133     TabBarBuilderFunc builder_;
134     WeakPtr<NG::UINode> content_ = nullptr;
135     TabBarStyle tabBarStyle_ = TabBarStyle::NOSTYLE;
136     FrameNode* node_ = nullptr;
137 };
138 
139 enum class AnimationType {
140     PRESS = 0,
141     HOVER,
142     HOVERTOPRESS,
143 };
144 
145 enum class TabBarState {
146     SHOW = 0,
147     HIDE
148 };
149 
150 enum class TabBarParamType {
151     NORMAL = 0,
152     CUSTOM_BUILDER,
153     COMPONENT_CONTENT,
154     SUB_COMPONENT_CONTENT
155 };
156 
157 class TabBarPattern : public Pattern {
158     DECLARE_ACE_TYPE(TabBarPattern, Pattern);
159 
160 public:
161     TabBarPattern();
162     ~TabBarPattern() override;
163 
IsAtomicNode()164     bool IsAtomicNode() const override
165     {
166         return false;
167     }
168 
CreateLayoutProperty()169     RefPtr<LayoutProperty> CreateLayoutProperty() override
170     {
171         return MakeRefPtr<TabBarLayoutProperty>();
172     }
173 
CreateLayoutAlgorithm()174     RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override
175     {
176         auto layoutAlgorithm = MakeRefPtr<TabBarLayoutAlgorithm>();
177         layoutAlgorithm->SetCurrentDelta(currentDelta_);
178         layoutAlgorithm->SetTabBarStyle(tabBarStyle_);
179         if (targetIndex_) {
180             layoutAlgorithm->SetTargetIndex(targetIndex_);
181         } else if (jumpIndex_) {
182             layoutAlgorithm->SetJumpIndex(jumpIndex_);
183         } else if (focusIndex_) {
184             layoutAlgorithm->SetFocusIndex(focusIndex_);
185         }
186         layoutAlgorithm->SetVisibleItemPosition(visibleItemPosition_);
187         layoutAlgorithm->SetCanOverScroll(canOverScroll_);
188         return layoutAlgorithm;
189     }
190 
CreatePaintProperty()191     RefPtr<PaintProperty> CreatePaintProperty() override
192     {
193         return MakeRefPtr<TabBarPaintProperty>();
194     }
195 
196     RefPtr<NodePaintMethod> CreateNodePaintMethod() override;
197 
CreateAccessibilityProperty()198     RefPtr<AccessibilityProperty> CreateAccessibilityProperty() override
199     {
200         return MakeRefPtr<TabBarAccessibilityProperty>();
201     }
202 
GetFocusPattern()203     FocusPattern GetFocusPattern() const override
204     {
205         return { FocusType::SCOPE, true };
206     }
207 
208     void SetController(const RefPtr<SwiperController>& controller);
209 
SetIndicator(int32_t indicator)210     void SetIndicator(int32_t indicator)
211     {
212         indicator_ = indicator;
213     }
214 
215     void OnTabBarIndexChange(int32_t index);
216 
217     void UpdateCurrentOffset(float offset);
218 
219     void UpdateIndicator(int32_t indicator);
220 
221     void UpdateTextColorAndFontWeight(int32_t indicator);
222 
223     void UpdateImageColor(int32_t indicator);
224 
225     void UpdateSymbolStats(int32_t index, int32_t preIndex);
226     void AdjustSymbolStats(int32_t index);
227 
228     void UpdateSymbolEffect(int32_t index);
229 
230     void UpdateSubTabBoard(int32_t index);
231 
232     void GetColumnId(int32_t& selectedColumnId, int32_t& focusedColumnId, int32_t indicator) const;
233 
234     SelectedMode GetSelectedMode() const;
235 
AddTabBarItemType(int32_t tabBarItemId,TabBarParamType type)236     void AddTabBarItemType(int32_t tabBarItemId, TabBarParamType type)
237     {
238         tabBarType_.emplace(std::make_pair(tabBarItemId, type));
239     }
240 
241     bool IsContainsBuilder();
242 
243     void SetAnimationCurve(const RefPtr<Curve>& curve);
244     const RefPtr<Curve> GetAnimationCurve(const RefPtr<Curve>& defaultCurve) const;
245 
SetAnimationDuration(int32_t animationDuration)246     void SetAnimationDuration(int32_t animationDuration)
247     {
248         animationDuration_ = animationDuration;
249     }
250 
SetTouching(bool isTouching)251     void SetTouching(bool isTouching)
252     {
253         touching_ = isTouching;
254     }
255 
IsTouching()256     bool IsTouching() const
257     {
258         return touching_;
259     }
260 
SetTabBarStyle(TabBarStyle tabBarStyle)261     void SetTabBarStyle(TabBarStyle tabBarStyle)
262     {
263         tabBarStyle_ = tabBarStyle;
264         InitLongPressAndDragEvent();
265     }
266 
GetTabBarStyle()267     TabBarStyle GetTabBarStyle() const
268     {
269         return tabBarStyle_;
270     }
271 
272     void TriggerTranslateAnimation(int32_t currentIndex, int32_t targetIndex);
273 
274     RectF GetOriginalPaintRect(int32_t currentIndex);
275 
276     void HandleBottomTabBarChange(int32_t index);
277 
GetChangeByClick()278     bool GetChangeByClick() const
279     {
280         return changeByClick_;
281     }
282 
SetChangeByClick(bool changeByClick)283     void SetChangeByClick(bool changeByClick)
284     {
285         changeByClick_ = changeByClick;
286     }
287 
GetClickRepeat()288     bool GetClickRepeat() const
289     {
290         return clickRepeat_;
291     }
292 
SetClickRepeat(bool clickRepeat)293     void SetClickRepeat(bool clickRepeat)
294     {
295         clickRepeat_ = clickRepeat;
296     }
297 
298     void SetSelectedMode(SelectedMode selectedMode, uint32_t position, bool newTabBar = false)
299     {
300         if (selectedModes_.size() <= position) {
301             selectedModes_.emplace_back(selectedMode);
302             return;
303         }
304 
305         if (newTabBar) {
306             selectedModes_.insert(selectedModes_.begin() + position, selectedMode);
307             return;
308         }
309 
310         selectedModes_[position] = selectedMode;
311     }
312 
313     void SetIndicatorStyle(const IndicatorStyle& indicatorStyle, uint32_t position, bool newTabBar = false)
314     {
315         if (indicatorStyles_.size() <= position) {
316             indicatorStyles_.emplace_back(indicatorStyle);
317             return;
318         }
319 
320         if (newTabBar) {
321             indicatorStyles_.insert(indicatorStyles_.begin() + position, indicatorStyle);
322             return;
323         }
324 
325         indicatorStyles_[position] = indicatorStyle;
326     }
327 
328     void SetTabBarStyle(TabBarStyle tabBarStyle, uint32_t position, bool newTabBar = false)
329     {
330         if (tabBarStyles_.size() <= position) {
331             tabBarStyles_.emplace_back(tabBarStyle);
332             return;
333         }
334 
335         if (newTabBar) {
336             tabBarStyles_.insert(tabBarStyles_.begin() + position, tabBarStyle);
337             return;
338         }
339 
340         tabBarStyles_[position] = tabBarStyle;
341     }
342 
343     void SetBottomTabBarStyle(const BottomTabBarStyle& bottomTabBarStyle, uint32_t position, bool newTabBar = false)
344     {
345         if (bottomTabBarStyles_.size() <= position) {
346             bottomTabBarStyles_.emplace_back(bottomTabBarStyle);
347             return;
348         }
349 
350         if (newTabBar) {
351             bottomTabBarStyles_.insert(bottomTabBarStyles_.begin() + position, bottomTabBarStyle);
352             return;
353         }
354 
355         bottomTabBarStyles_[position] = bottomTabBarStyle;
356     }
357 
SetLabelStyle(int32_t tabBarItemId,const LabelStyle & labelStyle)358     void SetLabelStyle(int32_t tabBarItemId, const LabelStyle& labelStyle)
359     {
360         labelStyles_[tabBarItemId] = labelStyle;
361     }
362 
363     void SetIconStyle(const IconStyle& iconStyle, uint32_t position, bool newTabBar = false)
364     {
365         if (iconStyles_.size() <= position) {
366             iconStyles_.emplace_back(iconStyle);
367             return;
368         }
369 
370         if (newTabBar) {
371             iconStyles_.insert(iconStyles_.begin() + position, iconStyle);
372             return;
373         }
374 
375         iconStyles_[position] = iconStyle;
376     }
377 
GetIconStyle()378     std::vector<IconStyle> GetIconStyle()
379     {
380         return iconStyles_;
381     }
382 
383     void SetSymbol(const TabBarSymbol& symbol, uint32_t position, bool newTabBar = false)
384     {
385         if (symbolArray_.size() <= position) {
386             symbolArray_.emplace_back(symbol);
387             return;
388         }
389 
390         if (newTabBar) {
391             symbolArray_.insert(symbolArray_.begin() + position, symbol);
392             return;
393         }
394 
395         symbolArray_[position] = symbol;
396     }
397 
GetSymbol()398     std::vector<TabBarSymbol> GetSymbol()
399     {
400         return symbolArray_;
401     }
402 
IsMaskAnimationByCreate()403     bool IsMaskAnimationByCreate()
404     {
405         return isMaskAnimationByCreate_;
406     }
407 
SetMaskAnimationByCreate(bool isMaskAnimationByCreate)408     void SetMaskAnimationByCreate(bool isMaskAnimationByCreate)
409     {
410         isMaskAnimationByCreate_ = isMaskAnimationByCreate;
411     }
412 
IsMaskAnimationExecuted()413     bool IsMaskAnimationExecuted()
414     {
415         return isMaskAnimationExecuted_;
416     }
417 
SetMaskAnimationExecuted(bool isMaskAnimationExecuted)418     void SetMaskAnimationExecuted(bool isMaskAnimationExecuted)
419     {
420         isMaskAnimationExecuted_ = isMaskAnimationExecuted;
421     }
422 
SetImageColorOnIndex(int32_t index)423     void SetImageColorOnIndex(int32_t index)
424     {
425         imageColorOnIndex_ = index;
426     }
427 
GetImageColorOnIndex()428     std::optional<int32_t> GetImageColorOnIndex()
429     {
430         return imageColorOnIndex_;
431     }
432 
GetIndicator()433     int32_t GetIndicator()
434     {
435         return indicator_;
436     }
437 
438     bool IsAtTop() const;
439 
440     bool IsAtBottom() const;
441     std::string ProvideRestoreInfo() override;
442     void OnRestoreInfo(const std::string& restoreInfo) override;
443 
444     void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override;
445     void FromJson(const std::unique_ptr<JsonValue>& json) override;
446 
ResetIndicatorAnimationState()447     void ResetIndicatorAnimationState()
448     {
449         isAnimating_ = false;
450         animationTargetIndex_.reset();
451     }
452 
GetTouchingSwiper()453     bool GetTouchingSwiper() const
454     {
455         return isTouchingSwiper_;
456     }
457 
GetTabBarStyle(uint32_t position)458     TabBarStyle GetTabBarStyle(uint32_t position) const
459     {
460         if (position < 0 || position >= tabBarStyles_.size()) {
461             return TabBarStyle::NOSTYLE;
462         }
463         return tabBarStyles_[position];
464     }
465 
GetBottomTabBarStyle(uint32_t position)466     const BottomTabBarStyle& GetBottomTabBarStyle(uint32_t position) const
467     {
468         if (position < 0 || position >= bottomTabBarStyles_.size()) {
469             return bottomTabBarStyle_;
470         }
471         return bottomTabBarStyles_[position];
472     }
473 
GetBottomTabLabelStyle(int32_t tabBarItemId)474     LabelStyle GetBottomTabLabelStyle(int32_t tabBarItemId) const
475     {
476         auto iter = labelStyles_.find(tabBarItemId);
477         if (iter == labelStyles_.end()) {
478             LabelStyle labelStyle{};
479             return labelStyle;
480         }
481         return iter->second;
482     }
483 
484     void DumpAdvanceInfo() override;
485     void DumpAdvanceInfo(std::unique_ptr<JsonValue>& json) override;
486     void SetRegionInfo(std::unique_ptr<JsonValue>& json);
487 
GetAnimationDuration()488     std::optional<int32_t> GetAnimationDuration()
489     {
490         return animationDuration_;
491     }
492 
GetTabContentWillChangeFlag()493     bool GetTabContentWillChangeFlag()
494     {
495         return tabContentWillChangeFlag_;
496     }
497 
ResetTabContentWillChangeFlag()498     void ResetTabContentWillChangeFlag()
499     {
500         tabContentWillChangeFlag_ = false;
501     }
502 
503     void UpdateAnimationDuration();
504 
HasSurfaceChangedCallback()505     bool HasSurfaceChangedCallback()
506     {
507         return surfaceChangedCallbackId_.has_value();
508     }
509 
UpdateSurfaceChangedCallbackId(int32_t id)510     void UpdateSurfaceChangedCallbackId(int32_t id)
511     {
512         surfaceChangedCallbackId_ = id;
513     }
514 
515     bool ContentWillChange(int32_t comingIndex);
516     bool ContentWillChange(int32_t currentIndex, int32_t comingIndex);
517 
518     void AddTabBarItemClickAndTouchEvent(const RefPtr<FrameNode>& tabBarItem);
519     void AddTabBarItemCallBack(const RefPtr<FrameNode>& tabBarItem);
520 
RemoveTabBarItemInfo(int32_t tabBarItemId)521     void RemoveTabBarItemInfo(int32_t tabBarItemId)
522     {
523         clickEvents_.erase(tabBarItemId);
524         touchEvents_.erase(tabBarItemId);
525         labelStyles_.erase(tabBarItemId);
526     }
527 
SetIsExecuteBuilder(bool isExecuteBuilder)528     void SetIsExecuteBuilder(bool isExecuteBuilder)
529     {
530         isExecuteBuilder_ = isExecuteBuilder;
531     }
532 
533     void AddTabBarItemId(int32_t tabBarItemId, uint32_t position, bool newTabBar = false)
534     {
535         if (tabBarItemIds_.size() <= position) {
536             tabBarItemIds_.emplace_back(tabBarItemId);
537             return;
538         }
539 
540         if (newTabBar) {
541             tabBarItemIds_.insert(tabBarItemIds_.begin() + position, tabBarItemId);
542             return;
543         }
544 
545         tabBarItemIds_[position] = tabBarItemId;
546     }
547 
IsNewTabBar(int32_t tabBarItemId)548     bool IsNewTabBar(int32_t tabBarItemId) const
549     {
550         return std::find(tabBarItemIds_.begin(), tabBarItemIds_.end(), tabBarItemId) == tabBarItemIds_.end();
551     }
552 
553     void AdjustTabBarInfo();
554     bool CanScroll() const;
555 
SetTabBarFocusActive(bool isFocusActive)556     void SetTabBarFocusActive(bool isFocusActive)
557     {
558         isTabBarFocusActive_ = isFocusActive;
559     }
560 
SetFocusIndicator(int32_t focusIndicator)561     void SetFocusIndicator(int32_t focusIndicator)
562     {
563         focusIndicator_ = focusIndicator;
564     }
565 
566     void ResetOnForceMeasure(int32_t index);
567     void OnColorModeChange(uint32_t colorMode) override;
568 
569 private:
570     void OnModifyDone() override;
571     void OnAttachToFrameNode() override;
572     void OnDetachFromFrameNode(FrameNode* node) override;
573     void BeforeCreateLayoutWrapper() override;
574     void SetTabBarFinishCallback();
575     void InitSurfaceChangedCallback();
576     bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override;
577     bool CustomizeExpandSafeArea() override;
578     void OnSyncGeometryNode(const DirtySwapConfig& config) override;
579 
580     void InitLongPressEvent(const RefPtr<GestureEventHub>& gestureHub);
581     void InitDragEvent(const RefPtr<GestureEventHub>& gestureHub);
582     void InitScrollableEvent(
583         const RefPtr<TabBarLayoutProperty>& layoutProperty, const RefPtr<GestureEventHub>& gestureHub);
584     void InitScrollable(const RefPtr<GestureEventHub>& gestureHub);
585     bool InsideTabBarRegion(const TouchLocationInfo& locationInfo);
586     void InitHoverEvent();
587     void InitMouseEvent();
588     void SetSurfaceChangeCallback();
589 
590     void HandleMouseEvent(const MouseInfo& info);
591     void HandleHoverEvent(bool isHover);
592     void HandleHoverOnEvent(int32_t index);
593     void HandleMoveAway(int32_t index);
594     RefPtr<FocusHub> GetCurrentFocusNode();
595     ScopeFocusAlgorithm GetScopeFocusAlgorithm() override;
596     WeakPtr<FocusHub> GetNextFocusNode(FocusStep step);
597     std::optional<int32_t> GetNextFocusIndicator(int32_t indicator, FocusStep step);
598     void HandleLongPressEvent(const GestureEvent& info);
599     void ShowDialogWithNode(int32_t index);
600     void CloseDialog();
601     void InitLongPressAndDragEvent();
602     void HandleClick(SourceType type, int32_t index);
603     void ClickTo(const RefPtr<FrameNode>& host, int32_t index);
604     void HandleTouchEvent(TouchType touchType, int32_t index);
605     void HandleSubTabBarClick(const RefPtr<TabBarLayoutProperty>& layoutProperty, int32_t index);
606     void HandleBottomTabBarClick(int32_t selectedIndex, int32_t unselectedIndex);
607     void ChangeMask(int32_t index, float imageSize, const OffsetF& originalMaskOffset, float opacity,
608         float radiusRatio, bool isSelected);
609     void PlayMaskAnimation(float selectedImageSize, const OffsetF& originalSelectedMaskOffset, int32_t selectedIndex,
610         float unselectedImageSize, const OffsetF& originalUnselectedMaskOffset, int32_t unselectedIndex);
611     static void MaskAnimationFinish(const RefPtr<FrameNode>& host, int32_t selectedIndex, bool isSelected);
612     void GetBottomTabBarImageSizeAndOffset(const std::vector<int32_t>& selectedIndexes,
613         int32_t maskIndex, float& selectedImageSize, float& unselectedImageSize, OffsetF& originalSelectedMaskOffset,
614         OffsetF& originalUnselectedMaskOffset);
615     void UpdateBottomTabBarImageColor(const std::vector<int32_t>& selectedIndexes, int32_t maskIndex);
616     void UpdateSymbolApply(const RefPtr<NG::FrameNode>& symbolNode, RefPtr<TextLayoutProperty>& symbolProperty,
617         int32_t index, std::string type);
618     bool CheckSvg(int32_t index) const;
619 
620     void HandleTouchDown(int32_t index);
621     void HandleTouchUp(int32_t index);
622     int32_t CalculateSelectedIndex(const Offset& info);
623 
624     void PlayPressAnimation(int32_t index, const Color& pressColor, AnimationType animationType);
625     void PlayTabBarTranslateAnimation(AnimationOption option, float targetCurrentOffset);
626     void PlayIndicatorTranslateAnimation(AnimationOption option, RectF originalPaintRect, RectF targetPaintRect,
627         float targetOffset);
628     void CreateIndicatorTranslateProperty(const RefPtr<FrameNode>& host, const std::string& propertyName);
629     void StopTranslateAnimation(bool isImmediately = false);
630     float CalculateTargetOffset(int32_t targetIndex);
631     void UpdateIndicatorCurrentOffset(float offset);
632 
633     void GetInnerFocusPaintRect(RoundRect& paintRect);
634     void PaintFocusState(bool needMarkDirty = true);
635     void FocusIndexChange(int32_t index);
636     void FocusCurrentOffset(int32_t index);
637     void UpdateGradientRegions(bool needMarkDirty = true);
638 
639     float GetSpace(int32_t indicator);
640     float CalculateFrontChildrenMainSize(int32_t indicator);
641     float CalculateBackChildrenMainSize(int32_t indicator);
642     void SetEdgeEffect(const RefPtr<GestureEventHub>& gestureHub);
643     void SetEdgeEffectCallback(const RefPtr<ScrollEdgeEffect>& scrollEffect);
644     bool IsOutOfBoundary();
645     void SetAccessibilityAction();
646     void TabBarClickEvent(int32_t index) const;
647     void OnCustomContentTransition(int32_t fromIndex, int32_t toIndex);
648     void ApplyTurnPageRateToIndicator(float turnPageRate);
649     bool CheckSwiperDisable() const;
650     void SetSwiperCurve(const RefPtr<Curve>& curve) const;
651     void InitTurnPageRateEvent();
652     void SetTurnPageRateCallback();
653     void GetIndicatorStyle(IndicatorStyle& indicatorStyle, OffsetF& indicatorOffset, RectF& tabBarItemRect);
654     void CalculateIndicatorStyle(
655         int32_t startIndex, int32_t nextIndex, IndicatorStyle& indicatorStyle, OffsetF& indicatorOffset);
656     Color GetTabBarBackgroundColor() const;
657     SizeF GetContentSize() const;
658     float GetLeftPadding() const;
659     void HandleBottomTabBarAnimation(int32_t index);
660     void UpdatePaintIndicator(int32_t indicator, bool needMarkDirty);
661     std::pair<float, float> GetOverScrollInfo(const SizeF& size);
662     void RemoveTabBarEventCallback();
663     void AddTabBarEventCallback();
664     void AddMaskItemClickEvent();
665     bool IsValidIndex(int32_t index);
666     int32_t GetLoopIndex(int32_t originalIndex) const;
667     RefPtr<SwiperPattern> GetSwiperPattern() const;
668     void UpdateBackBlurStyle(const RefPtr<TabTheme>& tabTheme);
669     void UpdateChildrenClipEdge();
670 
671     void StartShowTabBar(int32_t delay = 0);
672     void StartShowTabBarImmediately();
673     void CancelShowTabBar();
674     void StartHideTabBar();
675     void StopHideTabBar();
676     void InitTabBarProperty();
677     void UpdateTabBarHiddenOffset(float offset);
678     void SetTabBarTranslate(const TranslateOptions& options, bool isUserDefined = false);
679     void SetTabBarOpacity(float opacity);
GetUserDefinedTranslateY()680     float GetUserDefinedTranslateY() const
681     {
682         return userDefinedTranslateY_;
683     }
684 
685     void AddIsFocusActiveUpdateEvent();
686     void RemoveIsFocusActiveUpdateEvent();
687     void HandleFocusEvent();
688     void HandleBlurEvent();
689     bool HandleKeyEvent(const KeyEvent& event);
690     void InitTabBarProperties(const RefPtr<TabTheme>& tabTheme);
691     void InitFocusEvent();
692     const Color& GetSubTabBarHoverColor(int32_t index) const;
693     void UpdateFocusToSelectedNode(bool isFocusActive);
694     void UpdateFocusTabBarPageState();
695     void UpdateSubTabBarItemStyles(const RefPtr<FrameNode>& columnNode, int32_t focusedColumnId,
696         int32_t selectedColumnId, OHOS::Ace::Axis axis, int32_t index);
697     void UpdateSelectedTextColor(const RefPtr<TabTheme>& tabTheme, OHOS::Ace::Axis axis,
698         RefPtr<TextLayoutProperty> textLayoutProperty, int32_t index, int32_t columnId);
699     void UpdateSubTabFocusedTextColor(const RefPtr<TabTheme>& tabTheme, int32_t isFocusedItem,
700         RefPtr<TextLayoutProperty> textLayoutProperty, int32_t index, bool isSelected);
701 
702     template<typename T>
703     void UpdateTabBarInfo(std::vector<T>& info, const std::set<int32_t>& retainedIndex);
704 
705     RefPtr<NodeAnimatablePropertyFloat> tabBarProperty_;
706     CancelableCallback<void()> showTabBarTask_;
707     bool isTabBarShowing_ = false;
708     bool isTabBarHiding_ = false;
709     TabBarState tabBarState_ = TabBarState::SHOW;
710 
711     std::map<int32_t, RefPtr<ClickEvent>> clickEvents_;
712     std::map<int32_t, RefPtr<TouchEventImpl>> touchEvents_;
713     RefPtr<LongPressEvent> longPressEvent_;
714     RefPtr<ScrollableEvent> scrollableEvent_;
715     RefPtr<InputEvent> mouseEvent_;
716     RefPtr<InputEvent> hoverEvent_;
717     RefPtr<SwiperController> swiperController_;
718     RefPtr<ScrollEdgeEffect> scrollEffect_;
719     RefPtr<FrameNode> dialogNode_;
720     RefPtr<DragEvent> dragEvent_;
721     AnimationStartEventPtr animationStartEvent_;
722     AnimationEndEventPtr animationEndEvent_;
723 
724     float bigScale_ = 0.0f;
725     float largeScale_ = 0.0f;
726     float maxScale_ = 0.0f;
727     int32_t indicator_ = 0;
728     int32_t focusIndicator_ = 0;
729     int32_t accessibilityFocusIndicator_ = 0;
730     Axis axis_ = Axis::HORIZONTAL;
731     std::unordered_map<int32_t, TabBarParamType> tabBarType_;
732     RefPtr<Curve> animationCurve_;
733     std::optional<int32_t> animationDuration_;
734 
735     std::shared_ptr<AnimationUtils::Animation> tabbarIndicatorAnimation_;
736     std::shared_ptr<AnimationUtils::Animation> translateAnimation_;
737     std::shared_ptr<AnimationUtils::Animation> maskAnimation_;
738 
739     bool indicatorAnimationIsRunning_ = false;
740     bool translateAnimationIsRunning_ = false;
741 
742     bool isRTL_ = false;
743     bool clipEdge_ = true;
744 
745     bool touching_ = false; // whether the item is in touching
746     bool isHover_ = false;
747     bool isMaskAnimationByCreate_ = false;
748     bool isMaskAnimationExecuted_ = false;
749     bool tabContentWillChangeFlag_ = false;
750     std::optional<int32_t> imageColorOnIndex_;
751     std::set<int32_t> touchingIndex_;
752     std::optional<int32_t> hoverIndex_;
753     std::optional<int32_t> moveIndex_;
754     TabBarStyle tabBarStyle_ = TabBarStyle::NOSTYLE;
755     float currentIndicatorOffset_ = 0.0f;
756     std::vector<SelectedMode> selectedModes_;
757     std::vector<IndicatorStyle> indicatorStyles_;
758     std::vector<TabBarStyle> tabBarStyles_;
759     std::vector<int32_t> tabBarItemIds_;
760     std::unordered_map<int32_t, LabelStyle> labelStyles_;
761     std::vector<IconStyle> iconStyles_;
762     std::vector<TabBarSymbol> symbolArray_;
763     bool isTouchingSwiper_ = false;
764     float indicatorStartPos_ = 0.0f;
765     float indicatorEndPos_ = 0.0f;
766     float turnPageRate_ = 0.0f;
767     int32_t swiperStartIndex_ = 0;
768     std::vector<BottomTabBarStyle> bottomTabBarStyles_;
769     BottomTabBarStyle bottomTabBarStyle_;
770 
771     RefPtr<TabBarModifier> tabBarModifier_;
772     std::vector<bool> gradientRegions_ = {false, false, false, false};
773     bool isAnimating_ = false;
774     bool changeByClick_ = false;
775     bool clickRepeat_ = false;
776     float scrollMargin_ = 0.0f;
777     bool isFirstLayout_ = true;
778     bool isExecuteBuilder_ = false;
779     std::optional<int32_t> animationTargetIndex_;
780     std::optional<int32_t> surfaceChangedCallbackId_;
781     std::optional<WindowSizeChangeReason> windowSizeChangeReason_;
782     std::pair<double, double> prevRootSize_;
783     float userDefinedTranslateY_ = 0.0f;
784 
785     std::optional<int32_t> jumpIndex_;
786     std::optional<int32_t> targetIndex_;
787     std::optional<int32_t> focusIndex_;
788     float currentDelta_ = 0.0f;
789     float currentOffset_ = 0.0f;
790     float barGridMargin_ = 0.0f;
791     std::map<int32_t, ItemInfo> visibleItemPosition_;
792     bool canOverScroll_ = false;
793     bool isTabBarFocusActive_ = false;
794     std::function<void(bool)> isFocusActiveUpdateEvent_;
795     Color tabBarItemDefaultBgColor_ = Color::TRANSPARENT;
796     Color tabBarItemFocusBgColor_ = Color::TRANSPARENT;
797     Color tabBarItemHoverColor_ = Color::TRANSPARENT;
798     ACE_DISALLOW_COPY_AND_MOVE(TabBarPattern);
799 };
800 } // namespace OHOS::Ace::NG
801 
802 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TABS_TAB_BAR_PATTERN_H
803