Commit 5cc2e5bd by Daniel Dahan

development: updated ToolbarController, SearchNarController,…

development: updated ToolbarController, SearchNarController, NavigationBarController, and Bar types to adjust for HeightPreset
parent 63ce6b94
......@@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
9640ED151DAE115D0085CDA1 /* AppStatusBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9640ED141DAE115D0085CDA1 /* AppStatusBarController.swift */; };
96CC49CD1D8DD984002CAB55 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96CC49CC1D8DD984002CAB55 /* AppDelegate.swift */; };
96CC49CF1D8DD984002CAB55 /* RootViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96CC49CE1D8DD984002CAB55 /* RootViewController.swift */; };
96CC49D41D8DD984002CAB55 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 96CC49D31D8DD984002CAB55 /* Assets.xcassets */; };
......@@ -29,6 +30,7 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
9640ED141DAE115D0085CDA1 /* AppStatusBarController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppStatusBarController.swift; sourceTree = "<group>"; };
96CC49C91D8DD984002CAB55 /* NavigationController.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = NavigationController.app; sourceTree = BUILT_PRODUCTS_DIR; };
96CC49CC1D8DD984002CAB55 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
96CC49CE1D8DD984002CAB55 /* RootViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RootViewController.swift; sourceTree = "<group>"; };
......@@ -70,6 +72,7 @@
isa = PBXGroup;
children = (
96CC49CC1D8DD984002CAB55 /* AppDelegate.swift */,
9640ED141DAE115D0085CDA1 /* AppStatusBarController.swift */,
96CC49DE1D8DD9E8002CAB55 /* AppNavigationController.swift */,
96CC49CE1D8DD984002CAB55 /* RootViewController.swift */,
96CC49E41D8DDF61002CAB55 /* NextViewController.swift */,
......@@ -152,6 +155,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
9640ED151DAE115D0085CDA1 /* AppStatusBarController.swift in Sources */,
96CC49DF1D8DD9E8002CAB55 /* AppNavigationController.swift in Sources */,
96CC49E51D8DDF61002CAB55 /* NextViewController.swift in Sources */,
96CC49CF1D8DD984002CAB55 /* RootViewController.swift in Sources */,
......
......@@ -38,7 +38,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func applicationDidFinishLaunching(_ application: UIApplication) {
window = UIWindow(frame: Device.bounds)
window!.rootViewController = AppNavigationController(rootViewController: RootViewController())
window!.rootViewController = AppStatusBarController(rootViewController: AppNavigationController(rootViewController: RootViewController()))
window!.makeKeyAndVisible()
}
}
......
......@@ -38,8 +38,8 @@ class AppNavigationController: NavigationController {
return
}
statusBarStyle = .lightContent
v.backgroundColor = Color.blue.base
v.depthPreset = .none
v.dividerColor = Color.grey.lighten3
}
}
/*
* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of CosmicMind nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import UIKit
import Material
class AppStatusBarController: StatusBarController {
open override func prepare() {
super.prepare()
statusBarStyle = .default
statusBar.backgroundColor = .white
}
}
......@@ -34,19 +34,17 @@ import Material
class NextViewController: UIViewController {
open override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
view.backgroundColor = Color.grey.lighten5
prepareNavigationItem()
}
private func prepareNavigationItem() {
navigationItem.title = "Title"
navigationItem.titleLabel.textColor = .white
navigationItem.detail = "Detail Description"
navigationItem.detailLabel.textColor = Color.lightBlue.lighten5
navigationItem.backButton.tintColor = .white
// Access the back button.
// navigationItem.backButton.tintColor = .white
}
}
......@@ -56,26 +56,20 @@ class RootViewController: UIViewController {
}
private func prepareMenuButton() {
menuButton = IconButton(image: Icon.cm.menu, tintColor: .white)
menuButton.pulseColor = .white
menuButton = IconButton(image: Icon.cm.menu)
}
private func prepareStarButton() {
starButton = IconButton(image: Icon.cm.star, tintColor: .white)
starButton.pulseColor = .white
starButton = IconButton(image: Icon.cm.star)
}
private func prepareSearchButton() {
searchButton = IconButton(image: Icon.cm.search, tintColor: .white)
searchButton.pulseColor = .white
searchButton = IconButton(image: Icon.cm.search)
}
private func prepareNavigationItem() {
navigationItem.title = "Material"
navigationItem.titleLabel.textColor = .white
navigationItem.detail = "Build Beautiful Software"
navigationItem.detailLabel.textColor = Color.lightBlue.lighten5
navigationItem.leftViews = [menuButton]
navigationItem.rightViews = [starButton, searchButton]
......
......@@ -32,9 +32,35 @@ import UIKit
import Material
class AppSearchBarController: SearchBarController {
private var menuButton: IconButton!
private var moreButton: IconButton!
open override func prepare() {
super.prepare()
statusBarStyle = .default
prepareMenuButton()
prepareMoreButton()
prepareStatusBar()
prepareSearchBar()
}
private func prepareMenuButton() {
menuButton = IconButton(image: Icon.cm.menu)
}
private func prepareMoreButton() {
moreButton = IconButton(image: Icon.cm.moreVertical)
}
private func prepareStatusBar() {
statusBarStyle = .lightContent
// Access the statusBar.
// statusBar.backgroundColor = .green
}
private func prepareSearchBar() {
searchBar.leftViews = [menuButton]
searchBar.rightViews = [moreButton]
}
}
......@@ -32,37 +32,18 @@ import UIKit
import Material
class RootViewController: UIViewController {
private var menuButton: IconButton!
private var moreButton: IconButton!
open override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = Color.grey.lighten1
}
open override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
view.backgroundColor = Color.grey.lighten5
prepareMenuButton()
prepareMoreButton()
prepareSearchBar()
}
private func prepareMenuButton() {
menuButton = IconButton(image: Icon.cm.menu)
}
private func prepareMoreButton() {
moreButton = IconButton(image: Icon.cm.moreVertical)
}
private func prepareSearchBar() {
guard let sc = searchBarController else {
return
}
sc.searchBar.leftViews = [menuButton]
sc.searchBar.rightViews = [moreButton]
// Access the searchBar.
// guard let searchBar = searchBarController?.searchBar else {
// return
// }
}
}
......@@ -32,11 +32,43 @@ import UIKit
import Material
class AppToolbarController: ToolbarController {
private var menuButton: IconButton!
private var starButton: IconButton!
private var searchButton: IconButton!
open override func prepare() {
super.prepare()
statusBarStyle = .default
// toolbar.heightPreset = .large
toolbar.height = 100
prepareMenuButton()
prepareStarButton()
prepareSearchButton()
prepareStatusBar()
prepareToolbar()
}
private func prepareMenuButton() {
menuButton = IconButton(image: Icon.cm.menu, tintColor: .white)
menuButton.pulseColor = .white
}
private func prepareStarButton() {
starButton = IconButton(image: Icon.cm.star, tintColor: .white)
starButton.pulseColor = .white
}
private func prepareSearchButton() {
searchButton = IconButton(image: Icon.cm.search, tintColor: .white)
searchButton.pulseColor = .white
}
private func prepareStatusBar() {
statusBarStyle = .lightContent
statusBar.backgroundColor = Color.blue.darken3
}
private func prepareToolbar() {
toolbar.backgroundColor = Color.blue.darken2
toolbar.leftViews = [menuButton]
toolbar.rightViews = [starButton, searchButton]
}
}
......@@ -32,49 +32,25 @@ import UIKit
import Material
class RootViewController: UIViewController {
private var menuButton: IconButton!
private var starButton: IconButton!
private var searchButton: IconButton!
open override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
}
open override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
view.backgroundColor = Color.grey.lighten5
prepareMenuButton()
prepareStarButton()
prepareSearchButton()
prepareToolbar()
}
private func prepareMenuButton() {
menuButton = IconButton(image: Icon.cm.menu)
}
private func prepareStarButton() {
starButton = IconButton(image: Icon.cm.star)
}
private func prepareSearchButton() {
searchButton = IconButton(image: Icon.cm.search)
}
private func prepareToolbar() {
guard let tc = toolbarController else {
guard let toolbar = toolbarController?.toolbar else {
return
}
tc.toolbar.title = "Marterial"
tc.toolbar.titleLabel.textAlignment = .left
tc.toolbar.detail = "Build Beautiful Software"
tc.toolbar.detailLabel.textAlignment = .left
toolbar.title = "Marterial"
toolbar.titleLabel.textColor = .white
toolbar.titleLabel.textAlignment = .left
tc.toolbar.leftViews = [menuButton]
tc.toolbar.rightViews = [starButton, searchButton]
toolbar.detail = "Build Beautiful Software"
toolbar.detailLabel.textColor = .white
toolbar.detailLabel.textAlignment = .left
}
}
......@@ -281,7 +281,6 @@ open class NavigationBar: UINavigationBar {
when subclassing.
*/
open func prepare() {
heightPreset = .default
barStyle = .black
isTranslucent = false
depthPreset = .depth1
......
......@@ -95,12 +95,15 @@ open class NavigationController: UINavigationController {
open override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
// Load the initial topItem.
if let v = navigationBar as? NavigationBar {
if let item = v.topItem {
v.layoutNavigationItem(item: item)
guard let v = navigationBar as? NavigationBar else {
return
}
guard let item = v.topItem else {
return
}
v.layoutNavigationItem(item: item)
}
/**
......@@ -111,6 +114,8 @@ open class NavigationController: UINavigationController {
when subclassing.
*/
open func prepare() {
navigationBar.heightPreset = .normal
view.clipsToBounds = true
view.backgroundColor = .white
view.contentScaleFactor = Device.scale
......
......@@ -137,6 +137,7 @@ open class SearchBar: Bar {
*/
open override func prepare() {
super.prepare()
heightPreset = .normal
prepareTextField()
prepareClearButton()
}
......
......@@ -48,23 +48,38 @@ extension UIViewController {
}
}
open class SearchBarController: RootController {
open class SearchBarController: StatusBarController {
/**
A Display value to indicate whether or not to
display the rootViewController to the full view
bounds, or up to the searchBar height.
*/
open var display = Display.partial {
didSet {
layoutSubviews()
}
}
/// Reference to the SearchBar.
open private(set) lazy var searchBar: SearchBar = SearchBar()
open override func layoutSubviews() {
super.layoutSubviews()
statusBar.layoutIfNeeded()
searchBar.layoutEdgeInsets.top = .phone == Device.userInterfaceIdiom && Device.isLandscape ? 0 : 20
let y = statusBar.isHidden ? 0 : statusBar.height
let p = y + searchBar.height
let p = searchBar.intrinsicContentSize.height + searchBar.layoutEdgeInsets.top + searchBar.layoutEdgeInsets.bottom
searchBar.width = view.width + searchBar.layoutEdgeInsets.left + searchBar.layoutEdgeInsets.right
searchBar.height = p
searchBar.y = y
searchBar.width = view.width
switch display {
case .partial:
rootViewController.view.y = p
rootViewController.view.height = view.height - p
case .full:
rootViewController.view.frame = view.bounds
}
}
/**
......
......@@ -78,7 +78,7 @@ open class StatusBarController: RootController {
/// Prepares the statusBar.
private func prepareStatusBar() {
statusBar.zPosition = 3000
statusBar.backgroundColor = Color.black.withAlphaComponent(0.12)
statusBar.backgroundColor = Color.grey.lighten3
view.layout(statusBar).top().horizontally().height(20)
}
}
......@@ -154,6 +154,7 @@ open class Toolbar: Bar {
*/
open override func prepare() {
super.prepare()
heightPreset = .normal
contentViewAlignment = .center
prepareTitleLabel()
prepareDetailLabel()
......
......@@ -69,6 +69,11 @@ public protocol ToolbarControllerDelegate {
@objc(ToolbarController)
open class ToolbarController: StatusBarController {
/**
A Display value to indicate whether or not to
display the rootViewController to the full view
bounds, or up to the toolbar height.
*/
open var display = Display.partial {
didSet {
layoutSubviews()
......@@ -166,11 +171,13 @@ open class ToolbarController: StatusBarController {
open override func layoutSubviews() {
super.layoutSubviews()
statusBar.layoutIfNeeded()
toolbar.y = .phone == Device.userInterfaceIdiom && Device.isLandscape ? 0 : 20
toolbar.width = view.width
let y = statusBar.isHidden ? 0 : statusBar.height
let p = y + toolbar.height
let p = toolbar.y + toolbar.height
toolbar.y = y
toolbar.width = view.width
switch display {
case .partial:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment