diff --git a/GliaWidgets/SecureConversations/Welcome/Theme+SecureConversationsWelcome.swift b/GliaWidgets/SecureConversations/Welcome/Theme+SecureConversationsWelcome.swift index e418b6be1..2c297c7d7 100644 --- a/GliaWidgets/SecureConversations/Welcome/Theme+SecureConversationsWelcome.swift +++ b/GliaWidgets/SecureConversations/Welcome/Theme+SecureConversationsWelcome.swift @@ -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) ) diff --git a/GliaWidgets/Sources/Extensions/UIFont+Extensions.swift b/GliaWidgets/Sources/Extensions/UIFont+Extensions.swift index 1f0919a89..a7caf9c7e 100644 --- a/GliaWidgets/Sources/Extensions/UIFont+Extensions.swift +++ b/GliaWidgets/Sources/Extensions/UIFont+Extensions.swift @@ -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) + } +} diff --git a/GliaWidgets/Sources/Theme/Survey/Theme.Survey.BooleanQuestion.swift b/GliaWidgets/Sources/Theme/Survey/Theme.Survey.BooleanQuestion.swift index 21bbacd8e..d0f36248a 100644 --- a/GliaWidgets/Sources/Theme/Survey/Theme.Survey.BooleanQuestion.swift +++ b/GliaWidgets/Sources/Theme/Survey/Theme.Survey.BooleanQuestion.swift @@ -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( diff --git a/GliaWidgets/Sources/Theme/Survey/Theme.Survey.InputQuestion.swift b/GliaWidgets/Sources/Theme/Survey/Theme.Survey.InputQuestion.swift index 2e3873b14..f8d4ae7b8 100644 --- a/GliaWidgets/Sources/Theme/Survey/Theme.Survey.InputQuestion.swift +++ b/GliaWidgets/Sources/Theme/Survey/Theme.Survey.InputQuestion.swift @@ -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( diff --git a/GliaWidgets/Sources/Theme/Survey/Theme.Survey.ScaleQuestion.swift b/GliaWidgets/Sources/Theme/Survey/Theme.Survey.ScaleQuestion.swift index 183a82342..f26385c5a 100644 --- a/GliaWidgets/Sources/Theme/Survey/Theme.Survey.ScaleQuestion.swift +++ b/GliaWidgets/Sources/Theme/Survey/Theme.Survey.ScaleQuestion.swift @@ -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( diff --git a/GliaWidgets/Sources/Theme/Survey/Theme.Survey.SingleQuestion.swift b/GliaWidgets/Sources/Theme/Survey/Theme.Survey.SingleQuestion.swift index a344dfe58..91e30fc51 100644 --- a/GliaWidgets/Sources/Theme/Survey/Theme.Survey.SingleQuestion.swift +++ b/GliaWidgets/Sources/Theme/Survey/Theme.Survey.SingleQuestion.swift @@ -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, diff --git a/GliaWidgets/Sources/Theme/Theme+Gva.swift b/GliaWidgets/Sources/Theme/Theme+Gva.swift index 6f7fd7e70..3d73f82b9 100644 --- a/GliaWidgets/Sources/Theme/Theme+Gva.swift +++ b/GliaWidgets/Sources/Theme/Theme+Gva.swift @@ -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) ), @@ -60,7 +60,7 @@ extension Theme { title: .init( font: font.mediumSubtitle1, textColor: color.baseDark, - textStyle: .body + textStyle: .headline ), subtitle: .init( font: font.caption, diff --git a/GliaWidgets/Sources/Theme/ThemeFont.swift b/GliaWidgets/Sources/Theme/ThemeFont.swift index f1ec51830..9c810f7e2 100644 --- a/GliaWidgets/Sources/Theme/ThemeFont.swift +++ b/GliaWidgets/Sources/Theme/ThemeFont.swift @@ -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 @@ -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: diff --git a/GliaWidgets/Sources/View/Chat/Message/Content/Text/ChatTextContentView.swift b/GliaWidgets/Sources/View/Chat/Message/Content/Text/ChatTextContentView.swift index 86b774537..0864774dd 100644 --- a/GliaWidgets/Sources/View/Chat/Message/Content/Text/ChatTextContentView.swift +++ b/GliaWidgets/Sources/View/Chat/Message/Content/Text/ChatTextContentView.swift @@ -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) ]