Skip to content

Commit aeb34b1

Browse files
authored
Merge pull request #11 from ServerDriven/develop
FontType Usage 0.5.0
2 parents f1d8fb6 + 5f748f6 commit aeb34b1

File tree

4 files changed

+41
-19
lines changed

4 files changed

+41
-19
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//
2+
// SDFont.swift
3+
//
4+
//
5+
// Created by Leif on 2/23/21.
6+
//
7+
8+
import SwiftUI
9+
10+
import ScreenData
11+
12+
public struct SDFont {
13+
public static var largeTitleFont: Font?
14+
public static var titleFont: Font?
15+
public static var headlingFont: Font?
16+
public static var bodyFont: Font?
17+
public static var footnoteFont: Font?
18+
public static var captionFont: Font?
19+
20+
public static func font(for fontType: FontType) -> Font {
21+
switch fontType {
22+
case .largeTitle:
23+
return largeTitleFont ?? .largeTitle
24+
case .title:
25+
return titleFont ?? .title
26+
case .headline:
27+
return headlingFont ?? .headline
28+
case .body:
29+
return bodyFont ?? .body
30+
case .footnote:
31+
return footnoteFont ?? .footnote
32+
case .caption:
33+
return captionFont ?? .caption
34+
}
35+
}
36+
37+
}

Sources/ScreenDataUI/Views/SDButton.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public struct SDButton: View {
4343
}
4444
}) {
4545
Text(button.title)
46+
.font(SDFont.font(for: .body))
4647
.background(with: button.style)
4748
}
4849
.sheet(item: $modalScreen) { (destination) in

Sources/ScreenDataUI/Views/SDLabel.swift

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,6 @@ import ScreenDataNavigation
1212
public struct SDLabel: View {
1313
public var label: SomeLabel
1414

15-
private var font: Font {
16-
switch label.font {
17-
case .largeTitle:
18-
return .largeTitle
19-
case .title:
20-
return .title
21-
case .headline:
22-
return .headline
23-
case .body:
24-
return .body
25-
case .footnote:
26-
return .footnote
27-
case .caption:
28-
return .caption
29-
}
30-
}
31-
3215
public init(
3316
label: SomeLabel
3417
) {
@@ -40,13 +23,13 @@ public struct SDLabel: View {
4023
VStack {
4124
// Title
4225
Text(label.title)
43-
.font(font)
26+
.font(SDFont.font(for: label.font))
4427
.multilineTextAlignment(label.destination.map { _ in .center } ?? .leading)
4528

4629
// Subtitle
4730
label.subtitle.map {
4831
Text($0)
49-
.font(.headline)
32+
.font(SDFont.font(for: .headline))
5033
.multilineTextAlignment(.leading)
5134
}
5235
}

Sources/ScreenDataUI/Views/SDText.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public struct SDText: View {
1717

1818
public var body: some View {
1919
Text(text.title)
20+
.font(SDFont.font(for: .body))
2021
.background(with: text.style)
2122
.multilineTextAlignment(.leading)
2223
}

0 commit comments

Comments
 (0)