Commit 7aee3d67 by Daniel Dahan

development: updated PresenterCard to use mathematical layout rather than…

development: updated PresenterCard to use mathematical layout rather than AutoLayout for performance reasons
parent 34e53600
...@@ -172,6 +172,7 @@ open class Button: UIButton { ...@@ -172,6 +172,7 @@ open class Button: UIButton {
layoutShape() layoutShape()
layoutVisualLayer() layoutVisualLayer()
} }
open override func layoutSubviews() { open override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
layoutShadowPath() layoutShadowPath()
......
...@@ -71,6 +71,9 @@ open class Card: PulseView { ...@@ -71,6 +71,9 @@ open class Card: PulseView {
open var toolbar: Toolbar? { open var toolbar: Toolbar? {
didSet { didSet {
oldValue?.removeFromSuperview() oldValue?.removeFromSuperview()
if let v = toolbar {
container.addSubview(v)
}
layoutSubviews() layoutSubviews()
} }
} }
...@@ -95,6 +98,10 @@ open class Card: PulseView { ...@@ -95,6 +98,10 @@ open class Card: PulseView {
open var contentView: UIView? { open var contentView: UIView? {
didSet { didSet {
oldValue?.removeFromSuperview() oldValue?.removeFromSuperview()
if let v = contentView {
v.clipsToBounds = true
container.addSubview(v)
}
layoutSubviews() layoutSubviews()
} }
} }
...@@ -119,6 +126,9 @@ open class Card: PulseView { ...@@ -119,6 +126,9 @@ open class Card: PulseView {
open var bottomBar: Bar? { open var bottomBar: Bar? {
didSet { didSet {
oldValue?.removeFromSuperview() oldValue?.removeFromSuperview()
if let v = bottomBar {
container.addSubview(v)
}
layoutSubviews() layoutSubviews()
} }
} }
...@@ -169,12 +179,15 @@ open class Card: PulseView { ...@@ -169,12 +179,15 @@ open class Card: PulseView {
self.init(frame: .zero) self.init(frame: .zero)
prepareProperties(toolbar: toolbar, contentView: contentView, bottomBar: bottomBar) prepareProperties(toolbar: toolbar, contentView: contentView, bottomBar: bottomBar)
} }
open override func layoutSubviews() { open override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
guard willLayout else { guard willLayout else {
return return
} }
container.width = width
reload() reload()
} }
...@@ -256,6 +269,37 @@ open class Card: PulseView { ...@@ -256,6 +269,37 @@ open class Card: PulseView {
} }
/** /**
Prepare the view size from a given top position.
- Parameter view: A UIView.
- Parameter edge insets: An EdgeInsets.
- Parameter from top: A CGFloat.
- Returns: A CGFloat.
*/
open func prepare(view: UIView?, with insets: EdgeInsets, from top: CGFloat) -> CGFloat {
guard let v = view else {
return top
}
let t = insets.top + top
v.y = t
v.x = insets.left
let w = container.width - insets.left - insets.right
var h = v.height
if 0 == h {
(v as? UILabel)?.sizeToFit()
h = v.sizeThatFits(CGSize(width: w, height: CGFloat.greatestFiniteMagnitude)).height
}
v.width = w
v.height = h
return t + h + insets.bottom
}
/**
A preparation method that sets the base UI elements. A preparation method that sets the base UI elements.
- Parameter toolbar: An optional Toolbar. - Parameter toolbar: An optional Toolbar.
- Parameter contentView: An optional UIView. - Parameter contentView: An optional UIView.
...@@ -270,6 +314,6 @@ open class Card: PulseView { ...@@ -270,6 +314,6 @@ open class Card: PulseView {
/// Prepares the container. /// Prepares the container.
private func prepareContainer() { private func prepareContainer() {
container.clipsToBounds = true container.clipsToBounds = true
layout(container).edges() addSubview(container)
} }
} }
...@@ -237,7 +237,7 @@ public class Grid { ...@@ -237,7 +237,7 @@ public class Grid {
canvas.addSubview(v) canvas.addSubview(v)
} }
// Forces the views to adjust accordingly to size changes, ie: UILabel. // Forces the view to adjust accordingly to size changes, ie: UILabel.
(v as? UILabel)?.sizeToFit() (v as? UILabel)?.sizeToFit()
switch axis.direction { switch axis.direction {
......
...@@ -83,7 +83,7 @@ internal class MaterialLayer { ...@@ -83,7 +83,7 @@ internal class MaterialLayer {
} }
/// Enables automatic shadowPath sizing. /// Enables automatic shadowPath sizing.
internal var isShadowPathAutoSizing = true internal var isShadowPathAutoSizing = false
/** /**
Initializer that takes in a CALayer. Initializer that takes in a CALayer.
...@@ -315,7 +315,13 @@ extension CALayer { ...@@ -315,7 +315,13 @@ extension CALayer {
guard isShadowPathAutoSizing else { guard isShadowPathAutoSizing else {
return return
} }
z
shadowPath = .none == depthPreset ? nil : UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath if .none == depthPreset {
shadowPath = nil
} else if nil == shadowPath {
shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath
} else {
animate(animation: Animation.shadowPath(path: UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath, duration: 0))
}
} }
} }
...@@ -52,55 +52,23 @@ open class PresenterCard: Card { ...@@ -52,55 +52,23 @@ open class PresenterCard: Card {
open var presenterView: UIView? { open var presenterView: UIView? {
didSet { didSet {
oldValue?.removeFromSuperview() oldValue?.removeFromSuperview()
if let v = presenterView {
v.clipsToBounds = true
container.addSubview(v)
}
layoutSubviews() layoutSubviews()
} }
} }
open override func reload() { open override func reload() {
var top: CGFloat = 0 var top: CGFloat = 0
var bottom: CGFloat = 0
container.removeConstraints(container.constraints) top = prepare(view: toolbar, with: toolbarEdgeInsets, from: top)
top = prepare(view: presenterView, with: presenterViewEdgeInsets, from: top)
top = prepare(view: contentView, with: contentViewEdgeInsets, from: top)
top = prepare(view: bottomBar, with: bottomBarEdgeInsets, from: top)
if let v = toolbar { container.height = top
top += toolbarEdgeInsets.top height = top
container.layout(v).top(top).left(toolbarEdgeInsets.left).right(toolbarEdgeInsets.right).height(v.height)
top += v.height + toolbarEdgeInsets.bottom
}
if let v = presenterView {
top += presenterViewEdgeInsets.top
container.layout(v).top(top).left(presenterViewEdgeInsets.left).right(presenterViewEdgeInsets.right)
top += v.height + presenterViewEdgeInsets.bottom
}
//
// if let v = contentView {
// top += contentViewEdgeInsets.top
// container.layout(v).top(top).left(contentViewEdgeInsets.left).right(contentViewEdgeInsets.right)
// top += v.height + contentViewEdgeInsets.bottom
// }
//
// if let v = bottomBar {
// top += bottomBarEdgeInsets.top
// container.layout(v).top(top).left(bottomBarEdgeInsets.left).right(bottomBarEdgeInsets.right).bottom(bottomBarEdgeInsets.bottom)
// bottom += v.height + bottomBarEdgeInsets.top + bottomBarEdgeInsets.bottom
// }
//
// if let v = contentView {
// bottom += contentViewEdgeInsets.bottom
// container.layout(v).bottom(bottom)
// bottom += v.height + contentViewEdgeInsets.top
// }
//
// if let v = presenterView {
// bottom += presenterViewEdgeInsets.bottom
// container.layout(v).bottom(bottom)
// bottom += v.height + presenterViewEdgeInsets.top
// }
//
// if let v = toolbar {
// bottom += toolbarEdgeInsets.bottom
// container.layout(v).bottom(bottom)
// }
} }
} }
...@@ -122,6 +122,7 @@ open class TabBar: Bar { ...@@ -122,6 +122,7 @@ open class TabBar: Bar {
line.height = value line.height = value
} }
} }
open override func layoutSubviews() { open override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
guard willLayout else { guard willLayout else {
......
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