Skip to content

Commit

Permalink
🎨 Use rounded font
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Friese <[email protected]>
  • Loading branch information
peterfriese committed Dec 9, 2021
1 parent 91f33c8 commit 35d45cf
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 9 deletions.
4 changes: 4 additions & 0 deletions code/frontend/MakeItSo/MakeItSo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
88A1B7442756541400DB0494 /* ReminderListRowViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88A1B7422756541400DB0494 /* ReminderListRowViewModel.swift */; };
88C30CD6274D1B4500E6694D /* ReminderDetailsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88C30CD5274D1B4500E6694D /* ReminderDetailsViewModel.swift */; };
88C30CD7274D1B4500E6694D /* ReminderDetailsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88C30CD5274D1B4500E6694D /* ReminderDetailsViewModel.swift */; };
88E25439275E494900341C5C /* Font+Rounded.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88E25438275E494900341C5C /* Font+Rounded.swift */; };
88E7B7BE274CF30A00AF477D /* ReminderDetailsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88E7B7BD274CF30A00AF477D /* ReminderDetailsView.swift */; };
88E7B7BF274CF30A00AF477D /* ReminderDetailsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88E7B7BD274CF30A00AF477D /* ReminderDetailsView.swift */; };
88FA998D274D63A400670474 /* View+ConfirmationDialog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88FA998C274D63A400670474 /* View+ConfirmationDialog.swift */; };
Expand All @@ -37,6 +38,7 @@
887B6FA9273ED4180028263D /* EmptyStateView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EmptyStateView.swift; sourceTree = "<group>"; };
88A1B7422756541400DB0494 /* ReminderListRowViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReminderListRowViewModel.swift; sourceTree = "<group>"; };
88C30CD5274D1B4500E6694D /* ReminderDetailsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReminderDetailsViewModel.swift; sourceTree = "<group>"; };
88E25438275E494900341C5C /* Font+Rounded.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Font+Rounded.swift"; sourceTree = "<group>"; };
88E7B7BD274CF30A00AF477D /* ReminderDetailsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReminderDetailsView.swift; sourceTree = "<group>"; };
88FA998C274D63A400670474 /* View+ConfirmationDialog.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+ConfirmationDialog.swift"; sourceTree = "<group>"; };
88FA99912750090200670474 /* View+InteractiveDismissDisable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+InteractiveDismissDisable.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -72,6 +74,7 @@
881EF5BB272DC366004761E5 /* Extensions */ = {
isa = PBXGroup;
children = (
88E25438275E494900341C5C /* Font+Rounded.swift */,
881EF5BC272DC399004761E5 /* View+Focus.swift */,
88FA998C274D63A400670474 /* View+ConfirmationDialog.swift */,
88FA99912750090200670474 /* View+InteractiveDismissDisable.swift */,
Expand Down Expand Up @@ -285,6 +288,7 @@
88FA998D274D63A400670474 /* View+ConfirmationDialog.swift in Sources */,
88FEECFA27280F3D00ED368C /* ReminderListRowView.swift in Sources */,
88A1B7432756541400DB0494 /* ReminderListRowViewModel.swift in Sources */,
88E25439275E494900341C5C /* Font+Rounded.swift in Sources */,
88FA99922750090200670474 /* View+InteractiveDismissDisable.swift in Sources */,
887B6FAD273ED4180028263D /* EmptyStateView.swift in Sources */,
88E7B7BE274CF30A00AF477D /* ReminderDetailsView.swift in Sources */,
Expand Down
52 changes: 52 additions & 0 deletions code/frontend/MakeItSo/Shared/Extensions/Font+Rounded.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// Appearance.swift
// MakeItSo (iOS)
//
// Created by Peter Friese on 06.12.21.
// Copyright © 2021 Google LLC. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import SwiftUI

extension UIFontDescriptor {
static func largeTitle() -> UIFontDescriptor? {
UIFontDescriptor.preferredFontDescriptor(withTextStyle: .largeTitle).withSymbolicTraits(.traitBold)
}

static func headline() -> UIFontDescriptor? {
UIFontDescriptor.preferredFontDescriptor(withTextStyle: .headline).withSymbolicTraits(.traitBold)
}

func rounded() -> UIFontDescriptor? {
self.withDesign(.rounded)
}
}


// see https://gist.github.com/darrensapalo/bd6dddab6a70ae0a2d6cf8ac5aeb6b1a for more
extension UIFont {
static func roundedLargeTitle() -> UIFont? {
guard let descriptor = UIFontDescriptor.largeTitle()?.rounded() else { return nil }
return UIFont(descriptor: descriptor, size: 0)
}

static func roundedHeadline() -> UIFont? {
guard let descriptor = UIFontDescriptor.headline()?.rounded() else { return nil }
return UIFont(descriptor: descriptor, size: 0)
}
}

extension View {
}

Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,10 @@ struct RemindersListView: View {
@FocusState
var focusedReminder: Focusable?

init() {
// Turn this into a view modifier. See [Navigation Bar Styling in SwiftUI - YouTube](https://youtu.be/kCJyhG8zjvY)
let navBarAppearance = UINavigationBarAppearance()
navBarAppearance.largeTitleTextAttributes = [.foregroundColor: UIColor.systemRed]
UINavigationBar.appearance().standardAppearance = navBarAppearance
}

var body: some View {
List {
ForEach($viewModel.reminders) { $reminder in
ReminderListRowView(reminder: $reminder)
.accentColor(Color(UIColor.systemRed))
.focused($focusedReminder, equals: .row(id: reminder.id))
.onSubmit {
viewModel.createNewReminder()
Expand Down Expand Up @@ -79,7 +71,6 @@ struct RemindersListView: View {
Text("New Reminder")
}
}
.accentColor(Color(UIColor.systemRed))
// needed to push the button to the left
Spacer()
}
Expand Down
15 changes: 15 additions & 0 deletions code/frontend/MakeItSo/Shared/MakeItSoApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,27 @@ struct MakeItSoApp: App {
@StateObject
var viewModel = RemindersListViewModel(reminders: Reminder.samples)

init() {
let navBarAppearance = UINavigationBarAppearance()

navBarAppearance.largeTitleTextAttributes[.font] = UIFont.roundedLargeTitle()
navBarAppearance.largeTitleTextAttributes[.foregroundColor] = UIColor(Color.accentColor)
navBarAppearance.titleTextAttributes[.font] = UIFont.roundedHeadline()
// Purposefully don't set the foreground color for normal text nav bar -
// in Reminders.app, this isn't tinted as well!
// navBarAppearance.titleTextAttributes[.foregroundColor] = foregroundColor

UINavigationBar.appearance().standardAppearance = navBarAppearance
}

var body: some Scene {
WindowGroup {
NavigationView {
RemindersListView()
.font(.system(.body, design: .rounded))
.environmentObject(viewModel)
}
.accentColor(.red)
}
}
}

0 comments on commit 35d45cf

Please sign in to comment.