Commit 068676f9 by Daniel Dahan

development: updated willRenderView to willLayout

parent a969227d
...@@ -63,9 +63,10 @@ open class BarView: ContentView { ...@@ -63,9 +63,10 @@ open class BarView: ContentView {
open override func layoutSubviews() { open override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
if willRenderView { guard willLayout else {
divider.reload() return
} }
divider.reload()
} }
/** /**
......
...@@ -31,27 +31,71 @@ ...@@ -31,27 +31,71 @@
import UIKit import UIKit
open class ContentCard: PulseView { open class ContentCard: PulseView {
/// Will render the view.
open var willLayout: 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 contentEdgeInsets: 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
}
}
/// An internal reference to the titleToolbar. /// An internal reference to the titleToolbar.
internal var internalTitleToolbar: Toolbar? internal var internalTitleToolbar: Toolbar?
/// An internal reference to the contentView.
internal var internalContentView: UIView?
/// An internal reference to the detailToolbar.
internal var internalDetailToolbar: Toolbar?
/// A reference to the titleToolbar. /// A reference to the titleToolbar.
open var titleToolbar: Toolbar { open var titleToolbar: Toolbar {
prepareTitleToolbar() prepareTitleToolbar()
return internalTitleToolbar! return internalTitleToolbar!
} }
/// An internal reference to the contentView.
internal var internalContentView: UIView?
/// A reference to the contentView. /// A reference to the contentView.
open var contentView: UIView { open var contentView: UIView {
prepareContentView() prepareContentView()
return internalContentView! return internalContentView!
} }
/// An internal reference to the detailToolbar.
internal var internalDetailToolbar: Toolbar?
/// A reference to the detailToolbar. /// A reference to the detailToolbar.
open var detailToolbar: Toolbar { open var detailToolbar: Toolbar {
prepareDetailToolbar() prepareDetailToolbar()
...@@ -70,15 +114,36 @@ open class ContentCard: PulseView { ...@@ -70,15 +114,36 @@ open class ContentCard: PulseView {
pulseAnimation = .none pulseAnimation = .none
} }
/// Reloads the open override func layoutSubviews() {
open func reload() { super.layoutSubviews()
guard willLayout else {
return
}
// clear constraints so new ones do not conflict // clear constraints so new ones do not conflict
removeConstraints(constraints) removeConstraints(constraints)
for v in subviews { for v in subviews {
v.removeFromSuperview() v.removeFromSuperview()
} }
var h: CGFloat = 0
if let v = internalTitleToolbar {
v.layoutIfNeeded()
h += v.height
}
if let v = internalContentView {
v.layoutIfNeeded()
h += v.height
}
if let v = internalDetailToolbar {
v.layoutIfNeeded()
h += v.height
}
height = h
} }
/// Prepares the titleToolbar. /// Prepares the titleToolbar.
......
...@@ -45,7 +45,7 @@ open class ContentView: View { ...@@ -45,7 +45,7 @@ open class ContentView: View {
} }
/// Will render the view. /// Will render the view.
open var willRenderView: Bool { open var willLayout: Bool {
return 0 < width && 0 < height && nil != superview return 0 < width && 0 < height && nil != superview
} }
...@@ -162,7 +162,10 @@ open class ContentView: View { ...@@ -162,7 +162,10 @@ open class ContentView: View {
open override func layoutSubviews() { open override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
if willRenderView { guard willLayout else {
return
}
var lc = 0 var lc = 0
var rc = 0 var rc = 0
let l = (CGFloat(leftControls.count) * interimSpace) let l = (CGFloat(leftControls.count) * interimSpace)
...@@ -213,7 +216,6 @@ open class ContentView: View { ...@@ -213,7 +216,6 @@ open class ContentView: View {
grid.commit() grid.commit()
contentView.grid.commit() contentView.grid.commit()
} }
}
/** /**
Prepares the view instance when intialized. When subclassing, Prepares the view instance when intialized. When subclassing,
......
...@@ -270,7 +270,7 @@ open class Menu: View { ...@@ -270,7 +270,7 @@ open class Menu: View {
usingSpringWithDamping: usingSpringWithDamping, usingSpringWithDamping: usingSpringWithDamping,
initialSpringVelocity: initialSpringVelocity, initialSpringVelocity: initialSpringVelocity,
options: options, options: options,
animations: { [weak self, base = base, v = views[i]] in animations: { [base = base, v = views[i]] in
v.alpha = 0 v.alpha = 0
v.y = base.y v.y = base.y
...@@ -366,11 +366,7 @@ open class Menu: View { ...@@ -366,11 +366,7 @@ open class Menu: View {
usingSpringWithDamping: usingSpringWithDamping, usingSpringWithDamping: usingSpringWithDamping,
initialSpringVelocity: initialSpringVelocity, initialSpringVelocity: initialSpringVelocity,
options: options, options: options,
animations: { [weak self, base = base, v = views[i]] in animations: { [base = base, v = views[i]] in
guard let s = self else {
return
}
v.alpha = 0 v.alpha = 0
v.y = base.y + h v.y = base.y + h
...@@ -462,7 +458,7 @@ open class Menu: View { ...@@ -462,7 +458,7 @@ open class Menu: View {
usingSpringWithDamping: usingSpringWithDamping, usingSpringWithDamping: usingSpringWithDamping,
initialSpringVelocity: initialSpringVelocity, initialSpringVelocity: initialSpringVelocity,
options: options, options: options,
animations: { [weak self, v = views[i]] in animations: { [v = views[i]] in
v.alpha = 0 v.alpha = 0
v.x = base.x v.x = base.x
...@@ -553,19 +549,14 @@ open class Menu: View { ...@@ -553,19 +549,14 @@ open class Menu: View {
let w = baseSize.width let w = baseSize.width
for i in 1..<views.count { for i in 1..<views.count {
UIView.animate(withDuration: Double(i) * duration, UIView.animate(withDuration: Double(i) * duration,
delay: delay, delay: delay,
usingSpringWithDamping: usingSpringWithDamping, usingSpringWithDamping: usingSpringWithDamping,
initialSpringVelocity: initialSpringVelocity, initialSpringVelocity: initialSpringVelocity,
options: options, options: options,
animations: { [weak self, base = base, v = views[i]] in animations: { [base = base, v = views[i]] in
guard let s = self else {
return
}
v.alpha = 0 v.alpha = 0
v.x = s.x + w v.x = base.x + w
animations?(v) animations?(v)
}) { [weak self, v = views[i]] _ in }) { [weak self, v = views[i]] _ in
......
...@@ -67,11 +67,7 @@ open class MenuController: RootController { ...@@ -67,11 +67,7 @@ open class MenuController: RootController {
} }
s.rootViewController.view.alpha = 0.25 s.rootViewController.view.alpha = 0.25
}) })
menu.open { [weak self] (view) in menu.open { [completion = completion] (view) in
guard let s = self else {
return
}
completion?(view) completion?(view)
} }
} }
......
...@@ -60,7 +60,7 @@ open class NavigationBar: UINavigationBar { ...@@ -60,7 +60,7 @@ open class NavigationBar: UINavigationBar {
internal var animating = false internal var animating = false
/// Will render the view. /// Will render the view.
open var willRenderView: Bool { open var willLayout: Bool {
return 0 < width && 0 < height && nil != superview return 0 < width && 0 < height && nil != superview
} }
...@@ -190,7 +190,10 @@ open class NavigationBar: UINavigationBar { ...@@ -190,7 +190,10 @@ open class NavigationBar: UINavigationBar {
- Parameter item: A UINavigationItem to layout. - Parameter item: A UINavigationItem to layout.
*/ */
internal func layoutNavigationItem(item: UINavigationItem) { internal func layoutNavigationItem(item: UINavigationItem) {
if willRenderView { guard willLayout else {
return
}
prepareItem(item: item) prepareItem(item: item)
prepareTitleView(item: item) prepareTitleView(item: item)
...@@ -282,7 +285,6 @@ open class NavigationBar: UINavigationBar { ...@@ -282,7 +285,6 @@ open class NavigationBar: UINavigationBar {
item.detailLabel.removeFromSuperview() item.detailLabel.removeFromSuperview()
} }
} }
}
/** /**
Prepares the view instance when intialized. When subclassing, Prepares the view instance when intialized. When subclassing,
......
...@@ -92,11 +92,13 @@ open class SearchBar: BarView { ...@@ -92,11 +92,13 @@ open class SearchBar: BarView {
open override func layoutSubviews() { open override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
if willRenderView { guard willLayout else {
return
}
textField.frame = contentView.bounds textField.frame = contentView.bounds
layoutClearButton() layoutClearButton()
} }
}
/** /**
An initializer that initializes the object with a NSCoder object. An initializer that initializes the object with a NSCoder object.
......
...@@ -79,9 +79,11 @@ open class Snackbar: BarView { ...@@ -79,9 +79,11 @@ open class Snackbar: BarView {
open override func layoutSubviews() { open override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
if willRenderView { guard willLayout else {
textLabel.frame = contentView.bounds return
} }
textLabel.frame = contentView.bounds
} }
/** /**
......
...@@ -129,7 +129,10 @@ open class TabBar: BarView { ...@@ -129,7 +129,10 @@ open class TabBar: BarView {
open override func layoutSubviews() { open override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
if willRenderView { guard willLayout else {
return
}
guard 0 < buttons.count else { guard 0 < buttons.count else {
return return
} }
...@@ -152,7 +155,6 @@ open class TabBar: BarView { ...@@ -152,7 +155,6 @@ open class TabBar: BarView {
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)
} }
}
/// Handles the button touch event. /// Handles the button touch event.
@objc @objc
......
...@@ -102,7 +102,10 @@ open class Toolbar: BarView { ...@@ -102,7 +102,10 @@ open class Toolbar: BarView {
open override func layoutSubviews() { open override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
if willRenderView { guard willLayout else {
return
}
if nil != title && "" != title { if nil != title && "" != title {
if nil == titleLabel.superview { if nil == titleLabel.superview {
contentView.addSubview(titleLabel) contentView.addSubview(titleLabel)
...@@ -136,7 +139,6 @@ open class Toolbar: BarView { ...@@ -136,7 +139,6 @@ open class Toolbar: BarView {
detailLabel.removeFromSuperview() detailLabel.removeFromSuperview()
} }
} }
}
/** /**
Prepares the view instance when intialized. When subclassing, Prepares the view instance when intialized. When subclassing,
......
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