Commit 0d43dc6e by Daniel Dahan

development: updated Layout and Grid calculations

parent c1c421de
Pod::Spec.new do |s|
s.name = 'Material'
s.version = '2.3.22'
s.version = '2.4.0'
s.license = 'BSD-3-Clause'
s.summary = 'Material is an animation and graphics framework that is used to create beautiful applications.'
s.homepage = 'http://materialswift.com'
......
......@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>2.3.22</string>
<string>2.4.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
......
......@@ -93,7 +93,8 @@ open class CollectionReusableView: UICollectionReusableView, Pulseable {
much greater flexibility than the contentsGravity property in
terms of how the image is cropped and stretched.
*/
@IBInspectable open var contentsRect: CGRect {
@IBInspectable
open var contentsRect: CGRect {
get {
return visualLayer.contentsRect
}
......@@ -106,7 +107,8 @@ open class CollectionReusableView: UICollectionReusableView, Pulseable {
A CGRect that defines a stretchable region inside the visualLayer
with a fixed border around the edge.
*/
@IBInspectable open var contentsCenter: CGRect {
@IBInspectable
open var contentsCenter: CGRect {
get {
return visualLayer.contentsCenter
}
......@@ -120,7 +122,8 @@ open class CollectionReusableView: UICollectionReusableView, Pulseable {
dimensions of the visualLayer's contents property and the size
of the view. By default, this value is set to the Screen.scale.
*/
@IBInspectable open var contentsScale: CGFloat {
@IBInspectable
open var contentsScale: CGFloat {
get {
return visualLayer.contentsScale
}
......@@ -137,7 +140,8 @@ open class CollectionReusableView: UICollectionReusableView, Pulseable {
}
/// Determines how content should be aligned within the visualLayer's bounds.
@IBInspectable open var contentsGravity: String {
@IBInspectable
open var contentsGravity: String {
get {
return visualLayer.contentsGravity
}
......@@ -157,7 +161,8 @@ open class CollectionReusableView: UICollectionReusableView, Pulseable {
}
/// A reference to EdgeInsets.
@IBInspectable open var contentEdgeInsets: UIEdgeInsets {
@IBInspectable
open var contentEdgeInsets: UIEdgeInsets {
get {
return grid.contentEdgeInsets
}
......@@ -174,7 +179,8 @@ open class CollectionReusableView: UICollectionReusableView, Pulseable {
}
/// A wrapper around grid.interimSpace.
@IBInspectable open var interimSpace: InterimSpace {
@IBInspectable
open var interimSpace: InterimSpace {
get {
return grid.interimSpace
}
......@@ -184,7 +190,8 @@ open class CollectionReusableView: UICollectionReusableView, Pulseable {
}
/// A property that accesses the backing layer's background
@IBInspectable open override var backgroundColor: UIColor? {
@IBInspectable
open override var backgroundColor: UIColor? {
didSet {
layer.backgroundColor = backgroundColor?.cgColor
}
......@@ -283,7 +290,6 @@ open class CollectionReusableView: UICollectionReusableView, Pulseable {
*/
open func prepare() {
contentScaleFactor = Screen.scale
pulseAnimation = .none
prepareVisualLayer()
preparePulse()
}
......@@ -293,6 +299,7 @@ extension CollectionReusableView {
/// Prepares the pulse motion.
fileprivate func preparePulse() {
pulse = Pulse(pulseView: self, pulseLayer: visualLayer)
pulseAnimation = .none
}
/// Prepares the visualLayer property.
......
......@@ -204,16 +204,13 @@ public struct Grid {
}
}
canvas.setNeedsLayout()
canvas.layoutIfNeeded()
let count = views.count
guard 0 < canvas.width && 0 < canvas.height else {
guard 0 < count else {
return
}
let count = views.count
guard 0 < count else {
guard 0 < canvas.width && 0 < canvas.height else {
return
}
......
......@@ -113,9 +113,7 @@ open class Layer: CAShapeLayer {
open override var cornerRadius: CGFloat {
didSet {
layoutShadowPath()
if .circle == shapePreset {
shapePreset = .none
}
shapePreset = .none
}
}
......
......@@ -639,6 +639,8 @@ extension Layout {
public class func width(parent: UIView, child: UIView, width: CGFloat = 0) {
prepareForConstraint(parent, child: child)
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .width, multiplier: 1, constant: width))
child.setNeedsLayout()
child.layoutIfNeeded()
}
/**
......@@ -650,6 +652,8 @@ extension Layout {
public class func height(parent: UIView, child: UIView, height: CGFloat = 0) {
prepareForConstraint(parent, child: child)
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .height, multiplier: 1, constant: height))
child.setNeedsLayout()
child.layoutIfNeeded()
}
/**
......@@ -682,6 +686,10 @@ extension Layout {
}
parent.addConstraint(NSLayoutConstraint(item: children[children.count - 1], attribute: .right, relatedBy: .equal, toItem: parent, attribute: .right, multiplier: 1, constant: -right))
}
for child in children {
child.setNeedsLayout()
child.layoutIfNeeded()
}
}
/**
......@@ -703,6 +711,10 @@ extension Layout {
}
parent.addConstraint(NSLayoutConstraint(item: children[children.count - 1], attribute: .bottom, relatedBy: .equal, toItem: parent, attribute: .bottom, multiplier: 1, constant: -bottom))
}
for child in children {
child.setNeedsLayout()
child.layoutIfNeeded()
}
}
/**
......@@ -716,6 +728,8 @@ extension Layout {
prepareForConstraint(parent, child: child)
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .left, relatedBy: .equal, toItem: parent, attribute: .left, multiplier: 1, constant: left))
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .right, relatedBy: .equal, toItem: parent, attribute: .right, multiplier: 1, constant: -right))
child.setNeedsLayout()
child.layoutIfNeeded()
}
/**
......@@ -729,6 +743,8 @@ extension Layout {
prepareForConstraint(parent, child: child)
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .top, relatedBy: .equal, toItem: parent, attribute: .top, multiplier: 1, constant: top))
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .bottom, relatedBy: .equal, toItem: parent, attribute: .bottom, multiplier: 1, constant: -bottom))
child.setNeedsLayout()
child.layoutIfNeeded()
}
/**
......@@ -755,6 +771,8 @@ extension Layout {
public class func top(parent: UIView, child: UIView, top: CGFloat = 0) {
prepareForConstraint(parent, child: child)
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .top, relatedBy: .equal, toItem: parent, attribute: .top, multiplier: 1, constant: top))
child.setNeedsLayout()
child.layoutIfNeeded()
}
/**
......@@ -767,6 +785,8 @@ extension Layout {
public class func left(parent: UIView, child: UIView, left: CGFloat = 0) {
prepareForConstraint(parent, child: child)
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .left, relatedBy: .equal, toItem: parent, attribute: .left, multiplier: 1, constant: left))
child.setNeedsLayout()
child.layoutIfNeeded()
}
/**
......@@ -779,6 +799,8 @@ extension Layout {
public class func bottom(parent: UIView, child: UIView, bottom: CGFloat = 0) {
prepareForConstraint(parent, child: child)
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .bottom, relatedBy: .equal, toItem: parent, attribute: .bottom, multiplier: 1, constant: -bottom))
child.setNeedsLayout()
child.layoutIfNeeded()
}
/**
......@@ -791,6 +813,8 @@ extension Layout {
public class func right(parent: UIView, child: UIView, right: CGFloat = 0) {
prepareForConstraint(parent, child: child)
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .right, relatedBy: .equal, toItem: parent, attribute: .right, multiplier: 1, constant: -right))
child.setNeedsLayout()
child.layoutIfNeeded()
}
/**
......@@ -868,6 +892,8 @@ extension Layout {
public class func centerHorizontally(parent: UIView, child: UIView, offset: CGFloat = 0) {
prepareForConstraint(parent, child: child)
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .centerX, relatedBy: .equal, toItem: parent, attribute: .centerX, multiplier: 1, constant: offset))
child.setNeedsLayout()
child.layoutIfNeeded()
}
/**
......@@ -880,6 +906,8 @@ extension Layout {
public class func centerVertically(parent: UIView, child: UIView, offset: CGFloat = 0) {
prepareForConstraint(parent, child: child)
parent.addConstraint(NSLayoutConstraint(item: child, attribute: .centerY, relatedBy: .equal, toItem: parent, attribute: .centerY, multiplier: 1, constant: offset))
child.setNeedsLayout()
child.layoutIfNeeded()
}
/**
......
......@@ -30,40 +30,36 @@
import UIKit
internal struct MaterialLayer {
fileprivate struct MaterialLayer {
/// A reference to the CALayer.
internal weak var layer: CALayer?
fileprivate weak var layer: CALayer?
/// A property that sets the height of the layer's frame.
internal var heightPreset = HeightPreset.default {
fileprivate var heightPreset = HeightPreset.default {
didSet {
layer?.height = CGFloat(heightPreset.rawValue)
}
}
/// A property that sets the cornerRadius of the backing layer.
internal var cornerRadiusPreset = CornerRadiusPreset.none {
fileprivate var cornerRadiusPreset = CornerRadiusPreset.none {
didSet {
layer?.cornerRadius = CornerRadiusPresetToValue(preset: cornerRadiusPreset)
}
}
/// A preset property to set the borderWidth.
internal var borderWidthPreset = BorderWidthPreset.none {
fileprivate var borderWidthPreset = BorderWidthPreset.none {
didSet {
layer?.borderWidth = BorderWidthPresetToValue(preset: borderWidthPreset)
}
}
/// A preset property to set the shape.
internal var shapePreset = ShapePreset.none {
didSet {
layer?.layoutShape()
}
}
fileprivate var shapePreset = ShapePreset.none
/// A preset value for Depth.
internal var depthPreset: DepthPreset {
fileprivate var depthPreset: DepthPreset {
get {
return depth.preset
}
......@@ -73,7 +69,7 @@ internal struct MaterialLayer {
}
/// Grid reference.
internal var depth = Depth.zero {
fileprivate var depth = Depth.zero {
didSet {
guard let v = layer else {
return
......@@ -87,24 +83,24 @@ internal struct MaterialLayer {
}
/// Enables automatic shadowPath sizing.
internal var isShadowPathAutoSizing = false
fileprivate var isShadowPathAutoSizing = false
/**
Initializer that takes in a CALayer.
- Parameter view: A CALayer reference.
*/
internal init(layer: CALayer?) {
fileprivate init(layer: CALayer?) {
self.layer = layer
}
}
/// A memory reference to the MaterialLayer instance for CALayer extensions.
private var MaterialLayerKey: UInt8 = 0
fileprivate var MaterialLayerKey: UInt8 = 0
/// Grid extension for UIView.
extension CALayer {
/// MaterialLayer Reference.
internal var materialLayer: MaterialLayer {
fileprivate var materialLayer: MaterialLayer {
get {
return AssociatedObject(base: self, key: &MaterialLayerKey) {
return MaterialLayer(layer: self)
......@@ -273,17 +269,23 @@ extension CALayer {
/// Manages the layout for the shape of the view instance.
open func layoutShape() {
if .none != shapePreset {
if frame.height > frame.width {
frame.size.width = frame.height
} else if frame.height < frame.width {
frame.size.height = frame.width
}
guard .none != shapePreset else {
return
}
if .circle == shapePreset {
cornerRadius = bounds.size.width / 2
if 0 == frame.width {
frame.size.width = frame.height
}
if 0 == frame.height {
frame.size.height = frame.width
}
guard .circle == shapePreset else {
return
}
cornerRadius = bounds.size.width / 2
}
/// Sets the shadow path.
......
......@@ -142,6 +142,7 @@ open class TabBar: Bar {
prepareLineAnimationHandler(button: b)
}
}
contentView.grid.axis.columns = buttons.count
contentView.grid.reload()
if nil == selected {
......
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