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 @@ ...@@ -7,6 +7,7 @@
objects = { objects = {
/* Begin PBXBuildFile section */ /* 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 */; }; 96CC49CD1D8DD984002CAB55 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96CC49CC1D8DD984002CAB55 /* AppDelegate.swift */; };
96CC49CF1D8DD984002CAB55 /* RootViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96CC49CE1D8DD984002CAB55 /* RootViewController.swift */; }; 96CC49CF1D8DD984002CAB55 /* RootViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96CC49CE1D8DD984002CAB55 /* RootViewController.swift */; };
96CC49D41D8DD984002CAB55 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 96CC49D31D8DD984002CAB55 /* Assets.xcassets */; }; 96CC49D41D8DD984002CAB55 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 96CC49D31D8DD984002CAB55 /* Assets.xcassets */; };
...@@ -29,6 +30,7 @@ ...@@ -29,6 +30,7 @@
/* End PBXCopyFilesBuildPhase section */ /* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference 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; }; 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>"; }; 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>"; }; 96CC49CE1D8DD984002CAB55 /* RootViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RootViewController.swift; sourceTree = "<group>"; };
...@@ -70,6 +72,7 @@ ...@@ -70,6 +72,7 @@
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
96CC49CC1D8DD984002CAB55 /* AppDelegate.swift */, 96CC49CC1D8DD984002CAB55 /* AppDelegate.swift */,
9640ED141DAE115D0085CDA1 /* AppStatusBarController.swift */,
96CC49DE1D8DD9E8002CAB55 /* AppNavigationController.swift */, 96CC49DE1D8DD9E8002CAB55 /* AppNavigationController.swift */,
96CC49CE1D8DD984002CAB55 /* RootViewController.swift */, 96CC49CE1D8DD984002CAB55 /* RootViewController.swift */,
96CC49E41D8DDF61002CAB55 /* NextViewController.swift */, 96CC49E41D8DDF61002CAB55 /* NextViewController.swift */,
...@@ -152,6 +155,7 @@ ...@@ -152,6 +155,7 @@
isa = PBXSourcesBuildPhase; isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
9640ED151DAE115D0085CDA1 /* AppStatusBarController.swift in Sources */,
96CC49DF1D8DD9E8002CAB55 /* AppNavigationController.swift in Sources */, 96CC49DF1D8DD9E8002CAB55 /* AppNavigationController.swift in Sources */,
96CC49E51D8DDF61002CAB55 /* NextViewController.swift in Sources */, 96CC49E51D8DDF61002CAB55 /* NextViewController.swift in Sources */,
96CC49CF1D8DD984002CAB55 /* RootViewController.swift in Sources */, 96CC49CF1D8DD984002CAB55 /* RootViewController.swift in Sources */,
......
...@@ -38,7 +38,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { ...@@ -38,7 +38,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func applicationDidFinishLaunching(_ application: UIApplication) { func applicationDidFinishLaunching(_ application: UIApplication) {
window = UIWindow(frame: Device.bounds) window = UIWindow(frame: Device.bounds)
window!.rootViewController = AppNavigationController(rootViewController: RootViewController()) window!.rootViewController = AppStatusBarController(rootViewController: AppNavigationController(rootViewController: RootViewController()))
window!.makeKeyAndVisible() window!.makeKeyAndVisible()
} }
} }
......
...@@ -38,8 +38,8 @@ class AppNavigationController: NavigationController { ...@@ -38,8 +38,8 @@ class AppNavigationController: NavigationController {
return return
} }
statusBarStyle = .lightContent v.depthPreset = .none
v.backgroundColor = Color.blue.base 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 ...@@ -34,19 +34,17 @@ import Material
class NextViewController: UIViewController { class NextViewController: UIViewController {
open override func viewDidLoad() { open override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
view.backgroundColor = .white view.backgroundColor = Color.grey.lighten5
prepareNavigationItem() prepareNavigationItem()
} }
private func prepareNavigationItem() { private func prepareNavigationItem() {
navigationItem.title = "Title" navigationItem.title = "Title"
navigationItem.titleLabel.textColor = .white
navigationItem.detail = "Detail Description" 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 { ...@@ -56,26 +56,20 @@ class RootViewController: UIViewController {
} }
private func prepareMenuButton() { private func prepareMenuButton() {
menuButton = IconButton(image: Icon.cm.menu, tintColor: .white) menuButton = IconButton(image: Icon.cm.menu)
menuButton.pulseColor = .white
} }
private func prepareStarButton() { private func prepareStarButton() {
starButton = IconButton(image: Icon.cm.star, tintColor: .white) starButton = IconButton(image: Icon.cm.star)
starButton.pulseColor = .white
} }
private func prepareSearchButton() { private func prepareSearchButton() {
searchButton = IconButton(image: Icon.cm.search, tintColor: .white) searchButton = IconButton(image: Icon.cm.search)
searchButton.pulseColor = .white
} }
private func prepareNavigationItem() { private func prepareNavigationItem() {
navigationItem.title = "Material" navigationItem.title = "Material"
navigationItem.titleLabel.textColor = .white
navigationItem.detail = "Build Beautiful Software" navigationItem.detail = "Build Beautiful Software"
navigationItem.detailLabel.textColor = Color.lightBlue.lighten5
navigationItem.leftViews = [menuButton] navigationItem.leftViews = [menuButton]
navigationItem.rightViews = [starButton, searchButton] navigationItem.rightViews = [starButton, searchButton]
......
...@@ -32,9 +32,35 @@ import UIKit ...@@ -32,9 +32,35 @@ import UIKit
import Material import Material
class AppSearchBarController: SearchBarController { class AppSearchBarController: SearchBarController {
private var menuButton: IconButton!
private var moreButton: IconButton!
open override func prepare() { open override func prepare() {
super.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 ...@@ -32,37 +32,18 @@ import UIKit
import Material import Material
class RootViewController: UIViewController { class RootViewController: UIViewController {
private var menuButton: IconButton!
private var moreButton: IconButton!
open override func viewDidLoad() { open override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
view.backgroundColor = Color.grey.lighten1 view.backgroundColor = Color.grey.lighten5
}
open override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
prepareMenuButton()
prepareMoreButton()
prepareSearchBar() prepareSearchBar()
} }
private func prepareMenuButton() {
menuButton = IconButton(image: Icon.cm.menu)
}
private func prepareMoreButton() {
moreButton = IconButton(image: Icon.cm.moreVertical)
}
private func prepareSearchBar() { private func prepareSearchBar() {
guard let sc = searchBarController else { // Access the searchBar.
return // guard let searchBar = searchBarController?.searchBar else {
} // return
// }
sc.searchBar.leftViews = [menuButton]
sc.searchBar.rightViews = [moreButton]
} }
} }
...@@ -32,11 +32,43 @@ import UIKit ...@@ -32,11 +32,43 @@ import UIKit
import Material import Material
class AppToolbarController: ToolbarController { class AppToolbarController: ToolbarController {
private var menuButton: IconButton!
private var starButton: IconButton!
private var searchButton: IconButton!
open override func prepare() { open override func prepare() {
super.prepare() super.prepare()
statusBarStyle = .default prepareMenuButton()
// toolbar.heightPreset = .large prepareStarButton()
toolbar.height = 100 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 ...@@ -32,49 +32,25 @@ import UIKit
import Material import Material
class RootViewController: UIViewController { class RootViewController: UIViewController {
private var menuButton: IconButton!
private var starButton: IconButton!
private var searchButton: IconButton!
open override func viewDidLoad() { open override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
view.backgroundColor = .white view.backgroundColor = Color.grey.lighten5
}
open override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
prepareMenuButton()
prepareStarButton()
prepareSearchButton()
prepareToolbar() 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() { private func prepareToolbar() {
guard let tc = toolbarController else { guard let toolbar = toolbarController?.toolbar else {
return return
} }
tc.toolbar.title = "Marterial" toolbar.title = "Marterial"
tc.toolbar.titleLabel.textAlignment = .left toolbar.titleLabel.textColor = .white
toolbar.titleLabel.textAlignment = .left
tc.toolbar.detail = "Build Beautiful Software"
tc.toolbar.detailLabel.textAlignment = .left
tc.toolbar.leftViews = [menuButton] toolbar.detail = "Build Beautiful Software"
tc.toolbar.rightViews = [starButton, searchButton] toolbar.detailLabel.textColor = .white
toolbar.detailLabel.textAlignment = .left
} }
} }
...@@ -145,7 +145,7 @@ open class NavigationBar: UINavigationBar { ...@@ -145,7 +145,7 @@ open class NavigationBar: UINavigationBar {
super.layoutSubviews() super.layoutSubviews()
layoutShadowPath() layoutShadowPath()
if let v = topItem { if let v = topItem {
layoutNavigationItem(item: v) layoutNavigationItem(item: v)
} }
...@@ -281,10 +281,9 @@ open class NavigationBar: UINavigationBar { ...@@ -281,10 +281,9 @@ open class NavigationBar: UINavigationBar {
when subclassing. when subclassing.
*/ */
open func prepare() { open func prepare() {
heightPreset = .default
barStyle = .black barStyle = .black
isTranslucent = false isTranslucent = false
depthPreset = .depth1 depthPreset = .depth1
interimSpacePreset = .interimSpace3 interimSpacePreset = .interimSpace3
contentEdgeInsetsPreset = .square1 contentEdgeInsetsPreset = .square1
contentScaleFactor = Device.scale contentScaleFactor = Device.scale
......
...@@ -95,12 +95,15 @@ open class NavigationController: UINavigationController { ...@@ -95,12 +95,15 @@ open class NavigationController: UINavigationController {
open override func viewDidAppear(_ animated: Bool) { open override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated) super.viewDidAppear(animated)
// Load the initial topItem. guard let v = navigationBar as? NavigationBar else {
if let v = navigationBar as? NavigationBar { return
if let item = v.topItem { }
v.layoutNavigationItem(item: item)
} guard let item = v.topItem else {
} return
}
v.layoutNavigationItem(item: item)
} }
/** /**
...@@ -111,6 +114,8 @@ open class NavigationController: UINavigationController { ...@@ -111,6 +114,8 @@ open class NavigationController: UINavigationController {
when subclassing. when subclassing.
*/ */
open func prepare() { open func prepare() {
navigationBar.heightPreset = .normal
view.clipsToBounds = true view.clipsToBounds = true
view.backgroundColor = .white view.backgroundColor = .white
view.contentScaleFactor = Device.scale view.contentScaleFactor = Device.scale
......
...@@ -137,6 +137,7 @@ open class SearchBar: Bar { ...@@ -137,6 +137,7 @@ open class SearchBar: Bar {
*/ */
open override func prepare() { open override func prepare() {
super.prepare() super.prepare()
heightPreset = .normal
prepareTextField() prepareTextField()
prepareClearButton() prepareClearButton()
} }
......
...@@ -48,23 +48,38 @@ extension UIViewController { ...@@ -48,23 +48,38 @@ extension UIViewController {
} }
} }
open class SearchBarController: RootController { open class SearchBarController: StatusBarController {
/// Reference to the SearchBar. /**
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 private(set) lazy var searchBar: SearchBar = SearchBar()
open override func layoutSubviews() { open override func layoutSubviews() {
super.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.y = y
searchBar.height = p searchBar.width = view.width
rootViewController.view.y = p switch display {
rootViewController.view.height = view.height - p 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 { ...@@ -78,7 +78,7 @@ open class StatusBarController: RootController {
/// Prepares the statusBar. /// Prepares the statusBar.
private func prepareStatusBar() { private func prepareStatusBar() {
statusBar.zPosition = 3000 statusBar.zPosition = 3000
statusBar.backgroundColor = Color.black.withAlphaComponent(0.12) statusBar.backgroundColor = Color.grey.lighten3
view.layout(statusBar).top().horizontally().height(20) view.layout(statusBar).top().horizontally().height(20)
} }
} }
...@@ -154,6 +154,7 @@ open class Toolbar: Bar { ...@@ -154,6 +154,7 @@ open class Toolbar: Bar {
*/ */
open override func prepare() { open override func prepare() {
super.prepare() super.prepare()
heightPreset = .normal
contentViewAlignment = .center contentViewAlignment = .center
prepareTitleLabel() prepareTitleLabel()
prepareDetailLabel() prepareDetailLabel()
......
...@@ -69,6 +69,11 @@ public protocol ToolbarControllerDelegate { ...@@ -69,6 +69,11 @@ public protocol ToolbarControllerDelegate {
@objc(ToolbarController) @objc(ToolbarController)
open class ToolbarController: StatusBarController { 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 { open var display = Display.partial {
didSet { didSet {
layoutSubviews() layoutSubviews()
...@@ -166,11 +171,13 @@ open class ToolbarController: StatusBarController { ...@@ -166,11 +171,13 @@ open class ToolbarController: StatusBarController {
open override func layoutSubviews() { open override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
statusBar.layoutIfNeeded()
toolbar.y = .phone == Device.userInterfaceIdiom && Device.isLandscape ? 0 : 20
toolbar.width = view.width
let p = toolbar.y + toolbar.height let y = statusBar.isHidden ? 0 : statusBar.height
let p = y + toolbar.height
toolbar.y = y
toolbar.width = view.width
switch display { switch display {
case .partial: 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