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

✨ Add FontModifier #134

Merged
merged 5 commits into from
Nov 3, 2023
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
1 change: 1 addition & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
changelog:
name: Changelog
runs-on: ubuntu-latest
if: ${{ !github.event.pull_request.head.repo.fork }}
steps:
- uses: actions/checkout@v4
- name: Changelog Reminder
Expand Down
34 changes: 34 additions & 0 deletions ACKategories-iOS/SwiftUIExtensions/FontModifier.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import SwiftUI

@available(iOS 14.0, *)
extension View {
/// Sets font and line height for text in this view.
///
/// - Parameters:
/// - font: The font to use in this view.
/// - lineHeight: The line height to use in this view.
/// - textStyle: The text style for relative font scaling. If `nil`is specified then dynamic type is turned off.
func font(
_ font: UIFont,
lineHeight: Double,
textStyle: Font.TextStyle?
) -> some View {
let customFont: Font

// Do not scale font based on dynamic type when nil `relativeTo` specified
if let textStyle = textStyle {
customFont = .custom(
font.fontName,
size: font.pointSize,
relativeTo: textStyle
)
} else {
customFont = Font(font)
}

return self
.font(customFont)
.lineSpacing(lineHeight - font.lineHeight)
.padding(.vertical, (lineHeight - font.lineHeight) / 2)
}
}
11 changes: 5 additions & 6 deletions ACKategories-iOS/UIView+Spacer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import UIKit
public extension UIView {
private final class Spacer: UIView {
fileprivate var observation: NSKeyValueObservation?

init(
size: CGFloat,
axis: NSLayoutConstraint.Axis,
Expand All @@ -18,9 +18,9 @@ public extension UIView {
height: axis == .vertical ? size : 0
)
))

translatesAutoresizingMaskIntoConstraints = false

switch axis {
case .horizontal:
let constraint = widthAnchor.constraint(equalToConstant: size)
Expand All @@ -33,12 +33,12 @@ public extension UIView {
default: assertionFailure("Unknown axis \(axis)")
}
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}

private func createSpacer(_ size: CGFloat, axis: NSLayoutConstraint.Axis, priority: Float) -> UIView {
let spacer = Spacer(size: size, axis: axis, priority: priority)
spacer.isHidden = isHidden
Expand All @@ -58,4 +58,3 @@ public extension UIView {
createSpacer(width, axis: .horizontal, priority: priority)
}
}

21 changes: 19 additions & 2 deletions ACKategories.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
69FA5FBD23C868A900B44BCD /* ModalFlowCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 69FA5FAC23C868A900B44BCD /* ModalFlowCoordinator.swift */; };
69FA5FC223C8690A00B44BCD /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 69FA5FC123C8690A00B44BCD /* LaunchScreen.storyboard */; };
6A31C9F3250572FE0047A983 /* SelfSizingTableHeaderFooterView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A31C9F2250572FE0047A983 /* SelfSizingTableHeaderFooterView.swift */; };
6A572DB92ADE89B0002BD518 /* FontModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A572DB82ADE89B0002BD518 /* FontModifier.swift */; };
88EDD90425B8252E00207987 /* GradientViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88EDD90325B8252E00207987 /* GradientViewController.swift */; };
A33559012555270F009B9D89 /* FlowCoordinatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A33559002555270F009B9D89 /* FlowCoordinatorTests.swift */; };
A38883E3257E2D2D00B958DD /* ErrorHandlers.swift in Sources */ = {isa = PBXBuildFile; fileRef = A38883E2257E2D2D00B958DD /* ErrorHandlers.swift */; };
Expand Down Expand Up @@ -265,6 +266,7 @@
69FA5FC323C869A200B44BCD /* ACKategories.podspec */ = {isa = PBXFileReference; explicitFileType = text.script.ruby; path = ACKategories.podspec; sourceTree = "<group>"; };
69FA5FE423C8712D00B44BCD /* Package.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = "<group>"; };
6A31C9F2250572FE0047A983 /* SelfSizingTableHeaderFooterView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelfSizingTableHeaderFooterView.swift; sourceTree = "<group>"; };
6A572DB82ADE89B0002BD518 /* FontModifier.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FontModifier.swift; sourceTree = "<group>"; };
88EDD90325B8252E00207987 /* GradientViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GradientViewController.swift; sourceTree = "<group>"; };
A33559002555270F009B9D89 /* FlowCoordinatorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlowCoordinatorTests.swift; sourceTree = "<group>"; };
A38883E2257E2D2D00B958DD /* ErrorHandlers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ErrorHandlers.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -450,6 +452,8 @@
69E81A0823C773370054687B /* ACKategories-iOS */ = {
isa = PBXGroup;
children = (
6950963023C7747C00E8F457 /* Base */,
6A572DB72ADE8994002BD518 /* SwiftUIExtensions */,
697CECF023C877B20019FE61 /* Aliases.swift */,
A38883E2257E2D2D00B958DD /* ErrorHandlers.swift */,
6950964823C7751600E8F457 /* GradientView.swift */,
Expand All @@ -475,7 +479,6 @@
6984CE122A5C218A001EE958 /* UIViewController+FrontMost.swift */,
6950966723C78AC800E8F457 /* UIViewController+SafeAreaCompat.swift */,
6950966323C78AC800E8F457 /* UIViewExtensions.swift */,
6950963023C7747C00E8F457 /* Base */,
6950963523C7749F00E8F457 /* Supporting files */,
);
path = "ACKategories-iOS";
Expand Down Expand Up @@ -588,6 +591,14 @@
path = "Flow coordinators";
sourceTree = "<group>";
};
6A572DB72ADE8994002BD518 /* SwiftUIExtensions */ = {
isa = PBXGroup;
children = (
6A572DB82ADE89B0002BD518 /* FontModifier.swift */,
);
path = SwiftUIExtensions;
sourceTree = "<group>";
};
88EDD8FD25B824C200207987 /* GradientView */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -774,8 +785,9 @@
69E819DF23C773010054687B /* Project object */ = {
isa = PBXProject;
attributes = {
BuildIndependentTargetsInParallel = YES;
LastSwiftUpdateCheck = 1130;
LastUpgradeCheck = 1400;
LastUpgradeCheck = 1500;
TargetAttributes = {
695096D723C7908B00E8F457 = {
CreatedOnToolsVersion = 11.3;
Expand Down Expand Up @@ -979,6 +991,7 @@
6950967023C78AC900E8F457 /* UIControlEvents.swift in Sources */,
6950965723C7754D00E8F457 /* Reusable.swift in Sources */,
69F83E972A617A2500E9C8EA /* Combine+Concurrency.swift in Sources */,
6A572DB92ADE89B0002BD518 /* FontModifier.swift in Sources */,
6950962A23C7740B00E8F457 /* Logger.swift in Sources */,
6950967823C78AC900E8F457 /* UIViewController+Children.swift in Sources */,
6950967223C78AC900E8F457 /* UIViewExtensions.swift in Sources */,
Expand Down Expand Up @@ -1196,6 +1209,7 @@
DEAD_CODE_STRIPPING = YES;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
Expand Down Expand Up @@ -1234,6 +1248,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
DEAD_CODE_STRIPPING = YES;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
Expand Down Expand Up @@ -1575,6 +1590,7 @@
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "";
CODE_SIGN_STYLE = Automatic;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1;
Expand Down Expand Up @@ -1656,6 +1672,7 @@
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "";
CODE_SIGN_STYLE = Automatic;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1400"
LastUpgradeVersion = "1500"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1400"
LastUpgradeVersion = "1500"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1400"
LastUpgradeVersion = "1500"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
1 change: 0 additions & 1 deletion ACKategoriesCore/Combine+Concurrency.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@ public extension AnyPublisher where Failure == Error {
self = Future { try await operation() }.eraseToAnyPublisher()
}
}

2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
```

## Next
- Bump deployment target to iOS 12 ([#137](https://github.com/AckeeCZ/ACKategories/pull/137), kudos to @olejnjak)
- Add Font modifier for SwiftUI fonts ([#134](https://github.com/AckeeCZ/ACKategories/pull/134), kudos to @leinhauplk)

## 6.12.3
- Added `BetterURL` implementation to improve URL parsing ([#129](https://github.com/AckeeCZ/ACKategories/pull/129), kudos to @AGr-AlexandrGrigoryev)
Expand Down