Add navigation and toolbar theming for light mode. Issue #698

This commit is contained in:
Maurice Parker
2019-08-23 12:27:45 -05:00
parent 5a5a66d59f
commit 7f024586bb
9 changed files with 142 additions and 10 deletions

View File

@@ -14,6 +14,18 @@ struct AppAssets {
return UIColor(named: "avatarBackgroundColor")!
}()
static var barBackgroundColor: UIColor = {
return UIColor(named: "barBackgroundColor")!
}()
static var barTintColor: UIColor = {
return UIColor(named: "barTintColor")!
}()
static var barTitleColor: UIColor = {
return UIColor(named: "barTitleColor")!
}()
static var circleClosedImage: UIImage = {
return UIImage(systemName: "circle.fill")!
}()

View File

@@ -237,6 +237,7 @@ class AppCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
rootSplitViewController.delegate = self
masterNavigationController = (rootSplitViewController.viewControllers.first as! UINavigationController)
masterFeedViewController = UIStoryboard.main.instantiateController(ofType: MasterFeedViewController.self)
masterFeedViewController.coordinator = self
masterNavigationController.pushViewController(masterFeedViewController, animated: false)
@@ -1063,7 +1064,7 @@ private extension AppCoordinator {
if rootSplitViewController.isCollapsed {
return controller
} else {
let navController = UINavigationController(rootViewController: controller)
let navController = ThemedNavigationController.template(rootViewController: controller)
navController.isToolbarHidden = false
if showButton {
controller.navigationItem.leftBarButtonItem = rootSplitViewController.displayModeButtonItem

View File

@@ -0,0 +1,56 @@
//
// ThemedNavigationController.swift
// NetNewsWire
//
// Created by Maurice Parker on 8/22/19.
// Copyright © 2019 Ranchero Software. All rights reserved.
//
import UIKit
class ThemedNavigationController: UINavigationController {
static func template() -> UINavigationController {
let navController = ThemedNavigationController()
navController.configure()
return navController
}
static func template(rootViewController: UIViewController) -> UINavigationController {
let navController = ThemedNavigationController(rootViewController: rootViewController)
navController.configure()
return navController
}
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
if traitCollection.userInterfaceStyle != previousTraitCollection?.userInterfaceStyle {
configure()
}
}
private func configure() {
isToolbarHidden = false
if traitCollection.userInterfaceStyle == .dark {
navigationBar.standardAppearance = UINavigationBarAppearance()
navigationBar.tintColor = view.tintColor
toolbar.standardAppearance = UIToolbarAppearance()
toolbar.tintColor = view.tintColor
} else {
let navigationAppearance = UINavigationBarAppearance()
navigationAppearance.backgroundColor = AppAssets.barBackgroundColor
navigationAppearance.titleTextAttributes = [.foregroundColor: AppAssets.barTitleColor]
navigationAppearance.largeTitleTextAttributes = [.foregroundColor: AppAssets.barTitleColor]
navigationBar.standardAppearance = navigationAppearance
navigationBar.tintColor = AppAssets.barTintColor
let toolbarAppearance = UIToolbarAppearance()
toolbarAppearance.backgroundColor = UIColor.white
toolbar.standardAppearance = toolbarAppearance
toolbar.tintColor = AppAssets.barTintColor
}
}
}

View File

@@ -13,11 +13,7 @@ extension UISplitViewController {
static func template() -> UISplitViewController {
let splitViewController = UISplitViewController()
splitViewController.preferredDisplayMode = .automatic
let navController = UINavigationController()
navController.isToolbarHidden = false
splitViewController.viewControllers = [navController]
splitViewController.viewControllers = [ThemedNavigationController.template()]
return splitViewController
}

View File

@@ -29,7 +29,10 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner {
super.viewDidLoad()
navigationController?.navigationBar.prefersLargeTitles = true
if traitCollection.userInterfaceIdiom == .phone {
navigationController?.navigationBar.prefersLargeTitles = true
}
navigationItem.rightBarButtonItem = editButtonItem
tableView.register(MasterFeedTableViewSectionHeader.self, forHeaderFooterViewReuseIdentifier: "SectionHeader")

View File

@@ -0,0 +1,20 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
},
"colors" : [
{
"idiom" : "universal",
"color" : {
"color-space" : "srgb",
"components" : {
"red" : "1.000",
"alpha" : "1.000",
"blue" : "1.000",
"green" : "1.000"
}
}
}
]
}

View File

@@ -0,0 +1,20 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
},
"colors" : [
{
"idiom" : "universal",
"color" : {
"color-space" : "srgb",
"components" : {
"red" : "0x08",
"alpha" : "1.000",
"blue" : "0xEE",
"green" : "0x6A"
}
}
}
]
}

View File

@@ -0,0 +1,20 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
},
"colors" : [
{
"idiom" : "universal",
"color" : {
"color-space" : "srgb",
"components" : {
"red" : "0x08",
"alpha" : "1.000",
"blue" : "0xEE",
"green" : "0x6A"
}
}
}
]
}