Commit a6308b53 by Daniel Dahan

development: updated NavigationItem internals

parent 33b548eb
...@@ -167,7 +167,7 @@ open class ControlView: View { ...@@ -167,7 +167,7 @@ open class ControlView: View {
let g = Int(width / gridFactor) let g = Int(width / gridFactor)
let columns = g + 1 let columns = g + 1
grid.views = [] grid.views.removeAll()
grid.axis.columns = columns grid.axis.columns = columns
contentView.grid.columns = columns contentView.grid.columns = columns
......
...@@ -200,6 +200,7 @@ public class Grid { ...@@ -200,6 +200,7 @@ public class Grid {
var n: Int = 0 var n: Int = 0
for i in 0..<views.count { for i in 0..<views.count {
print(i, views.count, views)
let child = views[i] let child = views[i]
if let parent = context { if let parent = context {
......
...@@ -105,7 +105,7 @@ private var MaterialLayerKey: UInt8 = 0 ...@@ -105,7 +105,7 @@ private var MaterialLayerKey: UInt8 = 0
/// Grid extension for UIView. /// Grid extension for UIView.
extension CALayer { extension CALayer {
/// MaterialLayer Reference. /// MaterialLayer Reference.
internal var material: MaterialLayer { internal var materialLayer: MaterialLayer {
get { get {
return AssociatedObject(base: self, key: &MaterialLayerKey) { return AssociatedObject(base: self, key: &MaterialLayerKey) {
return MaterialLayer(layer: self) return MaterialLayer(layer: self)
...@@ -185,10 +185,10 @@ extension CALayer { ...@@ -185,10 +185,10 @@ extension CALayer {
*/ */
open var shapePreset: ShapePreset { open var shapePreset: ShapePreset {
get { get {
return material.shapePreset return materialLayer.shapePreset
} }
set(value) { set(value) {
material.shapePreset = value materialLayer.shapePreset = value
} }
} }
...@@ -205,10 +205,10 @@ extension CALayer { ...@@ -205,10 +205,10 @@ extension CALayer {
/// Grid reference. /// Grid reference.
open var depth: Depth { open var depth: Depth {
get { get {
return material.depth return materialLayer.depth
} }
set(value) { set(value) {
material.depth = value materialLayer.depth = value
} }
} }
...@@ -216,30 +216,30 @@ extension CALayer { ...@@ -216,30 +216,30 @@ extension CALayer {
@IBInspectable @IBInspectable
open var isShadowPathAutoSizing: Bool { open var isShadowPathAutoSizing: Bool {
get { get {
return material.isShadowPathAutoSizing return materialLayer.isShadowPathAutoSizing
} }
set(value) { set(value) {
material.isShadowPathAutoSizing = value materialLayer.isShadowPathAutoSizing = value
} }
} }
/// A property that sets the cornerRadius of the backing layer. /// A property that sets the cornerRadius of the backing layer.
open var cornerRadiusPreset: CornerRadiusPreset { open var cornerRadiusPreset: CornerRadiusPreset {
get { get {
return material.cornerRadiusPreset return materialLayer.cornerRadiusPreset
} }
set(value) { set(value) {
material.cornerRadiusPreset = value materialLayer.cornerRadiusPreset = value
} }
} }
/// A preset property to set the borderWidth. /// A preset property to set the borderWidth.
open var borderWidthPreset: BorderWidthPreset { open var borderWidthPreset: BorderWidthPreset {
get { get {
return material.borderWidthPreset return materialLayer.borderWidthPreset
} }
set(value) { set(value) {
material.borderWidthPreset = value materialLayer.borderWidthPreset = value
} }
} }
......
...@@ -264,16 +264,7 @@ extension UIView { ...@@ -264,16 +264,7 @@ extension UIView {
- Parameter animation: A CAAnimation instance. - Parameter animation: A CAAnimation instance.
*/ */
open func animate(animation: CAAnimation) { open func animate(animation: CAAnimation) {
if let a = animation as? CABasicAnimation { layer.animate(animation: animation)
a.fromValue = (nil == layer.presentation() ? layer : layer.presentation()!).value(forKeyPath: a.keyPath!)
}
if let a = animation as? CAPropertyAnimation {
layer.add(a, forKey: a.keyPath!)
} else if let a = animation as? CAAnimationGroup {
layer.add(a, forKey: nil)
} else if let a = animation as? CATransition {
layer.add(a, forKey: kCATransition)
}
} }
/** /**
...@@ -285,20 +276,7 @@ extension UIView { ...@@ -285,20 +276,7 @@ extension UIView {
if interrupted. if interrupted.
*/ */
open func animationDidStop(_ animation: CAAnimation, finished flag: Bool) { open func animationDidStop(_ animation: CAAnimation, finished flag: Bool) {
if let a = animation as? CAPropertyAnimation { layer.animationDidStop(animation, finished: flag)
if let b = a as? CABasicAnimation {
if let v = b.toValue {
if let k = b.keyPath {
layer.setValue(v, forKeyPath: k)
layer.removeAnimation(forKey: k)
}
}
}
} else if let a = animation as? CAAnimationGroup {
for x in a.animations! {
animationDidStop(x, finished: true)
}
}
} }
/// Manages the layout for the shape of the view instance. /// Manages the layout for the shape of the view instance.
......
...@@ -207,14 +207,13 @@ public class NavigationBar: UINavigationBar { ...@@ -207,14 +207,13 @@ public class NavigationBar: UINavigationBar {
contentView.grid.columns = columns contentView.grid.columns = columns
// leftControls // leftControls
if let v: Array<UIControl> = item.leftControls { if let v = item.leftControls {
for c in v { for c in v {
let w: CGFloat = c.intrinsicContentSize.width let w = c.intrinsicContentSize.width
(c as? UIButton)?.contentEdgeInsets = UIEdgeInsets.zero (c as? UIButton)?.contentEdgeInsets = UIEdgeInsets.zero
c.frame.size.height = titleView.frame.size.height - contentInset.top - contentInset.bottom c.frame.size.height = titleView.frame.size.height - contentInset.top - contentInset.bottom
let q: Int = Int(w / gridFactor) c.grid.columns = Int(w / gridFactor) + 1
c.grid.columns = q + 1
contentView.grid.columns -= c.grid.columns contentView.grid.columns -= c.grid.columns
...@@ -227,14 +226,13 @@ public class NavigationBar: UINavigationBar { ...@@ -227,14 +226,13 @@ public class NavigationBar: UINavigationBar {
titleView.grid.views.append(contentView) titleView.grid.views.append(contentView)
// rightControls // rightControls
if let v: Array<UIControl> = item.rightControls { if let v = item.rightControls {
for c in v { for c in v {
let w: CGFloat = c.intrinsicContentSize.width let w = c.intrinsicContentSize.width
(c as? UIButton)?.contentEdgeInsets = UIEdgeInsets.zero (c as? UIButton)?.contentEdgeInsets = UIEdgeInsets.zero
c.frame.size.height = titleView.frame.size.height - contentInset.top - contentInset.bottom c.frame.size.height = titleView.frame.size.height - contentInset.top - contentInset.bottom
let q: Int = Int(w / gridFactor) c.grid.columns = Int(w / gridFactor) + 1
c.grid.columns = q + 1
contentView.grid.columns -= c.grid.columns contentView.grid.columns -= c.grid.columns
...@@ -268,7 +266,7 @@ public class NavigationBar: UINavigationBar { ...@@ -268,7 +266,7 @@ public class NavigationBar: UINavigationBar {
item.titleLabel.sizeToFit() item.titleLabel.sizeToFit()
item.detailLabel.sizeToFit() item.detailLabel.sizeToFit()
let diff: CGFloat = (contentView.frame.height - item.titleLabel.frame.height - item.detailLabel.frame.height) / 2 let diff = (contentView.frame.height - item.titleLabel.frame.height - item.detailLabel.frame.height) / 2
item.titleLabel.frame.size.height += diff item.titleLabel.frame.size.height += diff
item.titleLabel.frame.size.width = contentView.frame.width item.titleLabel.frame.size.width = contentView.frame.width
......
...@@ -31,14 +31,14 @@ ...@@ -31,14 +31,14 @@
import UIKit import UIKit
/// A memory reference to the NavigationItem instance. /// A memory reference to the NavigationItem instance.
private var MaterialAssociatedObjectNavigationItemKey: UInt8 = 0 private var NavigationItemKey: UInt8 = 0
public class MaterialAssociatedObjectNavigationItem { public class NavigationItem {
/** /**
A boolean indicating whether keys are being observed A boolean indicating whether keys are being observed
on the UINavigationItem. on the UINavigationItem.
*/ */
internal var observed: Bool = false internal var observed = false
/// Back Button. /// Back Button.
public var backButton: IconButton? public var backButton: IconButton?
...@@ -53,10 +53,10 @@ public class MaterialAssociatedObjectNavigationItem { ...@@ -53,10 +53,10 @@ public class MaterialAssociatedObjectNavigationItem {
public private(set) var detailLabel: UILabel! public private(set) var detailLabel: UILabel!
/// Left controls. /// Left controls.
public var leftControls: Array<UIControl>? public var leftControls: [UIView]?
/// Right controls. /// Right controls.
public var rightControls: Array<UIControl>? public var rightControls: [UIView]?
/// Initializer. /// Initializer.
public init() { public init() {
...@@ -65,7 +65,7 @@ public class MaterialAssociatedObjectNavigationItem { ...@@ -65,7 +65,7 @@ public class MaterialAssociatedObjectNavigationItem {
} }
/// Reloads the subviews for the NavigationBar. /// Reloads the subviews for the NavigationBar.
internal func reloadNavigationBar() { internal func reload() {
guard let navigationBar = contentView?.superview?.superview as? NavigationBar else { guard let navigationBar = contentView?.superview?.superview as? NavigationBar else {
return return
} }
...@@ -89,34 +89,34 @@ public class MaterialAssociatedObjectNavigationItem { ...@@ -89,34 +89,34 @@ public class MaterialAssociatedObjectNavigationItem {
extension UINavigationItem { extension UINavigationItem {
/// NavigationItem reference. /// NavigationItem reference.
public internal(set) var item: MaterialAssociatedObjectNavigationItem { public internal(set) var navigationItem: NavigationItem {
get { get {
return AssociatedObject(base: self, key: &MaterialAssociatedObjectNavigationItemKey) { return AssociatedObject(base: self, key: &NavigationItemKey) {
return MaterialAssociatedObjectNavigationItem() return NavigationItem()
} }
} }
set(value) { set(value) {
AssociateObject(base: self, key: &MaterialAssociatedObjectNavigationItemKey, value: value) AssociateObject(base: self, key: &NavigationItemKey, value: value)
} }
} }
/// Back Button. /// Back Button.
public internal(set) var backButton: IconButton? { public internal(set) var backButton: IconButton? {
get { get {
return item.backButton return navigationItem.backButton
} }
set(value) { set(value) {
item.backButton = value navigationItem.backButton = value
} }
} }
/// Content View. /// Content View.
public internal(set) var contentView: UIView? { public internal(set) var contentView: UIView? {
get { get {
return item.contentView return navigationItem.contentView
} }
set(value) { set(value) {
item.contentView = value navigationItem.contentView = value
} }
} }
...@@ -127,13 +127,13 @@ extension UINavigationItem { ...@@ -127,13 +127,13 @@ extension UINavigationItem {
} }
set(value) { set(value) {
titleLabel.text = value titleLabel.text = value
item.reloadNavigationBar() navigationItem.reload()
} }
} }
/// Title Label. /// Title Label.
public var titleLabel: UILabel { public var titleLabel: UILabel {
return item.titleLabel return navigationItem.titleLabel
} }
/// Detail text. /// Detail text.
...@@ -143,32 +143,32 @@ extension UINavigationItem { ...@@ -143,32 +143,32 @@ extension UINavigationItem {
} }
set(value) { set(value) {
detailLabel.text = value detailLabel.text = value
item.reloadNavigationBar() navigationItem.reload()
} }
} }
/// Detail Label. /// Detail Label.
public var detailLabel: UILabel { public var detailLabel: UILabel {
return item.detailLabel return navigationItem.detailLabel
} }
/// Left side UIControls. /// Left side UIViews.
public var leftControls: Array<UIControl>? { public var leftControls: [UIView]? {
get { get {
return item.leftControls return navigationItem.leftControls
} }
set(value) { set(value) {
item.leftControls = value navigationItem.leftControls = value
} }
} }
/// Right side UIControls. /// Right side UIViews.
public var rightControls: Array<UIControl>? { public var rightControls: [UIView]? {
get { get {
return item.rightControls return navigationItem.rightControls
} }
set(value) { set(value) {
item.rightControls = value navigationItem.rightControls = value
} }
} }
} }
...@@ -62,7 +62,7 @@ open class RootController: UIViewController { ...@@ -62,7 +62,7 @@ open class RootController: UIViewController {
is recommended to use the transitionFromRootViewController is recommended to use the transitionFromRootViewController
helper method. helper method.
*/ */
public internal(set) var rootViewController: UIViewController! open internal(set) var rootViewController: UIViewController!
/** /**
An initializer that initializes the object with a NSCoder object. An initializer that initializes the object with a NSCoder object.
......
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