Commit 0bea0f61 by Daniel Dahan

development: updates to Grid and shape calculations

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