Commit 0bea0f61 by Daniel Dahan

development: updates to Grid and shape calculations

parent 402084c6
...@@ -180,6 +180,10 @@ open class Bar: View { ...@@ -180,6 +180,10 @@ open class Bar: View {
return return
} }
guard !grid.deferred else {
return
}
reload() reload()
} }
......
...@@ -74,13 +74,9 @@ open class BottomTabBar: UITabBar { ...@@ -74,13 +74,9 @@ open class BottomTabBar: UITabBar {
prepare() prepare()
} }
open override func layoutSublayers(of layer: CALayer) { open override func layoutSubviews() {
super.layoutSublayers(of: layer)
layoutShape()
}
open override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
layoutShape()
layoutShadowPath() layoutShadowPath()
if let v = items { if let v = items {
......
...@@ -163,14 +163,10 @@ open class Button: UIButton, Pulseable { ...@@ -163,14 +163,10 @@ open class Button: UIButton, Pulseable {
prepare() prepare()
} }
open override func layoutSublayers(of layer: CALayer) {
super.layoutSublayers(of: layer)
layoutShape()
layoutVisualLayer()
}
open override func layoutSubviews() { open override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
layoutShape()
layoutVisualLayer()
layoutShadowPath() layoutShadowPath()
} }
......
...@@ -217,15 +217,11 @@ open class CollectionReusableView: UICollectionReusableView, Pulseable { ...@@ -217,15 +217,11 @@ open class CollectionReusableView: UICollectionReusableView, Pulseable {
self.init(frame: .zero) self.init(frame: .zero)
} }
open override func layoutSublayers(of layer: CALayer) {
super.layoutSublayers(of: layer)
layoutShape()
layoutVisualLayer()
}
open override func layoutSubviews() { open override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
layoutShadowPath() layoutShape()
layoutVisualLayer()
layoutShadowPath()
} }
/** /**
......
...@@ -224,15 +224,11 @@ open class CollectionViewCell: UICollectionViewCell, Pulseable { ...@@ -224,15 +224,11 @@ open class CollectionViewCell: UICollectionViewCell, Pulseable {
self.init(frame: .zero) self.init(frame: .zero)
} }
open override func layoutSublayers(of layer: CALayer) {
super.layoutSublayers(of: layer)
layoutShape()
layoutVisualLayer()
}
open override func layoutSubviews() { open override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
layoutShadowPath() layoutShape()
layoutVisualLayer()
layoutShadowPath()
} }
/** /**
......
...@@ -204,6 +204,7 @@ public struct Grid { ...@@ -204,6 +204,7 @@ public struct Grid {
} }
} }
canvas.setNeedsLayout()
canvas.layoutIfNeeded() canvas.layoutIfNeeded()
guard 0 < canvas.width && 0 < canvas.height else { guard 0 < canvas.width && 0 < canvas.height else {
......
...@@ -310,10 +310,10 @@ extension CALayer { ...@@ -310,10 +310,10 @@ extension CALayer {
/// Manages the layout for the shape of the view instance. /// Manages the layout for the shape of the view instance.
open func layoutShape() { open func layoutShape() {
if .none != shapePreset { if .none != shapePreset {
if width < height { if frame.height > frame.width {
frame.size.width = height frame.size.width = frame.height
} else if width > height { } else if frame.height < frame.width {
frame.size.height = width frame.size.height = frame.width
} }
} }
......
...@@ -132,13 +132,9 @@ open class NavigationBar: UINavigationBar { ...@@ -132,13 +132,9 @@ open class NavigationBar: UINavigationBar {
return intrinsicContentSize return intrinsicContentSize
} }
open override func layoutSublayers(of layer: CALayer) {
super.layoutSublayers(of: layer)
layoutShape()
}
open override func layoutSubviews() { open override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
layoutShape()
layoutShadowPath() layoutShadowPath()
if let v = topItem { if let v = topItem {
......
...@@ -106,6 +106,11 @@ open class NavigationController: UINavigationController { ...@@ -106,6 +106,11 @@ open class NavigationController: UINavigationController {
v.layoutNavigationItem(item: item) v.layoutNavigationItem(item: item)
} }
open override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
navigationBar.width = view.width
}
/** /**
Prepares the view instance when intialized. When subclassing, Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepare method it is recommended to override the prepare method
...@@ -115,6 +120,7 @@ open class NavigationController: UINavigationController { ...@@ -115,6 +120,7 @@ open class NavigationController: UINavigationController {
*/ */
open func prepare() { open func prepare() {
navigationBar.heightPreset = .normal navigationBar.heightPreset = .normal
navigationBar.width = view.width
view.clipsToBounds = true view.clipsToBounds = true
view.backgroundColor = .white view.backgroundColor = .white
......
...@@ -101,15 +101,11 @@ open class TableViewCell: UITableViewCell, Pulseable { ...@@ -101,15 +101,11 @@ open class TableViewCell: UITableViewCell, Pulseable {
prepare() prepare()
} }
open override func layoutSublayers(of layer: CALayer) {
super.layoutSublayers(of: layer)
layoutShape()
layoutVisualLayer()
}
open override func layoutSubviews() { open override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
layoutShadowPath() layoutShape()
layoutVisualLayer()
layoutShadowPath()
} }
/** /**
......
...@@ -372,13 +372,15 @@ open class TextField: UITextField { ...@@ -372,13 +372,15 @@ open class TextField: UITextField {
open override func layoutSubviews() { open override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
guard willLayout && !isAnimating else {
return
}
layoutShape()
reload() reload()
} }
open override func layoutSublayers(of layer: CALayer) {
super.layoutSublayers(of: layer)
layoutShape()
}
/** /**
Prepares the view instance when intialized. When subclassing, Prepares the view instance when intialized. When subclassing,
...@@ -402,10 +404,6 @@ open class TextField: UITextField { ...@@ -402,10 +404,6 @@ open class TextField: UITextField {
/// Ensures that the components are sized correctly. /// Ensures that the components are sized correctly.
open func reload() { open func reload() {
guard willLayout && !isAnimating else {
return
}
layoutPlaceholderLabel() layoutPlaceholderLabel()
layoutDetailLabel() layoutDetailLabel()
layoutButton(button: clearIconButton) layoutButton(button: clearIconButton)
......
...@@ -149,15 +149,12 @@ open class TextView: UITextView { ...@@ -149,15 +149,12 @@ open class TextView: UITextView {
removeNotificationHandlers() removeNotificationHandlers()
} }
open override func layoutSublayers(of layer: CALayer) {
super.layoutSublayers(of: layer)
layoutShape()
}
open override func layoutSubviews() { open override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
layoutShadowPath() layoutShape()
placeholderLabel?.preferredMaxLayoutWidth = textContainer.size.width - textContainer.lineFragmentPadding * 2 layoutShadowPath()
placeholderLabel?.preferredMaxLayoutWidth = textContainer.size.width - textContainer.lineFragmentPadding * 2
titleLabel?.frame.size.width = bounds.width titleLabel?.frame.size.width = bounds.width
} }
......
...@@ -45,7 +45,7 @@ open class Toolbar: Bar { ...@@ -45,7 +45,7 @@ open class Toolbar: Bar {
} }
/// Title label. /// Title label.
open internal(set) lazy var titleLabel = UILabel() open fileprivate(set) lazy var titleLabel = UILabel()
/// A convenience property to set the detailLabel text. /// A convenience property to set the detailLabel text.
open var detail: String? { open var detail: String? {
...@@ -59,7 +59,7 @@ open class Toolbar: Bar { ...@@ -59,7 +59,7 @@ open class Toolbar: Bar {
} }
/// Detail label. /// Detail label.
open internal(set) lazy var detailLabel = UILabel() open fileprivate(set) lazy var detailLabel = UILabel()
deinit { deinit {
removeObserver(self, forKeyPath: "titleLabel.textAlignment") removeObserver(self, forKeyPath: "titleLabel.textAlignment")
......
...@@ -156,14 +156,10 @@ open class View: UIView { ...@@ -156,14 +156,10 @@ open class View: UIView {
prepare() prepare()
} }
open override func layoutSublayers(of layer: CALayer) {
super.layoutSublayers(of: layer)
layoutShape()
layoutVisualLayer()
}
open override func layoutSubviews() { open override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
layoutShape()
layoutVisualLayer()
layoutShadowPath() layoutShadowPath()
} }
......
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