!44545 修复navigationtitle透明度问题

Merge pull request !44545 from huangxiaolinabc123/9_26
This commit is contained in:
openharmony_ci 2024-09-27 09:38:40 +00:00 committed by Gitee
commit 1be0f78d8f
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 43 additions and 37 deletions

View File

@ -362,43 +362,6 @@ void MountBackButton(const RefPtr<TitleBarNode>& hostNode)
return;
}
}
void ResetSubTitleProperty(const RefPtr<FrameNode>& textNode, NavigationTitleMode titleMode, bool parentIsNavDest)
{
CHECK_NULL_VOID(textNode);
auto titleLayoutProperty = textNode->GetLayoutProperty<TextLayoutProperty>();
CHECK_NULL_VOID(titleLayoutProperty);
std::string contentStr;
if (titleLayoutProperty->HasContent()) {
contentStr = titleLayoutProperty->GetContentValue(std::string());
}
titleLayoutProperty->Reset();
titleLayoutProperty->UpdateContent(contentStr);
auto theme = NavigationGetTheme();
CHECK_NULL_VOID(theme);
auto subTitleSize = theme->GetSubTitleFontSize();
Color color = theme->GetSubTitleColor();
auto textHeightAdaptivePolicy = TextHeightAdaptivePolicy::MIN_FONT_SIZE_FIRST;
if (AceApplicationInfo::GetInstance().GreatOrEqualTargetAPIVersion(PlatformVersion::VERSION_TWELVE)) {
subTitleSize = theme->GetSubTitleFontSizeS();
color = theme->GetSubTitleFontColor();
textHeightAdaptivePolicy = TextHeightAdaptivePolicy::MAX_LINES_FIRST;
}
if (parentIsNavDest) {
titleLayoutProperty->UpdateHeightAdaptivePolicy(TextHeightAdaptivePolicy::MAX_LINES_FIRST);
} else if (titleMode == NavigationTitleMode::MINI) {
titleLayoutProperty->UpdateHeightAdaptivePolicy(textHeightAdaptivePolicy);
}
titleLayoutProperty->UpdateAdaptMinFontSize(MIN_ADAPT_SUBTITLE_FONT_SIZE);
titleLayoutProperty->UpdateAdaptMaxFontSize(subTitleSize);
titleLayoutProperty->UpdateMaxFontScale(STANDARD_FONT_SCALE);
titleLayoutProperty->UpdateMaxLines(1);
titleLayoutProperty->UpdateFontWeight(FontWeight::REGULAR); // ohos_id_text_font_family_regular
titleLayoutProperty->UpdateFontSize(subTitleSize);
titleLayoutProperty->UpdateTextOverflow(TextOverflow::ELLIPSIS);
SetTextColor(textNode, color);
}
} // namespace
void TitleBarPattern::MountSubTitle(const RefPtr<TitleBarNode>& hostNode)
@ -596,6 +559,47 @@ void TitleBarPattern::ResetMainTitleProperty(const RefPtr<FrameNode>& textNode,
}
}
void TitleBarPattern::ResetSubTitleProperty(const RefPtr<FrameNode>& textNode,
NavigationTitleMode titleMode, bool parentIsNavDest)
{
CHECK_NULL_VOID(textNode);
auto titleLayoutProperty = textNode->GetLayoutProperty<TextLayoutProperty>();
CHECK_NULL_VOID(titleLayoutProperty);
std::string contentStr;
if (titleLayoutProperty->HasContent()) {
contentStr = titleLayoutProperty->GetContentValue(std::string());
}
titleLayoutProperty->Reset();
titleLayoutProperty->UpdateContent(contentStr);
auto theme = NavigationGetTheme();
CHECK_NULL_VOID(theme);
auto subTitleSize = theme->GetSubTitleFontSize();
Color color = theme->GetSubTitleColor();
auto textHeightAdaptivePolicy = TextHeightAdaptivePolicy::MIN_FONT_SIZE_FIRST;
if (AceApplicationInfo::GetInstance().GreatOrEqualTargetAPIVersion(PlatformVersion::VERSION_TWELVE)) {
subTitleSize = theme->GetSubTitleFontSizeS();
color = theme->GetSubTitleFontColor();
textHeightAdaptivePolicy = TextHeightAdaptivePolicy::MAX_LINES_FIRST;
}
if (parentIsNavDest) {
titleLayoutProperty->UpdateHeightAdaptivePolicy(TextHeightAdaptivePolicy::MAX_LINES_FIRST);
} else if (titleMode == NavigationTitleMode::MINI) {
titleLayoutProperty->UpdateHeightAdaptivePolicy(textHeightAdaptivePolicy);
} else if (titleMode == NavigationTitleMode::FREE) {
UpdateSubTitleOpacity(opacity_.value_or(1.0f));
} else {
UpdateSubTitleOpacity(1.0);
}
titleLayoutProperty->UpdateAdaptMinFontSize(MIN_ADAPT_SUBTITLE_FONT_SIZE);
titleLayoutProperty->UpdateAdaptMaxFontSize(subTitleSize);
titleLayoutProperty->UpdateMaxFontScale(STANDARD_FONT_SCALE);
titleLayoutProperty->UpdateMaxLines(1);
titleLayoutProperty->UpdateFontWeight(FontWeight::REGULAR); // ohos_id_text_font_family_regular
titleLayoutProperty->UpdateFontSize(subTitleSize);
titleLayoutProperty->UpdateTextOverflow(TextOverflow::ELLIPSIS);
SetTextColor(textNode, color);
}
void TitleBarPattern::MountTitle(const RefPtr<TitleBarNode>& hostNode)
{

View File

@ -370,6 +370,8 @@ private:
void ResetMainTitleProperty(const RefPtr<FrameNode>& textNode,
const RefPtr<TitleBarLayoutProperty>& titleBarLayoutProperty,
NavigationTitleMode titleMode, bool hasSubTitle, bool parentIsNavDest);
void ResetSubTitleProperty(const RefPtr<FrameNode>& textNode,
NavigationTitleMode titleMode, bool parentIsNavDest);
void ApplyTitleModifierIfNeeded(const RefPtr<TitleBarNode>& hostNode);
void ApplyTitleModifier(const RefPtr<FrameNode>& textNode,
const TextStyleApplyFunc& applyFunc, bool needCheckFontSizeIsSetted);