Commit 3ff98d5a by Daniel Dahan

development: reducing code complexity with BarViews

parent 39e54828
...@@ -61,6 +61,13 @@ open class BarView: ControlView { ...@@ -61,6 +61,13 @@ open class BarView: ControlView {
super.init(leftControls: leftControls, rightControls: rightControls) super.init(leftControls: leftControls, rightControls: rightControls)
} }
open override func layoutSubviews() {
super.layoutSubviews()
if willRenderView {
divider.reload()
}
}
/** /**
Prepares the view instance when intialized. When subclassing, Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepareView method it is recommended to override the prepareView method
......
...@@ -162,8 +162,6 @@ open class ControlView: View { ...@@ -162,8 +162,6 @@ open class ControlView: View {
open override func layoutSubviews() { open override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
if willRenderView { if willRenderView {
layoutIfNeeded()
var lc = 0 var lc = 0
var rc = 0 var rc = 0
let l = (CGFloat(leftControls.count) * interimSpace) let l = (CGFloat(leftControls.count) * interimSpace)
......
...@@ -222,8 +222,6 @@ public class Grid { ...@@ -222,8 +222,6 @@ public class Grid {
return return
} }
canvas.layoutIfNeeded()
if canvas != child.superview { if canvas != child.superview {
child.removeFromSuperview() child.removeFromSuperview()
canvas.addSubview(child) canvas.addSubview(child)
......
...@@ -854,7 +854,7 @@ extension Layout { ...@@ -854,7 +854,7 @@ extension Layout {
- Parameter views: A Dictionary<String, Any> of view key / value pairs. - Parameter views: A Dictionary<String, Any> of view key / value pairs.
- Returns: The Array<NSLayoutConstraint> instance. - Returns: The Array<NSLayoutConstraint> instance.
*/ */
public class func constraint(format: String, options: NSLayoutFormatOptions, metrics: Dictionary<String, Any>?, views: Dictionary<String, Any>) -> [NSLayoutConstraint] { public class func constraint(format: String, options: NSLayoutFormatOptions, metrics: [String: Any]?, views: [String: Any]) -> [NSLayoutConstraint] {
for (_, a) in views { for (_, a) in views {
if let v = a as? UIView { if let v = a as? UIView {
v.translatesAutoresizingMaskIntoConstraints = false v.translatesAutoresizingMaskIntoConstraints = false
......
...@@ -164,8 +164,6 @@ open class PageTabBarController: RootController { ...@@ -164,8 +164,6 @@ open class PageTabBarController: RootController {
pageTabBar.y = y pageTabBar.y = y
rootViewController.view.y = 0 rootViewController.view.y = 0
} }
pageTabBar.divider.reload()
} }
/** /**
......
...@@ -69,8 +69,6 @@ open class SearchBarController: RootController { ...@@ -69,8 +69,6 @@ open class SearchBarController: RootController {
rootViewController.view.y = p rootViewController.view.y = p
rootViewController.view.height = view.height - p rootViewController.view.height = view.height - p
searchBar.divider.reload()
} }
/** /**
......
...@@ -77,6 +77,14 @@ open class Snackbar: BarView { ...@@ -77,6 +77,14 @@ open class Snackbar: BarView {
return super.hitTest(point, with: event) return super.hitTest(point, with: event)
} }
open override func layoutSubviews() {
super.layoutSubviews()
if willRenderView {
print("RENDING", contentView)
textLabel.frame = contentView.bounds
}
}
/** /**
Prepares the view instance when intialized. When subclassing, Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepareView method it is recommended to override the prepareView method
...@@ -103,8 +111,7 @@ open class Snackbar: BarView { ...@@ -103,8 +111,7 @@ open class Snackbar: BarView {
textLabel.textColor = Color.white textLabel.textColor = Color.white
textLabel.numberOfLines = 0 textLabel.numberOfLines = 0
contentView.grid.deferred = true contentView.backgroundColor = Color.green.base
contentView.grid.views.append(textLabel) contentView.addSubview(textLabel)
contentView.grid.deferred = false
} }
} }
...@@ -156,8 +156,9 @@ open class SnackbarController: RootController { ...@@ -156,8 +156,9 @@ open class SnackbarController: RootController {
return return
} }
snackbar.width = view.width
snackbar.height = snackbar.intrinsicContentSize.height + snackbar.grid.layoutEdgeInsets.top + snackbar.grid.layoutEdgeInsets.bottom
layoutSnackbar(status: snackbar.status) layoutSnackbar(status: snackbar.status)
layoutRootViewController(status: snackbar.status)
} }
/** /**
...@@ -183,26 +184,10 @@ open class SnackbarController: RootController { ...@@ -183,26 +184,10 @@ open class SnackbarController: RootController {
- Parameter status: A SnackbarStatus enum value. - Parameter status: A SnackbarStatus enum value.
*/ */
private func layoutSnackbar(status: SnackbarStatus) { private func layoutSnackbar(status: SnackbarStatus) {
let p = snackbar.intrinsicContentSize.height + snackbar.grid.layoutEdgeInsets.top + snackbar.grid.layoutEdgeInsets.bottom
snackbar.width = view.width
snackbar.height = p
if .bottom == snackbarAlignment { if .bottom == snackbarAlignment {
snackbar.y = .visible == status ? view.height - p : view.height snackbar.y = .visible == status ? view.height - snackbar.height : view.height
} else { } else {
snackbar.y = .visible == status ? 0 : -snackbar.height snackbar.y = .visible == status ? 0 : -snackbar.height
} }
snackbar.divider.reload()
}
/**
Lays out the rootViewController.
- Parameter status: A SnackbarStatus enum value.
*/
private func layoutRootViewController(status: SnackbarStatus) {
guard let vc = rootViewController else {
return
}
vc.view.frame = view.bounds
} }
} }
...@@ -57,54 +57,10 @@ public protocol TabBarDelegate { ...@@ -57,54 +57,10 @@ public protocol TabBarDelegate {
optional func tabBarDidSelectButton(tabBar: TabBar, button: UIButton) optional func tabBarDidSelectButton(tabBar: TabBar, button: UIButton)
} }
open class TabBar: View { open class TabBar: BarView {
/// A boolean indicating if the TabBar line is in an animation state. /// A boolean indicating if the TabBar line is in an animation state.
open internal(set) var isAnimating = false open internal(set) var isAnimating = false
/// Will render the view.
open var willRenderView: Bool {
return 0 < width && 0 < height && nil != superview
}
/// A preset wrapper around contentInset.
open var contentEdgeInsetsPreset: EdgeInsetsPreset {
get {
return grid.contentEdgeInsetsPreset
}
set(value) {
grid.contentEdgeInsetsPreset = value
}
}
/// A wrapper around grid.contentInset.
@IBInspectable
open var contentInset: EdgeInsets {
get {
return grid.contentEdgeInsets
}
set(value) {
grid.contentEdgeInsets = value
}
}
/// A preset wrapper around interimSpace.
open var interimSpacePreset = InterimSpacePreset.none {
didSet {
interimSpace = InterimSpacePresetToValue(preset: interimSpacePreset)
}
}
/// A wrapper around grid.interimSpace.
@IBInspectable
open var interimSpace: InterimSpace {
get {
return grid.interimSpace
}
set(value) {
grid.interimSpace = value
}
}
/// A delegation reference. /// A delegation reference.
open weak var delegate: TabBarDelegate? open weak var delegate: TabBarDelegate?
...@@ -171,9 +127,6 @@ open class TabBar: View { ...@@ -171,9 +127,6 @@ open class TabBar: View {
} }
} }
/// Layer Reference.
open internal(set) var divider: Divider!
open override func layoutSubviews() { open override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
if willRenderView { if willRenderView {
...@@ -195,7 +148,6 @@ open class TabBar: View { ...@@ -195,7 +148,6 @@ open class TabBar: View {
line.frame = CGRect(x: selected!.x, y: .bottom == lineAlignment ? height - lineHeight : 0, width: selected!.width, height: lineHeight) line.frame = CGRect(x: selected!.x, y: .bottom == lineAlignment ? height - lineHeight : 0, width: selected!.width, height: lineHeight)
} }
divider.reload()
} }
} }
...@@ -268,7 +220,6 @@ open class TabBar: View { ...@@ -268,7 +220,6 @@ open class TabBar: View {
/// Prepares the divider. /// Prepares the divider.
private func prepareDivider() { private func prepareDivider() {
divider = Divider(view: self)
divider.alignment = .top divider.alignment = .top
} }
......
...@@ -172,8 +172,6 @@ open class ToolbarController: RootController { ...@@ -172,8 +172,6 @@ open class ToolbarController: RootController {
rootViewController.view.y = p rootViewController.view.y = p
rootViewController.view.height = view.height - p rootViewController.view.height = view.height - p
toolbar.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