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