Commit e15b9fff by Daniel Dahan

cleanup and removal of duplicate code

parent 454b272a
...@@ -30,18 +30,18 @@ ...@@ -30,18 +30,18 @@
import UIKit import UIKit
public typealias MaterialAnimationRotationModeType = String public typealias AnimateRotationModeType = String
public enum MaterialAnimationRotationMode { public enum AnimateRotationMode {
case None case None
case Auto case Auto
case AutoReverse case AutoReverse
} }
/** /**
:name: MaterialAnimationRotationModeToValue :name: AnimateRotationModeToValue
*/ */
public func MaterialAnimationRotationModeToValue(mode: MaterialAnimationRotationMode) -> MaterialAnimationRotationModeType? { public func AnimateRotationModeToValue(mode: AnimateRotationMode) -> AnimateRotationModeType? {
switch mode { switch mode {
case .none: case .none:
return nil return nil
...@@ -52,15 +52,15 @@ public func MaterialAnimationRotationModeToValue(mode: MaterialAnimationRotation ...@@ -52,15 +52,15 @@ public func MaterialAnimationRotationModeToValue(mode: MaterialAnimationRotation
} }
} }
public extension MaterialAnimation { public extension Animate {
/** /**
:name: path :name: path
*/ */
public static func path(bezierPath: UIBezierPath, mode: MaterialAnimationRotationMode = .Auto, duration: CFTimeInterval? = nil) -> CAKeyframeAnimation { public static func path(bezierPath: UIBezierPath, mode: AnimateRotationMode = .Auto, duration: CFTimeInterval? = nil) -> CAKeyframeAnimation {
let animation: CAKeyframeAnimation = CAKeyframeAnimation() let animation: CAKeyframeAnimation = CAKeyframeAnimation()
animation.keyPath = "position" animation.keyPath = "position"
animation.path = bezierPath.CGPath animation.path = bezierPath.CGPath
animation.rotationMode = MaterialAnimationRotationModeToValue(mode) animation.rotationMode = AnimateRotationModeToValue(mode)
if let v: CFTimeInterval = duration { if let v: CFTimeInterval = duration {
animation.duration = v animation.duration = v
} }
......
...@@ -30,52 +30,46 @@ ...@@ -30,52 +30,46 @@
import UIKit import UIKit
@objc(MaterialAnimationDelegate) public typealias AnimationFillModeType = String
public protocol MaterialAnimationDelegate : MaterialDelegate {
optional func materialAnimationDidStart(animation: CAAnimation)
optional func materialAnimationDidStop(animation: CAAnimation, finished flag: Bool)
}
public typealias MaterialAnimationFillModeType = String
public enum MaterialAnimationFillMode { public enum AnimationFillMode {
case Forwards case forwards
case Backwards case backwards
case Both case both
case Removed case removed
} }
/** /**
:name: MaterialAnimationFillModeToValue :name: AnimationFillModeToValue
*/ */
public func MaterialAnimationFillModeToValue(mode: MaterialAnimationFillMode) -> MaterialAnimationFillModeType { public func AnimationFillModeToValue(mode: AnimationFillMode) -> AnimationFillModeType {
switch mode { switch mode {
case .Forwards: case .forwards:
return kCAFillModeForwards return kCAFillModeForwards
case .Backwards: case .backwards:
return kCAFillModeBackwards return kCAFillModeBackwards
case .Both: case .both:
return kCAFillModeBoth return kCAFillModeBoth
case .Removed: case .removed:
return kCAFillModeRemoved return kCAFillModeRemoved
} }
} }
public typealias MaterialAnimationDelayCancelBlock = (cancel : Bool) -> Void public typealias AnimationDelayCancelBlock = (cancel : Bool) -> Void
public struct MaterialAnimation { public struct Animation {
/// Delay helper method. /// Delay helper method.
public static func delay(time: TimeInterval, completion: ()-> Void) -> MaterialAnimationDelayCancelBlock? { public static func delay(time: TimeInterval, completion: ()-> Void) -> AnimationDelayCancelBlock? {
func dispatch_later(completion: ()-> Void) { func dispatch_later(completion: ()-> Void) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(time * Double(NSEC_PER_SEC))), dispatch_get_main_queue(), completion) DispatchQueue.main.after(when: DispatchTime.now() + time, execute: completion)
} }
var cancelable: MaterialAnimationDelayCancelBlock? var cancelable: AnimationDelayCancelBlock?
let delayed: MaterialAnimationDelayCancelBlock = { (cancel: Bool) in let delayed: AnimationDelayCancelBlock = { (cancel: Bool) in
if !cancel { if !cancel {
dispatch_async(dispatch_get_main_queue(), completion) DispatchQueue.main.asynchronously(execute: completion)
} }
cancelable = nil cancelable = nil
} }
...@@ -92,7 +86,7 @@ public struct MaterialAnimation { ...@@ -92,7 +86,7 @@ public struct MaterialAnimation {
/** /**
:name: delayCancel :name: delayCancel
*/ */
public static func delayCancel(completion: MaterialAnimationDelayCancelBlock?) { public static func delayCancel(completion: AnimationDelayCancelBlock?) {
completion?(cancel: true) completion?(cancel: true)
} }
...@@ -101,7 +95,7 @@ public struct MaterialAnimation { ...@@ -101,7 +95,7 @@ public struct MaterialAnimation {
:name: animationDisabled :name: animationDisabled
*/ */
public static func animationDisabled(animations: (() -> Void)) { public static func animationDisabled(animations: (() -> Void)) {
animateWithDuration(0, animations: animations) animateWithDuration(duration: 0, animations: animations)
} }
/** /**
...@@ -119,10 +113,10 @@ public struct MaterialAnimation { ...@@ -119,10 +113,10 @@ public struct MaterialAnimation {
/** /**
:name: animationGroup :name: animationGroup
*/ */
public static func animationGroup(animations: Array<CAAnimation>, duration: CFTimeInterval = 0.5) -> CAAnimationGroup { public static func animationGroup(animations: [CAAnimation], duration: CFTimeInterval = 0.5) -> CAAnimationGroup {
let group: CAAnimationGroup = CAAnimationGroup() let group: CAAnimationGroup = CAAnimationGroup()
group.fillMode = MaterialAnimationFillModeToValue(.Forwards) group.fillMode = AnimationFillModeToValue(mode: .forwards)
group.removedOnCompletion = false group.isRemovedOnCompletion = false
group.animations = animations group.animations = animations
group.duration = duration group.duration = duration
group.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut) group.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
...@@ -133,8 +127,8 @@ public struct MaterialAnimation { ...@@ -133,8 +127,8 @@ public struct MaterialAnimation {
:name: animateWithDelay :name: animateWithDelay
*/ */
public static func animateWithDelay(delay d: CFTimeInterval, duration: CFTimeInterval, animations: (() -> Void), completion: (() -> Void)? = nil) { public static func animateWithDelay(delay d: CFTimeInterval, duration: CFTimeInterval, animations: (() -> Void), completion: (() -> Void)? = nil) {
delay(d) { delay(time: d) {
animateWithDuration(duration, animations: animations, completion: completion) animateWithDuration(duration: duration, animations: animations, completion: completion)
} }
} }
} }
...@@ -217,12 +217,12 @@ public class Button: UIButton { ...@@ -217,12 +217,12 @@ public class Button: UIButton {
*/ */
public func pulse(point: CGPoint? = nil) { public func pulse(point: CGPoint? = nil) {
let p: CGPoint = nil == point ? CGPoint(x: CGFloat(width / 2), y: CGFloat(height / 2)) : point! let p: CGPoint = nil == point ? CGPoint(x: CGFloat(width / 2), y: CGFloat(height / 2)) : point!
MaterialAnimation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: p, width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation) Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: p, width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
MaterialAnimation.delay(time: 0.35) { [weak self] in Animation.delay(time: 0.35) { [weak self] in
guard let s = self else { guard let s = self else {
return return
} }
MaterialAnimation.pulseContractAnimation(layer: s.layer, visualLayer: s.visualLayer, pulseColor: s.pulseColor, pulseLayers: &s.pulseLayers, pulseAnimation: s.pulseAnimation) Animation.pulseContractAnimation(layer: s.layer, visualLayer: s.visualLayer, pulseColor: s.pulseColor, pulseLayers: &s.pulseLayers, pulseAnimation: s.pulseAnimation)
} }
} }
...@@ -234,7 +234,7 @@ public class Button: UIButton { ...@@ -234,7 +234,7 @@ public class Button: UIButton {
*/ */
public override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { public override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event) super.touchesBegan(touches, with: event)
MaterialAnimation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: layer.convert(touches.first!.location(in: self), from: layer), width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation) Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: layer.convert(touches.first!.location(in: self), from: layer), width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
} }
/** /**
...@@ -245,7 +245,7 @@ public class Button: UIButton { ...@@ -245,7 +245,7 @@ public class Button: UIButton {
*/ */
public override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) { public override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesEnded(touches, with: event) super.touchesEnded(touches, with: event)
MaterialAnimation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation) Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
} }
/** /**
...@@ -256,7 +256,7 @@ public class Button: UIButton { ...@@ -256,7 +256,7 @@ public class Button: UIButton {
*/ */
public override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) { public override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesCancelled(touches, with: event) super.touchesCancelled(touches, with: event)
MaterialAnimation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation) Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
} }
/** /**
...@@ -303,7 +303,7 @@ public class Button: UIButton { ...@@ -303,7 +303,7 @@ public class Button: UIButton {
} else if nil == shadowPath { } else if nil == shadowPath {
shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath
} else { } else {
animate(animation: MaterialAnimation.shadowPath(path: UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath, duration: 0)) animate(animation: Animation.shadowPath(path: UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath, duration: 0))
} }
} }
} }
......
...@@ -210,7 +210,7 @@ public class Capture : View, UIGestureRecognizerDelegate { ...@@ -210,7 +210,7 @@ public class Capture : View, UIGestureRecognizerDelegate {
} }
/// Content insert value. /// Content insert value.
public var contentInset: Inset = EdgeInsetsPresetToValue(preset: .square4) { public var contentInset: EdgeInsets = EdgeInsetsPresetToValue(preset: .square4) {
didSet { didSet {
reloadView() reloadView()
} }
...@@ -544,17 +544,26 @@ public class Capture : View, UIGestureRecognizerDelegate { ...@@ -544,17 +544,26 @@ public class Capture : View, UIGestureRecognizerDelegate {
} }
/// Animates the tap and layer. /// Animates the tap and layer.
private func animateTapLayer(layer v: Layer, point: CGPoint) { private func animateTapLayer(layer: Layer, point: CGPoint) {
MaterialAnimation.animationDisabled { Animation.animationDisabled { [weak layer] in
guard let v = layer else {
return
}
v.transform = CATransform3DIdentity v.transform = CATransform3DIdentity
v.position = point v.position = point
v.isHidden = false v.isHidden = false
} }
MaterialAnimation.animateWithDuration(duration: 0.25, animations: { Animation.animateWithDuration(duration: 0.25, animations: { [weak layer] in
guard let v = layer else {
return
}
v.transform = CATransform3DMakeScale(0.5, 0.5, 1) v.transform = CATransform3DMakeScale(0.5, 0.5, 1)
}) { }) {
MaterialAnimation.delay(0.4) { Animation.delay(time: 0.4) { [weak layer] in
MaterialAnimation.animationDisabled { Animation.animationDisabled { [weak layer] in
guard let v = layer else {
return
}
v.isHidden = true v.isHidden = true
} }
} }
......
...@@ -393,7 +393,7 @@ public class Card: PulseView { ...@@ -393,7 +393,7 @@ public class Card: PulseView {
super.prepareView() super.prepareView()
depthPreset = .depth1 depthPreset = .depth1
dividerColor = Color.grey.lighten3 dividerColor = Color.grey.lighten3
cornerRadiusPreset = .Radius1 cornerRadiusPreset = .cornerRadius1
} }
/** /**
......
...@@ -32,28 +32,28 @@ import UIKit ...@@ -32,28 +32,28 @@ import UIKit
public struct Color { public struct Color {
// clear // clear
public static let clear: UIColor = UIColor.clearColor() public static let clear: UIColor = UIColor.clear()
// white // white
public static let white: UIColor = UIColor.whiteColor() public static let white: UIColor = UIColor.white()
// black // black
public static let black: UIColor = UIColor.blackColor() public static let black: UIColor = UIColor.black()
// dark text // dark text
public struct darkText { public struct darkText {
public static let primary: UIColor = Color.black.colorWithAlphaComponent(0.87) public static let primary: UIColor = Color.black.withAlphaComponent(0.87)
public static let secondary: UIColor = Color.black.colorWithAlphaComponent(0.54) public static let secondary: UIColor = Color.black.withAlphaComponent(0.54)
public static let others: UIColor = Color.black.colorWithAlphaComponent(0.38) public static let others: UIColor = Color.black.withAlphaComponent(0.38)
public static let dividers: UIColor = Color.black.colorWithAlphaComponent(0.12) public static let dividers: UIColor = Color.black.withAlphaComponent(0.12)
} }
// light text // light text
public struct lightText { public struct lightText {
public static let primary: UIColor = Color.white public static let primary: UIColor = Color.white
public static let secondary: UIColor = Color.white.colorWithAlphaComponent(0.7) public static let secondary: UIColor = Color.white.withAlphaComponent(0.7)
public static let others: UIColor = Color.white.colorWithAlphaComponent(0.5) public static let others: UIColor = Color.white.withAlphaComponent(0.5)
public static let dividers: UIColor = Color.white.colorWithAlphaComponent(0.12) public static let dividers: UIColor = Color.white.withAlphaComponent(0.12)
} }
// red // red
......
...@@ -41,8 +41,8 @@ public class FabButton: Button { ...@@ -41,8 +41,8 @@ public class FabButton: Button {
public override func prepareView() { public override func prepareView() {
super.prepareView() super.prepareView()
depthPreset = .depth1 depthPreset = .depth1
shape = .circle shapePreset = .circle
pulseAnimation = .CenterWithBacking pulseAnimation = .centerWithBacking
pulseColor = Color.white pulseColor = Color.white
tintColor = Color.white tintColor = Color.white
backgroundColor = Color.red.base backgroundColor = Color.red.base
......
...@@ -40,7 +40,7 @@ public class FlatButton: Button { ...@@ -40,7 +40,7 @@ public class FlatButton: Button {
*/ */
public override func prepareView() { public override func prepareView() {
super.prepareView() super.prepareView()
cornerRadiusPreset = .Radius1 cornerRadiusPreset = .cornerRadius1
contentEdgeInsetsPreset = .wideRectangle3 contentEdgeInsetsPreset = .wideRectangle3
} }
} }
...@@ -40,7 +40,7 @@ public class IconButton: Button { ...@@ -40,7 +40,7 @@ public class IconButton: Button {
*/ */
public override func prepareView() { public override func prepareView() {
super.prepareView() super.prepareView()
cornerRadiusPreset = .Radius1 cornerRadiusPreset = .cornerRadius1
pulseAnimation = .center pulseAnimation = .center
} }
} }
...@@ -534,7 +534,7 @@ public class ImageCard: PulseView { ...@@ -534,7 +534,7 @@ public class ImageCard: PulseView {
super.prepareView() super.prepareView()
depthPreset = .depth1 depthPreset = .depth1
dividerColor = Color.grey.lighten3 dividerColor = Color.grey.lighten3
cornerRadiusPreset = .Radius1 cornerRadiusPreset = .cornerRadius1
} }
/** /**
......
/*
* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of CosmicMind nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import UIKit
public enum AnimationRotationMode {
case none
case auto
case autoReverse
}
/**
:name: AnimationRotationModeToValue
*/
public func AnimationRotationModeToValue(mode: AnimationRotationMode) -> String? {
switch mode {
case .none:
return nil
case .auto:
return kCAAnimationRotateAuto
case .autoReverse:
return kCAAnimationRotateAutoReverse
}
}
public extension Animation {
/**
:name: path
*/
public static func path(bezierPath: UIBezierPath, mode: AnimationRotationMode = .auto, duration: CFTimeInterval? = nil) -> CAKeyframeAnimation {
let animation: CAKeyframeAnimation = CAKeyframeAnimation()
animation.keyPath = "position"
animation.path = bezierPath.cgPath
animation.rotationMode = AnimationRotationModeToValue(mode: mode)
if let v = duration {
animation.duration = v
}
return animation
}
}
...@@ -309,7 +309,7 @@ public class Layer: CAShapeLayer { ...@@ -309,7 +309,7 @@ public class Layer: CAShapeLayer {
- Parameter animation: The currently running CAAnimation instance. - Parameter animation: The currently running CAAnimation instance.
*/ */
public override func animationDidStart(_ animation: CAAnimation) { public override func animationDidStart(_ animation: CAAnimation) {
(delegate as? MaterialAnimationDelegate)?.materialAnimationDidStart?(animation: animation) (delegate as? AnimationDelegate)?.materialAnimationDidStart?(animation: animation)
} }
/** /**
...@@ -330,7 +330,7 @@ public class Layer: CAShapeLayer { ...@@ -330,7 +330,7 @@ public class Layer: CAShapeLayer {
} }
} }
} }
(delegate as? MaterialAnimationDelegate)?.materialAnimationDidStop?(animation: animation, finished: flag) (delegate as? AnimationDelegate)?.materialAnimationDidStop?(animation: animation, finished: flag)
} else if let a: CAAnimationGroup = animation as? CAAnimationGroup { } else if let a: CAAnimationGroup = animation as? CAAnimationGroup {
for x in a.animations! { for x in a.animations! {
animationDidStop(x, finished: true) animationDidStop(x, finished: true)
...@@ -370,7 +370,7 @@ public class Layer: CAShapeLayer { ...@@ -370,7 +370,7 @@ public class Layer: CAShapeLayer {
} else if nil == shadowPath { } else if nil == shadowPath {
shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath
} else { } else {
animate(animation: MaterialAnimation.shadowPath(path: UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath, duration: 0)) animate(animation: Animation.shadowPath(path: UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath, duration: 0))
} }
} }
} }
......
...@@ -118,7 +118,7 @@ public class MaterialCollectionReusableView: UICollectionReusableView { ...@@ -118,7 +118,7 @@ public class MaterialCollectionReusableView: UICollectionReusableView {
/// A Preset for the contentsGravity property. /// A Preset for the contentsGravity property.
public var contentsGravityPreset: MaterialGravity { public var contentsGravityPreset: MaterialGravity {
didSet { didSet {
contentsGravity = MaterialGravityToValue(contentsGravityPreset) contentsGravity = MaterialGravityToValue(gravity: contentsGravityPreset)
} }
} }
...@@ -133,7 +133,7 @@ public class MaterialCollectionReusableView: UICollectionReusableView { ...@@ -133,7 +133,7 @@ public class MaterialCollectionReusableView: UICollectionReusableView {
} }
/// A preset wrapper around contentInset. /// A preset wrapper around contentInset.
public var contentEdgeInsetsPreset: Insets { public var contentEdgeInsetsPreset: EdgeInsetsPreset {
get { get {
return grid.contentEdgeInsetsPreset return grid.contentEdgeInsetsPreset
} }
...@@ -153,9 +153,9 @@ public class MaterialCollectionReusableView: UICollectionReusableView { ...@@ -153,9 +153,9 @@ public class MaterialCollectionReusableView: UICollectionReusableView {
} }
/// A preset wrapper around interimSpace. /// A preset wrapper around interimSpace.
public var interimSpacePreset: InterimSpace = .none { public var interimSpacePreset: InterimSpacePreset = .none {
didSet { didSet {
interimSpace = InterimSpacePresetToValue(interimSpacePreset) interimSpace = InterimSpacePresetToValue(preset: interimSpacePreset)
} }
} }
...@@ -208,7 +208,7 @@ public class MaterialCollectionReusableView: UICollectionReusableView { ...@@ -208,7 +208,7 @@ public class MaterialCollectionReusableView: UICollectionReusableView {
} }
set(value) { set(value) {
layer.frame.size.width = value layer.frame.size.width = value
if .none != shape { if .none != shapePreset {
layer.frame.size.height = value layer.frame.size.height = value
} }
} }
...@@ -226,7 +226,7 @@ public class MaterialCollectionReusableView: UICollectionReusableView { ...@@ -226,7 +226,7 @@ public class MaterialCollectionReusableView: UICollectionReusableView {
} }
set(value) { set(value) {
layer.frame.size.height = value layer.frame.size.height = value
if .none != shape { if .none != shapePreset {
layer.frame.size.width = value layer.frame.size.width = value
} }
} }
...@@ -310,12 +310,12 @@ public class MaterialCollectionReusableView: UICollectionReusableView { ...@@ -310,12 +310,12 @@ public class MaterialCollectionReusableView: UICollectionReusableView {
*/ */
public func pulse(point: CGPoint? = nil) { public func pulse(point: CGPoint? = nil) {
let p: CGPoint = nil == point ? CGPoint(x: CGFloat(width / 2), y: CGFloat(height / 2)) : point! let p: CGPoint = nil == point ? CGPoint(x: CGFloat(width / 2), y: CGFloat(height / 2)) : point!
MaterialAnimation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: p, width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation) Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: p, width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
MaterialAnimation.delay(time: 0.35) { [weak self] in Animation.delay(time: 0.35) { [weak self] in
guard let s = self else { guard let s = self else {
return return
} }
MaterialAnimation.pulseContractAnimation(layer: s.layer, visualLayer: s.visualLayer, pulseColor: s.pulseColor, pulseLayers: &s.pulseLayers, pulseAnimation: s.pulseAnimation) Animation.pulseContractAnimation(layer: s.layer, visualLayer: s.visualLayer, pulseColor: s.pulseColor, pulseLayers: &s.pulseLayers, pulseAnimation: s.pulseAnimation)
} }
} }
...@@ -327,7 +327,7 @@ public class MaterialCollectionReusableView: UICollectionReusableView { ...@@ -327,7 +327,7 @@ public class MaterialCollectionReusableView: UICollectionReusableView {
*/ */
public override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { public override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event) super.touchesBegan(touches, with: event)
MaterialAnimation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: layer.convert(touches.first!.location(in: self), from: layer), width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation) Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: layer.convert(touches.first!.location(in: self), from: layer), width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
} }
/** /**
...@@ -338,7 +338,7 @@ public class MaterialCollectionReusableView: UICollectionReusableView { ...@@ -338,7 +338,7 @@ public class MaterialCollectionReusableView: UICollectionReusableView {
*/ */
public override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) { public override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesEnded(touches, with: event) super.touchesEnded(touches, with: event)
MaterialAnimation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation) Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
} }
/** /**
...@@ -349,7 +349,7 @@ public class MaterialCollectionReusableView: UICollectionReusableView { ...@@ -349,7 +349,7 @@ public class MaterialCollectionReusableView: UICollectionReusableView {
*/ */
public override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) { public override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesCancelled(touches, with: event) super.touchesCancelled(touches, with: event)
MaterialAnimation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation) Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
} }
/** /**
...@@ -396,7 +396,7 @@ public class MaterialCollectionReusableView: UICollectionReusableView { ...@@ -396,7 +396,7 @@ public class MaterialCollectionReusableView: UICollectionReusableView {
} else if nil == shadowPath { } else if nil == shadowPath {
shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath
} else { } else {
animate(animation: MaterialAnimation.shadowPath(path: UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath, duration: 0)) animate(animation: Animation.shadowPath(path: UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath, duration: 0))
} }
} }
} }
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
import UIKit import UIKit
@IBDesignable @IBDesignable
public class MaterialCollectionView : UICollectionView { public class MaterialCollectionView: UICollectionView {
/// A property that accesses the layer.frame.origin.x property. /// A property that accesses the layer.frame.origin.x property.
@IBInspectable public var x: CGFloat { @IBInspectable public var x: CGFloat {
get { get {
...@@ -73,12 +73,12 @@ public class MaterialCollectionView : UICollectionView { ...@@ -73,12 +73,12 @@ public class MaterialCollectionView : UICollectionView {
} }
/// A preset wrapper around contentInset. /// A preset wrapper around contentInset.
public var contentEdgeInsetsPreset: Insets { public var contentEdgeInsetsPreset: EdgeInsets {
get { get {
return (collectionViewLayout as? MaterialCollectionViewLayout)!.contentEdgeInsetsPreset return (collectionViewLayout as? MaterialCollectionViewLayout)!.contentInset
} }
set(value) { set(value) {
(collectionViewLayout as? MaterialCollectionViewLayout)!.contentEdgeInsetsPreset = value (collectionViewLayout as? MaterialCollectionViewLayout)!.contentInset = value
} }
} }
...@@ -102,9 +102,9 @@ public class MaterialCollectionView : UICollectionView { ...@@ -102,9 +102,9 @@ public class MaterialCollectionView : UICollectionView {
} }
/// A preset wrapper around interimSpace. /// A preset wrapper around interimSpace.
public var interimSpacePreset: InterimSpace = .none { public var interimSpacePreset: InterimSpacePreset = .none {
didSet { didSet {
interimSpace = InterimSpacePresetToValue(interimSpacePreset) interimSpace = InterimSpacePresetToValue(preset: interimSpacePreset)
} }
} }
......
...@@ -118,7 +118,7 @@ public class MaterialCollectionViewCell: UICollectionViewCell { ...@@ -118,7 +118,7 @@ public class MaterialCollectionViewCell: UICollectionViewCell {
/// A Preset for the contentsGravity property. /// A Preset for the contentsGravity property.
public var contentsGravityPreset: MaterialGravity { public var contentsGravityPreset: MaterialGravity {
didSet { didSet {
contentsGravity = MaterialGravityToValue(contentsGravityPreset) contentsGravity = MaterialGravityToValue(gravity: contentsGravityPreset)
} }
} }
...@@ -153,9 +153,9 @@ public class MaterialCollectionViewCell: UICollectionViewCell { ...@@ -153,9 +153,9 @@ public class MaterialCollectionViewCell: UICollectionViewCell {
} }
/// A preset wrapper around interimSpace. /// A preset wrapper around interimSpace.
public var interimSpacePreset: InterimSpace = .none { public var interimSpacePreset: InterimSpacePreset = .none {
didSet { didSet {
interimSpace = InterimSpacePresetToValue(interimSpacePreset) interimSpace = InterimSpacePresetToValue(preset: interimSpacePreset)
} }
} }
...@@ -290,8 +290,8 @@ public class MaterialCollectionViewCell: UICollectionViewCell { ...@@ -290,8 +290,8 @@ public class MaterialCollectionViewCell: UICollectionViewCell {
self.init(frame: CGRect.zero) self.init(frame: CGRect.zero)
} }
public override func layoutSublayersOfLayer(layer: CALayer) { public override func layoutSublayers(of layer: CALayer) {
super.layoutSublayersOfLayer(layer) super.layoutSublayers(of: layer)
if self.layer == layer { if self.layer == layer {
layoutShape() layoutShape()
layoutVisualLayer() layoutVisualLayer()
...@@ -310,12 +310,12 @@ public class MaterialCollectionViewCell: UICollectionViewCell { ...@@ -310,12 +310,12 @@ public class MaterialCollectionViewCell: UICollectionViewCell {
*/ */
public func pulse(point: CGPoint? = nil) { public func pulse(point: CGPoint? = nil) {
let p: CGPoint = nil == point ? CGPoint(x: CGFloat(width / 2), y: CGFloat(height / 2)) : point! let p: CGPoint = nil == point ? CGPoint(x: CGFloat(width / 2), y: CGFloat(height / 2)) : point!
MaterialAnimation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: p, width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation) Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: p, width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
MaterialAnimation.delay(time: 0.35) { [weak self] in Animation.delay(time: 0.35) { [weak self] in
guard let s = self else { guard let s = self else {
return return
} }
MaterialAnimation.pulseContractAnimation(layer: s.layer, visualLayer: s.visualLayer, pulseColor: s.pulseColor, pulseLayers: &s.pulseLayers, pulseAnimation: s.pulseAnimation) Animation.pulseContractAnimation(layer: s.layer, visualLayer: s.visualLayer, pulseColor: s.pulseColor, pulseLayers: &s.pulseLayers, pulseAnimation: s.pulseAnimation)
} }
} }
...@@ -327,7 +327,7 @@ public class MaterialCollectionViewCell: UICollectionViewCell { ...@@ -327,7 +327,7 @@ public class MaterialCollectionViewCell: UICollectionViewCell {
*/ */
public override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { public override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event) super.touchesBegan(touches, with: event)
MaterialAnimation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: layer.convert(touches.first!.location(in: self), from: layer), width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation) Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: layer.convert(touches.first!.location(in: self), from: layer), width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
} }
/** /**
...@@ -338,7 +338,7 @@ public class MaterialCollectionViewCell: UICollectionViewCell { ...@@ -338,7 +338,7 @@ public class MaterialCollectionViewCell: UICollectionViewCell {
*/ */
public override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) { public override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesEnded(touches, with: event) super.touchesEnded(touches, with: event)
MaterialAnimation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation) Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
} }
/** /**
...@@ -349,7 +349,7 @@ public class MaterialCollectionViewCell: UICollectionViewCell { ...@@ -349,7 +349,7 @@ public class MaterialCollectionViewCell: UICollectionViewCell {
*/ */
public override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) { public override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesCancelled(touches, with: event) super.touchesCancelled(touches, with: event)
MaterialAnimation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation) Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
} }
/** /**
...@@ -390,12 +390,12 @@ public class MaterialCollectionViewCell: UICollectionViewCell { ...@@ -390,12 +390,12 @@ public class MaterialCollectionViewCell: UICollectionViewCell {
/// Sets the shadow path. /// Sets the shadow path.
internal func layoutShadowPath() { internal func layoutShadowPath() {
if shadowPathAutoSizeEnabled { if shadowPathAutoSizeEnabled {
if .none == depth { if .none == depthPreset {
shadowPath = nil shadowPath = nil
} else if nil == shadowPath { } else if nil == shadowPath {
shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).CGPath shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath
} else { } else {
animate(MaterialAnimation.shadowPath(UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).CGPath, duration: 0)) animate(animation: Animation.shadowPath(path: UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath, duration: 0))
} }
} }
} }
......
...@@ -30,10 +30,10 @@ ...@@ -30,10 +30,10 @@
import UIKit import UIKit
public protocol MaterialCollectionViewDataSource : UICollectionViewDataSource { public protocol MaterialCollectionViewDataSource: UICollectionViewDataSource {
/** /**
Retrieves the items for the collectionView. Retrieves the items for the collectionView.
- Returns: An Array of Arrays of MaterialDataSourceItem objects. - Returns: An Array of Arrays of MaterialDataSourceItem objects.
*/ */
func items() -> Array<MaterialDataSourceItem> func items() -> [MaterialDataSourceItem]
} }
\ No newline at end of file
...@@ -30,6 +30,6 @@ ...@@ -30,6 +30,6 @@
import UIKit import UIKit
public protocol MaterialCollectionViewDelegate : MaterialDelegate, UICollectionViewDelegate { public protocol MaterialCollectionViewDelegate: MaterialDelegate, UICollectionViewDelegate {
} }
\ No newline at end of file
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
import UIKit import UIKit
public class MaterialCollectionViewLayout : UICollectionViewLayout { public class MaterialCollectionViewLayout: UICollectionViewLayout {
/// Used to calculate the dimensions of the cells. /// Used to calculate the dimensions of the cells.
internal var offset: CGPoint = CGPoint.zero internal var offset: CGPoint = CGPoint.zero
......
...@@ -165,12 +165,12 @@ public class MaterialTableViewCell: UITableViewCell { ...@@ -165,12 +165,12 @@ public class MaterialTableViewCell: UITableViewCell {
*/ */
public func pulse(point: CGPoint? = nil) { public func pulse(point: CGPoint? = nil) {
let p: CGPoint = nil == point ? CGPoint(x: CGFloat(width / 2), y: CGFloat(height / 2)) : point! let p: CGPoint = nil == point ? CGPoint(x: CGFloat(width / 2), y: CGFloat(height / 2)) : point!
MaterialAnimation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: p, width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation) Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: p, width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
MaterialAnimation.delay(time: 0.35) { [weak self] in Animation.delay(time: 0.35) { [weak self] in
guard let s = self else { guard let s = self else {
return return
} }
MaterialAnimation.pulseContractAnimation(layer: s.layer, visualLayer: s.visualLayer, pulseColor: s.pulseColor, pulseLayers: &s.pulseLayers, pulseAnimation: s.pulseAnimation) Animation.pulseContractAnimation(layer: s.layer, visualLayer: s.visualLayer, pulseColor: s.pulseColor, pulseLayers: &s.pulseLayers, pulseAnimation: s.pulseAnimation)
} }
} }
...@@ -182,7 +182,7 @@ public class MaterialTableViewCell: UITableViewCell { ...@@ -182,7 +182,7 @@ public class MaterialTableViewCell: UITableViewCell {
*/ */
public override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { public override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event) super.touchesBegan(touches, with: event)
MaterialAnimation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: layer.convert(touches.first!.location(in: self), from: layer), width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation) Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: layer.convert(touches.first!.location(in: self), from: layer), width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
} }
/** /**
...@@ -193,7 +193,7 @@ public class MaterialTableViewCell: UITableViewCell { ...@@ -193,7 +193,7 @@ public class MaterialTableViewCell: UITableViewCell {
*/ */
public override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) { public override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesEnded(touches, with: event) super.touchesEnded(touches, with: event)
MaterialAnimation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation) Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
} }
/** /**
...@@ -204,7 +204,7 @@ public class MaterialTableViewCell: UITableViewCell { ...@@ -204,7 +204,7 @@ public class MaterialTableViewCell: UITableViewCell {
*/ */
public override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) { public override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesCancelled(touches, with: event) super.touchesCancelled(touches, with: event)
MaterialAnimation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation) Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
} }
/** /**
...@@ -243,9 +243,9 @@ public class MaterialTableViewCell: UITableViewCell { ...@@ -243,9 +243,9 @@ public class MaterialTableViewCell: UITableViewCell {
if .none == depth { if .none == depth {
shadowPath = nil shadowPath = nil
} else if nil == shadowPath { } else if nil == shadowPath {
shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).CGPath shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath
} else { } else {
animate(MaterialAnimation.shadowPath(UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).CGPath, duration: 0)) animate(Animation.shadowPath(UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath, duration: 0))
} }
} }
} }
......
...@@ -40,7 +40,7 @@ public enum PulseAnimation { ...@@ -40,7 +40,7 @@ public enum PulseAnimation {
case pointWithBacking case pointWithBacking
} }
internal extension MaterialAnimation { internal extension Animation {
/** /**
Triggers the expanding animation. Triggers the expanding animation.
- Parameter layer: Container CALayer. - Parameter layer: Container CALayer.
...@@ -66,7 +66,7 @@ internal extension MaterialAnimation { ...@@ -66,7 +66,7 @@ internal extension MaterialAnimation {
pulseLayers.insert(bLayer, at: 0) pulseLayers.insert(bLayer, at: 0)
visualLayer.addSublayer(bLayer) visualLayer.addSublayer(bLayer)
MaterialAnimation.animationDisabled(animations: { Animation.animationDisabled(animations: {
bLayer.frame = visualLayer.bounds bLayer.frame = visualLayer.bounds
pLayer.bounds = CGRect(x: 0, y: 0, width: n, height: n) pLayer.bounds = CGRect(x: 0, y: 0, width: n, height: n)
...@@ -88,19 +88,19 @@ internal extension MaterialAnimation { ...@@ -88,19 +88,19 @@ internal extension MaterialAnimation {
switch pulseAnimation { switch pulseAnimation {
case .centerWithBacking, .backing, .pointWithBacking: case .centerWithBacking, .backing, .pointWithBacking:
bLayer.add(MaterialAnimation.backgroundColor(color: pulseColor.withAlphaComponent(pulseOpacity / 2), duration: duration), forKey: nil) bLayer.add(Animation.backgroundColor(color: pulseColor.withAlphaComponent(pulseOpacity / 2), duration: duration), forKey: nil)
default:break default:break
} }
switch pulseAnimation { switch pulseAnimation {
case .center, .centerWithBacking, .centerRadialBeyondBounds, .point, .pointWithBacking: case .center, .centerWithBacking, .centerRadialBeyondBounds, .point, .pointWithBacking:
pLayer.add(MaterialAnimation.scale(scale: 1, duration: duration), forKey: nil) pLayer.add(Animation.scale(scale: 1, duration: duration), forKey: nil)
default:break default:break
} }
MaterialAnimation.delay(time: duration, completion: { Animation.delay(time: duration) {
bLayer.setValue(true, forKey: "animated") bLayer.setValue(true, forKey: "animated")
}) }
} }
/** /**
...@@ -114,31 +114,35 @@ internal extension MaterialAnimation { ...@@ -114,31 +114,35 @@ internal extension MaterialAnimation {
return return
} }
let animated: Bool? = bLayer.value(forKey: "animated") as? Bool guard let animated = bLayer.value(forKey: "animated") as? Bool else {
return
}
MaterialAnimation.delay(time: true == animated ? 0 : 0.15) { Animation.delay(time: animated ? 0 : 0.15) {
if let pLayer: CAShapeLayer = bLayer.sublayers?.first as? CAShapeLayer { guard let pLayer: CAShapeLayer = bLayer.sublayers?.first as? CAShapeLayer else {
let duration: CFTimeInterval = 0.325 return
}
switch pulseAnimation {
case .centerWithBacking, .backing, .pointWithBacking: let duration = 0.325
bLayer.add(MaterialAnimation.backgroundColor(color: pulseColor.withAlphaComponent(0), duration: 0.325), forKey: nil)
default:break switch pulseAnimation {
} case .centerWithBacking, .backing, .pointWithBacking:
bLayer.add(Animation.backgroundColor(color: pulseColor.withAlphaComponent(0), duration: duration), forKey: nil)
switch pulseAnimation { default:break
case .center, .centerWithBacking, .centerRadialBeyondBounds, .point, .pointWithBacking: }
pLayer.addAnimation(MaterialAnimation.animationGroup(animations: [
MaterialAnimation.scale(scale: .Center == pulseAnimation ? 1 : 1.325), switch pulseAnimation {
MaterialAnimation.backgroundColor(pulseColor.colorWithAlphaComponent(0)) case .center, .centerWithBacking, .centerRadialBeyondBounds, .point, .pointWithBacking:
], duration: duration), forKey: nil) pLayer.add(Animation.animationGroup(animations: [
default:break Animation.scale(scale: .center == pulseAnimation ? 1 : 1.325),
} Animation.backgroundColor(color: pulseColor.withAlphaComponent(0))
], duration: duration), forKey: nil)
MaterialAnimation.delay(time: duration, completion: { default:break
pLayer.removeFromSuperlayer() }
bLayer.removeFromSuperlayer()
}) Animation.delay(time: duration) {
pLayer.removeFromSuperlayer()
bLayer.removeFromSuperlayer()
} }
} }
} }
......
...@@ -54,12 +54,12 @@ public class PulseView: View { ...@@ -54,12 +54,12 @@ public class PulseView: View {
*/ */
public func pulse(point: CGPoint? = nil) { public func pulse(point: CGPoint? = nil) {
let p: CGPoint = nil == point ? CGPoint(x: CGFloat(width / 2), y: CGFloat(height / 2)) : point! let p: CGPoint = nil == point ? CGPoint(x: CGFloat(width / 2), y: CGFloat(height / 2)) : point!
MaterialAnimation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: p, width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation) Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: p, width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
MaterialAnimation.delay(time: 0.35) { [weak self] in Animation.delay(time: 0.35) { [weak self] in
guard let s = self else { guard let s = self else {
return return
} }
MaterialAnimation.pulseContractAnimation(layer: s.layer, visualLayer: s.visualLayer, pulseColor: s.pulseColor, pulseLayers: &s.pulseLayers, pulseAnimation: s.pulseAnimation) Animation.pulseContractAnimation(layer: s.layer, visualLayer: s.visualLayer, pulseColor: s.pulseColor, pulseLayers: &s.pulseLayers, pulseAnimation: s.pulseAnimation)
} }
} }
...@@ -71,7 +71,7 @@ public class PulseView: View { ...@@ -71,7 +71,7 @@ public class PulseView: View {
*/ */
public override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { public override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event) super.touchesBegan(touches, with: event)
MaterialAnimation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: layer.convert(touches.first!.location(in: self), from: layer), width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation) Animation.pulseExpandAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: layer.convert(touches.first!.location(in: self), from: layer), width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
} }
/** /**
...@@ -82,7 +82,7 @@ public class PulseView: View { ...@@ -82,7 +82,7 @@ public class PulseView: View {
*/ */
public override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) { public override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesEnded(touches, with: event) super.touchesEnded(touches, with: event)
MaterialAnimation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation) Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
} }
/** /**
...@@ -93,6 +93,6 @@ public class PulseView: View { ...@@ -93,6 +93,6 @@ public class PulseView: View {
*/ */
public override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) { public override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesCancelled(touches, with: event) super.touchesCancelled(touches, with: event)
MaterialAnimation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation) Animation.pulseContractAnimation(layer: layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
} }
} }
...@@ -41,7 +41,7 @@ public class RaisedButton: Button { ...@@ -41,7 +41,7 @@ public class RaisedButton: Button {
public override func prepareView() { public override func prepareView() {
super.prepareView() super.prepareView()
depthPreset = .depth1 depthPreset = .depth1
cornerRadiusPreset = .Radius1 cornerRadiusPreset = .cornerRadius1
contentEdgeInsetsPreset = .wideRectangle3 contentEdgeInsetsPreset = .wideRectangle3
backgroundColor = Color.white backgroundColor = Color.white
} }
......
...@@ -247,9 +247,9 @@ public class TextView: UITextView { ...@@ -247,9 +247,9 @@ public class TextView: UITextView {
if .none == depth { if .none == depth {
shadowPath = nil shadowPath = nil
} else if nil == shadowPath { } else if nil == shadowPath {
shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).CGPath shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath
} else { } else {
animate(MaterialAnimation.shadowPath(UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).CGPath, duration: 0)) animate(Animation.shadowPath(UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath, duration: 0))
} }
} }
} }
......
...@@ -30,17 +30,17 @@ ...@@ -30,17 +30,17 @@
import UIKit import UIKit
public typealias MaterialAnimationTransitionType = String public typealias AnimationTransitionType = String
public typealias MaterialAnimationTransitionSubTypeType = String public typealias AnimationTransitionSubTypeType = String
public enum MaterialAnimationTransition { public enum AnimationTransition {
case Fade case Fade
case MoveIn case MoveIn
case Push case Push
case Reveal case Reveal
} }
public enum MaterialAnimationTransitionSubType { public enum AnimationTransitionSubType {
case Right case Right
case Left case Left
case Top case Top
...@@ -48,9 +48,9 @@ public enum MaterialAnimationTransitionSubType { ...@@ -48,9 +48,9 @@ public enum MaterialAnimationTransitionSubType {
} }
/** /**
:name: MaterialAnimationTransitionToValue :name: AnimationTransitionToValue
*/ */
public func MaterialAnimationTransitionToValue(transition: MaterialAnimationTransition) -> MaterialAnimationTransitionType { public func AnimationTransitionToValue(transition: AnimationTransition) -> AnimationTransitionType {
switch transition { switch transition {
case .Fade: case .Fade:
return kCATransitionFade return kCATransitionFade
...@@ -64,9 +64,9 @@ public func MaterialAnimationTransitionToValue(transition: MaterialAnimationTran ...@@ -64,9 +64,9 @@ public func MaterialAnimationTransitionToValue(transition: MaterialAnimationTran
} }
/** /**
:name: MaterialAnimationTransitionSubTypeToValue :name: AnimationTransitionSubTypeToValue
*/ */
public func MaterialAnimationTransitionSubTypeToValue(direction: MaterialAnimationTransitionSubType) -> MaterialAnimationTransitionSubTypeType { public func AnimationTransitionSubTypeToValue(direction: AnimationTransitionSubType) -> AnimationTransitionSubTypeType {
switch direction { switch direction {
case .Right: case .Right:
return kCATransitionFromRight return kCATransitionFromRight
...@@ -79,19 +79,19 @@ public func MaterialAnimationTransitionSubTypeToValue(direction: MaterialAnimati ...@@ -79,19 +79,19 @@ public func MaterialAnimationTransitionSubTypeToValue(direction: MaterialAnimati
} }
} }
public extension MaterialAnimation { public extension Animation {
/** /**
:name: transition :name: transition
*/ */
public static func transition(type: MaterialAnimationTransition, direction: MaterialAnimationTransitionSubType? = nil, duration: CFTimeInterval? = nil) -> CATransition { public static func transition(type: AnimationTransition, direction: AnimationTransitionSubType? = nil, duration: CFTimeInterval? = nil) -> CATransition {
let animation: CATransition = CATransition() let animation: CATransition = CATransition()
animation.type = MaterialAnimationTransitionToValue(type) animation.type = AnimationTransitionToValue(transition: type)
if let d = direction { if let d = direction {
animation.subtype = MaterialAnimationTransitionSubTypeToValue(d) animation.subtype = AnimationTransitionSubTypeToValue(direction: d)
} }
if let v: CFTimeInterval = duration { if let v: CFTimeInterval = duration {
animation.duration = v animation.duration = v
} }
return animation return animation
} }
} }
\ No newline at end of file
...@@ -302,7 +302,7 @@ public class View: UIView { ...@@ -302,7 +302,7 @@ public class View: UIView {
} else if nil == shadowPath { } else if nil == shadowPath {
shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath
} else { } else {
animate(animation: MaterialAnimation.shadowPath(path: UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath, duration: 0)) animate(animation: Animation.shadowPath(path: UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath, duration: 0))
} }
} }
} }
......
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