Commit a6308b53 by Daniel Dahan

development: updated NavigationItem internals

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