Skip to content

Commit

Permalink
Fix title's font of gva persisent button
Browse files Browse the repository at this point in the history
  • Loading branch information
ykyivskyi-gl committed Nov 12, 2024
1 parent 012eafa commit 2f54c8a
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ extension Theme {
let messageTitleStyle = SecureConversations.WelcomeStyle.MessageTitleStyle(
title: Localization.MessageCenter.Welcome.messageTitle,
font: font.mediumSubtitle1,
textStyle: .subheadline,
textStyle: .headline,
color: .black,
accessibility: .init(isFontScalingEnabled: true)
)
Expand Down
22 changes: 22 additions & 0 deletions GliaWidgets/Sources/Extensions/UIFont+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,25 @@ extension UIFont {
return UIFont(descriptor: descriptor, size: size)
}
}

extension UIFont {
/// Returns a font instance that is scaled appropriately based on the user's current content size category preferences
/// for the specified `UIFont.TextStyle`. It resolves the internal `FontScaling.Style` and `FontScaling.Description`
/// to retrieve the original font's weight and size, then scales it according to the current content size category.
static func scaledFont(forTextStyle: UIFont.TextStyle) -> UIFont? {
var descriptor = UIFontDescriptor.preferredFontDescriptor(withTextStyle: forTextStyle)
guard let style = FontScaling.Style(forTextStyle),
let description = FontScaling.theme.descriptions[style] else {
return nil
}
descriptor = descriptor.addingAttributes(
[
UIFontDescriptor.AttributeName.traits: [UIFontDescriptor.TraitKey.weight: description.weight]
]
)
// Create a font copy with original size to scale it with current preferred content size category
let fontCopy = UIFont(descriptor: descriptor, size: description.size)

return UIFontMetrics(forTextStyle: forTextStyle).scaledFont(for: fontCopy)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public extension Theme.SurveyStyle {
title: .init(
color: color.baseDark.hex,
font: font.mediumSubtitle1,
textStyle: .subheadline,
textStyle: .headline,
accessibility: .init(isFontScalingEnabled: true)
),
option: .init(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public extension Theme.SurveyStyle {
title: .init(
color: color.baseDark.hex,
font: font.mediumSubtitle1,
textStyle: .subheadline,
textStyle: .headline,
accessibility: .init(isFontScalingEnabled: true)
),
option: .init(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public extension Theme.SurveyStyle {
title: .init(
color: color.baseDark.hex,
font: font.mediumSubtitle1,
textStyle: .subheadline,
textStyle: .headline,
accessibility: .init(isFontScalingEnabled: true)
),
option: .init(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public extension Theme.SurveyStyle {
title: .init(
color: color.baseDark.hex,
font: font.mediumSubtitle1,
textStyle: .subheadline,
textStyle: .headline,
accessibility: .init(isFontScalingEnabled: true)
),
tintColor: color.primary.hex,
Expand Down
4 changes: 2 additions & 2 deletions GliaWidgets/Sources/Theme/Theme+Gva.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extension Theme {
title: .init(
text: .init(
color: UIColor.black.hex,
font: font.bodyText,
font: font.mediumSubtitle1,
textStyle: .headline,
accessibility: .init(isFontScalingEnabled: true)
),
Expand Down Expand Up @@ -60,7 +60,7 @@ extension Theme {
title: .init(
font: font.mediumSubtitle1,
textColor: color.baseDark,
textStyle: .body
textStyle: .headline
),
subtitle: .init(
font: font.caption,
Expand Down
6 changes: 3 additions & 3 deletions GliaWidgets/Sources/Theme/ThemeFont.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public struct ThemeFont {
self.bodyText = fontScaling.uiFont(with: .body) // bodyText ?? Font.regular(16) // .body
self.subtitle = fontScaling.uiFont(with: .footnote) // subtitle ?? Font.regular(14) // .footnote
self.mediumSubtitle1 = fontScaling.uiFont(
with: .subheadline,
with: .headline,
font: .systemFont(ofSize: 16, weight: .medium)
) // medium16 ?? Font.medium(16) // .subheadline
self.mediumSubtitle2 = fontScaling.uiFont(with: .subheadline)// mediumSubtitle ?? Font.medium(14) // .subheadline
Expand Down Expand Up @@ -102,11 +102,11 @@ extension FontScaling.Style {
case .footnote:
return .init(weight: .regular, size: 14) // subtitle ?? Font.regular(14) // ???
case .headline:
return .init(weight: .bold, size: 17)
return .init(weight: .medium, size: 16) // mediumSubtitle1 ?? Font.medium(16)
case .largeTitle:
return .init(weight: .regular, size: 34)
case .subheadline:
return .init(weight: .medium, size: 14) // mediumSubtitle ?? Font.medium(14)
return .init(weight: .medium, size: 14) // mediumSubtitle2 ?? Font.medium(14)
case .title1:
return .init(weight: .bold, size: 24) // header1 ?? Font.bold(24)
case .title2:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,13 @@ class ChatTextContentView: BaseView {
var constraints = [NSLayoutConstraint](); defer { constraints.activate() }
constraints += textView.layoutInSuperview(insets: kTextInsets)
}

// Retrieve scaled font for given text style because font of attributed
// string does not change with dynamic size update
let scaledFont = UIFont.scaledFont(forTextStyle: style.text.textStyle) ?? style.text.font

let attributes: [NSAttributedString.Key: Any] = [
.font: UIFont.preferredFont(forTextStyle: style.text.textStyle),
.font: scaledFont,
.foregroundColor: UIColor(hex: style.text.color)
]

Expand Down

0 comments on commit 2f54c8a

Please sign in to comment.