Skip to content

Commit 593ba47

Browse files
committed
Disable font scaling by default when using SwiftUI View modifier
1 parent 41e8284 commit 593ba47

8 files changed

Lines changed: 27 additions & 19 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [4.4.0] - 2022-08-16
8+
## Changed
9+
- SwiftUI already scales fonts so scaling as part of the typography style View modifier e.g. `.typography(style: .interactive)` resulted in fonts being scaled twice. Therefore the default scaling mode when using this modifier in SwiftUI is disabled however the scaling mode can be specified as a parameter e.g. `.typography(style: .interactive, scalingMode: .fontMetrics)`.
10+
711
## [4.3.2] - 2022-03-16
812
## Changed
913
- Fixed an issue concerning font colors in SwiftUI.

Example/Pods/Pods.xcodeproj/project.pbxproj

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Pods.xcodeproj/xcshareddata/xcschemes/TypographyKit.xcscheme

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/TypographyKit.xcodeproj/project.pbxproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@
280280
isa = PBXProject;
281281
attributes = {
282282
LastSwiftUpdateCheck = 0720;
283-
LastUpgradeCheck = 1310;
283+
LastUpgradeCheck = 1340;
284284
ORGANIZATIONNAME = CocoaPods;
285285
TargetAttributes = {
286286
607FACCF1AFB9204008FA782 = {
@@ -611,7 +611,7 @@
611611
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
612612
INFOPLIST_FILE = TypographyKit/Info.plist;
613613
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
614-
MARKETING_VERSION = 4.3.2;
614+
MARKETING_VERSION = 4.4.0;
615615
MODULE_NAME = ExampleApp;
616616
PRODUCT_BUNDLE_IDENTIFIER = "com.rwbutler.TypographyKit-Example";
617617
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -627,7 +627,7 @@
627627
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
628628
INFOPLIST_FILE = TypographyKit/Info.plist;
629629
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
630-
MARKETING_VERSION = 4.3.2;
630+
MARKETING_VERSION = 4.4.0;
631631
MODULE_NAME = ExampleApp;
632632
PRODUCT_BUNDLE_IDENTIFIER = "com.rwbutler.TypographyKit-Example";
633633
PRODUCT_NAME = "$(TARGET_NAME)";

Example/TypographyKit.xcodeproj/xcshareddata/xcschemes/TypographyKit-Example.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1310"
3+
LastUpgradeVersion = "1340"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

TypographyKit.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'TypographyKit'
3-
s.version = '4.3.2'
3+
s.version = '4.4.0'
44
s.summary = 'Consistent & accessible visual styling on iOS with support for Dynamic Type'
55
s.swift_version = '5.0'
66
s.description = <<-DESC

TypographyKit/Classes/Typography.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public struct Typography {
5252
private static let monospacedDigitSystemFontName = "MonospacedDigit\(systemFontName)"
5353
private static let systemFontName = "System"
5454

55-
public init?(for textStyle: UIFont.TextStyle) {
55+
public init?(for textStyle: UIFont.TextStyle, scalingMode: ScalingMode? = nil) {
5656
guard let typographyStyle = TypographyKit.fontTextStyles[textStyle.rawValue] else {
5757
return nil
5858
}
@@ -63,7 +63,7 @@ public struct Typography {
6363
self.pointSize = typographyStyle.pointSize
6464
self.letterCase = typographyStyle.letterCase
6565
self.letterSpacing = typographyStyle.letterSpacing
66-
self.scalingMode = typographyStyle.scalingMode
66+
self.scalingMode = scalingMode ?? typographyStyle.scalingMode
6767
self.textColor = typographyStyle.textColor
6868
self.textStyle = textStyle
6969
}

TypographyKit/Classes/ViewAdditions.swift

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,29 @@ private struct TypographyStyle: ViewModifier {
1616
@Environment(\.sizeCategory) var sizeCategory
1717

1818
var color: Color? {
19-
guard let textColor = Typography(for: style)?.textColor else {
19+
guard let textColor = Typography(for: style, scalingMode: scalingMode)?.textColor else {
2020
return nil
2121
}
2222
return Color(textColor)
2323
}
2424

2525
var font: Font? {
26-
guard let font = Typography(for: style)?.font() else {
26+
guard let font = Typography(for: style, scalingMode: scalingMode)?.font() else {
2727
return nil
2828
}
29-
return Font.custom(font.fontName, size: font.pointSize)
29+
return Font(font as CTFont)
3030
}
3131

32-
var style: UIFont.TextStyle
32+
let scalingMode: ScalingMode?
33+
let style: UIFont.TextStyle
3334

3435
func body(content: Content) -> some View {
3536
return content
36-
.ifLet(font) { $0.font($1) }
37-
.ifLet(color) { $0.foregroundColor($1) }
37+
.ifLet(font) { content, font in
38+
content.font(font) }
39+
.ifLet(color) { view, color in
40+
view.foregroundColor(color)
41+
}
3842
}
3943

4044
}
@@ -56,8 +60,8 @@ extension View {
5660

5761
@available(iOS 13, macCatalyst 13, tvOS 13, watchOS 6, *)
5862
public extension View {
59-
func typography(style: UIFont.TextStyle) -> some View {
60-
return modifier(TypographyStyle(style: style))
63+
func typography(style: UIFont.TextStyle, scalingMode: ScalingMode? = .disabled) -> some View {
64+
return modifier(TypographyStyle(scalingMode: scalingMode, style: style))
6165
}
6266
}
6367

0 commit comments

Comments
 (0)