Commit 15e00b24 by Daniel Dahan

development: updated RootController calculations, TabBar API, and updated…

development: updated RootController calculations, TabBar API, and updated Divider in Navigational controls
parent 1ca469bb
...@@ -31,6 +31,9 @@ ...@@ -31,6 +31,9 @@
import UIKit import UIKit
open class BarView: ControlView { open class BarView: ControlView {
/// Divider layer.
open internal(set) var divider: Divider!
/** /**
An initializer that initializes the object with a NSCoder object. An initializer that initializes the object with a NSCoder object.
- Parameter aDecoder: A NSCoder instance. - Parameter aDecoder: A NSCoder instance.
...@@ -68,5 +71,11 @@ open class BarView: ControlView { ...@@ -68,5 +71,11 @@ open class BarView: ControlView {
open override func prepareView() { open override func prepareView() {
super.prepareView() super.prepareView()
depthPreset = .depth1 depthPreset = .depth1
} prepareDivider()
}
/// Prepares the divider.
private func prepareDivider() {
divider = Divider(view: self)
}
} }
...@@ -42,32 +42,35 @@ open class Divider { ...@@ -42,32 +42,35 @@ open class Divider {
/// A reference to the UIView. /// A reference to the UIView.
internal weak var view: UIView? internal weak var view: UIView?
/// A reference to the height.
internal var height: CGFloat
/// A reference to the divider UIView. /// A reference to the divider UIView.
internal var divider: UIView? internal var line: UIView?
/// Divider color. /// Divider color.
open var color: UIColor? { open var color: UIColor? {
get { get {
return divider?.backgroundColor return line?.backgroundColor
} }
set(value) { set(value) {
guard let v = value else { guard let v = value else {
divider?.removeFromSuperview() line?.removeFromSuperview()
divider = nil line = nil
return return
} }
if nil == divider { if nil == line {
divider = UIView() line = UIView()
divider?.zPosition = 5000 line?.zPosition = 5000
view?.addSubview(divider!) view?.addSubview(line!)
reload() reload()
} }
divider?.backgroundColor = v line?.backgroundColor = v
} }
} }
/// A reference to the dividerAlignment. /// A reference to the dividerAlignment.
internal var alignment = DividerAlignment.top { open var alignment = DividerAlignment.top {
didSet { didSet {
reload() reload()
} }
...@@ -77,8 +80,9 @@ open class Divider { ...@@ -77,8 +80,9 @@ open class Divider {
Initializer that takes in a UIView. Initializer that takes in a UIView.
- Parameter view: A UIView reference. - Parameter view: A UIView reference.
*/ */
internal init(view: UIView?) { internal init(view: UIView?, height: CGFloat = 1) {
self.view = view self.view = view
self.height = height
} }
/// Lays out the divider. /// Lays out the divider.
...@@ -87,19 +91,15 @@ open class Divider { ...@@ -87,19 +91,15 @@ open class Divider {
return return
} }
guard let d = divider else {
return
}
switch alignment { switch alignment {
case .top: case .top:
d.frame = CGRect(x: 0, y: 0, width: v.width, height: 1) line?.frame = CGRect(x: 0, y: 0, width: v.width, height: height)
case .bottom: case .bottom:
d.frame = CGRect(x: 0, y: v.height - 1, width: v.width, height: 1) line?.frame = CGRect(x: 0, y: v.height - height, width: v.width, height: height)
case .left: case .left:
d.frame = CGRect(x: 0, y: 0, width: 1, height: v.height) line?.frame = CGRect(x: 0, y: 0, width: height, height: v.height)
case .right: case .right:
d.frame = CGRect(x: v.width - 1, y: 0, width: 1, height: v.height) line?.frame = CGRect(x: v.width - height, y: 0, width: height, height: v.height)
} }
} }
} }
...@@ -51,8 +51,11 @@ extension UINavigationBar { ...@@ -51,8 +51,11 @@ extension UINavigationBar {
} }
@IBDesignable @IBDesignable
public class NavigationBar: UINavigationBar { open class NavigationBar: UINavigationBar {
public override var intrinsicContentSize: CGSize { /// A reference to the divider.
open internal(set) var divider: Divider!
open override var intrinsicContentSize: CGSize {
switch navigationBarStyle { switch navigationBarStyle {
case .small: case .small:
return CGSize(width: Device.width, height: 32) return CGSize(width: Device.width, height: 32)
...@@ -64,45 +67,48 @@ public class NavigationBar: UINavigationBar { ...@@ -64,45 +67,48 @@ public class NavigationBar: UINavigationBar {
} }
/// NavigationBarStyle value. /// NavigationBarStyle value.
public var navigationBarStyle = NavigationBarStyle.medium open var navigationBarStyle = NavigationBarStyle.medium
internal var animating: Bool = false internal var animating = false
/// Will render the view. /// Will render the view.
public var willRenderView: Bool { open var willRenderView: Bool {
return 0 < width && 0 < height && nil != superview return 0 < width && 0 < height && nil != superview
} }
/// A preset wrapper around contentInset. /// A preset wrapper around contentInset.
public var contentEdgeInsetsPreset = EdgeInsetsPreset.none { open var contentEdgeInsetsPreset = EdgeInsetsPreset.none {
didSet { didSet {
contentInset = EdgeInsetsPresetToValue(preset: contentEdgeInsetsPreset) contentInset = EdgeInsetsPresetToValue(preset: contentEdgeInsetsPreset)
} }
} }
/// A wrapper around grid.contentInset. /// A wrapper around grid.contentInset.
@IBInspectable public var contentInset = EdgeInsets.zero { @IBInspectable
open var contentInset = EdgeInsets.zero {
didSet { didSet {
layoutSubviews() layoutSubviews()
} }
} }
/// A preset wrapper around interimSpace. /// A preset wrapper around interimSpace.
public var interimSpacePreset = InterimSpacePreset.none { open var interimSpacePreset = InterimSpacePreset.none {
didSet { didSet {
interimSpace = InterimSpacePresetToValue(preset: interimSpacePreset) interimSpace = InterimSpacePresetToValue(preset: interimSpacePreset)
} }
} }
/// A wrapper around grid.interimSpace. /// A wrapper around grid.interimSpace.
@IBInspectable public var interimSpace: InterimSpace = 0 { @IBInspectable
open var interimSpace: InterimSpace = 0 {
didSet { didSet {
layoutSubviews() layoutSubviews()
} }
} }
/// Grid cell factor. /// Grid cell factor.
@IBInspectable public var gridFactor: CGFloat = 24 { @IBInspectable
open var gridFactor: CGFloat = 24 {
didSet { didSet {
assert(0 < gridFactor, "[Material Error: gridFactor must be greater than 0.]") assert(0 < gridFactor, "[Material Error: gridFactor must be greater than 0.]")
layoutSubviews() layoutSubviews()
...@@ -110,10 +116,11 @@ public class NavigationBar: UINavigationBar { ...@@ -110,10 +116,11 @@ public class NavigationBar: UINavigationBar {
} }
/** /**
The back button image writes to the backIndicatorImage property and The back button image writes to the backIndicatorImage property and
backIndicatorTransitionMaskImage property. backIndicatorTransitionMaskImage property.
*/ */
@IBInspectable public var backButtonImage: UIImage? { @IBInspectable
open var backButtonImage: UIImage? {
get { get {
return backIndicatorImage return backIndicatorImage
} }
...@@ -125,27 +132,28 @@ public class NavigationBar: UINavigationBar { ...@@ -125,27 +132,28 @@ public class NavigationBar: UINavigationBar {
} }
/// A property that accesses the backing layer's backgroundColor. /// A property that accesses the backing layer's backgroundColor.
@IBInspectable public override var backgroundColor: UIColor? { @IBInspectable
open override var backgroundColor: UIColor? {
didSet { didSet {
barTintColor = backgroundColor barTintColor = backgroundColor
} }
} }
/** /**
An initializer that initializes the object with a NSCoder object. An initializer that initializes the object with a NSCoder object.
- Parameter aDecoder: A NSCoder instance. - Parameter aDecoder: A NSCoder instance.
*/ */
public required init?(coder aDecoder: NSCoder) { public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder) super.init(coder: aDecoder)
prepareView() prepareView()
} }
/** /**
An initializer that initializes the object with a CGRect object. An initializer that initializes the object with a CGRect object.
If AutoLayout is used, it is better to initilize the instance If AutoLayout is used, it is better to initilize the instance
using the init() initializer. using the init() initializer.
- Parameter frame: A CGRect instance. - Parameter frame: A CGRect instance.
*/ */
public override init(frame: CGRect) { public override init(frame: CGRect) {
super.init(frame: frame) super.init(frame: frame)
prepareView() prepareView()
...@@ -156,18 +164,18 @@ public class NavigationBar: UINavigationBar { ...@@ -156,18 +164,18 @@ public class NavigationBar: UINavigationBar {
self.init(frame: .zero) self.init(frame: .zero)
} }
public override func sizeThatFits(_ size: CGSize) -> CGSize { open override func sizeThatFits(_ size: CGSize) -> CGSize {
return intrinsicContentSize return intrinsicContentSize
} }
public override func layoutSublayers(of layer: CALayer) { open override func layoutSublayers(of layer: CALayer) {
super.layoutSublayers(of: layer) super.layoutSublayers(of: layer)
if self.layer == layer { if self.layer == layer {
layoutShape() layoutShape()
} }
} }
public override func layoutSubviews() { open override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
layoutShadowPath() layoutShadowPath()
...@@ -178,17 +186,19 @@ public class NavigationBar: UINavigationBar { ...@@ -178,17 +186,19 @@ public class NavigationBar: UINavigationBar {
if let v = backItem { if let v = backItem {
layoutNavigationItem(item: v) layoutNavigationItem(item: v)
} }
divider?.reload()
} }
public override func pushItem(_ item: UINavigationItem, animated: Bool) { open override func pushItem(_ item: UINavigationItem, animated: Bool) {
super.pushItem(item, animated: animated) super.pushItem(item, animated: animated)
layoutNavigationItem(item: item) layoutNavigationItem(item: item)
} }
/** /**
Lays out the UINavigationItem. Lays out the UINavigationItem.
- Parameter item: A UINavigationItem to layout. - Parameter item: A UINavigationItem to layout.
*/ */
internal func layoutNavigationItem(item: UINavigationItem) { internal func layoutNavigationItem(item: UINavigationItem) {
if willRenderView { if willRenderView {
prepareItem(item: item) prepareItem(item: item)
...@@ -284,12 +294,12 @@ public class NavigationBar: UINavigationBar { ...@@ -284,12 +294,12 @@ public class NavigationBar: UINavigationBar {
} }
/** /**
Prepares the view instance when intialized. When subclassing, Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepareView method it is recommended to override the prepareView method
to initialize property values and other setup operations. to initialize property values and other setup operations.
The super.prepareView method should always be called immediately The super.prepareView method should always be called immediately
when subclassing. when subclassing.
*/ */
public func prepareView() { public func prepareView() {
barStyle = .black barStyle = .black
isTranslucent = false isTranslucent = false
...@@ -298,26 +308,27 @@ public class NavigationBar: UINavigationBar { ...@@ -298,26 +308,27 @@ public class NavigationBar: UINavigationBar {
contentEdgeInsetsPreset = .square1 contentEdgeInsetsPreset = .square1
contentScaleFactor = Device.scale contentScaleFactor = Device.scale
backButtonImage = Icon.cm.arrowBack backButtonImage = Icon.cm.arrowBack
let image: UIImage? = UIImage.imageWithColor(color: Color.clear, size: CGSize(width: 1, height: 1)) let image = UIImage.imageWithColor(color: Color.clear, size: CGSize(width: 1, height: 1))
shadowImage = image shadowImage = image
setBackgroundImage(image, for: .default) setBackgroundImage(image, for: .default)
backgroundColor = Color.white backgroundColor = Color.white
prepareDivider()
} }
/** /**
Prepare the item by setting the title property to equal an empty string. Prepare the item by setting the title property to equal an empty string.
- Parameter item: A UINavigationItem to layout. - Parameter item: A UINavigationItem to layout.
*/ */
private func prepareItem(item: UINavigationItem) { private func prepareItem(item: UINavigationItem) {
item.hidesBackButton = false item.hidesBackButton = false
item.setHidesBackButton(true, animated: false) item.setHidesBackButton(true, animated: false)
} }
/** /**
Prepare the titleView. Prepare the titleView.
- Parameter item: A UINavigationItem to layout. - Parameter item: A UINavigationItem to layout.
- Returns: A UIView, which is the item.titleView. - Returns: A UIView, which is the item.titleView.
*/ */
private func prepareTitleView(item: UINavigationItem) -> UIView { private func prepareTitleView(item: UINavigationItem) -> UIView {
if nil == item.titleView { if nil == item.titleView {
item.titleView = UIView(frame: .zero) item.titleView = UIView(frame: .zero)
...@@ -326,10 +337,10 @@ public class NavigationBar: UINavigationBar { ...@@ -326,10 +337,10 @@ public class NavigationBar: UINavigationBar {
} }
/** /**
Prepare the contentView. Prepare the contentView.
- Parameter item: A UINavigationItem to layout. - Parameter item: A UINavigationItem to layout.
- Returns: A UIView, which is the item.contentView. - Returns: A UIView, which is the item.contentView.
*/ */
private func prepareContentView(item: UINavigationItem) -> UIView { private func prepareContentView(item: UINavigationItem) -> UIView {
if nil == item.contentView { if nil == item.contentView {
item.contentView = UIView(frame: .zero) item.contentView = UIView(frame: .zero)
...@@ -337,4 +348,10 @@ public class NavigationBar: UINavigationBar { ...@@ -337,4 +348,10 @@ public class NavigationBar: UINavigationBar {
item.contentView!.grid.axis.direction = .vertical item.contentView!.grid.axis.direction = .vertical
return item.contentView! return item.contentView!
} }
/// Prepares the divider.
private func prepareDivider() {
divider = Divider(view: self)
divider.alignment = .bottom
}
} }
...@@ -32,7 +32,7 @@ import UIKit ...@@ -32,7 +32,7 @@ import UIKit
@IBDesignable @IBDesignable
open class NavigationController: UINavigationController, UIGestureRecognizerDelegate { open class NavigationController: UINavigationController, UIGestureRecognizerDelegate {
/** /**
An initializer that initializes the object with a NSCoder object. An initializer that initializes the object with a NSCoder object.
- Parameter aDecoder: A NSCoder instance. - Parameter aDecoder: A NSCoder instance.
*/ */
...@@ -86,7 +86,7 @@ open class NavigationController: UINavigationController, UIGestureRecognizerDele ...@@ -86,7 +86,7 @@ open class NavigationController: UINavigationController, UIGestureRecognizerDele
} }
} }
} }
/** /**
Detects the gesture recognizer being used. This is necessary when using Detects the gesture recognizer being used. This is necessary when using
NavigationDrawerController. It eliminates the conflict in panning. NavigationDrawerController. It eliminates the conflict in panning.
......
...@@ -72,8 +72,8 @@ open class PageTabBarController: RootController { ...@@ -72,8 +72,8 @@ open class PageTabBarController: RootController {
return return
} }
let h = Device.height let h = view.height
let w = Device.width let w = view.width
let p = v.intrinsicContentSize.height + v.grid.layoutEdgeInsets.top + v.grid.layoutEdgeInsets.bottom let p = v.intrinsicContentSize.height + v.grid.layoutEdgeInsets.top + v.grid.layoutEdgeInsets.bottom
let y = h - p let y = h - p
...@@ -83,6 +83,8 @@ open class PageTabBarController: RootController { ...@@ -83,6 +83,8 @@ open class PageTabBarController: RootController {
rootViewController.view.frame.origin.y = 0 rootViewController.view.frame.origin.y = 0
rootViewController.view.frame.size.height = y rootViewController.view.frame.size.height = y
v.divider.reload()
} }
/** /**
......
...@@ -119,7 +119,7 @@ open class RootController: UIViewController { ...@@ -119,7 +119,7 @@ open class RootController: UIViewController {
addChildViewController(toViewController) addChildViewController(toViewController)
toViewController.view.frame = rootViewController.view.frame toViewController.view.frame = rootViewController.view.frame
transition(from: rootViewController, transition(from: rootViewController,
to: toViewController, to: toViewController,
duration: duration, duration: duration,
options: options, options: options,
animations: animations, animations: animations,
......
...@@ -65,8 +65,8 @@ open class SearchBarController: RootController { ...@@ -65,8 +65,8 @@ open class SearchBarController: RootController {
v.grid.layoutEdgeInsets.top = .phone == Device.userInterfaceIdiom && Device.isLandscape ? 0 : 20 v.grid.layoutEdgeInsets.top = .phone == Device.userInterfaceIdiom && Device.isLandscape ? 0 : 20
let h = Device.height let h = view.height
let w = Device.width let w = view.width
let p = v.intrinsicContentSize.height + v.grid.layoutEdgeInsets.top + v.grid.layoutEdgeInsets.bottom let p = v.intrinsicContentSize.height + v.grid.layoutEdgeInsets.top + v.grid.layoutEdgeInsets.bottom
v.width = w + v.grid.layoutEdgeInsets.left + v.grid.layoutEdgeInsets.right v.width = w + v.grid.layoutEdgeInsets.left + v.grid.layoutEdgeInsets.right
...@@ -74,6 +74,8 @@ open class SearchBarController: RootController { ...@@ -74,6 +74,8 @@ open class SearchBarController: RootController {
rootViewController.view.frame.origin.y = p rootViewController.view.frame.origin.y = p
rootViewController.view.frame.size.height = h - p rootViewController.view.frame.size.height = h - p
v.divider.reload()
} }
/** /**
......
...@@ -38,7 +38,17 @@ public enum TabBarLineAlignment: Int { ...@@ -38,7 +38,17 @@ public enum TabBarLineAlignment: Int {
open class TabBar: View { open class TabBar: View {
/// A reference to the line UIView. /// A reference to the line UIView.
open internal(set) var line: UIView! internal var line: UIView!
/// The line color.
open var lineColor: UIColor? {
get {
return line.backgroundColor
}
set(value) {
line.backgroundColor = value
}
}
/// A value for the line alignment. /// A value for the line alignment.
open var lineAlignment = TabBarLineAlignment.bottom { open var lineAlignment = TabBarLineAlignment.bottom {
...@@ -46,6 +56,16 @@ open class TabBar: View { ...@@ -46,6 +56,16 @@ open class TabBar: View {
layoutSubviews() layoutSubviews()
} }
} }
/// The line height.
open var lineHeight: CGFloat {
get {
return line.height
}
set(value) {
line.height = value
}
}
/// Will render the view. /// Will render the view.
open var willRenderView: Bool { open var willRenderView: Bool {
...@@ -124,7 +144,7 @@ open class TabBar: View { ...@@ -124,7 +144,7 @@ open class TabBar: View {
b.addTarget(self, action: #selector(handleButton(button:)), for: .touchUpInside) b.addTarget(self, action: #selector(handleButton(button:)), for: .touchUpInside)
} }
grid.reload() grid.reload()
line.frame = CGRect(x: 0, y: .bottom == lineAlignment ? height - 3 : 0, width: buttons.first!.width, height: 3) line.frame = CGRect(x: 0, y: .bottom == lineAlignment ? height - lineHeight : 0, width: buttons.first!.width, height: lineHeight)
} }
divider.reload() divider.reload()
} }
...@@ -160,8 +180,10 @@ open class TabBar: View { ...@@ -160,8 +180,10 @@ open class TabBar: View {
// Prepares the line. // Prepares the line.
private func prepareLine() { private func prepareLine() {
line = UIView() line = UIView()
line.backgroundColor = Color.blueGrey.lighten3 line.zPosition = 5100
addSubview(line) lineColor = Color.blueGrey.lighten3
lineHeight = 3
addSubview(line)
} }
/// Prepares the divider. /// Prepares the divider.
......
...@@ -138,6 +138,7 @@ public class Toolbar: BarView { ...@@ -138,6 +138,7 @@ public class Toolbar: BarView {
super.prepareView() super.prepareView()
prepareTitleLabel() prepareTitleLabel()
prepareDetailLabel() prepareDetailLabel()
prepareDivider()
} }
/// Prepares the titleLabel. /// Prepares the titleLabel.
...@@ -155,4 +156,9 @@ public class Toolbar: BarView { ...@@ -155,4 +156,9 @@ public class Toolbar: BarView {
detailLabel.font = RobotoFont.regularWithSize(size: 12) detailLabel.font = RobotoFont.regularWithSize(size: 12)
detailLabel.textAlignment = .left detailLabel.textAlignment = .left
} }
/// Prepares the divider.
private func prepareDivider() {
divider.alignment = .bottom
}
} }
...@@ -168,8 +168,8 @@ open class ToolbarController: RootController { ...@@ -168,8 +168,8 @@ open class ToolbarController: RootController {
v.grid.layoutEdgeInsets.top = .phone == Device.userInterfaceIdiom && Device.isLandscape ? 0 : 20 v.grid.layoutEdgeInsets.top = .phone == Device.userInterfaceIdiom && Device.isLandscape ? 0 : 20
let h = Device.height let h = view.height
let w = Device.width let w = view.width
let p = v.intrinsicContentSize.height + v.grid.layoutEdgeInsets.top + v.grid.layoutEdgeInsets.bottom let p = v.intrinsicContentSize.height + v.grid.layoutEdgeInsets.top + v.grid.layoutEdgeInsets.bottom
v.width = w + v.grid.layoutEdgeInsets.left + v.grid.layoutEdgeInsets.right v.width = w + v.grid.layoutEdgeInsets.left + v.grid.layoutEdgeInsets.right
...@@ -177,6 +177,8 @@ open class ToolbarController: RootController { ...@@ -177,6 +177,8 @@ open class ToolbarController: RootController {
rootViewController.view.frame.origin.y = p rootViewController.view.frame.origin.y = p
rootViewController.view.frame.size.height = h - p rootViewController.view.frame.size.height = h - p
v.divider.reload()
} }
/** /**
......
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