Commit 9696080d by Daniel Dahan

reduced code and drawing logic when rendering ControlViews

parent e9d23e09
......@@ -109,7 +109,7 @@ class AppSearchBarViewController: SearchBarViewController {
searchBarView.tintColor = MaterialColor.grey.darken4
searchBarView.textColor = MaterialColor.grey.darken4
searchBarView.placeholderTextColor = MaterialColor.grey.darken4
searchBarView.textField.font = RobotoFont.regularWithSize(17)
searchBarView.textField.font = RobotoFont.regular
searchBarView.textField.delegate = self
searchBarView.clearButton = clearButton
......
......@@ -31,6 +31,11 @@
import UIKit
public class ControlView : MaterialView {
/// Will render the view.
public var willRenderView: Bool {
return 0 < width
}
/// A preset wrapper around contentInset.
public var contentInsetPreset: MaterialEdgeInset {
get {
......@@ -74,14 +79,36 @@ public class ControlView : MaterialView {
/// Left side UIControls.
public var leftControls: Array<UIControl>? {
didSet {
reloadView()
if let v: Array<UIControl> = oldValue {
for b in v {
b.removeFromSuperview()
}
}
if let v: Array<UIControl> = leftControls {
for b in v {
addSubview(b)
}
}
layoutSubviews()
}
}
/// Right side UIControls.
public var rightControls: Array<UIControl>? {
didSet {
reloadView()
if let v: Array<UIControl> = oldValue {
for b in v {
b.removeFromSuperview()
}
}
if let v: Array<UIControl> = rightControls {
for b in v {
addSubview(b)
}
}
layoutSubviews()
}
}
......@@ -115,24 +142,11 @@ public class ControlView : MaterialView {
public override func layoutSubviews() {
super.layoutSubviews()
reloadView()
}
public override func didMoveToSuperview() {
super.didMoveToSuperview()
reloadView()
}
/// Reloads the view.
public func reloadView() {
for v in subviews {
v.removeFromSuperview()
}
if 0 < width {
if willRenderView {
// Size of single grid column.
if let g: CGFloat = width / CGFloat(0 < grid.axis.columns ? grid.axis.columns : 1) {
grid.views = []
contentView.grid.views = []
contentView.grid.columns = grid.axis.columns
// leftControls
......@@ -145,13 +159,10 @@ public class ControlView : MaterialView {
c.grid.columns = 0 == g ? 1 : Int(ceil(w / g))
contentView.grid.columns -= c.grid.columns
addSubview(c)
grid.views?.append(c)
}
}
addSubview(contentView)
grid.views?.append(contentView)
// rightControls
......@@ -165,13 +176,11 @@ public class ControlView : MaterialView {
c.grid.columns = 0 == g ? 1 : Int(ceil(w / g))
contentView.grid.columns -= c.grid.columns
addSubview(c)
grid.views?.append(c)
}
}
grid.reloadLayout()
contentView.grid.reloadLayout()
}
}
}
......@@ -191,6 +200,7 @@ public class ControlView : MaterialView {
/// Prepares the contentView.
public func prepareContentView() {
contentView.backgroundColor = nil
addSubview(contentView)
}
/**
......
......@@ -42,7 +42,7 @@ public class NavigationBarView : StatusBarView {
if let v: UILabel = titleLabel {
contentView.addSubview(v)
}
reloadView()
layoutSubviews()
}
}
......@@ -52,7 +52,7 @@ public class NavigationBarView : StatusBarView {
if let v: UILabel = detailLabel {
contentView.addSubview(v)
}
reloadView()
layoutSubviews()
}
}
......@@ -76,6 +76,8 @@ public class NavigationBarView : StatusBarView {
public override func layoutSubviews() {
super.layoutSubviews()
if willRenderView {
// TitleView alignment.
if let v: UILabel = titleLabel {
if let d: UILabel = detailLabel {
......@@ -95,30 +97,25 @@ public class NavigationBarView : StatusBarView {
}
}
reloadView()
}
/// Prepares the contentView.
public override func prepareContentView() {
super.prepareContentView()
contentView.grid.axis.direction = .Vertical
}
/// Reloads the view.
public override func reloadView() {
super.reloadView()
if 0 < width {
contentView.grid.views = []
if let v: UILabel = titleLabel {
contentView.grid.views?.append(v)
}
if let v: UILabel = detailLabel {
contentView.grid.views?.append(v)
}
contentView.grid.reloadLayout()
}
}
/// Prepares the contentView.
public override func prepareContentView() {
super.prepareContentView()
contentView.grid.axis.direction = .Vertical
}
/**
Used to trigger property changes that initializers avoid.
- Parameter titleLabel: UILabel for the title.
......
......@@ -164,7 +164,7 @@ public class NavigationBarViewController: StatusBarViewController {
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 at the end
The super.prepareView method should always be called immediately
when subclassing.
*/
public override func prepareView() {
......
......@@ -85,24 +85,22 @@ public class SearchBarView : StatusBarView {
self.init(frame: CGRectZero)
}
public override func reloadView() {
super.reloadView()
contentView.grid.views = [textField]
public override func layoutSubviews() {
super.layoutSubviews()
if willRenderView {
contentView.grid.views?.append(textField)
textField.font = textField.font?.fontWithSize(20)
textField.reloadView()
}
}
/**
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 override func prepareView() {
super.prepareView()
/// Prepares the contentView.
public override func prepareContentView() {
super.prepareContentView()
prepareTextField()
}
/// Prepares the textField.
private func prepareTextField() {
textField.placeholder = "Search"
......
......@@ -86,12 +86,12 @@ public class SearchBarViewController: StatusBarViewController {
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 at the end
The super.prepareView method should always be called immediately
when subclassing.
*/
public override func prepareView() {
prepareSearchBarView()
super.prepareView()
prepareSearchBarView()
}
/// Prepares the SearchBarView.
......
......@@ -63,15 +63,15 @@ public class StatusBarView : ControlView {
}
public override func layoutSubviews() {
super.layoutSubviews()
// Ensures a width.
if 1 > width {
if !willRenderView {
width = MaterialDevice.width
}
grid.axis.columns = Int(width / 48)
super.layoutSubviews()
// General alignment.
if .iPhone == MaterialDevice.type && MaterialDevice.landscape {
grid.contentInset.top = 8
......@@ -80,8 +80,6 @@ public class StatusBarView : ControlView {
grid.contentInset.top = heightForStatusBar + 8
height = heightForPortraitOrientation
}
reloadView()
}
public override func intrinsicContentSize() -> CGSize {
......
......@@ -109,7 +109,7 @@ public class StatusBarViewController: UIViewController {
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 at the end
The super.prepareView method should always be called immediately
when subclassing.
*/
public func prepareView() {
......
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