Skip to content

Commit fca0281

Browse files
Increase text size toggle (#623)
* feat: UIKit font scaling * feat: SwiftUI font scaling * feat: add notification for text size refresh across views * Minor edits to comments for punctuation and capitalization --------- Co-authored-by: Andrew Tavis McAllister <andrew.t.mcallister@gmail.com>
1 parent 5751b1d commit fca0281

17 files changed

Lines changed: 144 additions & 31 deletions

Scribe/AppDelegate.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1515
_: UIApplication,
1616
didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?
1717
) -> Bool {
18+
initializeFontSize()
1819
// Override point for customization after application launch.
1920
if #available(iOS 13.0, *) {
2021
let appearance = UITabBarAppearance()

Scribe/AppExtensions.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,6 @@ extension Locale {
5353

5454
extension Notification.Name {
5555
static let keyboardsUpdatedNotification = Notification.Name("keyboardsHaveUpdated")
56+
static let fontSizeUpdatedNotification = Notification.Name("fontSizeHasUpdated")
57+
5658
}

Scribe/AppTexts/AppTextStyling.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,22 @@ import UIKit
99
let preferredLanguage = Locale.preferredLanguages[0]
1010

1111
var fontSize = CGFloat(0)
12+
func initializeFontSize() {
13+
if DeviceType.isPhone {
14+
if UIScreen.main.bounds.width > 413 || UIScreen.main.bounds.width <= 375 {
15+
fontSize = UIScreen.main.bounds.height / 59
16+
} else {
17+
fontSize = UIScreen.main.bounds.height / 50
18+
}
19+
} else if DeviceType.isPad {
20+
fontSize = UIScreen.main.bounds.height / 50
21+
}
1222

23+
let userDefaults = UserDefaults(suiteName: "group.be.scri.userDefaultsContainer")!
24+
if userDefaults.bool(forKey: "increaseTextSize") {
25+
fontSize *= 1.25
26+
}
27+
}
1328
/// Concatenates attributed strings.
1429
///
1530
/// - Parameters

Scribe/Button/CTAButton.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,18 @@
77
import SwiftUI
88

99
struct CTAButton: View {
10+
@AppStorage("increaseTextSize", store: UserDefaults(suiteName: "group.be.scri.userDefaultsContainer"))
11+
var increaseTextSize: Bool = false
12+
var textSizeMultiplier: CGFloat { increaseTextSize ? 1.25 : 1.0 }
13+
1014
let title: String
1115
let action: () -> Void
1216
@Environment(\.colorScheme) var colorScheme
1317

1418
var body: some View {
1519
Button(action: action) {
1620
Text(title)
17-
.font(.system(size: 20, weight: .bold))
21+
.font(.system(size: 20 * textSizeMultiplier, weight: .bold))
1822
.foregroundColor(Color("lightTextDarkCTA"))
1923
.frame(maxWidth: .infinity)
2024
.padding(.vertical, 16)

Scribe/Button/DownloadButton.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ struct ButtonConfig {
7070
}
7171

7272
struct DownloadButton: View {
73+
@AppStorage("increaseTextSize", store: UserDefaults(suiteName: "group.be.scri.userDefaultsContainer"))
74+
var increaseTextSize: Bool = false
75+
var textSizeMultiplier: CGFloat { increaseTextSize ? 1.25 : 1.0 }
76+
7377
let state: ButtonState
7478
let action: () -> Void
7579
@Environment(\.colorScheme) var colorScheme
@@ -86,7 +90,7 @@ struct DownloadButton: View {
8690
Image(systemName: state.config.icon)
8791
}
8892
}
89-
.font(.system(size: 12, weight: .semibold))
93+
.font(.system(size: 12 * textSizeMultiplier, weight: .semibold))
9094
.foregroundColor(state.config.foregroundColor)
9195
.frame(width: 120, height: 20)
9296
.padding(.vertical, 6)

Scribe/ConfirmDialog/ConfirmDialogView.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
import SwiftUI
88

99
struct ConfirmDialogView: View {
10+
@AppStorage("increaseTextSize", store: UserDefaults(suiteName: "group.be.scri.userDefaultsContainer"))
11+
var increaseTextSize: Bool = false
12+
var textSizeMultiplier: CGFloat { increaseTextSize ? 1.25 : 1.0 }
13+
1014
private let cardCornerRadius: CGFloat = 10
1115
private let iconSize: CGFloat = 30.0
1216
private let cardPadding: CGFloat = 16
@@ -35,7 +39,7 @@ struct ConfirmDialogView: View {
3539
.foregroundColor(Color.scribeCTA)
3640

3741
Text(infoText)
38-
.font(.system(size: DeviceType.isPad ? 22 : 0))
42+
.font(.system(size: DeviceType.isPad ? 22 * textSizeMultiplier : 17 * textSizeMultiplier))
3943
.fixedSize(horizontal: false, vertical: true)
4044
}
4145

@@ -45,7 +49,7 @@ struct ConfirmDialogView: View {
4549
action: onChange,
4650
label: {
4751
Text(changeButtonText)
48-
.font(.system(size: DeviceType.isPad ? 22 : 0))
52+
.font(.system(size: DeviceType.isPad ? 22 * textSizeMultiplier : 17 * textSizeMultiplier))
4953
.foregroundColor(Color.keyChar)
5054
})
5155
.buttonStyle(.borderedProminent)
@@ -61,6 +65,7 @@ struct ConfirmDialogView: View {
6165
label: {
6266
Text(confirmButtonText)
6367
.font(.system(size: DeviceType.isPad ? 22 : 0))
68+
.font(.system(size: DeviceType.isPad ? 22 * textSizeMultiplier : 17 * textSizeMultiplier))
6469
.foregroundColor(Color.keyChar)
6570
})
6671
.buttonStyle(.borderedProminent)

Scribe/InstallationTab/DownloadDataScreen.swift

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ struct RadioCircle: View {
3131
}
3232

3333
struct UpdateDataCardView: View {
34+
@AppStorage("increaseTextSize", store: UserDefaults(suiteName: "group.be.scri.userDefaultsContainer"))
35+
var increaseTextSize: Bool = false
36+
var textSizeMultiplier: CGFloat { increaseTextSize ? 1.25 : 1.0 }
37+
3438
var languages: [Section]
3539
private let title = NSLocalizedString(
3640
"i18n.app.download.menu_ui.update_data",
@@ -53,14 +57,14 @@ struct UpdateDataCardView: View {
5357
var body: some View {
5458
VStack(alignment: .leading, spacing: 6) {
5559
Text(title)
56-
.font(.system(size: 19, weight: .semibold))
60+
.font(.system(size: 19 * textSizeMultiplier, weight: .semibold))
5761
.foregroundColor(.primary)
5862

5963
VStack(alignment: .leading, spacing: 12) {
6064
if !languages.isEmpty {
6165
HStack {
6266
Text(checkText)
63-
.font(.body)
67+
.font(.system(size: 17 * textSizeMultiplier))
6468
.foregroundColor(.primary)
6569

6670
Spacer()
@@ -86,6 +90,9 @@ struct UpdateDataCardView: View {
8690
}
8791

8892
struct LanguageDownloadCard: View {
93+
@AppStorage("increaseTextSize", store: UserDefaults(suiteName: "group.be.scri.userDefaultsContainer"))
94+
var increaseTextSize: Bool = false
95+
var textSizeMultiplier: CGFloat { increaseTextSize ? 1.25 : 1.0 }
8996
let language: String
9097
let state: ButtonState
9198
let action: () -> Void
@@ -94,7 +101,7 @@ struct LanguageDownloadCard: View {
94101
VStack(alignment: .leading, spacing: 12) {
95102
HStack {
96103
Text(language)
97-
.font(.body)
104+
.font(.system(size: 17 * textSizeMultiplier))
98105
.foregroundColor(.primary)
99106

100107
Spacer()
@@ -145,6 +152,9 @@ struct EmptyStateView: View {
145152
struct LanguageListView: View {
146153
var onNavigateToTranslationSource: ((String, String) -> Void)?
147154
var languages: [Section]
155+
@AppStorage("increaseTextSize", store: UserDefaults(suiteName: "group.be.scri.userDefaultsContainer"))
156+
var increaseTextSize: Bool = false
157+
var textSizeMultiplier: CGFloat { increaseTextSize ? 1.25 : 1.0 }
148158

149159
@ObservedObject private var stateManager = DownloadStateManager.shared
150160

@@ -180,7 +190,7 @@ struct LanguageListView: View {
180190
ZStack {
181191
VStack(alignment: .leading, spacing: 6) {
182192
Text(title)
183-
.font(.system(size: 19, weight: .semibold))
193+
.font(.system(size: 19 * textSizeMultiplier, weight: .semibold))
184194
.foregroundColor(.primary)
185195
if languages.isEmpty {
186196
EmptyStateView()

Scribe/InstallationTab/InstallationDownload.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,23 @@ struct CardView: View {
1111
let mainText: String
1212
let subtitle: String
1313
let action: () -> Void
14+
@AppStorage("increaseTextSize", store: UserDefaults(suiteName: "group.be.scri.userDefaultsContainer"))
15+
var increaseTextSize: Bool = false
16+
17+
var textSizeMultiplier: CGFloat {
18+
increaseTextSize ? 1.25 : 1.0
19+
}
1420

1521
var body: some View {
1622
VStack(alignment: .leading, spacing: 6) {
1723
Text(title)
18-
.font(.system(size: 19, weight: .semibold))
24+
.font(.system(size: 19 * textSizeMultiplier, weight: .semibold))
1925
.foregroundColor(.primary)
2026

2127
VStack(alignment: .leading, spacing: 6) {
2228
HStack {
2329
Text(mainText)
24-
.font(.body)
30+
.font(.system(size: 17 * textSizeMultiplier))
2531
.foregroundColor(.primary)
2632

2733
Spacer()
@@ -31,7 +37,7 @@ struct CardView: View {
3137
}
3238

3339
Text(subtitle)
34-
.font(.subheadline)
40+
.font(.system(size: 15 * textSizeMultiplier))
3541
.foregroundColor(.secondary)
3642
}
3743
.padding()

Scribe/InstallationTab/InstallationVC.swift

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import SwiftUI
99

1010
/// A UIViewController that provides instructions on how to install Keyboards as well as information about Scribe.
1111
class InstallationVC: UIViewController {
12+
1213
// Variables linked to elements in AppScreen.storyboard.
1314
@IBOutlet var appTextViewPhone: UITextView!
1415
@IBOutlet var appTextViewPad: UITextView!
@@ -106,7 +107,18 @@ class InstallationVC: UIViewController {
106107
name: NSNotification.Name("NavigateToDownloadScreen"),
107108
object: nil
108109
)
110+
NotificationCenter.default.addObserver(
111+
self,
112+
selector: #selector(handleFontSizeUpdate),
113+
name: .fontSizeUpdatedNotification,
114+
object: nil
115+
)
109116
}
117+
@objc func handleFontSizeUpdate() {
118+
DispatchQueue.main.async {
119+
self.setCurrentUI()
120+
}
121+
}
110122

111123
@objc private func handleNavigateToDownloadScreen() {
112124
navigateToDownloadDataScreen()
@@ -246,17 +258,9 @@ class InstallationVC: UIViewController {
246258

247259
/// Creates the current app UI by applying constraints and calling child UI functions.
248260
func setCurrentUI() {
249-
// Sets the font size for the text in the app screen and corresponding UIImage icons.
250-
if DeviceType.isPhone {
251-
if UIScreen.main.bounds.width > 413 || UIScreen.main.bounds.width <= 375 {
252-
fontSize = UIScreen.main.bounds.height / 59
253-
} else if UIScreen.main.bounds.width <= 413 && UIScreen.main.bounds.width > 375 {
254-
fontSize = UIScreen.main.bounds.height / 50
255-
}
256261

257-
} else if DeviceType.isPad {
258-
fontSize = UIScreen.main.bounds.height / 50
259-
}
262+
// Sets the font size for the text in the app screen and corresponding UIImage icons.
263+
initializeFontSize()
260264

261265
installationHeaderLabel.text = NSLocalizedString(
262266
"i18n.app.installation.keyboard.title", value: "Keyboard installation", comment: ""

Scribe/ParentTableCellModel.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ enum UserInteractiveState {
7070
case autosuggestEmojis
7171
case toggleAccentCharacters
7272
case toggleWordForWordDeletion
73+
case increaseTextSize
7374
case none
7475
}
7576

0 commit comments

Comments
 (0)