Commit d8da014e by Daniel Dahan

fixed conflicts in merge

parents 6a1caacb 05cedcf6
...@@ -345,8 +345,6 @@ public class ImageCardView : MaterialPulseView { ...@@ -345,8 +345,6 @@ public class ImageCardView : MaterialPulseView {
borderWidth = MaterialTheme.imageCardView.borderWidth borderWidth = MaterialTheme.imageCardView.borderWidth
borderColor = MaterialTheme.imageCardView.bordercolor borderColor = MaterialTheme.imageCardView.bordercolor
dividerColor = MaterialTheme.imageCardView.dividerColor dividerColor = MaterialTheme.imageCardView.dividerColor
visualLayer.masksToBounds = true
} }
/** /**
...@@ -493,7 +491,7 @@ public class ImageCardView : MaterialPulseView { ...@@ -493,7 +491,7 @@ public class ImageCardView : MaterialPulseView {
internal func prepareImageLayer() { internal func prepareImageLayer() {
imageLayer = CAShapeLayer() imageLayer = CAShapeLayer()
imageLayer.zPosition = 0 imageLayer.zPosition = 0
visualLayer.addSublayer(imageLayer) materialLayer.visualLayer.addSublayer(imageLayer)
} }
// //
......
...@@ -21,6 +21,20 @@ import UIKit ...@@ -21,6 +21,20 @@ import UIKit
@objc(MaterialButton) @objc(MaterialButton)
public class MaterialButton : UIButton { public class MaterialButton : UIButton {
/** /**
:name: layerClass
*/
public override class func layerClass() -> AnyClass {
return MaterialLayer.self
}
/**
:name: materialLayer
*/
public var materialLayer: MaterialLayer {
return layer as! MaterialLayer
}
/**
:name: visualLayer :name: visualLayer
*/ */
public private(set) lazy var visualLayer: CAShapeLayer = CAShapeLayer() public private(set) lazy var visualLayer: CAShapeLayer = CAShapeLayer()
...@@ -33,7 +47,14 @@ public class MaterialButton : UIButton { ...@@ -33,7 +47,14 @@ public class MaterialButton : UIButton {
/** /**
:name: delegate :name: delegate
*/ */
public weak var delegate: MaterialAnimationDelegate? public weak var delegate: MaterialAnimationDelegate? {
get {
return materialLayer.animationDelegate
}
set(value) {
materialLayer.animationDelegate = delegate
}
}
/** /**
:name: pulseScale :name: pulseScale
...@@ -81,11 +102,23 @@ public class MaterialButton : UIButton { ...@@ -81,11 +102,23 @@ public class MaterialButton : UIButton {
} }
/** /**
:name: masksToBounds
*/
public var masksToBounds: Bool {
get {
return materialLayer.masksToBounds
}
set(value) {
materialLayer.masksToBounds = value
}
}
/**
:name: backgroundColor :name: backgroundColor
*/ */
public override var backgroundColor: UIColor? { public override var backgroundColor: UIColor? {
didSet { didSet {
layer.backgroundColor = backgroundColor?.CGColor materialLayer.backgroundColor = backgroundColor?.CGColor
} }
} }
...@@ -94,10 +127,10 @@ public class MaterialButton : UIButton { ...@@ -94,10 +127,10 @@ public class MaterialButton : UIButton {
*/ */
public var x: CGFloat { public var x: CGFloat {
get { get {
return frame.origin.x return materialLayer.x
} }
set(value) { set(value) {
frame.origin.x = value materialLayer.x = value
} }
} }
...@@ -106,10 +139,10 @@ public class MaterialButton : UIButton { ...@@ -106,10 +139,10 @@ public class MaterialButton : UIButton {
*/ */
public var y: CGFloat { public var y: CGFloat {
get { get {
return frame.origin.y return materialLayer.y
} }
set(value) { set(value) {
frame.origin.y = value materialLayer.y = value
} }
} }
...@@ -118,13 +151,10 @@ public class MaterialButton : UIButton { ...@@ -118,13 +151,10 @@ public class MaterialButton : UIButton {
*/ */
public var width: CGFloat { public var width: CGFloat {
get { get {
return frame.size.width return materialLayer.width
} }
set(value) { set(value) {
frame.size.width = value materialLayer.width = value
if .None != shape {
frame.size.height = value
}
} }
} }
...@@ -133,13 +163,10 @@ public class MaterialButton : UIButton { ...@@ -133,13 +163,10 @@ public class MaterialButton : UIButton {
*/ */
public var height: CGFloat { public var height: CGFloat {
get { get {
return frame.size.height return materialLayer.height
} }
set(value) { set(value) {
frame.size.height = value materialLayer.height = value
if .None != shape {
frame.size.width = value
}
} }
} }
...@@ -189,28 +216,11 @@ public class MaterialButton : UIButton { ...@@ -189,28 +216,11 @@ public class MaterialButton : UIButton {
} }
/** /**
:name: masksToBounds
*/
public var masksToBounds: Bool {
get {
return visualLayer.masksToBounds
}
set(value) {
visualLayer.masksToBounds = value
}
}
/**
:name: cornerRadius :name: cornerRadius
*/ */
public var cornerRadius: MaterialRadius? { public var cornerRadius: MaterialRadius {
didSet { didSet {
if let v: MaterialRadius = cornerRadius { materialLayer.cornerRadius = MaterialRadiusToValue(cornerRadius)
layer.cornerRadius = MaterialRadiusToValue(v)
if .Circle == shape {
shape = .None
}
}
} }
} }
...@@ -221,9 +231,9 @@ public class MaterialButton : UIButton { ...@@ -221,9 +231,9 @@ public class MaterialButton : UIButton {
didSet { didSet {
if .None != shape { if .None != shape {
if width < height { if width < height {
frame.size.width = height width = height
} else { } else {
frame.size.height = width height = width
} }
} }
} }
...@@ -234,7 +244,7 @@ public class MaterialButton : UIButton { ...@@ -234,7 +244,7 @@ public class MaterialButton : UIButton {
*/ */
public var borderWidth: MaterialBorder { public var borderWidth: MaterialBorder {
didSet { didSet {
layer.borderWidth = MaterialBorderToValue(borderWidth) materialLayer.borderWidth = MaterialBorderToValue(borderWidth)
} }
} }
...@@ -243,7 +253,7 @@ public class MaterialButton : UIButton { ...@@ -243,7 +253,7 @@ public class MaterialButton : UIButton {
*/ */
public var borderColor: UIColor? { public var borderColor: UIColor? {
didSet { didSet {
layer.borderColor = borderColor?.CGColor materialLayer.borderColor = borderColor?.CGColor
} }
} }
...@@ -301,6 +311,7 @@ public class MaterialButton : UIButton { ...@@ -301,6 +311,7 @@ public class MaterialButton : UIButton {
shadowDepth = .None shadowDepth = .None
shape = .None shape = .None
contentInsets = .None contentInsets = .None
cornerRadius = .None
super.init(coder: aDecoder) super.init(coder: aDecoder)
} }
...@@ -312,69 +323,33 @@ public class MaterialButton : UIButton { ...@@ -312,69 +323,33 @@ public class MaterialButton : UIButton {
shadowDepth = .None shadowDepth = .None
shape = .None shape = .None
contentInsets = .None contentInsets = .None
cornerRadius = .None
super.init(frame: frame) super.init(frame: frame)
prepareView() prepareView()
} }
/**
:name: init
*/
public convenience init() {
self.init(frame: CGRectNull)
}
/**
:name: layoutSubviews
*/
public override func layoutSubviews() {
super.layoutSubviews()
prepareShape()
visualLayer.frame = bounds
visualLayer.position = CGPointMake(width / 2, height / 2)
visualLayer.cornerRadius = layer.cornerRadius
}
/** /**
:name: animation :name: layoutSublayersOfLayer
*/ */
public func animation(animation: CAAnimation) { public override func layoutSublayersOfLayer(layer: CALayer) {
animation.delegate = self super.layoutSublayersOfLayer(layer)
if let a: CABasicAnimation = animation as? CABasicAnimation { if self.layer == layer {
a.fromValue = (nil == layer.presentationLayer() ? layer : layer.presentationLayer() as! CALayer).valueForKeyPath(a.keyPath!) prepareShape()
}
if let a: CAPropertyAnimation = animation as? CAPropertyAnimation {
layer.addAnimation(a, forKey: a.keyPath!)
} else if let a: CAAnimationGroup = animation as? CAAnimationGroup {
layer.addAnimation(a, forKey: nil)
} else if let a: CATransition = animation as? CATransition {
layer.addAnimation(a, forKey: kCATransition)
} }
} }
/** /**
:name: animationDidStart :name: init
*/ */
public override func animationDidStart(anim: CAAnimation) { public convenience init() {
delegate?.materialAnimationDidStart?(anim) self.init(frame: CGRectNull)
} }
/** /**
:name: animationDidStop :name: animation
*/ */
public override func animationDidStop(anim: CAAnimation, finished flag: Bool) { public func animation(animation: CAAnimation) {
if let a: CAPropertyAnimation = anim as? CAPropertyAnimation { materialLayer.animation(animation)
if let b: CABasicAnimation = a as? CABasicAnimation {
MaterialAnimation.animationDisabled({
self.layer.setValue(nil == b.toValue ? b.byValue : b.toValue, forKey: b.keyPath!)
})
}
delegate?.materialAnimationDidStop?(anim, finished: flag)
layer.removeAnimationForKey(a.keyPath!)
} else if let a: CAAnimationGroup = anim as? CAAnimationGroup {
for x in a.animations! {
animationDidStop(x, finished: true)
}
}
} }
/** /**
...@@ -442,14 +417,8 @@ public class MaterialButton : UIButton { ...@@ -442,14 +417,8 @@ public class MaterialButton : UIButton {
:name: prepareView :name: prepareView
*/ */
public func prepareView() { public func prepareView() {
// visualLayer
visualLayer.zPosition = -1
layer.addSublayer(visualLayer)
// pulseLayer // pulseLayer
pulseLayer.hidden = true materialLayer.visualLayer.addSublayer(pulseLayer)
pulseLayer.zPosition = 1
visualLayer.addSublayer(pulseLayer)
} }
// //
...@@ -457,7 +426,7 @@ public class MaterialButton : UIButton { ...@@ -457,7 +426,7 @@ public class MaterialButton : UIButton {
// //
internal func prepareShape() { internal func prepareShape() {
if .Circle == shape { if .Circle == shape {
layer.cornerRadius = width / 2 materialLayer.cornerRadius = width / 2
} }
} }
......
...@@ -24,7 +24,7 @@ public class MaterialLayer : CAShapeLayer { ...@@ -24,7 +24,7 @@ public class MaterialLayer : CAShapeLayer {
:name: visualLayer :name: visualLayer
*/ */
public private(set) lazy var visualLayer: CAShapeLayer = CAShapeLayer() public private(set) lazy var visualLayer: CAShapeLayer = CAShapeLayer()
/** /**
:name: x :name: x
*/ */
...@@ -292,7 +292,7 @@ public class MaterialLayer : CAShapeLayer { ...@@ -292,7 +292,7 @@ public class MaterialLayer : CAShapeLayer {
} }
// //
// :name: prepareShape // :name: prepareShape
// //
internal func prepareShape() { internal func prepareShape() {
if .Circle == shape { if .Circle == shape {
......
...@@ -131,13 +131,6 @@ public class MaterialPulseView : MaterialView { ...@@ -131,13 +131,6 @@ public class MaterialPulseView : MaterialView {
} }
/** /**
:name: actionForLayer
*/
public override func actionForLayer(layer: CALayer, forKey event: String) -> CAAction? {
return nil // returning nil enables the animations for the layer property that are normally disabled.
}
/**
:name: prepareView :name: prepareView
*/ */
public override func prepareView() { public override func prepareView() {
...@@ -159,9 +152,7 @@ public class MaterialPulseView : MaterialView { ...@@ -159,9 +152,7 @@ public class MaterialPulseView : MaterialView {
borderColor = MaterialTheme.pulseView.bordercolor borderColor = MaterialTheme.pulseView.bordercolor
// pulseLayer // pulseLayer
pulseLayer.hidden = true materialLayer.visualLayer.addSublayer(pulseLayer)
pulseLayer.zPosition = 1
visualLayer.addSublayer(pulseLayer)
} }
// //
......
...@@ -20,22 +20,41 @@ import UIKit ...@@ -20,22 +20,41 @@ import UIKit
@objc(MaterialView) @objc(MaterialView)
public class MaterialView : UIView { public class MaterialView : UIView {
// /**
// :name: visualLayer :name: layerClass
// */
public private(set) lazy var visualLayer: CAShapeLayer = CAShapeLayer() public override class func layerClass() -> AnyClass {
return MaterialLayer.self
}
/** /**
:name: visualLayer :name: materialLayer
*/ */
public weak var delegate: MaterialAnimationDelegate? public var materialLayer: MaterialLayer {
return layer as! MaterialLayer
}
/**
:name: delegate
*/
public weak var delegate: MaterialAnimationDelegate? {
get {
return materialLayer.animationDelegate
}
set(value) {
materialLayer.animationDelegate = delegate
}
}
/** /**
:name: image :name: image
*/ */
public var image: UIImage? { public var image: UIImage? {
didSet { get {
visualLayer.contents = image?.CGImage return materialLayer.image
}
set(value) {
materialLayer.image = value
} }
} }
...@@ -43,8 +62,11 @@ public class MaterialView : UIView { ...@@ -43,8 +62,11 @@ public class MaterialView : UIView {
:name: contentsRect :name: contentsRect
*/ */
public var contentsRect: CGRect { public var contentsRect: CGRect {
didSet { get {
visualLayer.contentsRect = contentsRect return materialLayer.contentsRect
}
set(value) {
materialLayer.contentsRect = value
} }
} }
...@@ -52,8 +74,11 @@ public class MaterialView : UIView { ...@@ -52,8 +74,11 @@ public class MaterialView : UIView {
:name: contentsCenter :name: contentsCenter
*/ */
public var contentsCenter: CGRect { public var contentsCenter: CGRect {
didSet { get {
visualLayer.contentsCenter = contentsCenter return materialLayer.contentsCenter
}
set(value) {
materialLayer.contentsCenter = value
} }
} }
...@@ -61,8 +86,11 @@ public class MaterialView : UIView { ...@@ -61,8 +86,11 @@ public class MaterialView : UIView {
:name: contentsScale :name: contentsScale
*/ */
public var contentsScale: CGFloat { public var contentsScale: CGFloat {
didSet { get {
visualLayer.contentsScale = contentsScale return materialLayer.contentsScale
}
set(value) {
materialLayer.contentsScale = value
} }
} }
...@@ -71,7 +99,7 @@ public class MaterialView : UIView { ...@@ -71,7 +99,7 @@ public class MaterialView : UIView {
*/ */
public var contentsGravity: MaterialGravity { public var contentsGravity: MaterialGravity {
didSet { didSet {
visualLayer.contentsGravity = MaterialGravityToString(contentsGravity) materialLayer.contentsGravity = MaterialGravityToString(contentsGravity)
} }
} }
...@@ -80,10 +108,10 @@ public class MaterialView : UIView { ...@@ -80,10 +108,10 @@ public class MaterialView : UIView {
*/ */
public var masksToBounds: Bool { public var masksToBounds: Bool {
get { get {
return visualLayer.masksToBounds return materialLayer.masksToBounds
} }
set(value) { set(value) {
visualLayer.masksToBounds = value materialLayer.masksToBounds = value
} }
} }
...@@ -92,7 +120,7 @@ public class MaterialView : UIView { ...@@ -92,7 +120,7 @@ public class MaterialView : UIView {
*/ */
public override var backgroundColor: UIColor? { public override var backgroundColor: UIColor? {
didSet { didSet {
layer.backgroundColor = backgroundColor?.CGColor materialLayer.backgroundColor = backgroundColor?.CGColor
} }
} }
...@@ -101,10 +129,10 @@ public class MaterialView : UIView { ...@@ -101,10 +129,10 @@ public class MaterialView : UIView {
*/ */
public var x: CGFloat { public var x: CGFloat {
get { get {
return frame.origin.x return materialLayer.x
} }
set(value) { set(value) {
frame.origin.x = value materialLayer.x = value
} }
} }
...@@ -113,10 +141,10 @@ public class MaterialView : UIView { ...@@ -113,10 +141,10 @@ public class MaterialView : UIView {
*/ */
public var y: CGFloat { public var y: CGFloat {
get { get {
return frame.origin.y return materialLayer.y
} }
set(value) { set(value) {
frame.origin.y = value materialLayer.y = value
} }
} }
...@@ -125,13 +153,10 @@ public class MaterialView : UIView { ...@@ -125,13 +153,10 @@ public class MaterialView : UIView {
*/ */
public var width: CGFloat { public var width: CGFloat {
get { get {
return frame.size.width return materialLayer.width
} }
set(value) { set(value) {
frame.size.width = value materialLayer.width = value
if .None != shape {
frame.size.height = value
}
} }
} }
...@@ -140,13 +165,10 @@ public class MaterialView : UIView { ...@@ -140,13 +165,10 @@ public class MaterialView : UIView {
*/ */
public var height: CGFloat { public var height: CGFloat {
get { get {
return frame.size.height return materialLayer.height
} }
set(value) { set(value) {
frame.size.height = value materialLayer.height = value
if .None != shape {
frame.size.width = value
}
} }
} }
...@@ -198,14 +220,9 @@ public class MaterialView : UIView { ...@@ -198,14 +220,9 @@ public class MaterialView : UIView {
/** /**
:name: cornerRadius :name: cornerRadius
*/ */
public var cornerRadius: MaterialRadius? { public var cornerRadius: MaterialRadius {
didSet { didSet {
if let v: MaterialRadius = cornerRadius { materialLayer.cornerRadius = MaterialRadiusToValue(cornerRadius)
layer.cornerRadius = MaterialRadiusToValue(v)
if .Circle == shape {
shape = .None
}
}
} }
} }
...@@ -216,9 +233,9 @@ public class MaterialView : UIView { ...@@ -216,9 +233,9 @@ public class MaterialView : UIView {
didSet { didSet {
if .None != shape { if .None != shape {
if width < height { if width < height {
frame.size.width = height width = height
} else { } else {
frame.size.height = width height = width
} }
} }
} }
...@@ -229,7 +246,7 @@ public class MaterialView : UIView { ...@@ -229,7 +246,7 @@ public class MaterialView : UIView {
*/ */
public var borderWidth: MaterialBorder { public var borderWidth: MaterialBorder {
didSet { didSet {
layer.borderWidth = MaterialBorderToValue(borderWidth) materialLayer.borderWidth = MaterialBorderToValue(borderWidth)
} }
} }
...@@ -238,7 +255,7 @@ public class MaterialView : UIView { ...@@ -238,7 +255,7 @@ public class MaterialView : UIView {
*/ */
public var borderColor: UIColor? { public var borderColor: UIColor? {
didSet { didSet {
layer.borderColor = borderColor?.CGColor materialLayer.borderColor = borderColor?.CGColor
} }
} }
...@@ -282,13 +299,11 @@ public class MaterialView : UIView { ...@@ -282,13 +299,11 @@ public class MaterialView : UIView {
:name: init :name: init
*/ */
public required init?(coder aDecoder: NSCoder) { public required init?(coder aDecoder: NSCoder) {
contentsRect = MaterialTheme.view.contentsRect
contentsCenter = MaterialTheme.view.contentsCenter
contentsScale = MaterialTheme.view.contentsScale
contentsGravity = MaterialTheme.view.contentsGravity contentsGravity = MaterialTheme.view.contentsGravity
cornerRadius = .None
shape = .None
borderWidth = MaterialTheme.view.borderWidth borderWidth = MaterialTheme.view.borderWidth
shadowDepth = .None shadowDepth = .None
shape = .None
super.init(coder: aDecoder) super.init(coder: aDecoder)
} }
...@@ -296,77 +311,37 @@ public class MaterialView : UIView { ...@@ -296,77 +311,37 @@ public class MaterialView : UIView {
:name: init :name: init
*/ */
public override init(frame: CGRect) { public override init(frame: CGRect) {
contentsRect = MaterialTheme.view.contentsRect
contentsCenter = MaterialTheme.view.contentsCenter
contentsScale = MaterialTheme.view.contentsScale
contentsGravity = MaterialTheme.view.contentsGravity contentsGravity = MaterialTheme.view.contentsGravity
cornerRadius = .None
shape = .None
borderWidth = MaterialTheme.view.borderWidth borderWidth = MaterialTheme.view.borderWidth
shadowDepth = .None shadowDepth = .None
shape = .None
super.init(frame: frame) super.init(frame: frame)
prepareView() prepareView()
} }
/** /**
:name: init :name: layoutSublayersOfLayer
*/ */
public convenience init() { public override func layoutSublayersOfLayer(layer: CALayer) {
self.init(frame: CGRectNull) super.layoutSublayersOfLayer(layer)
if self.layer == layer {
prepareShape()
}
} }
/** /**
:name: layoutSubviews :name: init
*/ */
public override func layoutSubviews() { public convenience init() {
super.layoutSubviews() self.init(frame: CGRectNull)
prepareShape()
visualLayer.frame = bounds
visualLayer.position = CGPointMake(width / 2, height / 2)
visualLayer.cornerRadius = layer.cornerRadius
} }
/** /**
:name: animation :name: animation
*/ */
public func animation(animation: CAAnimation) { public func animation(animation: CAAnimation) {
animation.delegate = self materialLayer.animation(animation)
if let a: CABasicAnimation = animation as? CABasicAnimation {
a.fromValue = (nil == layer.presentationLayer() ? layer : layer.presentationLayer() as! CALayer).valueForKeyPath(a.keyPath!)
}
if let a: CAPropertyAnimation = animation as? CAPropertyAnimation {
layer.addAnimation(a, forKey: a.keyPath!)
} else if let a: CAAnimationGroup = animation as? CAAnimationGroup {
layer.addAnimation(a, forKey: nil)
} else if let a: CATransition = animation as? CATransition {
layer.addAnimation(a, forKey: kCATransition)
}
}
/**
:name: animationDidStart
*/
public override func animationDidStart(anim: CAAnimation) {
delegate?.materialAnimationDidStart?(anim)
}
/**
:name: animationDidStop
*/
public override func animationDidStop(anim: CAAnimation, finished flag: Bool) {
if let a: CAPropertyAnimation = anim as? CAPropertyAnimation {
if let b: CABasicAnimation = a as? CABasicAnimation {
MaterialAnimation.animationDisabled({
self.layer.setValue(nil == b.toValue ? b.byValue : b.toValue, forKey: b.keyPath!)
})
}
delegate?.materialAnimationDidStop?(anim, finished: flag)
layer.removeAnimationForKey(a.keyPath!)
} else if let a: CAAnimationGroup = anim as? CAAnimationGroup {
for x in a.animations! {
animationDidStop(x, finished: true)
}
}
} }
// //
...@@ -376,16 +351,16 @@ public class MaterialView : UIView { ...@@ -376,16 +351,16 @@ public class MaterialView : UIView {
userInteractionEnabled = MaterialTheme.view.userInteractionEnabled userInteractionEnabled = MaterialTheme.view.userInteractionEnabled
backgroundColor = MaterialTheme.view.backgroundColor backgroundColor = MaterialTheme.view.backgroundColor
shadowDepth = MaterialTheme.view.shadowDepth contentsRect = MaterialTheme.view.contentsRect
contentsCenter = MaterialTheme.view.contentsCenter
contentsScale = MaterialTheme.view.contentsScale
shape = .None
shadowColor = MaterialTheme.view.shadowColor shadowColor = MaterialTheme.view.shadowColor
zPosition = MaterialTheme.view.zPosition zPosition = MaterialTheme.view.zPosition
masksToBounds = MaterialTheme.view.masksToBounds masksToBounds = MaterialTheme.view.masksToBounds
cornerRadius = MaterialTheme.view.cornerRadius cornerRadius = MaterialTheme.view.cornerRadius
borderColor = MaterialTheme.view.bordercolor borderColor = MaterialTheme.view.bordercolor
// visualLayer
visualLayer.zPosition = -1
layer.addSublayer(visualLayer)
} }
// //
...@@ -393,7 +368,7 @@ public class MaterialView : UIView { ...@@ -393,7 +368,7 @@ public class MaterialView : UIView {
// //
internal func prepareShape() { internal func prepareShape() {
if .Circle == shape { if .Circle == shape {
layer.cornerRadius = width / 2 materialLayer.cornerRadius = width / 2
} }
} }
} }
......
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