Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 12.1.1 #55

Merged
merged 8 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ADUtils.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = 'ADUtils'
spec.version = '12.1.0'
spec.version = '12.1.1'
spec.authors = 'Fabernovel'
spec.homepage = 'https://github.com/faberNovel/ADUtils'
spec.summary = 'Fabernovel\'s toolbox for iOS'
Expand Down
4 changes: 4 additions & 0 deletions ADUtils.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
57E1CD491C884F8900A7DFFB /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57E1CD481C884F8900A7DFFB /* AppDelegate.swift */; };
57F7ECC41BB0042D0095AEEC /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 57F7ECC31BB0042D0095AEEC /* Localizable.strings */; };
57F7ECC61BB004510095AEEC /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 57F7ECC51BB004500095AEEC /* InfoPlist.strings */; };
73865A2F2B8760BD00214C69 /* SystemFont.plist in Resources */ = {isa = PBXBuildFile; fileRef = 73865A2E2B8760BD00214C69 /* SystemFont.plist */; };
7A0EC6541535D8ED00E5F54A /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7A0EC6531535D8ED00E5F54A /* UIKit.framework */; };
7A0EC6561535D8ED00E5F54A /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7A0EC6551535D8ED00E5F54A /* Foundation.framework */; };
7A0EC6581535D8ED00E5F54A /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7A0EC6571535D8ED00E5F54A /* CoreGraphics.framework */; };
Expand Down Expand Up @@ -128,6 +129,7 @@
57F7ECC51BB004500095AEEC /* InfoPlist.strings */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; path = InfoPlist.strings; sourceTree = "<group>"; };
5DE795FD4906461A70860D2B /* Pods-ADUtilsApp.production.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ADUtilsApp.production.xcconfig"; path = "Pods/Target Support Files/Pods-ADUtilsApp/Pods-ADUtilsApp.production.xcconfig"; sourceTree = "<group>"; };
6423630AD4B44DC50EA87D8A /* UIRectEdgeTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIRectEdgeTest.swift; sourceTree = "<group>"; };
73865A2E2B8760BD00214C69 /* SystemFont.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = SystemFont.plist; sourceTree = "<group>"; };
7A0EC64F1535D8ED00E5F54A /* ADUtilsApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ADUtilsApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
7A0EC6531535D8ED00E5F54A /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
7A0EC6551535D8ED00E5F54A /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -246,6 +248,7 @@
49D1F133216CCEF4009F87AB /* ADViewLayoutGuideTestsObjc.m */,
921907DE21F7AE4400EF2B67 /* ADLayoutGuideTestsObjc.m */,
EC626C6C1FA07281001C332C /* HelveticaNeue.plist */,
73865A2E2B8760BD00214C69 /* SystemFont.plist */,
49D1F130216C968E009F87AB /* ADUtilsTests-Bridging-Header.h */,
F2F326C02448431300BB5700 /* NSDirectionalEdgeInsetsTests.swift */,
57397F7C24CAD105001C6F2E /* LocaleUserPreferredTimeFormatTests.swift */,
Expand Down Expand Up @@ -503,6 +506,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
73865A2F2B8760BD00214C69 /* SystemFont.plist in Resources */,
EC626C6D1FA07281001C332C /* HelveticaNeue.plist in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"pins" : [
{
"identity" : "swift-snapshot-testing",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-snapshot-testing.git",
"state" : {
"revision" : "e7b77228b34057041374ebef00c0fd7739d71a2b",
"version" : "1.15.3"
}
},
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-syntax.git",
"state" : {
"revision" : "64889f0c732f210a935a0ad7cda38f77f876262d",
"version" : "509.1.1"
}
}
],
"version" : 2
}
65 changes: 63 additions & 2 deletions ADUtilsTests/DynamicFontTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,21 @@ private extension UIFont {
class func ad_mainFont(forTextStyle textStyle: UIFont.TextStyle) -> UIFont {
return FontHelper.shared.helveticaNeueDynamicFont.font(forTextStyle: textStyle)
}

class func ad_systemFont(forTextStyle textStyle: UIFont.TextStyle) -> UIFont {
return FontHelper.shared.systemFont.font(forTextStyle: textStyle)
}
}

private extension Font {

static func ad_mainFont(forTextStyle textStyle: Font.TextStyle) -> Font {
return FontHelper.shared.helveticaNeueDynamicFont.font(forTextStyle: textStyle)
}

static func ad_systemFont(forTextStyle textStyle: Font.TextStyle) -> Font {
return FontHelper.shared.systemFont.font(forTextStyle: textStyle)
}
}

private class FontHelper {
Expand All @@ -38,6 +46,15 @@ private class FontHelper {
return DynamicFont()
}
}()

lazy var systemFont: DynamicFont = {
do {
return try DynamicFont(fontName: "SystemFont", in: Bundle(for: type(of: self)))
} catch {
assertionFailure("Unable to create systemFont")
return DynamicFont()
}
}()
}

@MainActor
Expand Down Expand Up @@ -83,13 +100,40 @@ class DynamicFontTest: QuickSpec {
named: "DynamicFontLayoutXXLTest"
)
}

it("should render system font properly") {
let labels = types.map { (type) -> UILabel in
let label = UILabel()
label.font = UIFont.ad_systemFont(forTextStyle: type)
label.adjustsFontForContentSizeCategory = true
label.text = "Lorem sizzle pimpin' sit amizzle"
label.numberOfLines = 0
return label
}

let stackView = UIStackView(arrangedSubviews: labels)
stackView.frame = CGRect(x: 0.0, y: 0.0, width: 200.0, height: 1000.0)
stackView.axis = .vertical
stackView.distribution = .fillEqually

stackView.layoutIfNeeded()
assertSnapshot(matching: stackView, as: .image, named: "SystemFontLayoutTest")
assertSnapshot(
matching: stackView,
as: .image(traits: UITraitCollection(preferredContentSizeCategory: .extraExtraExtraLarge)),
named: "SystemFontLayoutXXLTest"
)
}
}

describe("display SwiftUI fonts") {

struct DynamicFontsView: View {

let fontProvider: (Font.TextStyle) -> Font

let types: [Font.TextStyle] = [
.largeTitle,
.title,
.title2,
.title3,
Expand All @@ -105,13 +149,13 @@ class DynamicFontTest: QuickSpec {
var body: some View {
VStack(alignment: .leading, spacing: 8) {
ForEach(types.indices, id: \.self) { index in
Text("Lorem sizzle pimpin' sit amizzle").font(.ad_mainFont(forTextStyle: types[index]))
Text("Lorem sizzle pimpin' sit amizzle").font(fontProvider(types[index]))
}
}
}
}
it("should layout labels properly") {
let view = DynamicFontsView()
let view = DynamicFontsView(fontProvider: { .ad_mainFont(forTextStyle: $0) })
assertSnapshot(
matching: view,
as: .image(layout: .fixed(width: 200, height: 1000)),
Expand All @@ -126,6 +170,23 @@ class DynamicFontTest: QuickSpec {
named: "SwiftUIDynamicFontLayoutXXLTest"
)
}

it("should render system font properly") {
let view = DynamicFontsView(fontProvider: { .ad_systemFont(forTextStyle: $0) })
assertSnapshot(
matching: view,
as: .image(layout: .fixed(width: 200, height: 1000)),
named: "SwiftUISystemFontLayoutTest"
)
assertSnapshot(
matching: view,
as: .image(
layout: .fixed(width: 200, height: 1000),
traits: UITraitCollection(preferredContentSizeCategory: .extraExtraExtraLarge)
),
named: "SwiftUISystemFontLayoutXXLTest"
)
}
}
}
}
83 changes: 83 additions & 0 deletions ADUtilsTests/SystemFont.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>UICTFontTextStyleTitle0</key>
<dict>
<key>name</key>
<string>black</string>
<key>size</key>
<integer>18</integer>
</dict>
<key>UICTFontTextStyleTitle1</key>
<dict>
<key>name</key>
<string>bold</string>
<key>size</key>
<integer>16</integer>
</dict>
<key>UICTFontTextStyleTitle2</key>
<dict>
<key>name</key>
<string>heavy</string>
<key>size</key>
<integer>14</integer>
</dict>
<key>UICTFontTextStyleTitle3</key>
<dict>
<key>name</key>
<string>light</string>
<key>size</key>
<integer>13</integer>
</dict>
<key>UICTFontTextStyleHeadline</key>
<dict>
<key>name</key>
<string>medium</string>
<key>size</key>
<integer>14</integer>
</dict>
<key>UICTFontTextStyleSubhead</key>
<dict>
<key>name</key>
<string>regular</string>
<key>size</key>
<integer>13</integer>
</dict>
<key>UICTFontTextStyleBody</key>
<dict>
<key>name</key>
<string>semibold</string>
<key>size</key>
<integer>15</integer>
</dict>
<key>UICTFontTextStyleCallout</key>
<dict>
<key>name</key>
<string>thin</string>
<key>size</key>
<integer>13</integer>
</dict>
<key>UICTFontTextStyleFootnote</key>
<dict>
<key>name</key>
<string>ultrathin</string>
<key>size</key>
<integer>11</integer>
</dict>
<key>UICTFontTextStyleCaption1</key>
<dict>
<key>name</key>
<string>regular</string>
<key>size</key>
<integer>10</integer>
</dict>
<key>UICTFontTextStyleCaption2</key>
<dict>
<key>name</key>
<string>regular</string>
<key>size</key>
<integer>11</integer>
</dict>
</dict>
</plist>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

## [12.1.1] - 2024-02-22

### Fixed
- Handle default system font weights for SwiftUI
- Add largeTitle style in font tests

## [12.1.0] - 2024-01-15

### Added
Expand Down
5 changes: 2 additions & 3 deletions MAINTAINER.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

## How to release a version

- create & push a release branch `release/vA.B.C` -> the prepare_release action will automatically create the PR to merge this release into master.
- Update version in podfile & run pod install to update podfile
- update changelog
- create release branch `release/vA.B.C`
- run `bundle exec fastlane prepare_release`, this will update the version number in the podspec based on the release branch.
- merge PR -> the CI action will trigger a pod release and tag the commit
- once the PR is merged, merge the branch `release/vA.B.C` into master
38 changes: 38 additions & 0 deletions Modules/ADUtils/DynamicFont.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ private struct CustomFontDynamicFontProvider: DynamicFontProvider {

private func throwingFont(forTextStyle textStyle: Font.TextStyle) throws -> Font {
let styleDescription = try fontDescription.fontStyleDescription(for: textStyle)
guard UIFont(name: styleDescription.name, size: styleDescription.size) != nil else {
return try systemFont(weightName: styleDescription.name, size: styleDescription.size)
}
return Font.custom(styleDescription.name, size: styleDescription.size, relativeTo: textStyle)
}

Expand All @@ -125,6 +128,13 @@ private struct CustomFontDynamicFontProvider: DynamicFontProvider {
}
return UIFont.systemFont(ofSize: size, weight: weight)
}

private func systemFont(weightName: String, size: CGFloat) throws -> Font {
guard let weight = Font.Weight(name: weightName) else {
throw FontDescriptionError.fontMissing
}
return Font.system(size: size, weight: weight)
}
}

private extension UIFont.Weight {
Expand Down Expand Up @@ -154,3 +164,31 @@ private extension UIFont.Weight {
}
}
}

private extension Font.Weight {

init?(name: String) {
switch name.lowercased() {
case "black":
self = .black
case "bold":
self = .bold
case "heavy":
self = .heavy
case "light":
self = .light
case "medium":
self = .medium
case "regular":
self = .regular
case "semibold":
self = .semibold
case "thin":
self = .thin
case "ultralight":
self = .ultraLight
default:
return nil
}
}
}
12 changes: 6 additions & 6 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
PODS:
- ADUtils (12.1.0):
- ADUtils/objc (= 12.1.0)
- ADUtils/objc (12.1.0):
- ADUtils (12.1.1):
- ADUtils/objc (= 12.1.1)
- ADUtils/objc (12.1.1):
- ADUtils/Swift
- ADUtils/Security (12.1.0)
- ADUtils/Swift (12.1.0)
- ADUtils/Security (12.1.1)
- ADUtils/Swift (12.1.1)
- Nimble (12.0.1)
- OCMock (3.9.1)
- Quick (7.0.2)
Expand All @@ -30,7 +30,7 @@ EXTERNAL SOURCES:
:path: "./"

SPEC CHECKSUMS:
ADUtils: dc0a66494ee1853cb2b78476773755bd244ded7e
ADUtils: a3e9fdcfe76222dd3abfa4659ad1e8249ed16c95
Nimble: b279b3ca9e094508778aab5c76417be158d3ad04
OCMock: 9491e4bec59e0b267d52a9184ff5605995e74be8
Quick: efab97aca76d60be86c15daa533b2cdfbe1a74d3
Expand Down
Loading