1 /* 2 * Copyright (c) 2021 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_BRIDGE_COMMON_DOM_DOM_TAB_BAR_H 17 #define FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_DOM_DOM_TAB_BAR_H 18 19 #include "core/components/tab_bar/tab_bar_component.h" 20 #include "core/components/tab_bar/tab_bar_indicator_component.h" 21 #include "core/components/tab_bar/tab_bar_item_component.h" 22 #include "frameworks/bridge/common/dom/dom_node.h" 23 #include "frameworks/bridge/common/dom/dom_tabs.h" 24 25 namespace OHOS::Ace::Framework { 26 27 class DOMTabBar final : public DOMNode { 28 DECLARE_ACE_TYPE(DOMTabBar, DOMNode); 29 30 public: 31 DOMTabBar(NodeId nodeId, const std::string& nodeName); 32 ~DOMTabBar() override = default; 33 34 void InitializeStyle() override; 35 GetSpecializedComponent()36 RefPtr<Component> GetSpecializedComponent() override 37 { 38 return tabBarChild_; 39 } 40 41 void UpdateIndex(uint32_t currentIndex); 42 BindToTabs(const RefPtr<DOMNode> & tabsNode)43 void BindToTabs(const RefPtr<DOMNode>& tabsNode) 44 { 45 OnMounted(tabsNode); 46 } 47 SetVertical(bool vertical_)48 void SetVertical(bool vertical_) 49 { 50 tabBarChild_->SetVertical(vertical_); 51 } 52 53 protected: 54 void OnMounted(const RefPtr<DOMNode>& parentNode) override; 55 void OnChildNodeAdded(const RefPtr<DOMNode>& child, int32_t slot) override; 56 void OnChildNodeRemoved(const RefPtr<DOMNode>& child) override; 57 bool SetSpecializedAttr(const std::pair<std::string, std::string>& attr) override; 58 bool SetSpecializedStyle(const std::pair<std::string, std::string>& style) override; 59 void PrepareSpecializedComponent() override; 60 void ResetInitializedStyle() override; 61 62 private: 63 void PrepareChangeListener(); 64 void OnChildActive(const RefPtr<DOMNode>& node, bool active); 65 Edge ParseEdge(const std::string& value) const; 66 67 RefPtr<TabBarComponent> tabBarChild_; 68 RefPtr<TabBarIndicatorComponent> tabBarIndicator_; 69 uint32_t lastIndex_ = 0; 70 uint32_t controllerId_ = 0; 71 bool vertical_ = false; 72 TabBarMode tabBarMode_ = TabBarMode::SCROLLABLE; 73 Edge padding_; 74 std::optional<Color> indicatorColor_; 75 }; 76 77 } // namespace OHOS::Ace::Framework 78 79 #endif // FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_DOM_DOM_TAB_BAR_H 80