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_CONTENT_PATTERN_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TABS_TAB_CONTENT_PATTERN_H 18 19 #include "base/log/dump_log.h" 20 #include "base/memory/referenced.h" 21 #include "base/utils/noncopyable.h" 22 #include "core/components_ng/pattern/pattern.h" 23 #include "core/components_ng/pattern/tabs/tab_bar_pattern.h" 24 #include "core/components_ng/pattern/tabs/tab_content_layout_property.h" 25 #include "core/components_ng/syntax/shallow_builder.h" 26 27 namespace OHOS::Ace::NG { 28 29 class ACE_EXPORT TabContentPattern : public Pattern { 30 DECLARE_ACE_TYPE(TabContentPattern, Pattern); 31 32 public: TabContentPattern(const RefPtr<ShallowBuilder> & shallowBuilder)33 explicit TabContentPattern(const RefPtr<ShallowBuilder>& shallowBuilder) 34 : shallowBuilder_(shallowBuilder), tabBarParam_(std::string(""), std::string(""), nullptr) 35 {} 36 ~TabContentPattern() override = default; 37 IsAtomicNode()38 bool IsAtomicNode() const override 39 { 40 return false; 41 } 42 IsMeasureBoundary()43 bool IsMeasureBoundary() const override 44 { 45 return false; 46 } 47 UsResRegion()48 bool UsResRegion() override 49 { 50 return false; 51 } 52 OnAttachToFrameNode()53 void OnAttachToFrameNode() override 54 { 55 auto host = GetHost(); 56 CHECK_NULL_VOID(host); 57 host->GetRenderContext()->UpdateClipEdge(true); 58 } 59 BeforeCreateLayoutWrapper()60 void BeforeCreateLayoutWrapper() override 61 { 62 if (shallowBuilder_ && !shallowBuilder_->IsExecuteDeepRenderDone()) { 63 shallowBuilder_->ExecuteDeepRender(); 64 shallowBuilder_.Reset(); 65 } 66 } 67 CreateLayoutProperty()68 RefPtr<LayoutProperty> CreateLayoutProperty() override 69 { 70 return MakeRefPtr<TabContentLayoutProperty>(); 71 } 72 SetTabBar(const std::string & text,const std::string & icon,TabBarBuilderFunc && builder)73 void SetTabBar(const std::string& text, const std::string& icon, TabBarBuilderFunc&& builder) 74 { 75 tabBarParam_.SetText(text); 76 tabBarParam_.SetIcon(icon); 77 tabBarParam_.SetBuilder(move(builder)); 78 } 79 GetTabBarParam()80 const TabBarParam& GetTabBarParam() const 81 { 82 return tabBarParam_; 83 } 84 SetTabBarStyle(TabBarStyle tabBarStyle)85 void SetTabBarStyle(TabBarStyle tabBarStyle) 86 { 87 tabBarParam_.SetTabBarStyle(tabBarStyle); 88 } 89 GetTabBarStyle()90 TabBarStyle GetTabBarStyle() const 91 { 92 return tabBarParam_.GetTabBarStyle(); 93 } 94 SetIndicatorStyle(const IndicatorStyle & indicatorStyle)95 void SetIndicatorStyle(const IndicatorStyle& indicatorStyle) 96 { 97 indicatorStyle_ = indicatorStyle; 98 } 99 GetIndicatorStyle()100 const IndicatorStyle& GetIndicatorStyle() const 101 { 102 return indicatorStyle_; 103 } 104 SetSelectedMode(SelectedMode selectedMode)105 void SetSelectedMode(SelectedMode selectedMode) 106 { 107 selectedMode_ = selectedMode; 108 } 109 GetSelectedMode()110 SelectedMode GetSelectedMode() const 111 { 112 return selectedMode_; 113 } 114 SetBoardStyle(const BoardStyle & boardStyle)115 void SetBoardStyle(const BoardStyle& boardStyle) 116 { 117 boardStyle_ = boardStyle; 118 } 119 GetBoardStyle()120 const BoardStyle& GetBoardStyle() const 121 { 122 return boardStyle_; 123 } 124 SetLabelStyle(const LabelStyle & labelStyle)125 void SetLabelStyle(const LabelStyle& labelStyle) 126 { 127 labelStyle_ = labelStyle; 128 } 129 GetLabelStyle()130 const LabelStyle& GetLabelStyle() const 131 { 132 return labelStyle_; 133 } 134 SetPadding(const PaddingProperty & padding)135 void SetPadding(const PaddingProperty& padding) 136 { 137 padding_ = padding; 138 } 139 GetPadding()140 const PaddingProperty& GetPadding() const 141 { 142 return padding_; 143 } 144 SetSymmetricExtensible(bool isExtensible)145 void SetSymmetricExtensible(bool isExtensible) 146 { 147 bottomTabBarStyle_.symmetricExtensible = isExtensible; 148 } 149 SetLayoutMode(LayoutMode layoutMode)150 void SetLayoutMode(LayoutMode layoutMode) 151 { 152 bottomTabBarStyle_.layoutMode = layoutMode; 153 } 154 SetVerticalAlign(FlexAlign verticalAlign)155 void SetVerticalAlign(FlexAlign verticalAlign) 156 { 157 bottomTabBarStyle_.verticalAlign = verticalAlign; 158 } 159 SetId(const std::string & id)160 void SetId(const std::string& id) 161 { 162 tabBarInspectorId_ = id; 163 } 164 GetId()165 const std::string& GetId() const 166 { 167 return tabBarInspectorId_; 168 } 169 GetBottomTabBarStyle()170 const BottomTabBarStyle& GetBottomTabBarStyle() const 171 { 172 return bottomTabBarStyle_; 173 } 174 DumpAdvanceInfo()175 void DumpAdvanceInfo() override 176 { 177 switch (selectedMode_) { 178 case SelectedMode::INDICATOR: { 179 DumpLog::GetInstance().AddDesc("SelectedMode:INDICATOR"); 180 break; 181 } 182 case SelectedMode::BOARD: { 183 DumpLog::GetInstance().AddDesc("SelectedMode:BOARD"); 184 break; 185 } 186 default: { 187 break; 188 } 189 } 190 } 191 192 private: 193 RefPtr<ShallowBuilder> shallowBuilder_; 194 TabBarParam tabBarParam_; 195 IndicatorStyle indicatorStyle_; 196 SelectedMode selectedMode_ = SelectedMode::INDICATOR; 197 BoardStyle boardStyle_; 198 LabelStyle labelStyle_; 199 PaddingProperty padding_; 200 std::string tabBarInspectorId_; 201 BottomTabBarStyle bottomTabBarStyle_; 202 203 ACE_DISALLOW_COPY_AND_MOVE(TabContentPattern); 204 }; 205 206 } // namespace OHOS::Ace::NG 207 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TABS_TAB_CONTENT_PATTERN_H 208