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 #include "core/components_ng/pattern/tabs/tab_content_model_ng.h"
17
18 #include "base/memory/ace_type.h"
19 #include "base/memory/referenced.h"
20 #include "base/utils/utils.h"
21 #include "core/components/tab_bar/tab_theme.h"
22 #include "core/components_ng/base/frame_node.h"
23 #include "core/components_ng/base/view_stack_processor.h"
24 #include "core/components_ng/pattern/image/image_layout_property.h"
25 #include "core/components_ng/pattern/image/image_pattern.h"
26 #include "core/components_ng/pattern/linear_layout/linear_layout_pattern.h"
27 #include "core/components_ng/pattern/swiper/swiper_pattern.h"
28 #include "core/components_ng/pattern/tabs/tab_bar_pattern.h"
29 #include "core/components_ng/pattern/tabs/tab_content_node.h"
30 #include "core/components_ng/pattern/tabs/tab_content_pattern.h"
31 #include "core/components_ng/pattern/tabs/tabs_node.h"
32 #include "core/components_ng/pattern/text/text_pattern.h"
33 #include "core/components_v2/inspector/inspector_constants.h"
34
35 namespace OHOS::Ace::NG {
36 namespace {
37 const uint8_t PIXEL_ROUND = 18;
38 }
39
Create(std::function<void ()> && deepRenderFunc)40 void TabContentModelNG::Create(std::function<void()>&& deepRenderFunc)
41 {
42 auto* stack = ViewStackProcessor::GetInstance();
43 auto nodeId = stack->ClaimNodeId();
44 auto deepRender = [nodeId, deepRenderFunc = std::move(deepRenderFunc)]() -> RefPtr<UINode> {
45 CHECK_NULL_RETURN(deepRenderFunc, nullptr);
46 ScopedViewStackProcessor scopedViewStackProcessor;
47 deepRenderFunc();
48 auto deepChild = ViewStackProcessor::GetInstance()->Finish();
49 auto parent = FrameNode::GetFrameNode(V2::TAB_CONTENT_ITEM_ETS_TAG, nodeId);
50 if (deepChild && parent) {
51 deepChild->MountToParent(parent);
52 }
53 return deepChild;
54 };
55 ACE_LAYOUT_SCOPED_TRACE("Create[%s][self:%d]", V2::TAB_CONTENT_ITEM_ETS_TAG, nodeId);
56 auto frameNode = TabContentNode::GetOrCreateTabContentNode(V2::TAB_CONTENT_ITEM_ETS_TAG, nodeId,
57 [shallowBuilder = AceType::MakeRefPtr<ShallowBuilder>(std::move(deepRender))]() {
58 return AceType::MakeRefPtr<TabContentPattern>(shallowBuilder);
59 });
60 stack->Push(frameNode);
61 auto pipelineContext = PipelineContext::GetCurrentContext();
62 CHECK_NULL_VOID(pipelineContext);
63 auto tabTheme = pipelineContext->GetTheme<TabTheme>();
64 CHECK_NULL_VOID(tabTheme);
65 SetTabBar(tabTheme->GetDefaultTabBarName(), "", nullptr, true); // Set default tab bar.
66 ACE_UPDATE_LAYOUT_PROPERTY(TabContentLayoutProperty, Text, tabTheme->GetDefaultTabBarName());
67 }
68
Create()69 void TabContentModelNG::Create()
70 {
71 auto* stack = ViewStackProcessor::GetInstance();
72 int32_t nodeId = stack->ClaimNodeId();
73 ACE_LAYOUT_SCOPED_TRACE("Create[%s][self:%d]", V2::TAB_CONTENT_ITEM_ETS_TAG, nodeId);
74 auto frameNode = TabContentNode::GetOrCreateTabContentNode(
75 V2::TAB_CONTENT_ITEM_ETS_TAG, nodeId, []() { return AceType::MakeRefPtr<TabContentPattern>(nullptr); });
76 stack->Push(frameNode);
77 auto pipelineContext = PipelineContext::GetCurrentContext();
78 CHECK_NULL_VOID(pipelineContext);
79 auto tabTheme = pipelineContext->GetTheme<TabTheme>();
80 CHECK_NULL_VOID(tabTheme);
81 SetTabBar(tabTheme->GetDefaultTabBarName(), "", nullptr, true); // Set default tab bar.
82 ACE_UPDATE_LAYOUT_PROPERTY(TabContentLayoutProperty, Text, tabTheme->GetDefaultTabBarName());
83 }
84
Pop()85 void TabContentModelNG::Pop()
86 {
87 auto tabContent = NG::ViewStackProcessor::GetInstance()->GetMainFrameNode();
88 AddTabBarItem(tabContent, DEFAULT_NODE_SLOT, true);
89 NG::ViewStackProcessor::GetInstance()->PopContainer();
90 }
91
FindTabsNode(const RefPtr<UINode> & tabContent)92 RefPtr<TabsNode> TabContentModelNG::FindTabsNode(const RefPtr<UINode>& tabContent)
93 {
94 CHECK_NULL_RETURN(tabContent, nullptr);
95 RefPtr<UINode> parent = tabContent->GetParent();
96
97 while (parent) {
98 if (AceType::InstanceOf<TabsNode>(parent)) {
99 return AceType::DynamicCast<TabsNode>(parent);
100 }
101 parent = parent->GetParent();
102 }
103 return nullptr;
104 }
105
AddTabBarItem(const RefPtr<UINode> & tabContent,int32_t position,bool update)106 void TabContentModelNG::AddTabBarItem(const RefPtr<UINode>& tabContent, int32_t position, bool update)
107 {
108 CHECK_NULL_VOID(tabContent);
109 auto tabContentId = tabContent->GetId();
110
111 auto tabContentNode = AceType::DynamicCast<TabContentNode>(tabContent);
112 CHECK_NULL_VOID(tabContentNode);
113
114 if (update && !tabContentNode->HasTabBarItemId()) {
115 return;
116 }
117
118 auto tabsNode = FindTabsNode(tabContent);
119 CHECK_NULL_VOID(tabsNode);
120
121 auto tabBarNode = tabsNode->GetTabBar();
122 CHECK_NULL_VOID(tabBarNode);
123 auto tabContentPattern = tabContentNode->GetPattern<TabContentPattern>();
124 CHECK_NULL_VOID(tabContentPattern);
125 const auto& tabBarParam = tabContentPattern->GetTabBarParam();
126
127 // Create column node to contain image and text or builder.
128 auto columnNode = FrameNode::GetOrCreateFrameNode(V2::COLUMN_ETS_TAG, tabContentNode->GetTabBarItemId(),
129 []() { return AceType::MakeRefPtr<LinearLayoutPattern>(true); });
130 auto pipelineContext = PipelineContext::GetCurrentContext();
131 CHECK_NULL_VOID(pipelineContext);
132 auto tabTheme = pipelineContext->GetTheme<TabTheme>();
133 CHECK_NULL_VOID(tabTheme);
134 auto linearLayoutProperty = columnNode->GetLayoutProperty<LinearLayoutProperty>();
135 CHECK_NULL_VOID(linearLayoutProperty);
136 linearLayoutProperty->UpdateMainAxisAlign(FlexAlign::CENTER);
137 linearLayoutProperty->UpdateCrossAxisAlign(FlexAlign::CENTER);
138 linearLayoutProperty->UpdateSpace(tabTheme->GetBottomTabBarSpace());
139 linearLayoutProperty->UpdatePixelRound(PIXEL_ROUND);
140 auto columnRenderContext = columnNode->GetRenderContext();
141 CHECK_NULL_VOID(columnRenderContext);
142 columnRenderContext->UpdateClipEdge(true);
143 auto tabBarFrameNode = AceType::DynamicCast<FrameNode>(tabBarNode);
144 CHECK_NULL_VOID(tabBarFrameNode);
145 auto tabBarPattern = tabBarFrameNode->GetPattern<TabBarPattern>();
146 CHECK_NULL_VOID(tabBarPattern);
147 tabBarPattern->SetTabBarStyle(tabBarParam.GetTabBarStyle());
148 auto selectedMode = tabContentPattern->GetSelectedMode();
149 auto indicatorStyle = tabContentPattern->GetIndicatorStyle();
150 auto boardStyle = tabContentPattern->GetBoardStyle();
151 auto bottomTabBarStyle = tabContentPattern->GetBottomTabBarStyle();
152 auto padding = tabContentPattern->GetPadding();
153
154 auto linearLayoutPattern = columnNode->GetPattern<LinearLayoutPattern>();
155 CHECK_NULL_VOID(linearLayoutPattern);
156
157 if (tabBarParam.GetTabBarStyle() == TabBarStyle::BOTTOMTABBATSTYLE) {
158 if (bottomTabBarStyle.layoutMode == LayoutMode::HORIZONTAL) {
159 linearLayoutProperty->UpdateFlexDirection(FlexDirection::ROW);
160 linearLayoutProperty->UpdateSpace(tabTheme->GetHorizontalBottomTabBarSpace());
161 linearLayoutProperty->UpdateCrossAxisAlign(bottomTabBarStyle.verticalAlign);
162 linearLayoutProperty->SetIsVertical(false);
163 } else {
164 linearLayoutProperty->UpdateFlexDirection(FlexDirection::COLUMN);
165 linearLayoutProperty->UpdateSpace(tabTheme->GetBottomTabBarSpace());
166 linearLayoutProperty->UpdateMainAxisAlign(bottomTabBarStyle.verticalAlign);
167 linearLayoutProperty->SetIsVertical(true);
168 }
169 }
170
171 auto swiperNode = AceType::DynamicCast<FrameNode>(tabsNode->GetTabs());
172 CHECK_NULL_VOID(swiperNode);
173 auto myIndex = swiperNode->GetChildFlatIndex(tabContentId).second;
174
175 tabBarPattern->SetTabBarStyle(tabBarParam.GetTabBarStyle(), myIndex);
176 tabBarPattern->SetBottomTabBarStyle(bottomTabBarStyle, myIndex);
177 auto labelStyle = tabContentPattern->GetLabelStyle();
178 tabBarPattern->SetLabelStyle(labelStyle, myIndex);
179 auto tabBarStyle = tabContentPattern->GetTabBarStyle();
180 if (tabBarStyle == TabBarStyle::SUBTABBATSTYLE) {
181 auto renderContext = columnNode->GetRenderContext();
182 CHECK_NULL_VOID(renderContext);
183 BorderRadiusProperty borderRadiusProperty;
184 borderRadiusProperty.SetRadius(boardStyle.borderRadius);
185 renderContext->UpdateBorderRadius(borderRadiusProperty);
186 }
187 if (tabBarStyle != TabBarStyle::SUBTABBATSTYLE) {
188 indicatorStyle.marginTop = 0.0_vp;
189 }
190 tabBarPattern->SetSelectedMode(selectedMode, myIndex);
191 tabBarPattern->SetIndicatorStyle(indicatorStyle, myIndex);
192 tabBarPattern->UpdateSubTabBoard();
193
194 // Create tab bar with builder.
195 if (tabBarParam.HasBuilder()) {
196 ScopedViewStackProcessor builderViewStackProcessor;
197 tabBarParam.ExecuteBuilder();
198 auto builderNode = ViewStackProcessor::GetInstance()->Finish();
199 if (static_cast<int32_t>(columnNode->GetChildren().size()) != 0) {
200 columnNode->Clean();
201 }
202 if (builderNode) {
203 builderNode->MountToParent(columnNode);
204 }
205 auto oldColumnNode = tabsNode->GetBuilderByContentId(tabContentId, columnNode);
206 if (!oldColumnNode) {
207 columnNode->MountToParent(tabBarNode, myIndex);
208 } else {
209 tabBarNode->ReplaceChild(oldColumnNode, columnNode);
210 }
211 tabBarPattern->AddTabBarItemType(tabContentId, true);
212 tabBarFrameNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF);
213 return;
214 }
215
216 // Create text node and image node.
217 RefPtr<FrameNode> textNode;
218 RefPtr<FrameNode> imageNode;
219 auto layoutProperty = columnNode->GetLayoutProperty();
220 CHECK_NULL_VOID(layoutProperty);
221 if (tabBarStyle == TabBarStyle::SUBTABBATSTYLE || tabBarStyle == TabBarStyle::BOTTOMTABBATSTYLE) {
222 layoutProperty->UpdatePadding(padding);
223 auto accessibilityProperty = columnNode->GetAccessibilityProperty<AccessibilityProperty>();
224 accessibilityProperty->SetAccessibilityGroup(true);
225 auto id = tabContentPattern->GetId();
226 columnNode->UpdateInspectorId(id);
227 } else {
228 auto deviceType = SystemProperties::GetDeviceType();
229 auto tabBarItemPadding = deviceType == DeviceType::PHONE ? tabTheme->GetSubTabHorizontalPadding()
230 : tabTheme->GetSubtabLandscapeHorizontalPadding();
231 layoutProperty->UpdatePadding({ CalcLength(tabBarItemPadding), CalcLength(tabBarItemPadding),
232 CalcLength(tabBarItemPadding), CalcLength(tabBarItemPadding) });
233 }
234
235 if (static_cast<int32_t>(columnNode->GetChildren().size()) == 0) {
236 ImageSourceInfo imageSourceInfo(tabBarParam.GetIcon());
237 imageNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
238 []() { return AceType::MakeRefPtr<ImagePattern>(); });
239 textNode = FrameNode::GetOrCreateFrameNode(V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
240 []() { return AceType::MakeRefPtr<TextPattern>(); });
241 CHECK_NULL_VOID(textNode);
242 CHECK_NULL_VOID(imageNode);
243 columnNode->MountToParent(tabBarNode, position);
244 imageNode->MountToParent(columnNode);
245 textNode->MountToParent(columnNode);
246 } else {
247 imageNode = AceType::DynamicCast<FrameNode>(columnNode->GetChildren().front());
248 textNode = AceType::DynamicCast<FrameNode>(columnNode->GetChildren().back());
249 }
250 CHECK_NULL_VOID(textNode);
251 CHECK_NULL_VOID(imageNode);
252
253 auto swiperPattern = swiperNode->GetPattern<SwiperPattern>();
254 CHECK_NULL_VOID(swiperPattern);
255 auto swiperLayoutProperty = swiperNode->GetLayoutProperty<SwiperLayoutProperty>();
256 CHECK_NULL_VOID(swiperLayoutProperty);
257 int32_t indicator = swiperLayoutProperty->GetIndexValue(0);
258 int32_t totalCount = swiperPattern->TotalCount();
259 if (indicator > totalCount - 1 || indicator < 0) {
260 indicator = 0;
261 }
262
263 // Update property of text.
264 auto textLayoutProperty = textNode->GetLayoutProperty<TextLayoutProperty>();
265 CHECK_NULL_VOID(textLayoutProperty);
266 if (!swiperPattern->IsUseCustomAnimation() || !swiperPattern->GetCustomAnimationToIndex().has_value()) {
267 if (myIndex == indicator) {
268 textLayoutProperty->UpdateTextColor(tabTheme->GetSubTabTextOnColor());
269 } else {
270 textLayoutProperty->UpdateTextColor(tabTheme->GetSubTabTextOffColor());
271 }
272 }
273
274 auto textRenderContext = textNode->GetRenderContext();
275 CHECK_NULL_VOID(textRenderContext);
276 textRenderContext->UpdateClipEdge(true);
277 textLayoutProperty->UpdateContent(tabBarParam.GetText());
278 textLayoutProperty->UpdateFontSize(tabTheme->GetSubTabTextDefaultFontSize());
279 textLayoutProperty->UpdateTextAlign(TextAlign::CENTER);
280 if (tabBarStyle == TabBarStyle::BOTTOMTABBATSTYLE && bottomTabBarStyle.layoutMode == LayoutMode::HORIZONTAL) {
281 textLayoutProperty->UpdateTextAlign(TextAlign::LEFT);
282 }
283 textLayoutProperty->UpdateMaxLines(1);
284 textLayoutProperty->UpdateTextOverflow(TextOverflow::ELLIPSIS);
285 if (tabBarStyle == TabBarStyle::BOTTOMTABBATSTYLE) {
286 textLayoutProperty->UpdateFlexShrink(1.0f);
287 }
288
289 // Update property of image.
290 auto imageProperty = imageNode->GetLayoutProperty<ImageLayoutProperty>();
291 CHECK_NULL_VOID(imageProperty);
292 if (!tabBarParam.GetIcon().empty() || tabBarStyle == TabBarStyle::BOTTOMTABBATSTYLE) {
293 textLayoutProperty->UpdateFontSize(tabTheme->GetBottomTabTextSize());
294 imageProperty->UpdateUserDefinedIdealSize(CalcSize(
295 NG::CalcLength(tabTheme->GetBottomTabImageSize()), NG::CalcLength(tabTheme->GetBottomTabImageSize())));
296 } else {
297 imageProperty->UpdateUserDefinedIdealSize(CalcSize());
298 }
299 if (tabBarStyle == TabBarStyle::BOTTOMTABBATSTYLE) {
300 textLayoutProperty->UpdateFontWeight(FontWeight::MEDIUM);
301 } else if (tabBarStyle == TabBarStyle::SUBTABBATSTYLE) {
302 textLayoutProperty->UpdateFontWeight(myIndex == indicator ? FontWeight::MEDIUM : FontWeight::NORMAL);
303 }
304 UpdateLabelStyle(labelStyle, textLayoutProperty);
305 ImageSourceInfo imageSourceInfo(tabBarParam.GetIcon());
306 if (imageSourceInfo.IsSvg()) {
307 if (myIndex == indicator) {
308 tabBarPattern->SetImageColorOnIndex(indicator);
309 imageSourceInfo.SetFillColor(tabTheme->GetBottomTabIconOn());
310 } else {
311 imageSourceInfo.SetFillColor(tabTheme->GetBottomTabIconOff());
312 }
313 }
314
315 imageProperty->UpdateImageSourceInfo(imageSourceInfo);
316 columnNode->MarkModifyDone();
317 textNode->MarkModifyDone();
318 textNode->MarkDirtyNode();
319 imageNode->MarkModifyDone();
320 tabBarPattern->AddTabBarItemType(tabContentId, false);
321 tabBarFrameNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF);
322 }
323
RemoveTabBarItem(const RefPtr<TabContentNode> & tabContentNode)324 void TabContentModelNG::RemoveTabBarItem(const RefPtr<TabContentNode>& tabContentNode)
325 {
326 CHECK_NULL_VOID(tabContentNode);
327 if (!tabContentNode->HasTabBarItemId()) {
328 return;
329 }
330
331 auto tabBarItemId = tabContentNode->GetTabBarItemId();
332 auto tabBarItemNode = ElementRegister::GetInstance()->GetUINodeById(tabBarItemId);
333 CHECK_NULL_VOID(tabBarItemNode);
334 auto tabBarNode = tabBarItemNode->GetParent();
335 tabBarNode->RemoveChild(tabBarItemNode);
336 CHECK_NULL_VOID(tabBarNode);
337 tabContentNode->ResetTabBarItemId();
338
339 auto tabsNode = FindTabsNode(tabContentNode);
340 CHECK_NULL_VOID(tabsNode);
341 tabsNode->RemoveBuilderByContentId(tabContentNode->GetId());
342 auto tabBar = tabsNode->GetTabBar();
343 CHECK_NULL_VOID(tabBar);
344 auto tabBarFrameNode = AceType::DynamicCast<FrameNode>(tabBar);
345 CHECK_NULL_VOID(tabBarFrameNode);
346 tabBarFrameNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF);
347 }
348
SetTabBar(const std::optional<std::string> & text,const std::optional<std::string> & icon,TabBarBuilderFunc && builder,bool)349 void TabContentModelNG::SetTabBar(const std::optional<std::string>& text, const std::optional<std::string>& icon,
350 TabBarBuilderFunc&& builder, bool /*useContentOnly*/)
351 {
352 ACE_UPDATE_LAYOUT_PROPERTY(TabContentLayoutProperty, Icon, icon.value_or(""));
353 ACE_UPDATE_LAYOUT_PROPERTY(TabContentLayoutProperty, Text, text.value_or(""));
354 auto frameNodePattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<TabContentPattern>();
355 CHECK_NULL_VOID(frameNodePattern);
356 frameNodePattern->SetTabBar(text.value_or(""), icon.value_or(""), std::move(builder));
357 }
358
SetTabBarStyle(TabBarStyle tabBarStyle)359 void TabContentModelNG::SetTabBarStyle(TabBarStyle tabBarStyle)
360 {
361 auto frameNodePattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<TabContentPattern>();
362 CHECK_NULL_VOID(frameNodePattern);
363 frameNodePattern->SetTabBarStyle(tabBarStyle);
364 }
365
SetIndicator(const IndicatorStyle & indicator)366 void TabContentModelNG::SetIndicator(const IndicatorStyle& indicator)
367 {
368 auto frameNodePattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<TabContentPattern>();
369 CHECK_NULL_VOID(frameNodePattern);
370 frameNodePattern->SetIndicatorStyle(indicator);
371 }
372
SetBoard(const BoardStyle & board)373 void TabContentModelNG::SetBoard(const BoardStyle& board)
374 {
375 auto frameNodePattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<TabContentPattern>();
376 CHECK_NULL_VOID(frameNodePattern);
377 frameNodePattern->SetBoardStyle(board);
378 }
379
SetSelectedMode(SelectedMode selectedMode)380 void TabContentModelNG::SetSelectedMode(SelectedMode selectedMode)
381 {
382 auto frameNodePattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<TabContentPattern>();
383 CHECK_NULL_VOID(frameNodePattern);
384 frameNodePattern->SetSelectedMode(selectedMode);
385 }
386
SetLabelStyle(const LabelStyle & labelStyle)387 void TabContentModelNG::SetLabelStyle(const LabelStyle& labelStyle)
388 {
389 auto frameNodePattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<TabContentPattern>();
390 CHECK_NULL_VOID(frameNodePattern);
391 frameNodePattern->SetLabelStyle(labelStyle);
392 }
393
SetPadding(const PaddingProperty & padding)394 void TabContentModelNG::SetPadding(const PaddingProperty& padding)
395 {
396 auto frameNodePattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<TabContentPattern>();
397 CHECK_NULL_VOID(frameNodePattern);
398 frameNodePattern->SetPadding(padding);
399 }
400
SetLayoutMode(LayoutMode layoutMode)401 void TabContentModelNG::SetLayoutMode(LayoutMode layoutMode)
402 {
403 auto frameNodePattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<TabContentPattern>();
404 CHECK_NULL_VOID(frameNodePattern);
405 frameNodePattern->SetLayoutMode(layoutMode);
406 }
407
SetVerticalAlign(FlexAlign verticalAlign)408 void TabContentModelNG::SetVerticalAlign(FlexAlign verticalAlign)
409 {
410 auto frameNodePattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<TabContentPattern>();
411 CHECK_NULL_VOID(frameNodePattern);
412 frameNodePattern->SetVerticalAlign(verticalAlign);
413 }
414
SetSymmetricExtensible(bool isExtensible)415 void TabContentModelNG::SetSymmetricExtensible(bool isExtensible)
416 {
417 auto frameNodePattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<TabContentPattern>();
418 CHECK_NULL_VOID(frameNodePattern);
419 frameNodePattern->SetSymmetricExtensible(isExtensible);
420 }
421
SetId(const std::string & id)422 void TabContentModelNG::SetId(const std::string& id)
423 {
424 auto frameNodePattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern<TabContentPattern>();
425 CHECK_NULL_VOID(frameNodePattern);
426 frameNodePattern->SetId(id);
427 }
428
UpdateLabelStyle(const LabelStyle & labelStyle,RefPtr<TextLayoutProperty> textLayoutProperty)429 void TabContentModelNG::UpdateLabelStyle(const LabelStyle& labelStyle, RefPtr<TextLayoutProperty> textLayoutProperty)
430 {
431 CHECK_NULL_VOID(textLayoutProperty);
432
433 if (labelStyle.fontSize.has_value()) {
434 textLayoutProperty->UpdateFontSize(labelStyle.fontSize.value());
435 }
436 if (labelStyle.fontWeight.has_value()) {
437 textLayoutProperty->UpdateFontWeight(labelStyle.fontWeight.value());
438 }
439 if (labelStyle.fontStyle.has_value()) {
440 textLayoutProperty->UpdateItalicFontStyle(labelStyle.fontStyle.value());
441 }
442 if (labelStyle.fontFamily.has_value()) {
443 textLayoutProperty->UpdateFontFamily(labelStyle.fontFamily.value());
444 }
445 if (labelStyle.textOverflow.has_value()) {
446 textLayoutProperty->UpdateTextOverflow(labelStyle.textOverflow.value());
447 }
448 if (labelStyle.maxLines.has_value()) {
449 textLayoutProperty->UpdateMaxLines(labelStyle.maxLines.value());
450 }
451 if (labelStyle.minFontSize.has_value()) {
452 textLayoutProperty->UpdateAdaptMinFontSize(labelStyle.minFontSize.value());
453 }
454 if (labelStyle.maxFontSize.has_value()) {
455 textLayoutProperty->UpdateAdaptMaxFontSize(labelStyle.maxFontSize.value());
456 }
457 if (labelStyle.heightAdaptivePolicy.has_value()) {
458 textLayoutProperty->UpdateHeightAdaptivePolicy(labelStyle.heightAdaptivePolicy.value());
459 }
460 }
461 } // namespace OHOS::Ace::NG
462