1 /* 2 * Copyright (c) 2021-2022 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_TAB_BAR_TAB_BAR_ELEMENT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TAB_BAR_TAB_BAR_ELEMENT_H 18 19 #include "core/components/box/box_component.h" 20 #include "core/components/box/box_element.h" 21 #include "core/components/tab_bar/tab_bar_component.h" 22 #include "core/components/tab_bar/tab_controller.h" 23 #include "core/focus/focus_node.h" 24 #include "core/pipeline/base/component_group_element.h" 25 26 namespace OHOS::Ace { 27 28 class TabBarElement : public ComponentGroupElement, public FocusGroup { 29 DECLARE_ACE_TYPE(TabBarElement, ComponentGroupElement, FocusGroup); 30 31 public: 32 void UpdateIndex(int32_t index); 33 void UpdateScrollIndicator(double percent, int32_t newIndex, bool needChange); 34 void PerformBuild() override; 35 void Update() override; 36 bool RequestNextFocus(bool vertical, bool reverse, const Rect& rect) override; GetTabBarComponent()37 RefPtr<TabBarComponent> GetTabBarComponent() const 38 { 39 return tabBar_; 40 } 41 GetTabController()42 RefPtr<TabController> GetTabController() const 43 { 44 return controller_; 45 } 46 47 protected: 48 void OnFocus() override; 49 void OnBlur() override; 50 51 private: 52 RefPtr<RenderNode> CreateRenderNode() override; 53 void UpdateElement(int32_t index); 54 55 bool vertical_ { false }; // the tab is vertical or not, default value is false 56 std::list<RefPtr<TabBarItemComponent>> tabs_; 57 RefPtr<TabController> controller_; 58 RefPtr<BoxComponent> indicatorStyle_; 59 RefPtr<BoxComponent> focusIndicatorStyle_; 60 RefPtr<TabBarComponent> tabBar_ = nullptr; 61 }; 62 63 } // namespace OHOS::Ace 64 65 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TAB_BAR_TAB_BAR_ELEMENT_H 66