Commit 2373b2b6 by Daniel Dahan

development: update NavigationViewController to NavigationView

parent 73bd9492
......@@ -15,8 +15,8 @@
65B965871B8BEEC60055B139 /* SideNavigationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65B965861B8BEEC60055B139 /* SideNavigationViewController.swift */; };
65DBE4201B9A9244000C804F /* Roboto-Bold.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 65DBE41E1B9A9244000C804F /* Roboto-Bold.ttf */; };
65DBE4211B9A9244000C804F /* Roboto-Thin.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 65DBE41F1B9A9244000C804F /* Roboto-Thin.ttf */; };
962F3E531BACA68C0004B8AD /* NavigationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 962F3E521BACA68C0004B8AD /* NavigationViewController.swift */; };
962F3E541BACA7FB0004B8AD /* NavigationViewController.swift in Headers */ = {isa = PBXBuildFile; fileRef = 962F3E521BACA68C0004B8AD /* NavigationViewController.swift */; settings = {ATTRIBUTES = (Public, ); }; };
962F3E531BACA68C0004B8AD /* NavigationBarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 962F3E521BACA68C0004B8AD /* NavigationBarView.swift */; };
962F3E541BACA7FB0004B8AD /* NavigationBarView.swift in Headers */ = {isa = PBXBuildFile; fileRef = 962F3E521BACA68C0004B8AD /* NavigationBarView.swift */; settings = {ATTRIBUTES = (Public, ); }; };
963832421B88DFD80015F710 /* MaterialKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 963832361B88DFD80015F710 /* MaterialKit.framework */; };
9638325A1B88E31A0015F710 /* MaterialKitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 963832581B88E31A0015F710 /* MaterialKitTests.swift */; };
963832691B88E5BF0015F710 /* Capture.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9638325E1B88E5BF0015F710 /* Capture.swift */; };
......@@ -66,7 +66,7 @@
65B965861B8BEEC60055B139 /* SideNavigationViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SideNavigationViewController.swift; sourceTree = "<group>"; };
65DBE41E1B9A9244000C804F /* Roboto-Bold.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Roboto-Bold.ttf"; sourceTree = "<group>"; };
65DBE41F1B9A9244000C804F /* Roboto-Thin.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Roboto-Thin.ttf"; sourceTree = "<group>"; };
962F3E521BACA68C0004B8AD /* NavigationViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NavigationViewController.swift; sourceTree = "<group>"; };
962F3E521BACA68C0004B8AD /* NavigationBarView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NavigationBarView.swift; sourceTree = "<group>"; };
963832361B88DFD80015F710 /* MaterialKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = MaterialKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
963832411B88DFD80015F710 /* MaterialKitTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MaterialKitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
963832541B88E30F0015F710 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
......@@ -115,7 +115,7 @@
isa = PBXGroup;
children = (
65B965861B8BEEC60055B139 /* SideNavigationViewController.swift */,
962F3E521BACA68C0004B8AD /* NavigationViewController.swift */,
962F3E521BACA68C0004B8AD /* NavigationBarView.swift */,
);
name = Navigation;
sourceTree = "<group>";
......@@ -272,7 +272,7 @@
657CD02D1B8EE0D3008C0029 /* MaterialButton.swift in Headers */,
96C910ED1B95804B00E7CE5C /* MaterialTheme.swift in Headers */,
657CD02F1B8EE0D3008C0029 /* ImageCardView.swift in Headers */,
962F3E541BACA7FB0004B8AD /* NavigationViewController.swift in Headers */,
962F3E541BACA7FB0004B8AD /* NavigationBarView.swift in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -383,7 +383,7 @@
963832691B88E5BF0015F710 /* Capture.swift in Sources */,
9A94D10B1B8A485C00F586A5 /* ImageCardView.swift in Sources */,
96B57D4E1B90AF7D00DE7BBB /* MaterialTheme.swift in Sources */,
962F3E531BACA68C0004B8AD /* NavigationViewController.swift in Sources */,
962F3E531BACA68C0004B8AD /* NavigationBarView.swift in Sources */,
9638326B1B88E5BF0015F710 /* FabButton.swift in Sources */,
9A94D1091B8A3F5100F586A5 /* MaterialCardView.swift in Sources */,
65B965871B8BEEC60055B139 /* SideNavigationViewController.swift in Sources */,
......
......@@ -403,7 +403,7 @@ public class BasicCardView : MaterialCardView, Comparable {
var views: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
// title
if nil != titleLabelContainer && nil != titleLabel {
if nil != titleLabel {
// clear for updated constraints
titleLabelContainer!.removeConstraints(titleLabelContainer!.constraints)
......@@ -422,7 +422,7 @@ public class BasicCardView : MaterialCardView, Comparable {
}
// detail
if nil != detailLabelContainer && nil != detailLabel {
if nil != detailLabel {
// clear for updated constraints
detailLabelContainer!.removeConstraints(detailLabelContainer!.constraints)
......@@ -440,7 +440,7 @@ public class BasicCardView : MaterialCardView, Comparable {
}
// buttons
if nil != buttonsContainer && (nil != leftButtons || nil != rightButtons) {
if nil != leftButtons || nil != rightButtons {
// clear for updated constraints
buttonsContainer!.removeConstraints(buttonsContainer!.constraints)
......
......@@ -515,7 +515,7 @@ public class ImageCardView : MaterialCardView, Comparable {
var views: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
// image
if nil != imageViewContainer && nil != imageView {
if nil != imageView {
// clear for updated constraints
imageViewContainer!.removeConstraints(imageViewContainer!.constraints)
......@@ -530,7 +530,7 @@ public class ImageCardView : MaterialCardView, Comparable {
}
// title
if nil != titleLabelContainer && nil != titleLabel {
if nil != titleLabel {
// clear for updated constraints
titleLabelContainer!.removeConstraints(titleLabelContainer!.constraints)
......@@ -555,7 +555,7 @@ public class ImageCardView : MaterialCardView, Comparable {
}
// detail
if nil != detailLabelContainer && nil != detailLabel {
if nil != detailLabel {
// clear for updated constraints
detailLabelContainer!.removeConstraints(detailLabelContainer!.constraints)
......@@ -574,7 +574,7 @@ public class ImageCardView : MaterialCardView, Comparable {
}
// buttons
if nil != buttonsContainer && (nil != leftButtons || nil != rightButtons) {
if nil != leftButtons || nil != rightButtons {
// clear for updated constraints
buttonsContainer!.removeConstraints(buttonsContainer!.constraints)
......
......@@ -18,16 +18,16 @@
import UIKit
public class NavigationViewController: UIViewController {
public class NavigationBarView: UIView {
//
// :name: layoutConstraints
//
internal lazy var layoutConstraints: Array<NSLayoutConstraint> = Array<NSLayoutConstraint>()
/**
:name: maximumTitleLabelHeight
*/
public var maximumTitleLabelHeight: CGFloat = 0 {
//
// :name: horizontalInset
//
public var horizontalInset: CGFloat = MaterialTheme.cardHorizontalInset / 2 {
didSet {
prepareNavigation()
}
......@@ -49,7 +49,7 @@ public class NavigationViewController: UIViewController {
titleLabelContainer = UIView()
titleLabelContainer!.translatesAutoresizingMaskIntoConstraints = false
titleLabelContainer!.backgroundColor = MaterialTheme.clear.color
view.addSubview(titleLabelContainer!)
addSubview(titleLabelContainer!)
}
// text
......@@ -57,7 +57,7 @@ public class NavigationViewController: UIViewController {
t.translatesAutoresizingMaskIntoConstraints = false
t.backgroundColor = MaterialTheme.clear.color
t.font = Roboto.regular
t.numberOfLines = 0
t.numberOfLines = 1
t.lineBreakMode = .ByTruncatingTail
t.textColor = MaterialTheme.white.color
} else {
......@@ -85,7 +85,7 @@ public class NavigationViewController: UIViewController {
leftButtonsContainer = UIView()
leftButtonsContainer!.translatesAutoresizingMaskIntoConstraints = false
leftButtonsContainer!.backgroundColor = MaterialTheme.clear.color
view.addSubview(leftButtonsContainer!)
addSubview(leftButtonsContainer!)
}
prepareNavigation()
}
......@@ -108,7 +108,7 @@ public class NavigationViewController: UIViewController {
rightButtonsContainer = UIView()
rightButtonsContainer!.translatesAutoresizingMaskIntoConstraints = false
rightButtonsContainer!.backgroundColor = MaterialTheme.clear.color
view.addSubview(rightButtonsContainer!)
addSubview(rightButtonsContainer!)
}
prepareNavigation()
}
......@@ -124,15 +124,23 @@ public class NavigationViewController: UIViewController {
/**
:name: init
*/
public init() {
super.init(nibName: nil, bundle: nil)
public override init(frame: CGRect) {
super.init(frame: frame)
prepareView()
}
/**
:name: init
*/
public convenience init() {
self.init(frame: CGRect.null)
}
/**
:name: init
*/
public init?(titleLabel: UILabel? = nil, leftButtons: Array<MaterialButton>? = nil, rightButtons: Array<MaterialButton>? = nil) {
super.init(nibName: nil, bundle: nil)
public convenience init?(titleLabel: UILabel? = nil, leftButtons: Array<MaterialButton>? = nil, rightButtons: Array<MaterialButton>? = nil) {
self.init(frame: CGRect.null)
prepareProperties(titleLabel, leftButtons: leftButtons, rightButtons: rightButtons)
}
......@@ -146,38 +154,15 @@ public class NavigationViewController: UIViewController {
}
//
// :name: viewDidLoad
//
public override func viewDidLoad() {
super.viewDidLoad()
prepareView()
prepareNavigation()
}
/**
:name: viewWillAppear
*/
public override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
}
/**
:name: viewDidDisappear
*/
public override func viewDidDisappear(animated: Bool) {
super.viewDidDisappear(animated)
}
//
// :name: prepareView
//
private func prepareView() {
view.translatesAutoresizingMaskIntoConstraints = false
view.layer.shadowColor = MaterialTheme.blueGrey.darken4.CGColor
view.layer.shadowOffset = CGSizeMake(0.2, 0.2)
view.layer.shadowOpacity = 0.5
view.layer.shadowRadius = 1
view.clipsToBounds = false
translatesAutoresizingMaskIntoConstraints = false
layer.shadowColor = MaterialTheme.blueGrey.darken4.CGColor
layer.shadowOffset = CGSizeMake(0.2, 0.2)
layer.shadowOpacity = 0.5
layer.shadowRadius = 1
clipsToBounds = false
}
//
......@@ -189,18 +174,14 @@ public class NavigationViewController: UIViewController {
layoutConstraints.removeAll(keepCapacity: false)
// detect all components and create constraints
var verticalFormat: String = "V:|"
var horizontalFormat: String = "H:|"
var views: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
// left buttons
if nil != leftButtonsContainer && (nil != leftButtons) {
if nil != leftButtons {
// clear for updated constraints
leftButtonsContainer!.removeConstraints(leftButtonsContainer!.constraints)
//container
verticalFormat += "[leftButtonsContainer]"
horizontalFormat += "|[leftButtonsContainer]"
views["leftButtonsContainer"] = leftButtonsContainer!
// leftButtons
......@@ -210,61 +191,64 @@ public class NavigationViewController: UIViewController {
let button: MaterialButton = leftButtons![i]
leftButtonsContainer!.addSubview(button)
buttonViews["button\(i)"] = button
hFormat += "-(buttonLeftInset)-[button\(i)]"
Layout.expandToParentVerticallyWithPad(leftButtonsContainer!, child: button, top: 8, bottom: 8)
hFormat += "-(horizontalInset)-[button\(i)]"
Layout.expandToParentVerticallyWithPad(leftButtonsContainer!, child: button)
}
leftButtonsContainer!.addConstraints(Layout.constraint(hFormat, options: [], metrics: ["buttonLeftInset": 8], views: buttonViews))
leftButtonsContainer!.addConstraints(Layout.constraint(hFormat + "|", options: [], metrics: ["horizontalInset": horizontalInset], views: buttonViews))
}
// title
if nil != titleLabelContainer && nil != titleLabel {
if nil != titleLabel {
// clear for updated constraints
titleLabelContainer!.removeConstraints(titleLabelContainer!.constraints)
// container
verticalFormat += "[titleLabelContainer]"
horizontalFormat += "[titleLabelContainer]"
views["titleLabelContainer"] = titleLabelContainer!
// common text
if 0 == maximumTitleLabelHeight {
Layout.expandToParentWithPad(titleLabelContainer!, child: titleLabel!, top: 8, left: 8, bottom: 8, right: 8)
} else {
Layout.expandToParentHorizontallyWithPad(titleLabelContainer!, child: titleLabel!, left: 8, right: 8)
titleLabelContainer!.addConstraints(Layout.constraint("V:|-(titleLabelTopInset)-[titleLabel(<=maximumTitleLabelHeight)]-(titleLabelBottomInset)-|", options: [], metrics: ["titleLabelTopInset": 8, "titleLabelBottomInset": 8, "maximumTitleLabelHeight": maximumTitleLabelHeight], views: ["titleLabel": titleLabel!]))
}
Layout.expandToParentVerticallyWithPad(titleLabelContainer!, child: titleLabel!)
Layout.expandToParentHorizontallyWithPad(titleLabelContainer!, child: titleLabel!)
}
// left buttons
if nil != rightButtonsContainer && (nil != leftButtons) {
// right buttons
if nil != rightButtons {
// clear for updated constraints
rightButtonsContainer!.removeConstraints(rightButtonsContainer!.constraints)
//container
verticalFormat += "[rightButtonsContainer]"
horizontalFormat += "[rightButtonsContainer]|"
views["rightButtonsContainer"] = rightButtonsContainer!
// leftButtons
var hFormat: String = "H:"
var hFormat: String = "H:|"
var buttonViews: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
for var i: Int = 0, l: Int = leftButtons!.count; i < l; ++i {
let button: MaterialButton = leftButtons![i]
for var i: Int = 0, l: Int = rightButtons!.count; i < l; ++i {
let button: MaterialButton = rightButtons![i]
rightButtonsContainer!.addSubview(button)
buttonViews["button\(i)"] = button
hFormat += "[button\(i)]-(buttonLeftInset)-"
Layout.expandToParentVerticallyWithPad(rightButtonsContainer!, child: button, top: 8, bottom: 8)
hFormat += "[button\(i)]-(horizontalInset)-"
Layout.expandToParentVerticallyWithPad(rightButtonsContainer!, child: button)
}
rightButtonsContainer!.addConstraints(Layout.constraint(hFormat + "|", options: [], metrics: ["buttonLeftInset": 8], views: buttonViews))
rightButtonsContainer!.addConstraints(Layout.constraint(hFormat + "|", options: [], metrics: ["horizontalInset": horizontalInset], views: buttonViews))
}
verticalFormat += "|"
if nil != leftButtons && nil != titleLabel {
layoutConstraints += Layout.constraint("H:|[leftButtonsContainer]-(inset)-[titleLabelContainer]", options: [], metrics: ["inset": horizontalInset], views: ["leftButtonsContainer": leftButtonsContainer!, "titleLabelContainer": titleLabelContainer!])
Layout.alignFromBottom(self, child: leftButtonsContainer!, bottom: horizontalInset)
Layout.alignFromBottom(self, child: titleLabelContainer!, bottom: horizontalInset + leftButtons!.first!.contentEdgeInsets.bottom - 1)
} else if nil != leftButtons {
layoutConstraints += Layout.constraint("H:|[leftButtonsContainer]", options: [], metrics: ["inset": horizontalInset], views: ["leftButtonsContainer": leftButtonsContainer!])
Layout.alignFromBottom(self, child: leftButtonsContainer!, bottom: horizontalInset)
} else if nil != titleLabel {
layoutConstraints += Layout.constraint("H:|-(inset)-[titleLabelContainer]", options: [], metrics: ["inset": horizontalInset], views: ["titleLabelContainer": titleLabelContainer!])
Layout.alignFromBottom(self, child: titleLabelContainer!, bottom: horizontalInset)
}
// combine constraints
if 0 < layoutConstraints.count {
layoutConstraints += Layout.constraint(verticalFormat, options: [], metrics: nil, views: views)
layoutConstraints += Layout.constraint(horizontalFormat, options: [], metrics: nil, views: views)
NSLayoutConstraint.activateConstraints(layoutConstraints)
if nil != rightButtons {
layoutConstraints += Layout.constraint("H:[rightButtonsContainer]|", options: [], metrics: ["inset": horizontalInset], views: ["rightButtonsContainer": rightButtonsContainer!])
Layout.alignFromBottom(self, child: rightButtonsContainer!, bottom: horizontalInset)
}
// constraints
NSLayoutConstraint.activateConstraints(layoutConstraints)
}
}
\ No newline at end of file
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